Package com.sodius.oslc.core.model
Class ResourceFields
java.lang.Object
com.sodius.oslc.core.model.ResourceFields
Provides helpers to handle fields of Resource classes, to ease the implementation and ensure consistency of behavior.
When a field type is Set or List, this class provides methods to:
- Get the field value as an array or unmodifiable collection
- Add a new value in the collection
- Replace the field value with a new collection
- Since:
- 3.4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>Adds a value in the field list, if not yet in it, and returns the modified list.static <T> Set<T>Adds a value in the field set, if not yet in it, and returns the modified set.static <T> T[]get(Collection<T> fieldValue, Class<T> valueType) Returns the content of the field collection as an array of the given type.static <T> List<T>Returns an unmodifiable facade of the field list.static <T> Set<T>Returns an unmodifiable facade of the field set.static <T> List<T>set(List<T> fieldValue, Collection<T> values) Replaces the content of the field list with the values of the given collection.static <T> List<T>Replaces the content of the field list with the values of the given array.static <T> Set<T>set(Set<T> fieldValue, Collection<T> values) Replaces the content of the field set with the values of the given collection.static <T> Set<T>Replaces the content of the field set with the values of the given array.
-
Method Details
-
get
Returns the content of the field collection as an array of the given type.- Type Parameters:
T- the type of elements in the collection and of the array to return- Parameters:
fieldValue- the value of the field, which may benullvalueType- the type of elements in the collection and of the array to return- Returns:
- the collection as an array, or an empty array if the argument is
null
-
get
Returns an unmodifiable facade of the field list.- Type Parameters:
T- the type of elements in the list- Parameters:
fieldValue- the value of the field, which may benull- Returns:
- an unmodifiable facade of the field list, or an empty list if the argument is
null
-
get
Returns an unmodifiable facade of the field set.- Type Parameters:
T- the type of elements in the set- Parameters:
fieldValue- the value of the field, which may benull- Returns:
- an unmodifiable facade of the field set, or an empty set if the argument is
null
-
add
Adds a value in the field list, if not yet in it, and returns the modified list. Callers must reassign the field with the value returned by this method.- Type Parameters:
T- the type of elements in the list- Parameters:
fieldValue- the value of the field, which may benullvalue- the value to add- Returns:
- an updated list, or
nullif the argument isnull
-
add
Adds a value in the field set, if not yet in it, and returns the modified set. Callers must reassign the field with the value returned by this method.- Type Parameters:
T- the type of elements in the set- Parameters:
fieldValue- the value of the field, which may benullvalue- the value to add- Returns:
- an updated set, or
nullif the argument isnull
-
set
Replaces the content of the field list with the values of the given array. Callers must reassign the field with the value returned by this method.- Type Parameters:
T- the type of elements in the list- Parameters:
fieldValue- the value of the field, which may benullvalues- the array values to add in the list, which may benull- Returns:
- an updated list, or
nullif the argument isnull
-
set
Replaces the content of the field list with the values of the given collection. Callers must reassign the field with the value returned by this method.- Type Parameters:
T- the type of elements in the list- Parameters:
fieldValue- the value of the field, which may benullvalues- the collection values to add in the list, which may benull- Returns:
- an updated list, or
nullif the argument isnull
-
set
Replaces the content of the field set with the values of the given array. Callers must reassign the field with the value returned by this method.- Type Parameters:
T- the type of elements in the set- Parameters:
fieldValue- the value of the field, which may benullvalues- the array values to add in the set, which may benull- Returns:
- an updated set, or
nullif the argument isnull
-
set
Replaces the content of the field set with the values of the given collection. Callers must reassign the field with the value returned by this method.- Type Parameters:
T- the type of elements in the set- Parameters:
fieldValue- the value of the field, which may benullvalues- the collection values to add in the set, which may benull- Returns:
- an updated set, or
nullif the argument isnull
-