|
RuntimeCollection.java
|
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\ //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ package ilog.language.design.backend;
|
import ilog.language.design.types.Type; import ilog.language.util.ToIntMap; import ilog.language.tools.Misc; import java.util.Iterator;
This is the mother of all runtime collection representations. There
are three abstract subclasses:
which only differ in their respective algebraic properties. Namely,
|
abstract public class RuntimeCollection implements RuntimeObject, IndexableContainer
{
| This indicates what kind of collection this is. By default it is taken to be a set. |
protected byte _kind = Type.SET;
| This flag is collection whenever this collection has "holes". A hole is a gap in the indexing sequence. |
protected boolean _hasHoles = false;
| This is the maximum index. When the collection has no holes, it is equal to the size of the collection. Otherwise, it is equal to the size of the collection at the time the first hole appeared + the number of insertions that happened after that. |
protected int _maxIndex = 0;
| This flag is set whenever at least one hole has appeared in the indices. |
protected boolean _isLocked = false;
| Returns the underlying index map representing the collection. |
abstract ToIntMap map ();
| Returns true iff there are holes in the indexing of this collection. |
protected final boolean _hasHoles ()
{
return _hasHoles;
}
| Sets the flag indicating that there are holes in the indexing to the specified boolean. |
protected final RuntimeCollection _setHasHoles (boolean flag)
{
_hasHoles = flag;
return this;
}
| Sets the max index to the specified int. |
protected final RuntimeCollection _setMaxIndex (int index)
{
_maxIndex = index;
return this;
}
| Locks this collection to prevent any further modification. |
public final void lock ()
{
_isLocked = true;
}
| Unlocks this collection to enable further modification. |
public final void unlock ()
{
_isLocked = false;
}
| Returns true iff this collection is locked. |
public final boolean isLocked ()
{
return _isLocked;
}
| Returns the number of elements in this collection. |
public final int size ()
{
return map().size();
}
| Returns true iff this collection is empty. |
public final boolean isEmpty ()
{
return map().isEmpty();
}
| Returns a hash code for this collection. |
public final int hashCode ()
{
return size();
}
Reassigns the indices of the elements of the collection to eliminate holes in such a
way as to preserve the order of the original indices.
|
protected final ToIntMap.Entry[] _resetIndices ()
{
ToIntMap.Entry[] entries = new ToIntMap.Entry[size()];
int index = 0;
for (Iterator i = map().iterator(); i.hasNext();)
entries[index++] = (ToIntMap.Entry)i.next();
//System.err.print("Sorting "+index+" elements...");
//long time = System.currentTimeMillis();
Misc.sort(entries);
//System.err.println(" in "+(System.currentTimeMillis()-time)+" ms");
for (; index-->0;)
entries[index].setValue(index);
_hasHoles = false;
_maxIndex = size();
return entries;
}
| Returns true when this collection is equal (as a collection) to the specified one, with a side-effect on the specified array of ints that will contain the index permutation when the collections are found to be equal. |
abstract public boolean equals (Object object, int[] permutation);
| Returns the first element of this collection as an int. If there is no such element, throws a NoSuchElementException. |
abstract public int firstInt () throws NoSuchElementException;
| Returns the first element of this collection as a double. If there is no such element, throws a NoSuchElementException. |
abstract public double firstReal () throws NoSuchElementException;
| Returns the first element of this collection as an object. If there is no such element, throws a NoSuchElementException. |
abstract public Object firstObject () throws NoSuchElementException;
| Returns the last element of this collection as an int. If there is no such element, throws a NoSuchElementException. |
abstract public int lastInt () throws NoSuchElementException;
| Returns the last element of this collection as a double. If there is no such element, throws a NoSuchElementException. |
abstract public double lastReal () throws NoSuchElementException;
| Returns the last element of this collection as an object. If there is no such element, throws a NoSuchElementException. |
abstract public Object lastObject () throws NoSuchElementException;
| Returns the position of given int if it is an element of this collection. If there is no such element, throws a NoSuchElementException. |
abstract public int ord (int element) throws NoSuchElementException;
| Returns the position of given double if it is an element of this collection. If there is no such element, throws a NoSuchElementException. |
abstract public int ord (double element) throws NoSuchElementException;
| Returns the position of given object if it is an element of this collection. If there is no such element, throws a NoSuchElementException. |
abstract public int ord (Object element) throws NoSuchElementException;
| Returns the element following the given one in this collection, as an int. If there is no such element, throws a NoSuchElementException. |
abstract public int next (int element) throws NoSuchElementException;
| Returns the element following the given one in this collection, as a double. If there is no such element, throws a NoSuchElementException. |
abstract public double next (double element) throws NoSuchElementException;
| Returns the element following the given one in this collection, as an object. If there is no such element, throws a NoSuchElementException. |
abstract public Object next (Object element) throws NoSuchElementException;
| Returns the element preceding the given one in this collection, as an int. If there is no such element, throws a NoSuchElementException. |
abstract public int prev (int element) throws NoSuchElementException;
| Returns the element preceding the given one in this collection, as a double. If there is no such element, throws a NoSuchElementException. |
abstract public double prev (double element) throws NoSuchElementException;
| Returns the element preceding the given one in this collection, as an object. If there is no such element, throws a NoSuchElementException. |
abstract public Object prev (Object element) throws NoSuchElementException;
| Returns the element following the given one in this collection, as an int, wrapping back to the beginning if necessary. If there is no such element, throws a NoSuchElementException. |
abstract public int nextc (int element) throws NoSuchElementException;
| Returns the element following the given one in this collection, as a double, wrapping back to the beginning if necessary. If there is no such element, throws a NoSuchElementException. |
abstract public double nextc (double element) throws NoSuchElementException;
| Returns the element following the given one in this collection, as an object, wrapping back to the beginning if necessary. If there is no such element, throws a NoSuchElementException. |
abstract public Object nextc (Object element) throws NoSuchElementException;
| Returns the element preceding the given one in this collection, as an int, wrapping to last element if necessary. If there is no such element, throws a NoSuchElementException. |
abstract public int prevc (int element) throws NoSuchElementException;
| Returns the element preceding the given one in this collection, as a double, wrapping to last element if necessary. If there is no such element, throws a NoSuchElementException. |
abstract public double prevc (double element) throws NoSuchElementException;
| Returns the element preceding the given one in this collection, as an object, wrapping to last element if necessary. If there is no such element, throws a NoSuchElementException. |
abstract public Object prevc (Object element) throws NoSuchElementException;
| Returns a copy of this collection. |
abstract public RuntimeCollection copy ();
| Returns true iff the specified collection is a subcollection of this collection. |
abstract public boolean contains (RuntimeCollection collection); abstract protected RuntimeCollection _add (int element); abstract protected RuntimeCollection _add (double element); abstract protected RuntimeCollection _add (Object element); abstract protected RuntimeCollection _remove (int element); abstract protected RuntimeCollection _remove (double element); abstract protected RuntimeCollection _remove (Object element);
| If this collection is not locked, adds the specified element to this collection if it does not already belong to this collection, and returns this collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection add (int element) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _add(element);
}
| If this collection is not locked, adds the specified element to this collection if it does not already belong to this collection, and returns this collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection add (double element) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _add(element);
}
| If this collection is not locked, adds the specified element to this collection if it does not already belong to this collection, and returns this collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection add (Object element) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _add(element);
}
| If this collection is not locked, removes the specified element from this collection and returns this collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection remove (int element) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _remove(element);
}
| If this collection is not locked, removes the specified element from this collection and returns this collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection remove (double element) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _remove(element);
}
| If this collection is not locked, removes the specified element from this collection and returns this collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection remove (Object element) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _remove(element);
}
abstract protected RuntimeCollection _union (RuntimeCollection collection);
abstract protected RuntimeCollection _intersection (RuntimeCollection collection);
abstract protected RuntimeCollection _minus (RuntimeCollection collection);
abstract protected RuntimeCollection _exclusion (RuntimeCollection collection);
| Returns this collection modified to contain the union of this and the specified collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection union (RuntimeCollection collection) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _union(collection);
}
| Returns this collection modified to contain the intersection of this and the specified collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection intersection (RuntimeCollection collection) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _intersection(collection);
}
| Returns this collection modified to contain the collection difference of this and the specified collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection minus (RuntimeCollection collection) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _minus(collection);
}
| Returns this collection modified to contain the symmetric difference of this and the specified collection. If this collection is locked, a LockViolationException is thrown. |
public final RuntimeCollection exclusion (RuntimeCollection collection) throws LockViolationException
{
if (_isLocked)
throw new LockViolationException();
return _exclusion(collection);
}
| Returns a new collection equal to the union of the two specified collections. |
public static final RuntimeCollection union (RuntimeCollection collection1, RuntimeCollection collection2)
{
return collection1.copy()._union(collection2);
}
| Returns a new collection equal to the intersection of the two specified collections. |
public static final RuntimeCollection intersection (RuntimeCollection collection1, RuntimeCollection collection2)
{
return collection1.copy()._intersection(collection2);
}
| Returns a new collection equal to the collection difference of the two specified collections. |
public static final RuntimeCollection minus (RuntimeCollection collection1, RuntimeCollection collection2)
{
return collection1.copy()._minus(collection2);
}
| Returns a new collection equal to the symmetric difference of the two specified collections. |
public static final RuntimeCollection exclusion (RuntimeCollection collection1, RuntimeCollection collection2)
{
return collection1.copy()._exclusion(collection2);
}
}
This file was generated on Tue Aug 03 11:24:02 PDT 2004 from file RuntimeCollection.java
by the ilog.language.tools.Hilite Java tool written by Hassan Aït-Kaci