org.sat4j.core
Class ReadOnlyVec<T>

java.lang.Object
  extended by org.sat4j.core.ReadOnlyVec<T>
Type Parameters:
T - the type of the container.
All Implemented Interfaces:
Serializable, IVec<T>

public final class ReadOnlyVec<T>
extends Object
implements IVec<T>

Utility class to allow Read Only access to an IVec.

Author:
daniel
See Also:
Serialized Form

Constructor Summary
ReadOnlyVec(IVec<T> vec)
           
 
Method Summary
 void clear()
           
 boolean contains(T element)
           
<E> void
copyTo(E[] dest)
           
 void copyTo(IVec<T> copy)
          Ces operations devraient se faire en temps constant.
 T delete(int i)
          Delete the ith element of the vector.
 void ensure(int nsize)
           
 T get(int i)
           
 void growTo(int newsize, T pad)
           
 int indexOf(T element)
           
 void insertFirst(T elem)
          Insert an element at the very begining of the vector.
 void insertFirstWithShifting(T elem)
           
 boolean isEmpty()
          To know if a vector is empty
 Iterator<T> iterator()
           
 T last()
          return the latest element on the stack.
 void moveTo(int dest, int source)
          Move elements inside the vector.
 void moveTo(IVec<T> dest)
          Move the content of the vector into dest.
 void pop()
          Pop the last element on the stack.
 IVec<T> push(T elem)
           
 void remove(T elem)
          Enleve un element qui se trouve dans le vecteur!!!
 void set(int i, T o)
           
 void shrink(int nofelems)
          Remove nofelems from the Vector.
 void shrinkTo(int newsize)
          reduce the Vector to exactly newsize elements
 int size()
           
 void sort(Comparator<T> comparator)
           
 void sortUnique(Comparator<T> comparator)
           
 T[] toArray()
          Allow to access the internal representation of the vector as an array.
 String toString()
           
 void unsafePush(T elem)
          To push an element in the vector when you know you have space for it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReadOnlyVec

public ReadOnlyVec(IVec<T> vec)
Method Detail

clear

public void clear()
Specified by:
clear in interface IVec<T>

copyTo

public void copyTo(IVec<T> copy)
Description copied from interface: IVec
Ces operations devraient se faire en temps constant. Ce n'est pas le cas ici.

Specified by:
copyTo in interface IVec<T>

copyTo

public <E> void copyTo(E[] dest)
Specified by:
copyTo in interface IVec<T>

delete

public T delete(int i)
Description copied from interface: IVec
Delete the ith element of the vector. The latest element of the vector replaces the removed element at the ith indexer.

Specified by:
delete in interface IVec<T>
Parameters:
i - the indexer of the element in the vector
Returns:
the former ith element of the vector that is now removed from the vector

ensure

public void ensure(int nsize)
Specified by:
ensure in interface IVec<T>

get

public T get(int i)
Specified by:
get in interface IVec<T>

growTo

public void growTo(int newsize,
                   T pad)
Specified by:
growTo in interface IVec<T>

insertFirst

public void insertFirst(T elem)
Description copied from interface: IVec
Insert an element at the very begining of the vector. The former first element is appended to the end of the vector in order to have a constant time operation.

Specified by:
insertFirst in interface IVec<T>
Parameters:
elem - the element to put first in the vector.

insertFirstWithShifting

public void insertFirstWithShifting(T elem)
Specified by:
insertFirstWithShifting in interface IVec<T>

isEmpty

public boolean isEmpty()
Description copied from interface: IVec
To know if a vector is empty

Specified by:
isEmpty in interface IVec<T>
Returns:
true iff the vector is empty.

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface IVec<T>

last

public T last()
Description copied from interface: IVec
return the latest element on the stack. It is assumed that the stack is not empty!

Specified by:
last in interface IVec<T>
Returns:
the last (top) element on the stack

moveTo

public void moveTo(IVec<T> dest)
Description copied from interface: IVec
Move the content of the vector into dest. Note that the vector become empty. The content of the vector is appended to dest.

Specified by:
moveTo in interface IVec<T>
Parameters:
dest - the vector where top put the content of this vector

moveTo

public void moveTo(int dest,
                   int source)
Description copied from interface: IVec
Move elements inside the vector. The content of the method is equivalent to: vec[dest] = vec[source]

Specified by:
moveTo in interface IVec<T>
Parameters:
dest - the index of the destination
source - the index of the source

pop

public void pop()
Description copied from interface: IVec
Pop the last element on the stack. It is assumed that the stack is not empty!

Specified by:
pop in interface IVec<T>

push

public IVec<T> push(T elem)
Specified by:
push in interface IVec<T>

remove

public void remove(T elem)
Description copied from interface: IVec
Enleve un element qui se trouve dans le vecteur!!!

Specified by:
remove in interface IVec<T>
Parameters:
elem - un element du vecteur

set

public void set(int i,
                T o)
Specified by:
set in interface IVec<T>

shrink

public void shrink(int nofelems)
Description copied from interface: IVec
Remove nofelems from the Vector. It is assumed that the number of elements to remove is smaller or equals to the current number of elements in the vector

Specified by:
shrink in interface IVec<T>
Parameters:
nofelems - the number of elements to remove.

shrinkTo

public void shrinkTo(int newsize)
Description copied from interface: IVec
reduce the Vector to exactly newsize elements

Specified by:
shrinkTo in interface IVec<T>
Parameters:
newsize - the new size of the vector.

size

public int size()
Specified by:
size in interface IVec<T>
Returns:
the number of elements contained in the vector

sort

public void sort(Comparator<T> comparator)
Specified by:
sort in interface IVec<T>

sortUnique

public void sortUnique(Comparator<T> comparator)
Specified by:
sortUnique in interface IVec<T>

toArray

public T[] toArray()
Description copied from interface: IVec
Allow to access the internal representation of the vector as an array. Note that only the content of index 0 to size() should be taken into account. USE WITH CAUTION

Specified by:
toArray in interface IVec<T>
Returns:
the internal representation of the Vector as an array.

unsafePush

public void unsafePush(T elem)
Description copied from interface: IVec
To push an element in the vector when you know you have space for it.

Specified by:
unsafePush in interface IVec<T>

contains

public boolean contains(T element)
Specified by:
contains in interface IVec<T>
Parameters:
element - an object
Returns:
true iff element is found in the vector.
Since:
2.1

indexOf

public int indexOf(T element)
Specified by:
indexOf in interface IVec<T>
Parameters:
element - an object
Returns:
the index of the element if it is found in the vector, else -1.
Since:
2.2

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011 Centre de Recherche en Informatique de Lens (CRIL). All Rights Reserved.