Class CountsOfThingsStringJoiner


  • public class CountsOfThingsStringJoiner
    extends java.lang.Object
    A StringJoiner variant that specifically optimizes creating comma-separated lists of counts of things (in english language).
    Author:
    Rene Schneider - initial API and implementation
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean addZeroCounts
      Whether to add counts of zero items.
      protected static java.lang.String DIVIDER
      The standard divider segment.
      protected static java.lang.String DIVIDER_LAST
      The divider segment to use as the last divider.
      protected java.util.List<CountsOfThingsStringJoiner.StringSegment> segments
      Is internally used to perform the string joining work.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long aCount, java.lang.String aSingularObjectName, java.lang.String aPluralObjectName)
      Adds the specified count of things.
      void add​(long aCount, java.lang.String aSingularObjectName, java.lang.String aPluralObjectName, java.lang.Object aDataObject)
      Adds the specified count of things.
      java.lang.String toString()  
      java.util.List<CountsOfThingsStringJoiner.StringSegment> toStringSegments()
      Returns a list with the individual string segments that make up the final joined string (as returned by toString()).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • addZeroCounts

        protected boolean addZeroCounts
        Whether to add counts of zero items.
      • DIVIDER

        protected static final java.lang.String DIVIDER
        The standard divider segment.
        See Also:
        Constant Field Values
      • DIVIDER_LAST

        protected static final java.lang.String DIVIDER_LAST
        The divider segment to use as the last divider.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CountsOfThingsStringJoiner

        public CountsOfThingsStringJoiner()
        Constructor.
      • CountsOfThingsStringJoiner

        public CountsOfThingsStringJoiner​(boolean anAddZeroCountsFlag)
        Constructor.
        Parameters:
        anAddZeroCountsFlag - whether to add anything at all for counts of 0 objects
    • Method Detail

      • add

        public void add​(long aCount,
                        java.lang.String aSingularObjectName,
                        java.lang.String aPluralObjectName)
        Adds the specified count of things.
        Parameters:
        aCount - the count to add
        aSingularObjectName - the object to be counted in its singular form
        aPluralObjectName - the object to be counted in plural form
      • add

        public void add​(long aCount,
                        java.lang.String aSingularObjectName,
                        java.lang.String aPluralObjectName,
                        java.lang.Object aDataObject)
        Adds the specified count of things.
        Parameters:
        aCount - the count to add
        aSingularObjectName - the object to be counted in its singular form
        aPluralObjectName - the object to be counted in plural form
        aDataObject - Optional data object to associate with this segment
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object