public class ParameterDescriptor extends Object implements Serializable
Constructor and Description |
---|
ParameterDescriptor()
Creates a new instance that is not associated with any field.
|
ParameterDescriptor(FieldDescriptor<T> fieldDescriptor,
T fieldValue)
Creates a new instance that is associated with a single field.
|
ParameterDescriptor(Map<FieldDescriptor<?>,Object> fieldsMap)
Creates a new instance that is associated with the provided fields.
|
ParameterDescriptor(String name)
Creates a new instance that is associated with a single field representing the name of the
parameter.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
addField(FieldDescriptor<T> fieldDescriptor,
T fieldValue)
Adds a single field descriptor with this parameter descriptor and maps it to the specified
value (stored values are overwritten when a field descriptor is already associated with this
instance).
|
<T> T |
addFieldIfAbsent(FieldDescriptor<T> fieldDescriptor,
T fieldValue)
Adds a single field descriptor with this parameter descriptor and maps it to the specified
value (stored values are overwritten when a field descriptor is already associated with this
instance).
|
Object |
addUntypedField(FieldDescriptor<?> fieldDescriptor,
Object fieldValue)
Adds a single field descriptor with this parameter descriptor and maps it to the specified
value (stored values are overwritten when a field descriptor is already associated with this
instance).
|
void |
addUntypedFields(Map<FieldDescriptor<?>,Object> fieldsMap)
Adds multiple field descriptors with this parameter descriptor and maps them to the specified
values (existing values are overwritten when a field descriptor is already associated with
this instance).
|
static boolean |
areEqual(ParameterDescriptor parameterDescriptor1,
ParameterDescriptor parameterDescriptor2,
Collection<FieldDescriptor<?>> fieldDescriptors)
Checks if two parameter descriptors are equal with respect to multiple field descriptors.
|
static boolean |
areEqual(ParameterDescriptor parameterDescriptor1,
ParameterDescriptor parameterDescriptor2,
FieldDescriptor<?>... fieldDescriptors)
Checks if two parameter descriptors are equal with respect to multiple field descriptors.
|
static boolean |
areEqual(ParameterDescriptor parameterDescriptor1,
ParameterDescriptor parameterDescriptor2,
FieldDescriptor<?> fieldDescriptor)
Checks if two parameter descriptors are equal with respect to a given field descriptor.
|
void |
clear()
Removes all the fields currently associated with this parameter descriptor.
|
boolean |
contains(FieldDescriptor<?> fieldDescriptor)
Checks if a field descriptor is currently associated with this parameter descriptor.
|
boolean |
contains(FieldDescriptor<?> fieldDescriptor,
Object fieldValue)
Checks if a field descriptor is currently associated with this parameter descriptor and
mapped to a given value.
|
ParameterDescriptor |
copy()
Performs a shallow copy of the parameter descriptor (the references to the field descriptors
and the mapped values are preserved).
|
boolean |
equals(Object object)
Indicates whether some other object is "equal to" this one.
|
boolean |
equals(ParameterDescriptor parameterDescriptor,
Collection<FieldDescriptor<?>> fieldDescriptors)
Checks if this parameter descriptor is equal to another one with respect to multiple field
descriptors.
|
boolean |
equals(ParameterDescriptor parameterDescriptor,
FieldDescriptor<?>... fieldDescriptors)
Checks if this parameter descriptor is equal to another one with respect to multiple field
descriptors.
|
boolean |
equals(ParameterDescriptor parameterDescriptor,
FieldDescriptor<?> fieldDescriptor)
Checks if this parameter descriptor is equal to another one with respect to a given field
descriptor.
|
ParameterDescriptor |
extractSubset(Collection<FieldDescriptor<?>> fieldDescriptors)
Returns a new ParameterDescriptor instance which is only associated with the
selected subset of field descriptors (the ones which are not currently associated with this
parameter descriptor are simply ignored; the field values remain unchanged).
|
ParameterDescriptor |
extractSubset(FieldDescriptor<?>... fieldDescriptors)
Returns a new ParameterDescriptor instance which is only associated with the
selected subset of field descriptors (the ones which are not currently associated with this
parameter descriptor are simply ignored; the field values remain unchanged).
|
Set<FieldDescriptor<?>> |
getAssociatedFieldDescriptors()
Gets the field descriptors currently associated with this parameter descriptor.
|
Map<FieldDescriptor<?>,Object> |
getAssociatedFields()
Gets the field descriptors currently associated with this parameter descriptor and the values
mapped to them.
|
<T> T |
getFieldValue(FieldDescriptor<T> fieldDescriptor)
Gets the value currently mapped to a given field descriptor.
|
String |
getName()
Gets the name of this parameter descriptor, which is comprised of the associated field values
separated by an underscore (printed in reverse order by default).
|
String |
getName(boolean reverseOrder)
Gets the name of this parameter descriptor, which is comprised of the associated field values
separated by an underscore.
|
String |
getName(String separator)
Gets the name of this parameter descriptor, which is comprised of the associated field values
separated by the specified string (printed in reverse order by default).
|
String |
getName(String separator,
boolean reverseOrder)
Gets the name of this parameter descriptor, which is comprised of the associated field values
separated by the specified string.
|
int |
hashCode() |
ParameterDescriptor |
intersectionWith(ParameterDescriptor descriptor)
Extracts the field descriptors associated with both this parameter descriptor and the one
provided, and which are mapped to the same value.
|
boolean |
isEmpty()
Checks whether this parameter descriptor is currently associated with anything or not.
|
boolean |
isMutable()
Checks if this parameter descriptor is currently mutable or not.
|
ParameterDescriptor |
mergeWith(ParameterDescriptor descriptor)
Merges this parameter descriptor with another one.
|
<T> T |
removeField(FieldDescriptor<T> fieldDescriptor)
Removes a given field descriptor from this parameter descriptor.
|
<T> boolean |
removeField(FieldDescriptor<T> fieldDescriptor,
T fieldValue)
Removes a given field descriptor from this parameter descriptor if it is currently mapped to
the specified value.
|
boolean |
removeUntypedField(FieldDescriptor<?> fieldDescriptor,
Object fieldValue)
Removes a given field descriptor from this parameter descriptor if it is currently mapped to
the specified value.
|
void |
removeUntypedFields(Collection<FieldDescriptor<?>> fieldDescriptors)
Removes multiple field descriptors and the associated values from this parameter descriptor.
|
void |
removeUntypedFields(FieldDescriptor<?>... fieldDescriptors)
Removes multiple field descriptors and the associated values from this parameter descriptor.
|
<T> T |
replaceField(FieldDescriptor<T> fieldDescriptor,
T fieldValue)
Replaces the value mapped to a given field descriptor if it is currently associated with this
parameter descriptor.
|
<T> boolean |
replaceField(FieldDescriptor<T> fieldDescriptor,
T oldFieldValue,
T newFieldValue)
Replaces the value mapped to a given field descriptor if it is currently associated with this
parameter descriptor and mapped to the specified value.
|
Object |
replaceUntypedField(FieldDescriptor<?> fieldDescriptor,
Object fieldValue)
Replaces the value mapped to a given field descriptor if it is currently associated with this
parameter descriptor.
|
boolean |
replaceUntypedField(FieldDescriptor<?> fieldDescriptor,
Object oldFieldValue,
Object newFieldValue)
Replaces the value mapped to a given field descriptor if it is currently associated with this
parameter descriptor and mapped to the specified value.
|
ParameterDescriptor |
setMutability(boolean enabled)
Enables or disables the mutability of this parameter descriptor.
|
String |
toString()
Gets a string representation of this parameter descriptor which includes the name of this
class, the name of associated the field descriptors and their mapped values (printed in
reverse order by default).
|
String |
toString(boolean reverseOrder)
Gets a string representation of this parameter descriptor which includes the name of this
class, the name of associated the field descriptors and their mapped values.
|
String |
toString(String keySeparator,
String entrySeparator,
boolean printClassName,
boolean printFieldName,
boolean printFieldValue,
boolean reverseOrder)
Gets a string representation of this parameter descriptor.
|
public ParameterDescriptor()
public ParameterDescriptor(String name)
name
- the name of the parameterpublic ParameterDescriptor(FieldDescriptor<T> fieldDescriptor, T fieldValue)
T
- the type of the field valuefieldDescriptor
- the field descriptorfieldValue
- the value mapped to the provided field descriptorIllegalArgumentException
- if the provided field descriptor or field value is null
public ParameterDescriptor(Map<FieldDescriptor<?>,Object> fieldsMap)
Important: each of the provided values must be assignable to the the class specified by the corresponding field descriptor. An exception will be automatically thrown if that is not the case.
fieldsMap
- the map between the initial field descriptors and the values mapped to themClassCastException
- if one of the provided values cannot be cast to the class specified by its field
descriptorpublic Map<FieldDescriptor<?>,Object> getAssociatedFields()
public Set<FieldDescriptor<?>> getAssociatedFieldDescriptors()
public boolean isMutable()
The mutability of this parameter descriptor can be enabled or disabled at will through the
setMutability(boolean)
method. Methods updating a parameter descriptor should always
check its mutability beforehand.
true
if this parameter descriptor is currently mutable, false
otherwisepublic ParameterDescriptor setMutability(boolean enabled)
enabled
- whether or not to allow this parameter descriptor to be mutablepublic boolean contains(FieldDescriptor<?> fieldDescriptor)
fieldDescriptor
- the field descriptor to checktrue
if the provided field descriptor is associated with this parameter
descriptor, false
otherwisepublic boolean contains(FieldDescriptor<?> fieldDescriptor, Object fieldValue)
fieldDescriptor
- the field descriptor to checkfieldValue
- the value expected to be mapped to the provided field descriptortrue
if the provided field descriptor is associated with this parameter
descriptor and mapped to the specified value, false
otherwisepublic final <T> T addField(FieldDescriptor<T> fieldDescriptor, T fieldValue)
T
- the type of the field valuefieldDescriptor
- the field descriptor to addfieldValue
- the value to be mapped to the specified field descriptornull
if this field descriptor was not
already associated with this parameter descriptorIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the provided field descriptor or field value is null
public final <T> T addFieldIfAbsent(FieldDescriptor<T> fieldDescriptor, T fieldValue)
Note: This method only adds the field if the field descriptor isn't already initialized in the map.
T
- the type of the field valuefieldDescriptor
- the field descriptor to addfieldValue
- the value to be mapped to the specified field descriptornull
if this field descriptor was not
already associated with this parameter descriptorIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the provided field descriptor or field value is null
public final Object addUntypedField(FieldDescriptor<?> fieldDescriptor, Object fieldValue)
Important: the provided value must be assignable to the class specified by the field descriptor. An exception will be automatically thrown if that is not the case.
fieldDescriptor
- the field descriptor to addfieldValue
- the value to be associated with the specified field descriptornull
if this field descriptor was not
already associated with this parameter descriptorIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the provided field descriptor or field value is null
ClassCastException
- if the provided field value cannot be cast to the class specified by the field
descriptorpublic final void addUntypedFields(Map<FieldDescriptor<?>,Object> fieldsMap)
Important: each of the provided values must be assignable to the the class specified by the corresponding field descriptor. An exception will be automatically thrown if that is not the case.
fieldsMap
- the field descriptors to be added and the values mapped to themIllegalStateException
- if this parameter descriptor is currently immutableIllegalArgumentException
- if one of the field descriptors or field values is null
ClassCastException
- if a field value cannot be cast to the class specified by the associated field
descriptorpublic <T> T replaceField(FieldDescriptor<T> fieldDescriptor, T fieldValue)
T
- the type of the field valuefieldDescriptor
- the field descriptor whose mapped value is to be replacedfieldValue
- the new value to be mapped to the specified field descriptornull
if this field descriptor is not
associated with this parameter descriptorIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the new field value is null
public <T> boolean replaceField(FieldDescriptor<T> fieldDescriptor, T oldFieldValue, T newFieldValue)
T
- the type of the field valuesfieldDescriptor
- the field descriptor whose mapped value is to be replacedoldFieldValue
- the value expected to be mapped to the specified field descriptornewFieldValue
- the new value to be mapped to the specified field descriptortrue
if the value mapped to the specified field descriptor was replaced,
false
otherwiseIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the new field value is null
public Object replaceUntypedField(FieldDescriptor<?> fieldDescriptor, Object fieldValue)
Important: the provided value must be assignable to the class specified by the field descriptor. An exception will be automatically thrown if that is not the case.
fieldDescriptor
- the field descriptor whose mapped value is to be replacedfieldValue
- the new value to be mapped to the specified field descriptornull
if this field descriptor is not
associated with this parameter descriptorIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the new field value is null
ClassCastException
- if the new field value cannot be cast to the class specified by the field descriptorpublic boolean replaceUntypedField(FieldDescriptor<?> fieldDescriptor, Object oldFieldValue, Object newFieldValue)
Important: the provided values must be assignable to the class specified by the field descriptor. An exception will be automatically thrown if that is not the case.
fieldDescriptor
- the field descriptor whose mapped value is to be replacedoldFieldValue
- the value expected to be mapped to the specified field descriptornewFieldValue
- the new value to be mapped to the specified field descriptortrue
if the value mapped to the specified field descriptor was replaced,
false
otherwiseIllegalStateException
- if this parameter descriptor is currently immutableNullArgumentException
- if the new field value is null
ClassCastException
- if the new field value cannot be cast to the class specified by the field descriptorpublic <T> T removeField(FieldDescriptor<T> fieldDescriptor)
T
- the type of the associated with the field descriptorfieldDescriptor
- the field descriptor to be removednull
if this field descriptor was not associated with this parameter
descriptorIllegalStateException
- if this parameter descriptor is currently immutablepublic <T> boolean removeField(FieldDescriptor<T> fieldDescriptor, T fieldValue)
T
- the type of the field valuefieldDescriptor
- the field descriptor to be removedfieldValue
- the value expected to be mapped with the specified field descriptortrue
if the specified field descriptor and its mapped value were removed,
false
otherwiseIllegalStateException
- if this parameter descriptor is currently immutablepublic boolean removeUntypedField(FieldDescriptor<?> fieldDescriptor, Object fieldValue)
fieldDescriptor
- the field descriptor to be removedfieldValue
- the value expected to be mapped with the specified field descriptortrue
if the specified field descriptor and its mapped value were removed,
false
otherwiseIllegalStateException
- if this parameter descriptor is currently immutablepublic void removeUntypedFields(FieldDescriptor<?>... fieldDescriptors)
fieldDescriptors
- the field descriptors to be removedIllegalStateException
- if this parameter descriptor is currently immutablepublic void removeUntypedFields(Collection<FieldDescriptor<?>> fieldDescriptors)
fieldDescriptors
- the field descriptors to be removedIllegalStateException
- if this parameter descriptor is currently immutablepublic void clear()
public boolean isEmpty()
true
if this parameter descriptor is not associated with anything,
false
otherwisepublic <T> T getFieldValue(FieldDescriptor<T> fieldDescriptor)
T
- the type of the field valuefieldDescriptor
- the field descriptornull
if the field
descriptor is not associated with this parameter descriptorNullArgumentException
- if the provided field descriptor is null
public ParameterDescriptor extractSubset(FieldDescriptor<?>... fieldDescriptors)
fieldDescriptors
- the selected field descriptorspublic ParameterDescriptor extractSubset(Collection<FieldDescriptor<?>> fieldDescriptors)
fieldDescriptors
- the selected field descriptorspublic ParameterDescriptor mergeWith(ParameterDescriptor descriptor)
The field descriptors of both this instance and the one provided are kept. When a field descriptor is associated with both instances, the provided parameter descriptor takes precedence and replaces the currently mapped value.
descriptor
- the other parameter descriptorpublic ParameterDescriptor intersectionWith(ParameterDescriptor descriptor)
descriptor
- the other parameter descriptorpublic String getName()
public String getName(boolean reverseOrder)
reverseOrder
- whether or not the field values should be printed in reverse orderpublic String getName(String separator)
separator
- the string used as separator between two field valuespublic String getName(String separator, boolean reverseOrder)
separator
- the string used as separator between two field valuesreverseOrder
- whether or not the field values should be printed in reverse orderpublic String toString()
public String toString(boolean reverseOrder)
reverseOrder
- whether or not the field descriptors and their mapped values should be printed in
reverse orderpublic String toString(String keySeparator, String entrySeparator, boolean printClassName, boolean printFieldName, boolean printFieldValue, boolean reverseOrder)
keySeparator
- the string used as separator between a key and its mapped valueentrySeparator
- the string used as separator between two entriesprintClassName
- whether or not the name of this class should be printedprintFieldName
- whether or not the name associated with the field descriptors should be printedprintFieldValue
- whether or not the values mapped to the field descriptors should be printedreverseOrder
- whether or not the field descriptors and their mapped values should be printed in
reverse orderpublic ParameterDescriptor copy()
public boolean equals(Object object)
This method only compares the associated field descriptors and the values mapped to them when checking if two ParameterDescriptor instances are equal or not. The order in which the field descriptors are stored and their mutability are not taken into account.
public boolean equals(ParameterDescriptor parameterDescriptor, FieldDescriptor<?> fieldDescriptor)
This method considers that two ParameterDescriptor instances are equal if the specified field descriptor is mapped to the same value in both instances, or if it is not associated with either of the instances.
parameterDescriptor
- the parameter descriptor to compare this instance withfieldDescriptor
- the field descriptor to checktrue
if the specified field descriptor is mapped to the same value in both
parameter descriptors, false
otherwisepublic boolean equals(ParameterDescriptor parameterDescriptor, FieldDescriptor<?>... fieldDescriptors)
This method considers that two ParameterDescriptor instances are equal if the specified field descriptors are mapped to the same values in both instances, or if they are not associated with either of the instances.
parameterDescriptor
- the parameter descriptor to compare this instance withfieldDescriptors
- the field descriptors to checktrue
if the specified field descriptors are mapped to the same values in both
parameter descriptors, false
otherwisepublic boolean equals(ParameterDescriptor parameterDescriptor, Collection<FieldDescriptor<?>> fieldDescriptors)
This method considers that two ParameterDescriptor instances are equal if the specified field descriptors are mapped to the same values in both instances, or if they are not associated with either of the instances.
parameterDescriptor
- the parameter descriptor to compare this instance withfieldDescriptors
- the field descriptors to checktrue
if the specified field descriptors are mapped to the same values in both
parameter descriptors, false
otherwisepublic static boolean areEqual(ParameterDescriptor parameterDescriptor1, ParameterDescriptor parameterDescriptor2, FieldDescriptor<?> fieldDescriptor)
This method considers that two ParameterDescriptor instances are equal if the specified field descriptor is mapped to the same value in both instances, or if it is not associated with either of the instances.
parameterDescriptor1
- the first parameter descriptorparameterDescriptor2
- the second parameter descriptorfieldDescriptor
- the field descriptor to checktrue
if the specified field descriptor is mapped to the same value in both
parameter descriptors, false
otherwisepublic static boolean areEqual(ParameterDescriptor parameterDescriptor1, ParameterDescriptor parameterDescriptor2, FieldDescriptor<?>... fieldDescriptors)
This method considers that two ParameterDescriptor instances are equal if the specified field descriptors are mapped to the same values in both instances, or if they are not associated with either of the instances.
parameterDescriptor1
- the first parameter descriptorparameterDescriptor2
- the second parameter descriptorfieldDescriptors
- the field descriptors to checktrue
if the specified field descriptors are mapped to the same values in both
parameter descriptors, false
otherwiseNullArgumentException
- if the provided field descriptor array is null
public static boolean areEqual(ParameterDescriptor parameterDescriptor1, ParameterDescriptor parameterDescriptor2, Collection<FieldDescriptor<?>> fieldDescriptors)
This method considers that two ParameterDescriptor instances are equal if the specified field descriptors are mapped to the same values in both instances, or if they are not associated with either of the instances.
parameterDescriptor1
- the first parameter descriptorparameterDescriptor2
- the second parameter descriptorfieldDescriptors
- the field descriptors to checktrue
if the specified field descriptors are mapped to the same values in both
parameter descriptors, false
otherwiseNullArgumentException
- if the provided field descriptor collection is null
Copyright © 2023 CNES. All rights reserved.