Package org.apache.calcite.util
Class NlsString
- java.lang.Object
-
- org.apache.calcite.util.NlsString
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<NlsString>
public class NlsString extends java.lang.Object implements java.lang.Comparable<NlsString>, java.lang.Cloneable
A string, optionally withcharacter set
andSqlCollation
. It is immutable.
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.calcite.avatica.util.ByteString
bytesValue
private java.nio.charset.Charset
charset
private java.lang.String
charsetName
private SqlCollation
collation
private static com.google.common.cache.LoadingCache<Pair<org.apache.calcite.avatica.util.ByteString,java.nio.charset.Charset>,java.lang.String>
DECODE_MAP
private java.lang.String
stringValue
-
Constructor Summary
Constructors Modifier Constructor Description NlsString(java.lang.String stringValue, java.lang.String charsetName, SqlCollation collation)
Easy constructor for Java string.private
NlsString(java.lang.String stringValue, org.apache.calcite.avatica.util.ByteString bytesValue, java.lang.String charsetName, SqlCollation collation)
Internal constructor; other constructors must call it.NlsString(org.apache.calcite.avatica.util.ByteString bytesValue, java.lang.String charsetName, SqlCollation collation)
Creates a string in a specified character set.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.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!'
.java.lang.Object
clone()
int
compareTo(NlsString other)
static NlsString
concat(java.util.List<NlsString> args)
Concatenates someNlsString
objects.NlsString
copy(java.lang.String value)
Creates a copy of thisNlsString
with different content but same charset and collation.boolean
equals(java.lang.Object obj)
java.nio.charset.Charset
getCharset()
java.lang.String
getCharsetName()
SqlCollation
getCollation()
java.lang.String
getValue()
org.apache.calcite.avatica.util.ByteString
getValueBytes()
Returns the value as aByteString
.int
hashCode()
NlsString
rtrim()
Returns a string the same as this but with spaces trimmed from the right.java.lang.String
toString()
Returns the string quoted for SQL, for example_ISO-8859-1'is it a plane? no it''s superman!'
.
-
-
-
Field Detail
-
DECODE_MAP
private static final com.google.common.cache.LoadingCache<Pair<org.apache.calcite.avatica.util.ByteString,java.nio.charset.Charset>,java.lang.String> DECODE_MAP
-
stringValue
private final java.lang.String stringValue
-
bytesValue
private final org.apache.calcite.avatica.util.ByteString bytesValue
-
charsetName
private final java.lang.String charsetName
-
charset
private final java.nio.charset.Charset charset
-
collation
private final SqlCollation collation
-
-
Constructor Detail
-
NlsString
public NlsString(org.apache.calcite.avatica.util.ByteString bytesValue, java.lang.String charsetName, SqlCollation collation)
Creates a string in a specified character set.- Parameters:
bytesValue
- Byte array constant, must not be nullcharsetName
- Name of the character set, must not be nullcollation
- Collation, may be null- Throws:
java.nio.charset.IllegalCharsetNameException
- If the given charset name is illegaljava.nio.charset.UnsupportedCharsetException
- If no support for the named charset is available in this instance of the Java virtual machinejava.lang.RuntimeException
- If the given value cannot be represented in the given charset
-
NlsString
public NlsString(java.lang.String stringValue, java.lang.String charsetName, SqlCollation collation)
Easy constructor for Java string.- Parameters:
stringValue
- String constant, must not be nullcharsetName
- Name of the character set, may be nullcollation
- Collation, may be null- Throws:
java.nio.charset.IllegalCharsetNameException
- If the given charset name is illegaljava.nio.charset.UnsupportedCharsetException
- If no support for the named charset is available in this instance of the Java virtual machinejava.lang.RuntimeException
- If the given value cannot be represented in the given charset
-
NlsString
private NlsString(java.lang.String stringValue, org.apache.calcite.avatica.util.ByteString bytesValue, java.lang.String charsetName, SqlCollation collation)
Internal constructor; other constructors must call it.
-
-
Method Detail
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(NlsString other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<NlsString>
-
getCharsetName
public java.lang.String getCharsetName()
-
getCharset
public java.nio.charset.Charset getCharset()
-
getCollation
public SqlCollation getCollation()
-
getValue
public java.lang.String getValue()
-
rtrim
public NlsString rtrim()
Returns a string the same as this but with spaces trimmed from the right.
-
asSql
public java.lang.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 namesuffix
- if true, suffix the collation clause- Returns:
- the quoted string
-
toString
public java.lang.String toString()
Returns the string quoted for SQL, for example_ISO-8859-1'is it a plane? no it''s superman!'
.- Overrides:
toString
in classjava.lang.Object
-
concat
public static NlsString concat(java.util.List<NlsString> args)
Concatenates someNlsString
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 ofNlsString
to be concatenated
-
copy
public NlsString copy(java.lang.String value)
Creates a copy of thisNlsString
with different content but same charset and collation.
-
getValueBytes
public org.apache.calcite.avatica.util.ByteString getValueBytes()
Returns the value as aByteString
.
-
-