java.lang.ObjectTally
public class Tally
This class represents a tally of integers, indexed from zero.
Field Summary | |
---|---|
static Tally |
IMPOSSIBLE
Singleton constant representing an impossible tally. |
Constructor Summary | |
---|---|
Tally(int n)
Constructs a tally of size n with all integers initialized to zero. |
|
Tally(int[] data)
Constructs a tally of size n from the given data, where n = data.length. |
Method Summary | |
---|---|
Tally |
add(Tally t)
Adds tally t to this tally, returning the "sum" as a new tally. |
boolean |
equals(java.lang.Object t)
Returns true iff this tally is value-identical to t. |
int |
getElement(int i)
Returns the int at position i. |
int |
hashCode()
Returns the product of this tally’s elements as its hash code. |
boolean |
isImpossible()
Returns whether the tally is impossible. |
int |
length()
Returns the length (i.e., the number of elements) of this tally. |
void |
setElement(int i,
int j)
Sets the int at position i to value j. |
java.lang.String |
toString()
Returns a string representation of this tally. |
int |
total()
Returns the total of the elements in this tally. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Tally IMPOSSIBLE
Constructor Detail |
---|
public Tally(int n)
n
- the number of elements in this tallypublic Tally(int[] data)
data
- the ints that should populate the tallyMethod Detail |
---|
public boolean isImpossible()
public void setElement(int i, int j)
i
- the position of the int to setj
- the value to which the position should be setpublic int getElement(int i)
i
- the position whose int is requested
public int length()
public int total()
public Tally add(Tally t)
t
- the tally to add to this tally
public boolean equals(java.lang.Object t)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()