|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -79,14 +79,23 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean contains(String name) { |
|
|
|
public boolean contains(String name) { |
|
|
|
return this.propertySourceList.contains(PropertySource.named(name)); |
|
|
|
for (PropertySource<?> propertySource : this.propertySourceList) { |
|
|
|
|
|
|
|
if (propertySource.getName().equals(name)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public PropertySource<?> get(String name) { |
|
|
|
public PropertySource<?> get(String name) { |
|
|
|
int index = this.propertySourceList.indexOf(PropertySource.named(name)); |
|
|
|
for (PropertySource<?> propertySource : this.propertySourceList) { |
|
|
|
return (index != -1 ? this.propertySourceList.get(index) : null); |
|
|
|
if (propertySource.getName().equals(name)) { |
|
|
|
|
|
|
|
return propertySource; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -94,16 +103,20 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
* Add the given property source object with highest precedence. |
|
|
|
* Add the given property source object with highest precedence. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addFirst(PropertySource<?> propertySource) { |
|
|
|
public void addFirst(PropertySource<?> propertySource) { |
|
|
|
removeIfPresent(propertySource); |
|
|
|
synchronized (this.propertySourceList) { |
|
|
|
this.propertySourceList.add(0, propertySource); |
|
|
|
removeIfPresent(propertySource); |
|
|
|
|
|
|
|
this.propertySourceList.add(0, propertySource); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add the given property source object with lowest precedence. |
|
|
|
* Add the given property source object with lowest precedence. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addLast(PropertySource<?> propertySource) { |
|
|
|
public void addLast(PropertySource<?> propertySource) { |
|
|
|
removeIfPresent(propertySource); |
|
|
|
synchronized (this.propertySourceList) { |
|
|
|
this.propertySourceList.add(propertySource); |
|
|
|
removeIfPresent(propertySource); |
|
|
|
|
|
|
|
this.propertySourceList.add(propertySource); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -112,9 +125,11 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addBefore(String relativePropertySourceName, PropertySource<?> propertySource) { |
|
|
|
public void addBefore(String relativePropertySourceName, PropertySource<?> propertySource) { |
|
|
|
assertLegalRelativeAddition(relativePropertySourceName, propertySource); |
|
|
|
assertLegalRelativeAddition(relativePropertySourceName, propertySource); |
|
|
|
removeIfPresent(propertySource); |
|
|
|
synchronized (this.propertySourceList) { |
|
|
|
int index = assertPresentAndGetIndex(relativePropertySourceName); |
|
|
|
removeIfPresent(propertySource); |
|
|
|
addAtIndex(index, propertySource); |
|
|
|
int index = assertPresentAndGetIndex(relativePropertySourceName); |
|
|
|
|
|
|
|
addAtIndex(index, propertySource); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -123,9 +138,11 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addAfter(String relativePropertySourceName, PropertySource<?> propertySource) { |
|
|
|
public void addAfter(String relativePropertySourceName, PropertySource<?> propertySource) { |
|
|
|
assertLegalRelativeAddition(relativePropertySourceName, propertySource); |
|
|
|
assertLegalRelativeAddition(relativePropertySourceName, propertySource); |
|
|
|
removeIfPresent(propertySource); |
|
|
|
synchronized (this.propertySourceList) { |
|
|
|
int index = assertPresentAndGetIndex(relativePropertySourceName); |
|
|
|
removeIfPresent(propertySource); |
|
|
|
addAtIndex(index + 1, propertySource); |
|
|
|
int index = assertPresentAndGetIndex(relativePropertySourceName); |
|
|
|
|
|
|
|
addAtIndex(index + 1, propertySource); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -141,8 +158,10 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public PropertySource<?> remove(String name) { |
|
|
|
public PropertySource<?> remove(String name) { |
|
|
|
int index = this.propertySourceList.indexOf(PropertySource.named(name)); |
|
|
|
synchronized (this.propertySourceList) { |
|
|
|
return (index != -1 ? this.propertySourceList.remove(index) : null); |
|
|
|
int index = this.propertySourceList.indexOf(PropertySource.named(name)); |
|
|
|
|
|
|
|
return (index != -1 ? this.propertySourceList.remove(index) : null); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -153,8 +172,10 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
* @see #contains |
|
|
|
* @see #contains |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void replace(String name, PropertySource<?> propertySource) { |
|
|
|
public void replace(String name, PropertySource<?> propertySource) { |
|
|
|
int index = assertPresentAndGetIndex(name); |
|
|
|
synchronized (this.propertySourceList) { |
|
|
|
this.propertySourceList.set(index, propertySource); |
|
|
|
int index = assertPresentAndGetIndex(name); |
|
|
|
|
|
|
|
this.propertySourceList.set(index, propertySource); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -169,6 +190,7 @@ public class MutablePropertySources implements PropertySources { |
|
|
|
return this.propertySourceList.toString(); |
|
|
|
return this.propertySourceList.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Ensure that the given property source is not being added relative to itself. |
|
|
|
* Ensure that the given property source is not being added relative to itself. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|