Class ByteBackedCharSequence

  • All Implemented Interfaces:
    java.lang.CharSequence

    public class ByteBackedCharSequence
    extends java.lang.Object
    implements java.lang.CharSequence
    A CharSequence whose data is stored as bytes (instead of a String) to reduce memory usage.

    The API of the class is intended to make this class immutable, although in practice clients of this class can easily violate the immutability of the class.

    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBackedCharSequence​(byte[] bytes)
      Creates a new ByteBackedCharSequence based on the given char sequence which stores the given byte array as its internal byte array.
      ByteBackedCharSequence​(char[] characters)
      Constructs a new ByteBackedCharSequence based on the given char sequence
      ByteBackedCharSequence​(java.lang.CharSequence sequence)
      Constructs a new ByteBackedCharSequence based on the given char sequence
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAt​(int index)  
      byte[] getBytes()  
      int length()  
      java.lang.CharSequence subSequence​(int start, int end)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.CharSequence

        chars, codePoints
    • Constructor Detail

      • ByteBackedCharSequence

        public ByteBackedCharSequence​(byte[] bytes)
        Creates a new ByteBackedCharSequence based on the given char sequence which stores the given byte array as its internal byte array.
        Parameters:
        bytes - the contents of this array must not be modified after this constructor is invoked.
      • ByteBackedCharSequence

        public ByteBackedCharSequence​(java.lang.CharSequence sequence)
        Constructs a new ByteBackedCharSequence based on the given char sequence
        Parameters:
        sequence - the sequence to store as an array of bytes.
        Throws:
        java.lang.IllegalArgumentException - if any of the characters in sequence are not in the range 0 to 127 inclusive
      • ByteBackedCharSequence

        public ByteBackedCharSequence​(char[] characters)
        Constructs a new ByteBackedCharSequence based on the given char sequence
        Parameters:
        characters - the characters to store as an array of bytes.
        Throws:
        java.lang.IllegalArgumentException - if any of the characters in sequence are not in the range 0 to 127 inclusive
    • Method Detail

      • length

        public int length()
        Specified by:
        length in interface java.lang.CharSequence
      • charAt

        public char charAt​(int index)
        Specified by:
        charAt in interface java.lang.CharSequence
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • getBytes

        public byte[] getBytes()
        Returns:
        the underlying bytes stored in this sequence. The caller of this method must not modify the bytes in the returned array.
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object