Class NlsString

java.lang.Object
org.apache.calcite.util.NlsString
All Implemented Interfaces:
Cloneable, Comparable<NlsString>

public class NlsString extends Object implements Comparable<NlsString>, Cloneable
A string, optionally with character set and SqlCollation. It is immutable.
  • Constructor Details

    • NlsString

      public NlsString(org.apache.calcite.avatica.util.ByteString bytesValue, String charsetName, @Nullable 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:
      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
    • NlsString

      public NlsString(String stringValue, @Nullable String charsetName, @Nullable 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:
      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
  • Method Details

    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • hashCode

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

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • compareTo

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

      @Pure public @Nullable String getCharsetName()
    • getCharset

      @Pure public @Nullable Charset getCharset()
    • getCollation

      @Pure public @Nullable SqlCollation getCollation()
    • getValue

      public String getValue()
    • rtrim

      public NlsString rtrim()
      Returns a string the same as this but with spaces trimmed from the right.
    • asSql

      public String asSql(boolean prefix, boolean suffix)
      As asSql(boolean, boolean, SqlDialect) but with SQL standard dialect.
    • asSql

      public String asSql(boolean prefix, boolean suffix, SqlDialect dialect)
      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
      dialect - Dialect
      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(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(String value)
      Creates a copy of this NlsString with different content but same charset and collation.
    • getValueBytes

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