|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.MutablePair<T1,T2>
public class MutablePair<T1,T2>
MutablePair is a Class for holding mutable pairs of objects. Implementation note: on a 32-bit JVM uses ~ 8 (this) + 4 (first) + 4 (second) = 16 bytes. on a 64-bit JVM uses ~ 16 (this) + 8 (first) + 8 (second) = 32 bytes. Many applications use a lot of MutablePairs so it's good to keep this number small.
Field Summary | |
---|---|
T1 |
first
Direct access is deprecated. |
T2 |
second
Direct access is deprecated. |
Constructor Summary | |
---|---|
MutablePair()
|
|
MutablePair(T1 first,
T2 second)
|
Method Summary | ||
---|---|---|
int |
compareTo(MutablePair<T1,T2> another)
Compares this MutablePair to another object. |
|
boolean |
equals(Object o)
|
|
T1 |
first()
|
|
int |
hashCode()
|
|
static MutablePair<String,String> |
internedStringPair(String first,
String second)
Returns an MutableInternedPair where the Strings have been interned. |
|
static
|
makePair(X x,
Y y)
Returns a MutablePair constructed from X and Y. |
|
static MutablePair<String,String> |
readStringPair(DataInputStream in)
Read a string representation of a MutablePair from a DataStream. |
|
void |
save(DataOutputStream out)
Write a string representation of a MutablePair to a DataStream. |
|
T2 |
second()
|
|
void |
setFirst(T1 o)
|
|
void |
setSecond(T2 o)
|
|
static MutablePair<String,String> |
stringIntern(MutablePair<String,String> p)
If first and second are Strings, then this returns an MutableInternedPair where the Strings have been interned, and if this MutablePair is serialized and then deserialized, first and second are interned upon deserialization. |
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public T1 first
public T2 second
Constructor Detail |
---|
public MutablePair()
public MutablePair(T1 first, T2 second)
Method Detail |
---|
public T1 first()
first
in interface Pair<T1,T2>
public T2 second()
second
in interface Pair<T1,T2>
public void setFirst(T1 o)
public void setSecond(T2 o)
public String toString()
toString
in class Object
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public static MutablePair<String,String> readStringPair(DataInputStream in)
String
.
public static <X,Y> MutablePair<X,Y> makePair(X x, Y y)
public void save(DataOutputStream out)
toString()
method is called on each of the pair
of objects and a String
representation is written.
This might not allow one to recover the pair of objects unless they
are of type String
.
public int compareTo(MutablePair<T1,T2> another)
MutablePair
to another object.
If the object is a MutablePair
, this function will work providing
the elements of the MutablePair
are themselves comparable.
It will then return a value based on the pair of objects, where
p > q iff p.first() > q.first() ||
(p.first().equals(q.first()) && p.second() > q.second())
.
If the other object is not a MutablePair
, it throws a
ClassCastException
.
compareTo
in interface Comparable<MutablePair<T1,T2>>
another
- the Object
to be compared.
0
if the argument is a
MutablePair
equal to this MutablePair
; a value less than
0
if the argument is a MutablePair
greater than this MutablePair
; and a value
greater than 0
if the argument is a
MutablePair
less than this MutablePair
.
ClassCastException
- if the argument is not a
MutablePair
.Comparable
public static MutablePair<String,String> stringIntern(MutablePair<String,String> p)
p
- A pair of Strings
public static MutablePair<String,String> internedStringPair(String first, String second)
Note: I put this in thinking that its use might be
faster than calling x = new MutablePair(a, b).stringIntern()
but it's not really clear whether this is true.
first
- The first objectsecond
- The second object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |