Package org.moeaframework.core
Class PropertyScope
java.lang.Object
org.moeaframework.core.PropertyScope
- All Implemented Interfaces:
AutoCloseable
Creates a scope for a
TypedProperties, allowing the properties to be temporarily overridden
within the scope. These should typically be used within try-with-resources so the scope is automatically
closed when exiting the block.
try (PropertyScope scope = properties.createScope()) {
// temporarily override properties within scope
properties.setInt("populationSize", 500);
}
Scopes are not thread-safe or thread-local. This means two threads referencing the same
underlying TypedProperties object will both see modifications made within the scope. If this is
a concern, create a copy of the properties before use.-
Constructor Summary
ConstructorsConstructorDescriptionPropertyScope(TypedProperties properties) Creates a new scope for the properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.Convenience method for setting a property within the scope.<T extends Enum<?>>
PropertyScopeConvenience method for setting a property within the scope.Convenience method for removing a property within the scope.
-
Constructor Details
-
PropertyScope
Creates a new scope for the properties.- Parameters:
properties- the properties
-
-
Method Details
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Type Parameters:
T- the enumeration type- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
with
Convenience method for setting a property within the scope.- Parameters:
key- the property keyvalue- the property value- Returns:
- a reference to this scope for chaining multiple calls together
-
without
Convenience method for removing a property within the scope.- Parameters:
key- the property key- Returns:
- a reference to this scope for chaining multiple calls together
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-