com.monica.javacom.util
Class MJCEqualityVector

java.lang.Object
  |
  +--com.monica.javacom.util.MJCEqualityVector

public class MJCEqualityVector
extends java.lang.Object

Class for implementing a Vector like functionality with using MJCEquality for checking equality between the contained objects.


Constructor Summary
MJCEqualityVector(MJCEquality e, boolean s, boolean iR, int m)
          Default constructor.
 
Method Summary
 boolean add(java.lang.Object o)
          Adds an object to the vector.
 int count(java.lang.Object o, boolean useEquality)
          Returns the number of occurances of the Object o.
 int firstIndex(java.lang.Object o, boolean useEquality)
          Returns the first occurance of the Object o.
 java.lang.Object get(int pos)
          Returns the Object at the position pos.
 boolean insert(java.lang.Object o, int pos)
          Inserts the supplied Object o to be the supplied position pos.
 int lastIndex(java.lang.Object o, boolean useEquality)
          Returns the last occurance of the Object o.
 int length()
          Returns the number of elements in the vector.
 void pack()
          Removes all preliminarily deleted elements finally from the vector.
 void remove(int pos)
          Removes the Object from the supplied position pos.
 boolean remove(java.lang.Object o, boolean useEquality)
          Removes the supplied Object o from the vector.
 void set(java.lang.Object o, int pos)
          Sets the supplied Object o to be the supplied position pos.
 void setEquality(MJCEquality e)
          Sets the MJCEquality to be used.
 void setSynchronizing(boolean s)
          Sets wether to use synchronization for all the operations, or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MJCEqualityVector

public MJCEqualityVector(MJCEquality e,
                         boolean s,
                         boolean iR,
                         int m)
Default constructor.
Parameters:
MJCEquality - e: the MJCEquality to be used for checking equality between contained objects
boolean - s: wether using synchronization for all the operations or not, true=synchronization
boolean - iR: wether to remove the removed elements from the memory list instantly or not, true=instant removal
int - m: the maximal number of objects in this Vector
Method Detail

setEquality

public void setEquality(MJCEquality e)
Sets the MJCEquality to be used.
Parameters:
MJCEquality - e: the MJCEquality to be used for checking equality between objects

setSynchronizing

public void setSynchronizing(boolean s)
Sets wether to use synchronization for all the operations, or not.
Parameters:
boolean - s: true for using synchronization

add

public boolean add(java.lang.Object o)
Adds an object to the vector.
Parameters:
Object - o: the Object to be added
Returns:
boolean: true if adding successful

firstIndex

public int firstIndex(java.lang.Object o,
                      boolean useEquality)
Returns the first occurance of the Object o.
Parameters:
Object - o: the Object whose first occurance should be returned
boolean - useEquality: wether to use the supplied MJCEquality or use Object.equals instead, true=use MJCEquality
Returns:
int: the first index of the Object o, -1 if not in the vector

lastIndex

public int lastIndex(java.lang.Object o,
                     boolean useEquality)
Returns the last occurance of the Object o.
Parameters:
Object - o: the Object whose last occurance should be returned
boolean - useEquality: wether to use the supplied MJCEquality or use Object.equals instead, true=use MJCEquality
Returns:
int: the first last of the Object o, -1 if not in the vector

count

public int count(java.lang.Object o,
                 boolean useEquality)
Returns the number of occurances of the Object o.
Parameters:
Object - o: the Object whose occurances should be counted
boolean - useEquality: wether to use the supplied MJCEquality or use Object.equals instead, true=use MJCEquality
Returns:
int: the number of occurances of o

get

public java.lang.Object get(int pos)
                     throws java.lang.Exception
Returns the Object at the position pos.
Parameters:
int - pos: the position of the returned Object
Returns:
Object: the Object at the position pos
Throws:
ArrayIndexOutOfBoundsException: - if pos>length of the vector
Exception: - if the wanted position is deleted

set

public void set(java.lang.Object o,
                int pos)
         throws java.lang.ArrayIndexOutOfBoundsException
Sets the supplied Object o to be the supplied position pos.
Parameters:
Object - o: the Object to be set
Throws:
ArrayIndexOutOfBoundsException: - if pos>=length of the vector

insert

public boolean insert(java.lang.Object o,
                      int pos)
               throws java.lang.ArrayIndexOutOfBoundsException
Inserts the supplied Object o to be the supplied position pos.
Parameters:
Object - o: the Object to be inserted
Throws:
ArrayIndexOutOfBoundsException: - if pos>length of the vector

remove

public boolean remove(java.lang.Object o,
                      boolean useEquality)
Removes the supplied Object o from the vector.
Parameters:
Object - o: the Object to be removed
boolean - useEquality: wether to use the supplied MJCEquality or use Object.equals instead, true=use MJCEquality
Returns:
boolean: wether to Object could be removed or not

remove

public void remove(int pos)
            throws java.lang.ArrayIndexOutOfBoundsException
Removes the Object from the supplied position pos.
Parameters:
int - pos: the position from that the Object has to be removed
Throws:
ArrayIndexOutOfBoundsException: - if pos>=length of the vector

pack

public void pack()
Removes all preliminarily deleted elements finally from the vector.

length

public int length()
Returns the number of elements in the vector.
Returns:
int: the number of elements in the vector