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 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 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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 be null
      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 be null
      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 be null
      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 be null
      value - the value to add
      Returns:
      an updated list, or null if the argument is null
    • 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 be null
      value - the value to add
      Returns:
      an updated set, or null if the argument is null
    • 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 be null
      values - the array values to add in the list, which may be null
      Returns:
      an updated list, or null if the argument is null
    • 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 be null
      values - the collection values to add in the list, which may be null
      Returns:
      an updated list, or null if the argument is null
    • 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 be null
      values - the array values to add in the set, which may be null
      Returns:
      an updated set, or null if the argument is null
    • 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 be null
      values - the collection values to add in the set, which may be null
      Returns:
      an updated set, or null if the argument is null