From de1139e6a0cce71a34a0b1ceeebfb585f319a548 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 29 Sep 2018 17:36:15 +0200 Subject: [PATCH] Polishing --- .../AbstractApplicationEventMulticaster.java | 20 ++++---- .../core/env/StandardEnvironmentTests.java | 48 ++++++++++--------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index 97ef358414..ef92882dc8 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,10 @@ package org.springframework.context.event; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -210,7 +211,7 @@ public abstract class AbstractApplicationEventMulticaster private Collection> retrieveApplicationListeners( ResolvableType eventType, Class sourceType, ListenerRetriever retriever) { - LinkedList> allListeners = new LinkedList>(); + List> allListeners = new ArrayList>(); Set> listeners; Set listenerBeans; synchronized (this.retrievalMutex) { @@ -345,23 +346,20 @@ public abstract class AbstractApplicationEventMulticaster */ private class ListenerRetriever { - public final Set> applicationListeners; + public final Set> applicationListeners = new LinkedHashSet>(); - public final Set applicationListenerBeans; + public final Set applicationListenerBeans = new LinkedHashSet(); private final boolean preFiltered; public ListenerRetriever(boolean preFiltered) { - this.applicationListeners = new LinkedHashSet>(); - this.applicationListenerBeans = new LinkedHashSet(); this.preFiltered = preFiltered; } public Collection> getApplicationListeners() { - LinkedList> allListeners = new LinkedList>(); - for (ApplicationListener listener : this.applicationListeners) { - allListeners.add(listener); - } + List> allListeners = new ArrayList>( + this.applicationListeners.size() + this.applicationListenerBeans.size()); + allListeners.addAll(this.applicationListeners); if (!this.applicationListenerBeans.isEmpty()) { BeanFactory beanFactory = getBeanFactory(); for (String listenerBeanName : this.applicationListenerBeans) { diff --git a/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java b/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java index e094e342d2..ea125edce0 100644 --- a/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ import static org.springframework.core.env.AbstractEnvironment.*; * @author Chris Beams * @author Juergen Hoeller */ +@SuppressWarnings("deprecation") public class StandardEnvironmentTests { private static final String ALLOWED_PROPERTY_NAME = "theanswer"; @@ -51,7 +52,8 @@ public class StandardEnvironmentTests { private static final Object NON_STRING_PROPERTY_NAME = new Object(); private static final Object NON_STRING_PROPERTY_VALUE = new Object(); - private ConfigurableEnvironment environment = new StandardEnvironment(); + private final ConfigurableEnvironment environment = new StandardEnvironment(); + @Test public void merge() { @@ -129,42 +131,42 @@ public class StandardEnvironmentTests { assertThat(activeProfiles.length, is(2)); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setActiveProfiles_withNullProfileArray() { - environment.setActiveProfiles((String[])null); + environment.setActiveProfiles((String[]) null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setActiveProfiles_withNullProfile() { - environment.setActiveProfiles((String)null); + environment.setActiveProfiles((String) null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setActiveProfiles_withEmptyProfile() { environment.setActiveProfiles(""); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setActiveProfiles_withNotOperator() { environment.setActiveProfiles("p1", "!p2"); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setDefaultProfiles_withNullProfileArray() { - environment.setDefaultProfiles((String[])null); + environment.setDefaultProfiles((String[]) null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setDefaultProfiles_withNullProfile() { - environment.setDefaultProfiles((String)null); + environment.setDefaultProfiles((String) null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setDefaultProfiles_withEmptyProfile() { environment.setDefaultProfiles(""); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void setDefaultProfiles_withNotOperator() { environment.setDefaultProfiles("d1", "!d2"); } @@ -204,7 +206,7 @@ public class StandardEnvironmentTests { System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void defaultProfileWithCircularPlaceholder() { System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}"); try { @@ -263,27 +265,26 @@ public class StandardEnvironmentTests { assertThat(Arrays.asList(environment.getDefaultProfiles()), hasItems("pd2", "pd3")); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void acceptsProfiles_withEmptyArgumentList() { environment.acceptsProfiles(); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void acceptsProfiles_withNullArgumentList() { - environment.acceptsProfiles((String[])null); + environment.acceptsProfiles((String[]) null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void acceptsProfiles_withNullArgument() { - environment.acceptsProfiles((String)null); + environment.acceptsProfiles((String) null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void acceptsProfiles_withEmptyArgument() { environment.acceptsProfiles(""); } - @Test public void acceptsProfiles_activeProfileSetProgrammatically() { assertThat(environment.acceptsProfiles("p1", "p2"), is(false)); @@ -321,7 +322,7 @@ public class StandardEnvironmentTests { assertThat(environment.acceptsProfiles("!p1"), is(false)); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void acceptsProfiles_withInvalidNotOperator() { environment.acceptsProfiles("p1", "!"); } @@ -488,6 +489,7 @@ public class StandardEnvironmentTests { getModifiableSystemEnvironment().remove(DISALLOWED_PROPERTY_NAME); } + @SuppressWarnings("unchecked") public static Map getModifiableSystemEnvironment() { // for os x / linux -- GitLab