Class Objects

java.lang.Object
com.sparsity.sparksee.gdb.Objects
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<Long>, Collection<Long>, Set<Long>

public class Objects extends Object implements Set<Long>, Closeable, Iterable<Long>
Object identifier set class.

It stores a collection of Sparksee object identifiers as a set. As a set, there is no order and no duplicated elements.

This class should be used just to store large collections. Otherwise, it is strongly recommended to use common classes from the language API.

This class is not thread-safe.

ObjectsIterator must be used to traverse all the elements into the set.

When the Objects instance is closed, it closes all existing and non-closed ObjectsIterator instances too.

Author:
Sparsity Technologies http://www.sparsity-technologies.com
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    Invalid object identifier constant.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(long e)
    Adds an element into the collection.
    boolean
    add(Long e)
    Adds the specified element to this set if it is not already present (optional operation).
    boolean
    addAll(Collection<? extends Long> clctn)
    Adds all of the elements in the specified collection to this set if they're not already present (optional operation).
    long
    any()
    Gets an element from the collection.
    void
    Clears the collection removing all its elements.
    void
    Closes the Objects instance.
    static Objects
    Creates a new Objects instance which is the difference of the two given.
    static Objects
    Creates a new Objects instance which is the intersection of the two given.
    static Objects
    combineUnion(Objects objs1, Objects objs2)
    Creates a new Objects instance which is the union of the two given.
    boolean
    Check if this objects contains the other one.
    boolean
    Returns true if this collections contains the specified element or Objects.
    boolean
    Returns true if this set contains all of the elements of the specified collection.
    Creates a new Objects instance as a copy of the given one.
    long
    copy(Objects objs)
    Performs the copy operation.
    long
    Gets the number of elements into the collection.
    long
    Performs the difference operation.
    boolean
    Checks if the given Objects contains the same information.
    boolean
    Returns true if the collection is equal to the object.
    boolean
    exists(long e)
    Gets if the given element exists into the collection.
    long
    Performs the intersection operation.
    boolean
    Gets if Objects instance has been closed or not.
    boolean
    Returns true if this Objects contains no elements.
    Gets an ObjectsIterator.
    Gets an ObjectsIterator starting from the given element.
    iteratorFromIndex(long index)
    Gets an ObjectsIterator skipping index elements.
    boolean
    remove(long e)
    Removes an element from the collection.
    boolean
    Removes the specified element from this set if it is present (optional operation).
    boolean
    Removes from this set all of its elements that are contained in the specified collection (optional operation).
    boolean
    Retains only the elements in this set that are contained in the specified collection (optional operation).
    sample(Objects exclude, long samples)
    Creates a new Objects instance which is a sample of the calling one.
    int
    Gets the size of the collection.
    Returns an array containing all of the object identifiers in this set.
    <T> T[]
    toArray(T[] ts)
    Returns an array containing all of the object identifiers in this set; the runtime type of the returned array is that of the specified array.
    long
    union(Objects objs)
    Performs the union operation.

    Methods inherited from class Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface Iterable

    forEach

    Methods inherited from interface Set

    hashCode, spliterator
  • Field Details

    • InvalidOID

      public static int InvalidOID
      Invalid object identifier constant.

  • Method Details

    • copy

      public long copy(Objects objs)
      Performs the copy operation.

      This updates the Objects calling instance and copies the given Objects instance.

      Parameters:
      objs - [in] Objects instance.
      Returns:
      Number of elements into the collection once the operation has been executed.
    • equals

      public boolean equals(Object o)
      Returns true if the collection is equal to the object.

      Specified by:
      equals in interface Collection<Long>
      Specified by:
      equals in interface Set<Long>
      Overrides:
      equals in class Object
      Parameters:
      o - object to compare with the collection.
      Returns:
      true if the objects are equal or false otherwise.
    • any

      public long any() throws RuntimeException, NoSuchElementException
      Gets an element from the collection.

      Errorfor other issues.

      Returns:
      Any element from the collection.
      Throws:
      RuntimeException - null
      NoSuchElementException - whether the collection is empty.
    • contains

      public boolean contains(Objects objs)
      Check if this objects contains the other one.

      Parameters:
      objs - Objects collection.
      Returns:
      True if it contains the given object.
    • combineIntersection

      public static Objects combineIntersection(Objects objs1, Objects objs2)
      Creates a new Objects instance which is the intersection of the two given.

      Two given Objects belong to the same Session.

      Parameters:
      objs1 - [in] Objects instance.
      objs2 - [in] Objects instance.
      Returns:
      New Objects instance.
    • iterator

      public ObjectsIterator iterator()
      Gets an ObjectsIterator.

      Specified by:
      iterator in interface Collection<Long>
      Specified by:
      iterator in interface Iterable<Long>
      Specified by:
      iterator in interface Set<Long>
      Returns:
      ObjectsIterator instance.
    • union

      public long union(Objects objs)
      Performs the union operation.

      This adds all existing elements of the given Objects instance to the Objects calling instance

      Parameters:
      objs - [in] Objects instance.
      Returns:
      Number of elements into the collection once the operation has been executed.
    • intersection

      public long intersection(Objects objs)
      Performs the intersection operation.

      Updates the Objects calling instance setting those existing elements at both two collections and removing all others.

      Parameters:
      objs - [in] Objects instance.
      Returns:
      Number of elements into the collection once the operation has been executed.
    • remove

      public boolean remove(Object o)
      Removes the specified element from this set if it is present (optional operation).

      More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the set contains such an element. Returns true if the set contained the specified element (or equivalently, if the set changed as a result of the call). (The set will not contain the specified element once the call returns.)

      Specified by:
      remove in interface Collection<Long>
      Specified by:
      remove in interface Set<Long>
      Parameters:
      o - object to be removed from this set, if present.
      Returns:
      true if the set contained the specified element.
    • clear

      public void clear()
      Clears the collection removing all its elements.

      Specified by:
      clear in interface Collection<Long>
      Specified by:
      clear in interface Set<Long>
    • iteratorFromIndex

      public ObjectsIterator iteratorFromIndex(long index)
      Gets an ObjectsIterator skipping index elements.

      Objects collection has no order, so this method is implementation-dependent.

      Parameters:
      index - [in] The number of elements to skip from the beginning. It must be in the range [0..Size).
      Returns:
      ObjectsIterator instance.
    • removeAll

      public boolean removeAll(Collection<?> clctn)
      Removes from this set all of its elements that are contained in the specified collection (optional operation).

      If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.

      Specified by:
      removeAll in interface Collection<Long>
      Specified by:
      removeAll in interface Set<Long>
      Parameters:
      clctn - collection that defines which elements will be removed from this set.
      Returns:
      true if this set changed as a result of the call
    • copy

      public Objects copy()
      Creates a new Objects instance as a copy of the given one.

      Returns:
      The new Objects instance.
    • combineDifference

      public static Objects combineDifference(Objects objs1, Objects objs2)
      Creates a new Objects instance which is the difference of the two given.

      Two given Objects belong to the same Session.

      Parameters:
      objs1 - [in] Objects instance.
      objs2 - [in] Objects instance.
      Returns:
      New Objects instance.
    • toArray

      public <T> T[] toArray(T[] ts)
      Returns an array containing all of the object identifiers in this set; the runtime type of the returned array is that of the specified array.

      Obeys the general contract of the Collection.toArray(Object[]) method.

      Specified by:
      toArray in interface Collection<Long>
      Specified by:
      toArray in interface Set<Long>
      Parameters:
      ts - 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 the elements of this set.
    • sample

      public Objects sample(Objects exclude, long samples)
      Creates a new Objects instance which is a sample of the calling one.

      Parameters:
      exclude - [in] If not NULL, elements into this collection will be excluded from the resulting one.
      samples - [in] Number of elements into the resulting collection.
      Returns:
      Sample collection.
    • add

      public boolean add(Long e)
      Adds the specified element to this set if it is not already present (optional operation).

      More formally, adds the specified element, o, to this set if this set contains no element e such that (o==null ? e==null : o.equals(e)). If this set already contains the specified element, the call leaves this set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements. The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throwing an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the the elements that they may contain.

      Specified by:
      add in interface Collection<Long>
      Specified by:
      add in interface Set<Long>
      Parameters:
      e - element to be added to this set.
      Returns:
      true if this set did not already contain the specified element.
    • close

      public void close()
      Closes the Objects instance.

      It must be called to ensure the integrity of all data.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • remove

      public boolean remove(long e)
      Removes an element from the collection.

      Parameters:
      e - [in] Element to be removed.
      Returns:
      TRUE if the element is removed, FALSE if the element was not into the collection.
    • iteratorFromElement

      public ObjectsIterator iteratorFromElement(long e)
      Gets an ObjectsIterator starting from the given element.

      Objects collection has no order, so this method is implementation-dependent. e[in] The first element to traverse in the resulting

      Parameters:
      e - [in] The first element to traverse in the resulting ObjectsIterator instance.
      Returns:
      ObjectsIterator instance.
    • toArray

      public Object[] toArray()
      Returns an array containing all of the object identifiers in this set.

      Obeys the general contract of the Collection.toArray method.

      Specified by:
      toArray in interface Collection<Long>
      Specified by:
      toArray in interface Set<Long>
      Returns:
      an array containing all of the elements in this set.
    • contains

      public boolean contains(Object o)
      Returns true if this collections contains the specified element or Objects.

      Specified by:
      contains in interface Collection<Long>
      Specified by:
      contains in interface Set<Long>
      Parameters:
      o - element or Objects whose presence in this set is to be tested.
      Returns:
      true if this set contains the specified element or Objects.
    • count

      public long count()
      Gets the number of elements into the collection.

      Returns:
      The number of elements into the collection.
    • equals

      public boolean equals(Objects objs)
      Checks if the given Objects contains the same information.

      Parameters:
      objs - [in] Objects instance.
      Returns:
      True if the objects are equal or false otherwise.
    • containsAll

      public boolean containsAll(Collection<?> clctn)
      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<Long>
      Specified by:
      containsAll in interface Set<Long>
      Parameters:
      clctn - collection to be checked for containment in this set.
      Returns:
      true if this set contains all of the elements of the specified collection.
    • isEmpty

      public boolean isEmpty()
      Returns true if this Objects contains no elements.

      Specified by:
      isEmpty in interface Collection<Long>
      Specified by:
      isEmpty in interface Set<Long>
      Returns:
      true if the collection contains no elements.
    • combineUnion

      public static Objects combineUnion(Objects objs1, Objects objs2)
      Creates a new Objects instance which is the union of the two given.

      Two given Objects belong to the same Session.

      Parameters:
      objs1 - [in] Objects instance.
      objs2 - [in] Objects instance.
      Returns:
      New Objects instance.
    • isClosed

      public boolean isClosed()
      Gets if Objects instance has been closed or not.

      Returns:
      TRUE if the Objects instance has been closed, FALSE otherwise.
      See Also:
    • size

      public int size()
      Gets the size of the collection.

      It is the same as count() if the number of elements is <= java.lang.Integer.MAX_VALUE, otherwise java.lang.Integer.MAX_VALUE is returned.

      Specified by:
      size in interface Collection<Long>
      Specified by:
      size in interface Set<Long>
      Returns:
      It returns the same as count() or java.lang.Integer.MAX_VALUE.
    • exists

      public boolean exists(long e)
      Gets if the given element exists into the collection.

      Parameters:
      e - [in] Element.
      Returns:
      TRUE if the element exists into the collection, FALSE otherwise.
    • addAll

      public boolean addAll(Collection<? extends Long> clctn)
      Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

      If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress.

      Specified by:
      addAll in interface Collection<Long>
      Specified by:
      addAll in interface Set<Long>
      Parameters:
      clctn - collection whose elements are to be added to this set.
      Returns:
      true if this set changed as a result of the call.
    • difference

      public long difference(Objects objs)
      Performs the difference operation.

      This updates the Objects calling instance removing those existing elements at the given Objects instance.

      Parameters:
      objs - [in] Objects instance.
      Returns:
      Number of elements into the collection once the operation has been executed.
    • add

      public boolean add(long e)
      Adds an element into the collection.

      Parameters:
      e - [in] Element to be added.
      Returns:
      TRUE if the element is added, FALSE if the element was already into the collection.
    • retainAll

      public boolean retainAll(Collection<?> clctn)
      Retains only the elements in this set that are contained in the specified collection (optional operation).

      In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.

      Specified by:
      retainAll in interface Collection<Long>
      Specified by:
      retainAll in interface Set<Long>
      Parameters:
      clctn - collection that defines which elements this set will retain.
      Returns:
      true if this collection changed as a result of the call.