public class FVector extends Object implements Cloneable, Serializable
Vector
.Modifier and Type | Field and Description |
---|---|
protected static int |
defaultCapacity
The default capacity of a vector upon first construction.
|
protected int |
size
The number of elements in the vector.
|
protected Feature[] |
vector
The elements of the vector.
|
Constructor and Description |
---|
FVector()
Constructs a new vector with capacity equal to
defaultCapacity . |
FVector(Feature[] v)
Constructs a new vector using the specified array as a starting point.
|
FVector(FVector v)
Constructs a copy of a vector starting with capacity equal to that vector's size.
|
FVector(int c)
Constructs a new vector with the specified capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Feature v)
Adds the specified value on to the end of the vector, expanding its capacity as necessary.
|
void |
addAll(FVector v)
Adds all the values in the given vector to the end of this vector, expanding its capacity as
necessary.
|
protected void |
boundsCheck(int i)
Throws an exception when the specified index is negative.
|
Object |
clone()
Returns a shallow clone of this vector; the vector itself is cloned, but the element objects
aren't.
|
void |
consolidate()
After calling this method, the new size and capacity of this vector will be equal to the
number of non-
null elements; all such elements will be retained in the same
relative order. |
boolean |
equals(Object o)
Two
FVector s are considered equal if they contain equivalent elements and have
the same size. |
protected void |
expandFor(int index,
Feature d)
Makes sure the capacity and size of the vector can accomodate the given index.
|
Feature |
get(int i)
Retrieves the value stored at the specified index of the vector, or
null if the
vector isn't long enough. |
Feature |
get(int i,
Feature d)
Retrieves the value stored at the specified index of the vector or
d if the
vector isn't long enough. |
int |
hashCode()
A hash code based on the hash code of
vector . |
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the binary representation of a vector from the specified stream, overwriting the data
in this object.
|
Feature |
remove(int i)
Removes the element at the specified index of the vector.
|
Feature |
set(int i,
Feature v)
Sets the value at the specified index to the given value.
|
Feature |
set(int i,
Feature v,
Feature d)
Sets the value at the specified index to the given value.
|
int |
size()
Returns the value of
size . |
void |
sort()
Sorts this vector in increasing order.
|
Feature[] |
toArray()
Returns a new array of features containing the same data as this vector.
|
String |
toString()
Returns a text representation of this vector.
|
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes a binary representation of this vector to the given stream.
|
protected static final int defaultCapacity
protected Feature[] vector
protected int size
public FVector()
defaultCapacity
.public FVector(int c)
c
- The initial capacity for the new vector.public FVector(Feature[] v)
v
- The initial array.public FVector(FVector v)
v
- The vector to copy.protected void boundsCheck(int i)
i
- The index.ArrayIndexOutOfBoundsException
- When i
< 0.public Feature get(int i)
null
if the
vector isn't long enough.i
- The index of the value to retrieve.ArrayIndexOutOfBoundsException
- When i
< 0.public Feature get(int i, Feature d)
d
if the
vector isn't long enough.i
- The index of the value to retrieve.d
- The default value.ArrayIndexOutOfBoundsException
- When i
< 0.public Feature set(int i, Feature v)
i
- The index of the value to set.v
- The new value at that index.i
.ArrayIndexOutOfBoundsException
- When i
< 0.public Feature set(int i, Feature v, Feature d)
i
- The index of the value to set.v
- The new value at that index.d
- The default value for other new indexes that might get created.i
.ArrayIndexOutOfBoundsException
- When i
< 0.public void add(Feature v)
v
- The new value to appear last in the vector.public void addAll(FVector v)
v
- The new vector of values to appear at the end of this vector.public Feature remove(int i)
i
- The index of the element to remove.public int size()
size
.public void sort()
public void consolidate()
null
elements; all such elements will be retained in the same
relative order.protected void expandFor(int index, Feature d)
index
- The index where a new value will be stored.d
- The default value for other new indexes that might get created.public Feature[] toArray()
public boolean equals(Object o)
FVector
s are considered equal if they contain equivalent elements and have
the same size.public int hashCode()
vector
.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
out
- The output stream.public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
in
- The input stream.public Object clone()
Copyright © 2016. All rights reserved.