nrc.fuzzy
Class IntervalVector

java.lang.Object
  |
  +--nrc.fuzzy.IntervalVector
All Implemented Interfaces:
java.io.Serializable

public class IntervalVector
extends java.lang.Object
implements java.io.Serializable

The IntervalVector class implements a growable array of Intervals. Like an array, the values can be accessed using an integer index. However, the size of an IntervalVector can grow as needed to accommodate the addition of Intervals after the IntervalVector has been created. An IntervalVector is the object returned as the result of either an alpha cut, or a request for the support of a set.

See Also:
Serialized Form

Field Summary
protected  int increment
          The increment amount by which the IntervalVector expands when it reaches capacity and has to insert another Interval.
protected  int index
          The current number of Intervals in the array, and the index of the array at which the next Interval should be inserted.
protected static int INITIAL_CAPACITY
          The default initial capacity of the IntervalVector.
protected  nrc.fuzzy.Interval[] intervals
          The array of Interval values.
 
Constructor Summary
IntervalVector()
          Creates an empty IntervalVector with the default initial capacity and increment values.
IntervalVector(int initialCapacity)
          Creates an empty IntervalVector with the specified initial capacity and the default increment value.
IntervalVector(nrc.fuzzy.Interval[] IntervalArray, int length)
          Creates a IntervalVector with the length specified in the parameters, and initialized for the full length of the IntervalVector from the Interval values contained in the passed array.
IntervalVector(int initialCapacity, int increment)
          Creates an empty IntervalVector with the specified initial capacity and increment value.
 
Method Summary
 void addInterval(nrc.fuzzy.Interval interval)
          Adds a Interval to the end of the IntervalVector, increasing its size by one.
 void concat(nrc.fuzzy.IntervalVector other)
          Concatenates the IntervalVector argument with this IntervalVector.
 void insertIntervalAt(nrc.fuzzy.Interval interval, int i)
          Inserts the Interval argument into the IntervalVector at the specified index.
 nrc.fuzzy.Interval intervalAt(int i)
          Returns the Interval at the specified index.
 boolean isEmpty()
          Tests whether or not the IntervalVector is empty, ie.
 void removeIntervalAt(int i)
          Removes the Interval from the IntervalVector at the specified index.
 void setIntervalAt(nrc.fuzzy.Interval interval, int i)
          Sets the Interval in the IntervalVector at the specified index.
 int size()
          Returns the size of the IntervalVector, or the number of Intervals in the IntervalVector.
 nrc.fuzzy.Interval[] toIntervalArray()
          Returns the array of Intervals, trimmed to size, that this IntervalVector contains.
 java.lang.String toString()
           
 void trimToSize()
          Trims the capacity of this IntervalVector to be the IntervalVector's current size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

protected static final int INITIAL_CAPACITY
The default initial capacity of the IntervalVector. This default initial capacity is only used when the initial capacity of the IntervalVector is not a parameter passed to the constructor used.

See Also:
Constant Field Values

increment

protected int increment
The increment amount by which the IntervalVector expands when it reaches capacity and has to insert another Interval. This increment value can be set by choosing a constructor that allows you to specify it.


intervals

protected nrc.fuzzy.Interval[] intervals
The array of Interval values. This array is manipulated in such a way that it will expand as required to accomodate the addition of Intervals after the IntervalVector is created.


index

protected int index
The current number of Intervals in the array, and the index of the array at which the next Interval should be inserted.

Constructor Detail

IntervalVector

public IntervalVector()
Creates an empty IntervalVector with the default initial capacity and increment values.


IntervalVector

public IntervalVector(int initialCapacity)
Creates an empty IntervalVector with the specified initial capacity and the default increment value.

Parameters:
initialCapacity - the int which specifies the desired initial capacity of the IntervalVector. This is best used it is known that the IntervalVector will be quite large so as to avoid multiple expansions of the IntervalVector, which is inefficient.

IntervalVector

public IntervalVector(int initialCapacity,
                      int increment)
Creates an empty IntervalVector with the specified initial capacity and increment value.

Parameters:
initialCapacity - the int to specify the desired initial capacity of the IntervalVector. This is best used it is known that the IntervalVector will be quite large so as to avoid multiple expansions of the IntervalVector, which is inefficient.
increment - the int to specify the desired increment of the IntervalVector

IntervalVector

public IntervalVector(nrc.fuzzy.Interval[] IntervalArray,
                      int length)
Creates a IntervalVector with the length specified in the parameters, and initialized for the full length of the IntervalVector from the Interval values contained in the passed array.

Parameters:
IntervalArray - the array of Intervals which contains the Intervals with which to initialize the IntervalVector.
length - this parameter is basically equivalent to the initial capacity parameter in the other constructors. However, it has one additional implication. It is expected that length is less than or equal to the length of IntervalArray.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the length parameter is greater than the length of IntervalArray.
Method Detail

addInterval

public void addInterval(nrc.fuzzy.Interval interval)
Adds a Interval to the end of the IntervalVector, increasing its size by one.


concat

public void concat(nrc.fuzzy.IntervalVector other)
Concatenates the IntervalVector argument with this IntervalVector. The values contained within the IntervalVector argument are effectively added to the end of this IntervalVector.

Parameters:
other - the IntervalVector to concatenate onto the end of this IntervalVector

intervalAt

public nrc.fuzzy.Interval intervalAt(int i)
Returns the Interval at the specified index.

Parameters:
i - the index in the IntervalVector of the desired Interval
Returns:
the Interval at the specified index

setIntervalAt

public void setIntervalAt(nrc.fuzzy.Interval interval,
                          int i)
Sets the Interval in the IntervalVector at the specified index.

Parameters:
i - the index in the IntervalVector of the Interval position that is desired to be set

removeIntervalAt

public void removeIntervalAt(int i)
Removes the Interval from the IntervalVector at the specified index. The subsequent values in the IntervalVector are then shifted down one index position.

Parameters:
i - the position of the Interval to remove

insertIntervalAt

public void insertIntervalAt(nrc.fuzzy.Interval interval,
                             int i)
Inserts the Interval argument into the IntervalVector at the specified index. The Interval at the specified index and all subsequent values in the IntervalVector are then shifted up one index position.

Parameters:
i - the index position of the IntervalVector into which the Interval argument is to be inserted

trimToSize

public void trimToSize()
Trims the capacity of this IntervalVector to be the IntervalVector's current size. This can be used to minimize the storage of a IntervalVector.


size

public int size()
Returns the size of the IntervalVector, or the number of Intervals in the IntervalVector.

Returns:
the size of the IntervalVector, or the number of Intervals contained within the IntervalVector

isEmpty

public boolean isEmpty()
Tests whether or not the IntervalVector is empty, ie. contains zero Intervals.

Returns:
true if the IntervalVector is empty, if it contains zero Intervals

toIntervalArray

public nrc.fuzzy.Interval[] toIntervalArray()
Returns the array of Intervals, trimmed to size, that this IntervalVector contains.

Returns:
the Interval[] of the values contained by the IntervalVector. The length of the returned Interval vector is the current size of the IntervalVector; in other words, the exact number of Intervals in the IntervalVector.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object