java.lang.Object
de.powerstat.validation.containers.GroupOf<T>
Type Parameters:
T - Use only entities
All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>

public class GroupOf<T> extends Object implements Set<T>
Group of a specific type.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final SortedSet<T>
    Group.
    private static final Pattern
    Group name regexp.
    private final String
    Group name.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GroupOf(String groupName)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(T e)
    Adds the specified element to this set if it is not already present.
    boolean
    addAll(Collection<? extends T> c)
    Returns true if this set contains all of the elements of the specified collection.
    void
    Removes all of the elements from this set (optional operation).
    boolean
    Returns true if this set contains the specified element.
    boolean
    Returns true if this set contains all of the elements of the specified collection.
    boolean
    Is equal with another object.
    int
    Calculate hash code.
    boolean
    Returns true if this set contains no elements.
    Returns an iterator over the elements in this set.
    Returns the name of this GroupOf.
    boolean
    Removes the specified element from this set if it is present.
    boolean
    Removes from this set all of its elements that are contained in the specified collection.
    boolean
    Retains only the elements in this set that are contained in the specified collection.
    int
    Returns the number of elements in this set (its cardinality).
    Returns an array containing all of the elements in this set.
    <T> T[]
    toArray(T[] a)
    Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
    Returns the string representation of this GroupOf.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.Set

    spliterator
  • Field Details

    • GROUPNAME_REGEXP

      private static final Pattern GROUPNAME_REGEXP
      Group name regexp.
    • name

      private final String name
      Group name.
    • group

      private final SortedSet<T> group
      Group.
  • Constructor Details

    • GroupOf

      public GroupOf(String groupName)
      Constructor.
      Parameters:
      groupName - Group name (maximum 40 characters)
  • Method Details

    • name

      public String name()
      Returns the name of this GroupOf.
      Returns:
      The name of this group.
    • hashCode

      public int hashCode()
      Calculate hash code.
      Specified by:
      hashCode in interface Collection<T>
      Specified by:
      hashCode in interface Set<T>
      Overrides:
      hashCode in class Object
      Returns:
      Hash
      See Also:
    • equals

      public boolean equals(Object obj)
      Is equal with another object.
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface Set<T>
      Overrides:
      equals in class Object
      Parameters:
      obj - Object
      Returns:
      true when equal, false otherwise
      Throws:
      NoSuchElementException - If there is no entry in this GroupOf
      See Also:
    • toString

      public String toString()
      Returns the string representation of this GroupOf. The exact details of this representation are unspecified and subject to change, but the following may be regarded as typical: "GroupOf<>[, ...]"
      Overrides:
      toString in class Object
      Returns:
      String representation of this GroupOf
      See Also:
    • size

      public int size()
      Returns the number of elements in this set (its cardinality).
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface Set<T>
      Returns:
      The number of elements in this set (its cardinality)
    • isEmpty

      public boolean isEmpty()
      Returns true if this set contains no elements.
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface Set<T>
      Returns:
      True if this set contains no elements
    • contains

      public boolean contains(Object o)
      Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)).
      Specified by:
      contains in interface Collection<T>
      Specified by:
      contains in interface Set<T>
      Parameters:
      o - Element whose presence in this set is to be tested
      Returns:
      true if this set contains the specified element
    • iterator

      public Iterator<T> iterator()
      Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>
      Returns:
      An iterator over the elements in this set
    • toArray

      public Object[] toArray()
      Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
      Returns:
      An array containing all the elements in this set
    • toArray

      public <T> T[] toArray(T[] a)
      Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
      Parameters:
      a - The array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
      An array containing all the elements in this set
    • add

      public boolean add(T e)
      Adds the specified element to this set if it is not already present.
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Set<T>
      Parameters:
      e - Element to be added to this set
      Returns:
      true if this set did not already contain the specified element
    • remove

      public boolean remove(Object o)
      Removes the specified element from this set if it is present.
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface Set<T>
      Parameters:
      o - object to be removed from this set, if present
      Returns:
      true if this set contained the specified element
    • containsAll

      public boolean containsAll(Collection<?> c)
      Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set.
      Specified by:
      containsAll in interface Collection<T>
      Specified by:
      containsAll in interface Set<T>
      Parameters:
      c - Collection to be checked for containment in this set
      Returns:
      true if this set contains all of the elements of the specified collection
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set.
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Set<T>
      Parameters:
      c - Collection to be checked for containment in this set
      Returns:
      true if this set contains all of the elements of the specified collection
    • retainAll

      public boolean retainAll(Collection<?> c)
      Retains only the elements in this set that are contained in the specified collection.
      Specified by:
      retainAll in interface Collection<T>
      Specified by:
      retainAll in interface Set<T>
      Parameters:
      c - Collection containing elements to be retained in this set
      Returns:
      true if this set changed as a result of the call
    • removeAll

      public boolean removeAll(Collection<?> c)
      Removes from this set all of its elements that are contained in the specified collection.
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface Set<T>
      Parameters:
      c - Collection containing elements to be removed from this set
      Returns:
      true if this set changed as a result of the call
    • clear

      public void clear()
      Removes all of the elements from this set (optional operation). The set will be empty after this call returns.
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface Set<T>