edu.neu.ccs.quick
Class StringIntPair

java.lang.Object
  extended byedu.neu.ccs.quick.StringIntPair

public class StringIntPair
extends Object

StringIntPair constructs an immutable pair object from a non-null String and an int.

The methods equals and hashCode are designed so that two Pair objects whose contents are equal will be considered equal and will return the same hash code.

Since:
2.5.0
Version:
2.5.0

Field Summary
private  int number
          The number in the pair.
static Comparator numberFirst
          Comparator for sorting StringIntPair objects by using the number for the primary sort and the string to distinguish ties.
private  String string
          The string in the pair.
static Comparator stringFirst
          Comparator for sorting StringIntPair objects by using the string for the primary sort and the number to distinguish ties.
 
Constructor Summary
StringIntPair(String string, int number)
          Constructor that constructs the string-int pair using a non-null String and an int.
 
Method Summary
 boolean equals(Object object)
          Returns true if the given object is a StringIntPair whose string and number are equal to the corresponding members of this object.
 int getInt()
          Returns the number in the pair.
 int getNumber()
          Returns the number in the pair.
 String getString()
          Returns the string in the pair.
 int hashCode()
          Returns the sum of the hashcode of the string with the number.
 String toString()
          Returns the string combined with the number with a space in between.
 String toString(int widthS)
          Returns the string padded on the right to widthS combined with the number with a space in between.
 String toString(int widthS, int widthN)
          Returns the string padded on the right to widthS combined with the number padded on the left to widthN with a space in between.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

string

private String string
The string in the pair.


number

private int number
The number in the pair.


stringFirst

public static final Comparator stringFirst

Comparator for sorting StringIntPair objects by using the string for the primary sort and the number to distinguish ties.

The compare throws ClassCastException if either argument is not of type StringIntPair.


numberFirst

public static final Comparator numberFirst

Comparator for sorting StringIntPair objects by using the number for the primary sort and the string to distinguish ties.

The compare throws ClassCastException if either argument is not of type StringIntPair.

Constructor Detail

StringIntPair

public StringIntPair(String string,
                     int number)

Constructor that constructs the string-int pair using a non-null String and an int.

Parameters:
string - the string for the pair
number - the number for the pair
Throws:
NullPointerException - if the string is null
Method Detail

getString

public String getString()
Returns the string in the pair.


getInt

public int getInt()

Returns the number in the pair.

Synonym for getNumber.


getNumber

public int getNumber()

Returns the number in the pair.

Synonym for getInt.


toString

public String toString()
Returns the string combined with the number with a space in between.


toString

public String toString(int widthS)
Returns the string padded on the right to widthS combined with the number with a space in between.


toString

public String toString(int widthS,
                       int widthN)
Returns the string padded on the right to widthS combined with the number padded on the left to widthN with a space in between.


equals

public boolean equals(Object object)

Returns true if the given object is a StringIntPair whose string and number are equal to the corresponding members of this object.

Returns false otherwise.


hashCode

public int hashCode()
Returns the sum of the hashcode of the string with the number.