org.eigenbase.util
Class NlsString

java.lang.Object
  extended by org.eigenbase.util.NlsString
All Implemented Interfaces:
Comparable<NlsString>

public class NlsString
extends Object
implements Comparable<NlsString>

A string, optionally with character set and SqlCollation. It is immutable.

Since:
May 28, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/util/NlsString.java#17 $
Author:
jhyde

Field Summary
private  Charset charset
           
private  String charsetName
           
private  SqlCollation collation
           
private  String value
           
 
Constructor Summary
NlsString(String value, String charsetName, SqlCollation collation)
          Creates a string in a specfied character set.
 
Method Summary
 String asSql(boolean prefix, boolean suffix)
          Returns the string quoted for SQL, for example _ISO-8859-1'is it a plane? no it''s superman!'.
 Object clone()
           
 int compareTo(NlsString other)
           
static NlsString concat(NlsString[] args)
          Concatenates some NlsString objects.
 boolean equals(Object obj)
           
 Charset getCharset()
           
 String getCharsetName()
           
 SqlCollation getCollation()
           
 String getValue()
           
 int hashCode()
           
 String toString()
          Returns the string quoted for SQL, for example _ISO-8859-1'is it a plane? no it''s superman!'.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

charsetName

private final String charsetName

value

private final String value

charset

private final Charset charset

collation

private final SqlCollation collation
Constructor Detail

NlsString

public NlsString(String value,
                 String charsetName,
                 SqlCollation collation)
          throws IllegalCharsetNameException,
                 UnsupportedCharsetException
Creates a string in a specfied character set.

Parameters:
value - String constant, must not be null
charsetName - Name of the character set, may be null
collation - Collation, may be null
Throws:
IllegalCharsetNameException - If the given charset name is illegal
UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine
RuntimeException - If the given value cannot be represented in the given charset
"Precondition:"
theString != null
Method Detail

clone

public Object clone()
Overrides:
clone in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

compareTo

public int compareTo(NlsString other)
Specified by:
compareTo in interface Comparable<NlsString>

getCharsetName

public String getCharsetName()

getCharset

public Charset getCharset()

getCollation

public SqlCollation getCollation()

getValue

public String getValue()

asSql

public String asSql(boolean prefix,
                    boolean suffix)
Returns the string quoted for SQL, for example _ISO-8859-1'is it a plane? no it''s superman!'.

Parameters:
prefix - if true, prefix the character set name
suffix - if true, suffix the collation clause
Returns:
the quoted string

toString

public String toString()
Returns the string quoted for SQL, for example _ISO-8859-1'is it a plane? no it''s superman!'.

Overrides:
toString in class Object

concat

public static NlsString concat(NlsString[] args)
Concatenates some NlsString objects. The result has the charset and collation of the first element. The other elements must have matching (or null) charset and collation. Concatenates all at once, not pairwise, to avoid string copies.

Parameters:
args - array of NlsString to be concatenated