com.sparsity.sparksee.gdb
Class Objects

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

public class Objects
extends java.lang.Object
implements java.util.Set<java.lang.Long>, java.io.Closeable, java.lang.Iterable<java.lang.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
static int InvalidOID
          Invalid object identifier constant.
 
Method Summary
 boolean add(long e)
          Adds an element into the collection.
 boolean add(java.lang.Long e)
          Adds the specified element to this set if it is not already present (optional operation).
 boolean addAll(java.util.Collection<? extends java.lang.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 clear()
          Clears the collection removing all its elements.
 void close()
          Closes the Objects instance.
static Objects combineDifference(Objects objs1, Objects objs2)
          Creates a new Objects instance which is the difference of the two given.
static Objects combineIntersection(Objects objs1, Objects objs2)
          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 contains(java.lang.Object o)
          Returns true if this collections contains the specified element or Objects.
 boolean contains(Objects objs)
          Check if this objects contains the other one.
 boolean containsAll(java.util.Collection<?> clctn)
          Returns true if this set contains all of the elements of the specified collection.
 Objects copy()
          Creates a new Objects instance as a copy of the given one.
 long copy(Objects objs)
          Performs the copy operation.
 long count()
          Gets the number of elements into the collection.
 long difference(Objects objs)
          Performs the difference operation.
 boolean equals(java.lang.Object o)
          Returns true if the collection is equal to the object.
 boolean equals(Objects objs)
          Checks if the given Objects contains the same information.
 boolean exists(long e)
          Gets if the given element exists into the collection.
 long intersection(Objects objs)
          Performs the intersection operation.
 boolean isClosed()
          Gets if Objects instance has been closed or not.
 boolean isEmpty()
          Returns true if this Objects contains no elements.
 ObjectsIterator iterator()
          Gets an ObjectsIterator.
 ObjectsIterator iteratorFromElement(long e)
          Gets an ObjectsIterator starting from the given element.
 ObjectsIterator iteratorFromIndex(long index)
          Gets an ObjectsIterator skipping index elements.
 boolean remove(long e)
          Removes an element from the collection.
 boolean remove(java.lang.Object o)
          Removes the specified element from this set if it is present (optional operation).
 boolean removeAll(java.util.Collection<?> clctn)
          Removes from this set all of its elements that are contained in the specified collection (optional operation).
 boolean retainAll(java.util.Collection<?> clctn)
          Retains only the elements in this set that are contained in the specified collection (optional operation).
 Objects sample(Objects exclude, long samples)
          Creates a new Objects instance which is a sample of the calling one.
 int size()
          Gets the size of the collection.
 java.lang.Object[] toArray()
          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 java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
hashCode
 

Field Detail

InvalidOID

public static int InvalidOID
Invalid object identifier constant.

Method Detail

any

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

Returns:
Any element from the collection.
Throws:
java.util.NoSuchElementException - whether the collection is empty.
java.lang.RuntimeException - null

contains

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

Specified by:
contains in interface java.util.Collection<java.lang.Long>
Specified by:
contains in interface java.util.Set<java.lang.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.

remove

public boolean remove(java.lang.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 java.util.Collection<java.lang.Long>
Specified by:
remove in interface java.util.Set<java.lang.Long>
Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.

equals

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

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

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.

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.

containsAll

public boolean containsAll(java.util.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 java.util.Collection<java.lang.Long>
Specified by:
containsAll in interface java.util.Set<java.lang.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.

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.

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.

add

public boolean add(java.lang.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 java.util.Collection<java.lang.Long>
Specified by:
add in interface java.util.Set<java.lang.Long>
Parameters:
e - element to be added to this set.
Returns:
true if this set did not already contain the specified element.

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.

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.

close

public void close()
Closes the Objects instance.

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

Specified by:
close in interface java.io.Closeable

isEmpty

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

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

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.

clear

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

Specified by:
clear in interface java.util.Collection<java.lang.Long>
Specified by:
clear in interface java.util.Set<java.lang.Long>

count

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

Returns:
The number of elements into the collection.

retainAll

public boolean retainAll(java.util.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 java.util.Collection<java.lang.Long>
Specified by:
retainAll in interface java.util.Set<java.lang.Long>
Parameters:
clctn - collection that defines which elements this set will retain.
Returns:
true if this collection changed as a result of the call.

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.

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.

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.

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:
close()

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.

removeAll

public boolean removeAll(java.util.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 java.util.Collection<java.lang.Long>
Specified by:
removeAll in interface java.util.Set<java.lang.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

toArray

public java.lang.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 java.util.Collection<java.lang.Long>
Specified by:
toArray in interface java.util.Set<java.lang.Long>
Returns:
an array containing all of the elements in this set.

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 java.util.Collection<java.lang.Long>
Specified by:
toArray in interface java.util.Set<java.lang.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.

addAll

public boolean addAll(java.util.Collection<? extends java.lang.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 java.util.Collection<java.lang.Long>
Specified by:
addAll in interface java.util.Set<java.lang.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.

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.

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.

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.

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 java.util.Collection<java.lang.Long>
Specified by:
size in interface java.util.Set<java.lang.Long>
Returns:
It returns the same as count() or java.lang.Integer.MAX_VALUE.

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.

iterator

public ObjectsIterator iterator()
Gets an ObjectsIterator.

Specified by:
iterator in interface java.lang.Iterable<java.lang.Long>
Specified by:
iterator in interface java.util.Collection<java.lang.Long>
Specified by:
iterator in interface java.util.Set<java.lang.Long>
Returns:
ObjectsIterator instance.

copy

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

Returns:
The new Objects instance.