1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2020 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.
@@ -79,31 +79,44 @@ public Stream<PropertySource<?>> stream() {
79
79
80
80
@ Override
81
81
public boolean contains (String name ) {
82
- return this .propertySourceList .contains (PropertySource .named (name ));
82
+ for (PropertySource <?> propertySource : this .propertySourceList ) {
83
+ if (propertySource .getName ().equals (name )) {
84
+ return true ;
85
+ }
86
+ }
87
+ return false ;
83
88
}
84
89
85
90
@ Override
86
91
@ Nullable
87
92
public PropertySource <?> get (String name ) {
88
- int index = this .propertySourceList .indexOf (PropertySource .named (name ));
89
- return (index != -1 ? this .propertySourceList .get (index ) : null );
93
+ for (PropertySource <?> propertySource : this .propertySourceList ) {
94
+ if (propertySource .getName ().equals (name )) {
95
+ return propertySource ;
96
+ }
97
+ }
98
+ return null ;
90
99
}
91
100
92
101
93
102
/**
94
103
* Add the given property source object with highest precedence.
95
104
*/
96
105
public void addFirst (PropertySource <?> propertySource ) {
97
- removeIfPresent (propertySource );
98
- this .propertySourceList .add (0 , propertySource );
106
+ synchronized (this .propertySourceList ) {
107
+ removeIfPresent (propertySource );
108
+ this .propertySourceList .add (0 , propertySource );
109
+ }
99
110
}
100
111
101
112
/**
102
113
* Add the given property source object with lowest precedence.
103
114
*/
104
115
public void addLast (PropertySource <?> propertySource ) {
105
- removeIfPresent (propertySource );
106
- this .propertySourceList .add (propertySource );
116
+ synchronized (this .propertySourceList ) {
117
+ removeIfPresent (propertySource );
118
+ this .propertySourceList .add (propertySource );
119
+ }
107
120
}
108
121
109
122
/**
@@ -112,9 +125,11 @@ public void addLast(PropertySource<?> propertySource) {
112
125
*/
113
126
public void addBefore (String relativePropertySourceName , PropertySource <?> propertySource ) {
114
127
assertLegalRelativeAddition (relativePropertySourceName , propertySource );
115
- removeIfPresent (propertySource );
116
- int index = assertPresentAndGetIndex (relativePropertySourceName );
117
- addAtIndex (index , propertySource );
128
+ synchronized (this .propertySourceList ) {
129
+ removeIfPresent (propertySource );
130
+ int index = assertPresentAndGetIndex (relativePropertySourceName );
131
+ addAtIndex (index , propertySource );
132
+ }
118
133
}
119
134
120
135
/**
@@ -123,9 +138,11 @@ public void addBefore(String relativePropertySourceName, PropertySource<?> prope
123
138
*/
124
139
public void addAfter (String relativePropertySourceName , PropertySource <?> propertySource ) {
125
140
assertLegalRelativeAddition (relativePropertySourceName , propertySource );
126
- removeIfPresent (propertySource );
127
- int index = assertPresentAndGetIndex (relativePropertySourceName );
128
- addAtIndex (index + 1 , propertySource );
141
+ synchronized (this .propertySourceList ) {
142
+ removeIfPresent (propertySource );
143
+ int index = assertPresentAndGetIndex (relativePropertySourceName );
144
+ addAtIndex (index + 1 , propertySource );
145
+ }
129
146
}
130
147
131
148
/**
@@ -141,8 +158,10 @@ public int precedenceOf(PropertySource<?> propertySource) {
141
158
*/
142
159
@ Nullable
143
160
public PropertySource <?> remove (String name ) {
144
- int index = this .propertySourceList .indexOf (PropertySource .named (name ));
145
- return (index != -1 ? this .propertySourceList .remove (index ) : null );
161
+ synchronized (this .propertySourceList ) {
162
+ int index = this .propertySourceList .indexOf (PropertySource .named (name ));
163
+ return (index != -1 ? this .propertySourceList .remove (index ) : null );
164
+ }
146
165
}
147
166
148
167
/**
@@ -153,8 +172,10 @@ public PropertySource<?> remove(String name) {
153
172
* @see #contains
154
173
*/
155
174
public void replace (String name , PropertySource <?> propertySource ) {
156
- int index = assertPresentAndGetIndex (name );
157
- this .propertySourceList .set (index , propertySource );
175
+ synchronized (this .propertySourceList ) {
176
+ int index = assertPresentAndGetIndex (name );
177
+ this .propertySourceList .set (index , propertySource );
178
+ }
158
179
}
159
180
160
181
/**
@@ -169,6 +190,7 @@ public String toString() {
169
190
return this .propertySourceList .toString ();
170
191
}
171
192
193
+
172
194
/**
173
195
* Ensure that the given property source is not being added relative to itself.
174
196
*/
0 commit comments