Class StringConstructor

  • All Implemented Interfaces:
    java.lang.CharSequence

    public class StringConstructor
    extends java.lang.Object
    implements java.lang.CharSequence
    A CharSequence object representing a String constructed out of a sequence of other Strings. This object does not copy any of the string data - rather, it stores pointers to the original Strings it was constructed with.
    Author:
    Matthew Wakeling
    • Constructor Summary

      Constructors 
      Constructor Description
      StringConstructor()
      Main constructor - creates an empty object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      StringConstructor append​(boolean b)
      Appends a boolean onto the end of this object.
      StringConstructor append​(double d)
      Appends a double onto the end of this object.
      StringConstructor append​(float f)
      Appends a float onto the end of this object.
      StringConstructor append​(int i)
      Appends an int onto the end of this object.
      StringConstructor append​(long l)
      Appends a long onto the end of this object.
      StringConstructor append​(java.lang.Object o)
      Appends an Object onto the end of this object.
      StringConstructor append​(java.lang.String string)
      Appends a String onto the end of this object.
      char charAt​(int index)
      java.util.Collection<java.lang.String> getStrings()
      Returns a Collection containing the Strings that form this object, in the correct order.
      int length()
      java.lang.CharSequence subSequence​(int start, int end)
      java.lang.String toString()
      Returns the String that this object represents - note that this method should be avoided, because it defeats the purpose of keeping the constituent Strings separate in the first place.
      • 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

      • StringConstructor

        public StringConstructor()
        Main constructor - creates an empty object.
    • Method Detail

      • append

        public StringConstructor append​(java.lang.String string)
        Appends a String onto the end of this object.
        Parameters:
        string - the String
        Returns:
        this
      • append

        public StringConstructor append​(java.lang.Object o)
        Appends an Object onto the end of this object.
        Parameters:
        o - an Object
        Returns:
        this
      • append

        public StringConstructor append​(boolean b)
        Appends a boolean onto the end of this object.
        Parameters:
        b - a boolean
        Returns:
        this
      • append

        public StringConstructor append​(int i)
        Appends an int onto the end of this object.
        Parameters:
        i - an int
        Returns:
        this
      • append

        public StringConstructor append​(long l)
        Appends a long onto the end of this object.
        Parameters:
        l - a long
        Returns:
        this
      • append

        public StringConstructor append​(float f)
        Appends a float onto the end of this object.
        Parameters:
        f - a float
        Returns:
        this
      • append

        public StringConstructor append​(double d)
        Appends a double onto the end of this object.
        Parameters:
        d - a double
        Returns:
        this
      • length

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

        public java.lang.String toString()
        Returns the String that this object represents - note that this method should be avoided, because it defeats the purpose of keeping the constituent Strings separate in the first place.
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String
      • 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
      • getStrings

        public java.util.Collection<java.lang.String> getStrings()
        Returns a Collection containing the Strings that form this object, in the correct order.
        Returns:
        a Collection of Strings