Class AggregateCharSequence

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.CharSequence, IWritableCharSequence

    public final class AggregateCharSequence
    extends java.lang.Object
    implements java.io.Serializable, IWritableCharSequence

    Character sequence that aggregates one or several CharSequence objects, without the need to clone them or convert them to String.

    Special implementation of the CharSequence interface that can replace String objects wherever a specific text literal is composed of several parts and we want to avoid creating new String objects for them, using instead objects of this class that simply keep an array of references to the original CharSequences.

    Note that any mutable CharSequence implementations used to build objects of this class should never be modified after the creation of the aggregated object.

    This class is thread-safe

    Since:
    3.0.0
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      AggregateCharSequence​(java.lang.CharSequence component)  
      AggregateCharSequence​(java.lang.CharSequence[] components)  
      AggregateCharSequence​(java.lang.CharSequence component0, java.lang.CharSequence component1)  
      AggregateCharSequence​(java.lang.CharSequence component0, java.lang.CharSequence component1, java.lang.CharSequence component2)  
      AggregateCharSequence​(java.lang.CharSequence component0, java.lang.CharSequence component1, java.lang.CharSequence component2, java.lang.CharSequence component3)  
      AggregateCharSequence​(java.lang.CharSequence component0, java.lang.CharSequence component1, java.lang.CharSequence component2, java.lang.CharSequence component3, java.lang.CharSequence component4)  
      AggregateCharSequence​(java.util.List<? extends java.lang.CharSequence> components)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAt​(int index)  
      boolean contentEquals​(java.lang.CharSequence cs)  
      boolean contentEquals​(java.lang.StringBuffer sb)  
      private static void copyChars​(java.lang.CharSequence src, int srcBegin, int srcEnd, char[] dst, int dstBegin)  
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      int length()  
      java.lang.CharSequence subSequence​(int beginIndex, int endIndex)  
      java.lang.String toString()  
      void write​(java.io.Writer writer)
      Write the contents of this char sequence directly to an output Writer.
      • Methods inherited from class java.lang.Object

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

        chars, codePoints
    • Field Detail

      • UNIQUE_ZERO_OFFSET

        private static final int[] UNIQUE_ZERO_OFFSET
      • values

        private final java.lang.CharSequence[] values
      • offsets

        private final int[] offsets
      • length

        private final int length
      • hash

        private int hash
    • Constructor Detail

      • AggregateCharSequence

        public AggregateCharSequence​(java.lang.CharSequence component)
      • AggregateCharSequence

        public AggregateCharSequence​(java.lang.CharSequence component0,
                                     java.lang.CharSequence component1)
      • AggregateCharSequence

        public AggregateCharSequence​(java.lang.CharSequence component0,
                                     java.lang.CharSequence component1,
                                     java.lang.CharSequence component2)
      • AggregateCharSequence

        public AggregateCharSequence​(java.lang.CharSequence component0,
                                     java.lang.CharSequence component1,
                                     java.lang.CharSequence component2,
                                     java.lang.CharSequence component3)
      • AggregateCharSequence

        public AggregateCharSequence​(java.lang.CharSequence component0,
                                     java.lang.CharSequence component1,
                                     java.lang.CharSequence component2,
                                     java.lang.CharSequence component3,
                                     java.lang.CharSequence component4)
      • AggregateCharSequence

        public AggregateCharSequence​(java.lang.CharSequence[] components)
      • AggregateCharSequence

        public AggregateCharSequence​(java.util.List<? extends java.lang.CharSequence> components)
    • 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 beginIndex,
                                                  int endIndex)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • write

        public void write​(java.io.Writer writer)
                   throws java.io.IOException
        Description copied from interface: IWritableCharSequence

        Write the contents of this char sequence directly to an output Writer.

        This method can avoid the need to create a String object containing all the contents in this character sequence just when we want to write it to a Writer.

        Specified by:
        write in interface IWritableCharSequence
        Parameters:
        writer - the writer to write the character sequence to.
        Throws:
        java.io.IOException - if an input/output exception happens during writing
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public boolean contentEquals​(java.lang.StringBuffer sb)
      • contentEquals

        public boolean contentEquals​(java.lang.CharSequence cs)
      • toString

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

        private static void copyChars​(java.lang.CharSequence src,
                                      int srcBegin,
                                      int srcEnd,
                                      char[] dst,
                                      int dstBegin)