Class SeparatorWriter


  • public class SeparatorWriter
    extends java.lang.Object
    Assistance for writing separators in strings. The user indicates if anything has been written and that a separator is necessary. Then, later, the user can make a request to write a separator to the string being built, and it will only be written if a previous request indicated that separator is necessary.
    • Constructor Summary

      Constructors 
      Constructor Description
      SeparatorWriter​(java.lang.StringBuilder sb, java.lang.String separatorStr)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void needSeparator()
      Indicate that a separator will be required the next time one is requested.
      void writeSeparator()
      Request to write a separator if one is necessary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SeparatorWriter

        public SeparatorWriter​(java.lang.StringBuilder sb,
                               java.lang.String separatorStr)
        Constructor.
        Parameters:
        sb - the StringBuilder being used to build the String
        separatorStr - the separator string to use
    • Method Detail

      • needSeparator

        public void needSeparator()
        Indicate that a separator will be required the next time one is requested. If this is not called, then calls to writeSeparator() will do nothing.
      • writeSeparator

        public void writeSeparator()
        Request to write a separator if one is necessary. Necessity is determined by a previous call to needSeparator() that has not yet been fulfilled.