org.pfsw.text
Class StringPair

java.lang.Object
  extended by org.pfsw.text.StringPair
All Implemented Interfaces:
org.pfsw.bif.text.IJSONConvertible, org.pfsw.bif.text.IMutableStringPair, org.pfsw.bif.text.IStringPair, org.pfsw.bif.text.IStringRepresentation

public class StringPair
extends java.lang.Object
implements org.pfsw.bif.text.IMutableStringPair, org.pfsw.bif.text.IJSONConvertible, org.pfsw.bif.text.IStringRepresentation

A simple pair of strings.


Field Summary
static StringPair[] EMPTY_ARRAY
           
static int NULL_HASHCODE
          Defines the hash code of instances that contain two null strings.
 
Fields inherited from interface org.pfsw.bif.text.IJSONConvertible
JSON_ARRAY_END, JSON_ARRAY_START, JSON_ELEMENT_SEPARATOR, JSON_LITERAL_FALSE, JSON_LITERAL_NULL, JSON_LITERAL_TRUE, JSON_OBJECT_END, JSON_OBJECT_START, JSON_PAIR_SEPARATOR, JSON_STRING_DELIMITER, JSON_STRING_ESCAPE
 
Constructor Summary
StringPair()
          Initialize the new instance with default values.
StringPair(org.pfsw.bif.text.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
 void appendAsJSONString(java.lang.Appendable output)
          Appends the internal state as JSON string representation to the given buffer.
 java.lang.String[] asArray()
          Returns both strings of this pair in a String array.
 java.lang.String asString()
          Returns the string representation of the pair with the default separator.
 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()
           
 java.lang.String getString2()
           
 int hashCode()
          Returns a hash built over the two contained strings.
protected  boolean isEqual(java.lang.String s1, java.lang.String s2)
           
 void setString1(java.lang.String newValue)
           
 void setString2(java.lang.String newValue)
           
 java.lang.String toJSON()
          Returns a JSON string representation of this object.
 java.lang.String toString()
          Returns the two strings with the default separator in between.
 
Methods inherited from class java.lang.Object
clone, finalize, 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(org.pfsw.bif.text.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

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

appendAsJSONString

public void appendAsJSONString(java.lang.Appendable output)
Appends the internal state as JSON string representation to the given buffer.

Specified by:
appendAsJSONString in interface org.pfsw.bif.text.IJSONConvertible
Parameters:
output - The buffer to which to append the JSON string (must not be null).

toJSON

public java.lang.String toJSON()
Returns a JSON string representation of this object.

Specified by:
toJSON in interface org.pfsw.bif.text.IJSONConvertible
Returns:
JSON object: {"string1":"string2"}

asArray

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

Specified by:
asArray in interface org.pfsw.bif.text.IStringPair

asString

public java.lang.String asString()
Returns the string representation of the pair with the default separator.

Specified by:
asString in interface org.pfsw.bif.text.IStringRepresentation

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 org.pfsw.bif.text.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 ":").


getString1

public java.lang.String getString1()
Specified by:
getString1 in interface org.pfsw.bif.text.IStringPair

setString1

public void setString1(java.lang.String newValue)
Specified by:
setString1 in interface org.pfsw.bif.text.IMutableStringPair

getString2

public java.lang.String getString2()
Specified by:
getString2 in interface org.pfsw.bif.text.IStringPair

setString2

public void setString2(java.lang.String newValue)
Specified by:
setString2 in interface org.pfsw.bif.text.IMutableStringPair

isEqual

protected boolean isEqual(java.lang.String s1,
                          java.lang.String s2)