org.pf.text
Class StringPair

java.lang.Object
  extended by org.pf.text.StringPair
All Implemented Interfaces:
IMutableStringPair, IStringPair

public class StringPair
extends java.lang.Object
implements IMutableStringPair

A simple pair of strings.

Version:
1.0
Author:
M.Duchrow

Field Summary
static StringPair[] EMPTY_ARRAY
           
static int NULL_HASHCODE
          Defines the hash code of instances that contain two null strings.
 
Constructor Summary
StringPair()
          Initialize the new instance with default values.
StringPair(IStringPair pair)
          Initialize the new instance from the given string pair.
StringPair(java.lang.String string)
          Initialize the new instance with one string.
StringPair(java.lang.String[] strings)
          Initialize the new instance with two strings in an array.
StringPair(java.lang.String s1, java.lang.String s2)
          Initialize the new instance with two strings.
 
Method Summary
 java.lang.String[] asArray()
          Returns both strings of this pair in a String array.
 java.lang.String asString(java.lang.String separator)
          Returns the two strings as one string separated by the given separator.
 boolean equals(java.lang.Object obj)
          Returns true if the given object is an IStringPair and its both strings are equal to the corresponding two strings of this object.
 java.lang.String getDefaultSeparator()
          Returns the default separator (here ":").
 java.lang.String getString1()
          Returns the first string of this pair.
 java.lang.String getString2()
          Returns the second string of this pair.
 int hashCode()
          Returns a hash built over the two contained strings.
 void setString1(java.lang.String newValue)
          Sets the first string to the given value.
 void setString2(java.lang.String newValue)
          Sets the second string to the given value.
 java.lang.String toString()
          Returns the two strings with the default separator in between.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final StringPair[] EMPTY_ARRAY

NULL_HASHCODE

public static final int NULL_HASHCODE
Defines the hash code of instances that contain two null strings.

Constructor Detail

StringPair

public StringPair()
Initialize the new instance with default values.


StringPair

public StringPair(java.lang.String string)
Initialize the new instance with one string. That is, both strings get initialized with the given string.


StringPair

public StringPair(java.lang.String s1,
                  java.lang.String s2)
Initialize the new instance with two strings.


StringPair

public StringPair(IStringPair pair)
Initialize the new instance from the given string pair.


StringPair

public StringPair(java.lang.String[] strings)
Initialize the new instance with two strings in an array.

Throws:
java.lang.IllegalArgumentException - If the array does not contain exactly 2 elements.
Method Detail

getString1

public java.lang.String getString1()
Description copied from interface: IStringPair
Returns the first string of this pair.

Specified by:
getString1 in interface IStringPair

setString1

public void setString1(java.lang.String newValue)
Description copied from interface: IMutableStringPair
Sets the first string to the given value.

Specified by:
setString1 in interface IMutableStringPair
Parameters:
newValue - The new value (may be null).

getString2

public java.lang.String getString2()
Description copied from interface: IStringPair
Returns the second string of this pair.

Specified by:
getString2 in interface IStringPair

setString2

public void setString2(java.lang.String newValue)
Description copied from interface: IMutableStringPair
Sets the second string to the given value.

Specified by:
setString2 in interface IMutableStringPair
Parameters:
newValue - The new value (may be null).

equals

public boolean equals(java.lang.Object obj)
Returns true if the given object is an IStringPair and its both strings are equal to the corresponding two strings of this object. That applies also to null values in the string variables.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash built over the two contained strings.

Overrides:
hashCode in class java.lang.Object

asArray

public java.lang.String[] asArray()
Returns both strings of this pair in a String array.

Specified by:
asArray in interface IStringPair

asString

public java.lang.String asString(java.lang.String separator)
Returns the two strings as one string separated by the given separator. If the provided separator is null, no separator should be put between the strings.

Specified by:
asString in interface IStringPair
Parameters:
separator - A separator to be placed between the two strings.

toString

public java.lang.String toString()
Returns the two strings with the default separator in between.

Overrides:
toString in class java.lang.Object

getDefaultSeparator

public java.lang.String getDefaultSeparator()
Returns the default separator (here ":").