Class 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 with character set and SqlCollation. 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 some NlsString objects.
      NlsString copy​(java.lang.String value)
      Creates a copy of this NlsString 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 a ByteString.
      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!'.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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
    • 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 null
        charsetName - Name of the character set, must not be null
        collation - Collation, may be null
        Throws:
        java.nio.charset.IllegalCharsetNameException - If the given charset name is illegal
        java.nio.charset.UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine
        java.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 null
        charsetName - Name of the character set, may be null
        collation - Collation, may be null
        Throws:
        java.nio.charset.IllegalCharsetNameException - If the given charset name is illegal
        java.nio.charset.UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine
        java.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 class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(NlsString other)
        Specified by:
        compareTo in interface java.lang.Comparable<NlsString>
      • getCharsetName

        public java.lang.String getCharsetName()
      • getCharset

        public java.nio.charset.Charset getCharset()
      • 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 name
        suffix - 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 class java.lang.Object
      • concat

        public static NlsString concat​(java.util.List<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
      • copy

        public NlsString copy​(java.lang.String value)
        Creates a copy of this NlsString with different content but same charset and collation.
      • getValueBytes

        public org.apache.calcite.avatica.util.ByteString getValueBytes()
        Returns the value as a ByteString.