Package com.sodius.oslc.core.model
Class ResourceFields
- java.lang.Object
-
- com.sodius.oslc.core.model.ResourceFields
-
public class ResourceFields extends Object
Provides helpers to handle fields of Resource classes, to ease the implementation and ensure consistency of behavior.When a field type is
Set
orList
, 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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> List<T>
add(List<T> fieldValue, T value)
Adds a value in the field list, if not yet in it, and returns the modified list.static <T> Set<T>
add(Set<T> fieldValue, T value)
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>
get(List<T> fieldValue)
Returns an unmodifiable facade of the field list.static <T> Set<T>
get(Set<T> fieldValue)
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>
set(List<T> fieldValue, T[] values)
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>
set(Set<T> fieldValue, T[] values)
Replaces the content of the field set with the values of the given array.
-
-
-
Method Detail
-
get
public static <T> T[] get(Collection<T> fieldValue, Class<T> valueType)
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 benull
valueType
- 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
public static <T> List<T> get(List<T> fieldValue)
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
public static <T> Set<T> get(Set<T> fieldValue)
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
public static <T> List<T> add(List<T> fieldValue, T value)
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 benull
value
- the value to add- Returns:
- an updated list, or
null
if the argument isnull
-
add
public static <T> Set<T> add(Set<T> fieldValue, T value)
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 benull
value
- the value to add- Returns:
- an updated set, or
null
if the argument isnull
-
set
public static <T> List<T> set(List<T> fieldValue, T[] values)
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 benull
values
- the array values to add in the list, which may benull
- Returns:
- an updated list, or
null
if the argument isnull
-
set
public 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. 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 benull
values
- the collection values to add in the list, which may benull
- Returns:
- an updated list, or
null
if the argument isnull
-
set
public static <T> Set<T> set(Set<T> fieldValue, T[] values)
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 benull
values
- the array values to add in the set, which may benull
- Returns:
- an updated set, or
null
if the argument isnull
-
set
public 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. 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 benull
values
- the collection values to add in the set, which may benull
- Returns:
- an updated set, or
null
if the argument isnull
-
-