1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .apache .commons .logging .LogFactory ;
25
25
26
26
import org .springframework .lang .Nullable ;
27
- import org .springframework .util .StringUtils ;
28
27
29
28
/**
30
29
* Default implementation of the {@link PropertySources} interface.
@@ -95,8 +94,7 @@ public Iterator<PropertySource<?>> iterator() {
95
94
*/
96
95
public void addFirst (PropertySource <?> propertySource ) {
97
96
if (logger .isDebugEnabled ()) {
98
- logger .debug (String .format ("Adding [%s] PropertySource with highest search precedence" ,
99
- propertySource .getName ()));
97
+ logger .debug ("Adding PropertySource '" + propertySource .getName () + "' with highest search precedence" );
100
98
}
101
99
removeIfPresent (propertySource );
102
100
this .propertySourceList .add (0 , propertySource );
@@ -107,8 +105,7 @@ public void addFirst(PropertySource<?> propertySource) {
107
105
*/
108
106
public void addLast (PropertySource <?> propertySource ) {
109
107
if (logger .isDebugEnabled ()) {
110
- logger .debug (String .format ("Adding [%s] PropertySource with lowest search precedence" ,
111
- propertySource .getName ()));
108
+ logger .debug ("Adding PropertySource '" + propertySource .getName () + "' with lowest search precedence" );
112
109
}
113
110
removeIfPresent (propertySource );
114
111
this .propertySourceList .add (propertySource );
@@ -120,8 +117,8 @@ public void addLast(PropertySource<?> propertySource) {
120
117
*/
121
118
public void addBefore (String relativePropertySourceName , PropertySource <?> propertySource ) {
122
119
if (logger .isDebugEnabled ()) {
123
- logger .debug (String . format ( "Adding [%s] PropertySource with search precedence immediately higher than [%s]" ,
124
- propertySource . getName (), relativePropertySourceName ) );
120
+ logger .debug ("Adding PropertySource '" + propertySource . getName () +
121
+ "' with search precedence immediately higher than '" + relativePropertySourceName + "'" );
125
122
}
126
123
assertLegalRelativeAddition (relativePropertySourceName , propertySource );
127
124
removeIfPresent (propertySource );
@@ -135,8 +132,8 @@ public void addBefore(String relativePropertySourceName, PropertySource<?> prope
135
132
*/
136
133
public void addAfter (String relativePropertySourceName , PropertySource <?> propertySource ) {
137
134
if (logger .isDebugEnabled ()) {
138
- logger .debug (String . format ( "Adding [%s] PropertySource with search precedence immediately lower than [%s]" ,
139
- propertySource . getName (), relativePropertySourceName ) );
135
+ logger .debug ("Adding PropertySource '" + propertySource . getName () +
136
+ "' with search precedence immediately lower than '" + relativePropertySourceName + "'" );
140
137
}
141
138
assertLegalRelativeAddition (relativePropertySourceName , propertySource );
142
139
removeIfPresent (propertySource );
@@ -158,7 +155,7 @@ public int precedenceOf(PropertySource<?> propertySource) {
158
155
@ Nullable
159
156
public PropertySource <?> remove (String name ) {
160
157
if (logger .isDebugEnabled ()) {
161
- logger .debug (String . format ( "Removing [%s] PropertySource" , name ) );
158
+ logger .debug ("Removing PropertySource '" + name + "'" );
162
159
}
163
160
int index = this .propertySourceList .indexOf (PropertySource .named (name ));
164
161
return (index != -1 ? this .propertySourceList .remove (index ) : null );
@@ -173,8 +170,7 @@ public PropertySource<?> remove(String name) {
173
170
*/
174
171
public void replace (String name , PropertySource <?> propertySource ) {
175
172
if (logger .isDebugEnabled ()) {
176
- logger .debug (String .format ("Replacing [%s] PropertySource with [%s]" ,
177
- name , propertySource .getName ()));
173
+ logger .debug ("Replacing PropertySource '" + name + "' with '" + propertySource .getName () + "'" );
178
174
}
179
175
int index = assertPresentAndGetIndex (name );
180
176
this .propertySourceList .set (index , propertySource );
@@ -189,11 +185,7 @@ public int size() {
189
185
190
186
@ Override
191
187
public String toString () {
192
- String [] names = new String [this .size ()];
193
- for (int i = 0 ; i < size (); i ++) {
194
- names [i ] = this .propertySourceList .get (i ).getName ();
195
- }
196
- return String .format ("[%s]" , StringUtils .arrayToCommaDelimitedString (names ));
188
+ return this .propertySourceList .toString ();
197
189
}
198
190
199
191
/**
@@ -203,7 +195,7 @@ protected void assertLegalRelativeAddition(String relativePropertySourceName, Pr
203
195
String newPropertySourceName = propertySource .getName ();
204
196
if (relativePropertySourceName .equals (newPropertySourceName )) {
205
197
throw new IllegalArgumentException (
206
- String . format ( "PropertySource named [%s] cannot be added relative to itself" , newPropertySourceName ) );
198
+ "PropertySource named '" + newPropertySourceName + "' cannot be added relative to itself" );
207
199
}
208
200
}
209
201
@@ -224,14 +216,13 @@ private void addAtIndex(int index, PropertySource<?> propertySource) {
224
216
225
217
/**
226
218
* Assert that the named property source is present and return its index.
227
- * @param name the {@linkplain PropertySource#getName() name of the property source}
228
- * to find
219
+ * @param name {@linkplain PropertySource#getName() name of the property source} to find
229
220
* @throws IllegalArgumentException if the named property source is not present
230
221
*/
231
222
private int assertPresentAndGetIndex (String name ) {
232
223
int index = this .propertySourceList .indexOf (PropertySource .named (name ));
233
224
if (index == -1 ) {
234
- throw new IllegalArgumentException (String . format ( "PropertySource named [%s] does not exist" , name ) );
225
+ throw new IllegalArgumentException ("PropertySource named '" + name + "' does not exist" );
235
226
}
236
227
return index ;
237
228
}
0 commit comments