Class TruncateTextBuilder

java.lang.Object
org.refcodes.textual.TruncateTextBuilder
All Implemented Interfaces:
org.refcodes.mixin.TruncateModeAccessor, org.refcodes.mixin.TruncateModeAccessor.TruncateModeBuilder<TruncateTextBuilder>, org.refcodes.mixin.TruncateModeAccessor.TruncateModeMutator, org.refcodes.mixin.TruncateModeAccessor.TruncateModeProperty, Text<TruncateTextBuilder>, TextAccessor, TextAccessor.TextBuilder<Text<TruncateTextBuilder>>, TextAccessor.TextMutator, TextAccessor.TextProperty, TextAccessor.TextProvider

public class TruncateTextBuilder
extends Object
implements Text<TruncateTextBuilder>, org.refcodes.mixin.TruncateModeAccessor.TruncateModeProperty, org.refcodes.mixin.TruncateModeAccessor.TruncateModeBuilder<TruncateTextBuilder>
Strips given characters from text's left hand side or right hand side or both.
  • Constructor Details

    • TruncateTextBuilder

      public TruncateTextBuilder()
  • Method Details

    • getTruncateMode

      public org.refcodes.mixin.TruncateMode getTruncateMode()
      Retrieves the truncate text mode from the truncate text mode property.
      Specified by:
      getTruncateMode in interface org.refcodes.mixin.TruncateModeAccessor
      Returns:
      The truncate text mode stored by the truncate text mode property.
    • setTruncateMode

      public void setTruncateMode​(org.refcodes.mixin.TruncateMode aTruncateTextMode)
      Sets the truncate text mode for the truncate text mode property.
      Specified by:
      setTruncateMode in interface org.refcodes.mixin.TruncateModeAccessor.TruncateModeMutator
      Parameters:
      aTruncateTextMode - The truncate text mode to be stored by the truncate text mode property.
    • getTruncateChars

      public char[] getTruncateChars()
      Retrieves the truncate chars from the truncate chars property.
      Returns:
      The truncate chars stored by the truncate chars property.
    • setTruncateChars

      public void setTruncateChars​(char... aTruncateChars)
      Sets the truncate chars for the truncate chars property.
      Parameters:
      aTruncateChars - The truncate chars to be stored by the text align mode property.
    • toStrings

      public String[] toStrings()
      The Strings being build by the builder upon the settings of the attributes.
      Specified by:
      toStrings in interface TextAccessor.TextProvider
      Returns:
      The according resulting String array
    • toStrings

      public String[] toStrings​(String... aText)
      Race condition safe shortcut for using Text.withText(String...) followed by TextAccessor.TextProvider.toStrings(). Implementation requirements: This method must not(!) be implemented by calling Text.withText(String...) followed by TextAccessor.TextProvider.toStrings() (do not change the text property) as this would not be thread safe!
      Specified by:
      toStrings in interface Text<TruncateTextBuilder>
      Parameters:
      aText - The text to be processed.
      Returns:
      The according resulting String array
    • withTruncateMode

      public TruncateTextBuilder withTruncateMode​(org.refcodes.mixin.TruncateMode aTruncateTextMode)
      Sets the truncate text mode for the truncate text mode property.
      Specified by:
      withTruncateMode in interface org.refcodes.mixin.TruncateModeAccessor.TruncateModeBuilder<TruncateTextBuilder>
      Parameters:
      aTruncateTextMode - The truncate text mode to be stored by the truncate text mode property.
      Returns:
      The builder for applying multiple build operations.
    • withText

      public TruncateTextBuilder withText​(String... aTextLines)
      Sets the String array for the text property.
      Specified by:
      withText in interface Text<TruncateTextBuilder>
      Specified by:
      withText in interface TextAccessor.TextBuilder<Text<TruncateTextBuilder>>
      Parameters:
      aTextLines - The String array be stored by the text property.
      Returns:
      The builder for applying multiple build operations.
    • withStripChars

      public TruncateTextBuilder withStripChars​(char... aStripChars)
      Sets the truncate chars for the truncate chars property.
      Parameters:
      aStripChars - The truncate chars to be stored by the text align mode property.
      Returns:
      The builder for applying multiple build operations.
    • toString

      public String toString() throws IllegalStateException
      The String being build by the builder upon the settings of the attributes.
      Specified by:
      toString in interface TextAccessor.TextProvider
      Returns:
      The according resulting String
      Throws:
      IllegalStateException - Thrown in case more than one text line has been set via the withText(String...) or TextAccessor.TextMutator.setText(String...) methods.
    • asTruncated

      public static String asTruncated​(String aText, org.refcodes.mixin.TruncateMode aTruncateTextMode)
      Returns a new String without the according leading and/or trailing whitespaces as of CharSet.WHITE_SPACES.
      Parameters:
      aText - The text to truncate.
      aTruncateTextMode - The TruncateMode describes how to truncate (left, right or both).
      Returns:
      The accordingly truncated String.
    • asTruncated

      public static String asTruncated​(String aText, org.refcodes.mixin.TruncateMode aTruncateTextMode, char... aChars)
      Returns a new String without the according leading and/or trailing chars.
      Parameters:
      aText - The text to truncate.
      aTruncateTextMode - The TruncateMode describes how to truncate (left, right or both).
      aChars - the chars to detect when truncating.
      Returns:
      The accordingly truncated String.
    • asTruncatedLeft

      public static String asTruncatedLeft​(String aText)
      Returns a new String without the according leading whitespaces as of CharSet.WHITE_SPACES.
      Parameters:
      aText - The text to truncate.
      Returns:
      The accordingly truncated String.
    • asTruncatedLeft

      public static String asTruncatedLeft​(String aText, char... aChars)
      Returns a new String without the according leading chars.
      Parameters:
      aText - The text to be stripped.
      aChars - the chars
      Returns:
      The stripped text.
    • asTruncatedRight

      public static String asTruncatedRight​(String aText)
      Returns a new String without the according trailing whitespaces as of CharSet.WHITE_SPACES.
      Parameters:
      aText - The text to truncate.
      Returns:
      The accordingly truncated String.
    • asTruncatedRight

      public static String asTruncatedRight​(String aText, char... aChars)
      Returns a new String without the according trailing chars.
      Parameters:
      aText - The text to truncate.
      aChars - the chars to detect when truncating.
      Returns:
      The accordingly truncated String.
    • doStripLeft

      protected static void doStripLeft​(StringBuffer aStringBuffer, char aChar)
      Removes all leading chars identical with specified char. E.g. if str=AAABBBAAABBB and ch=A the returned String will be BBBAAABBB.
      Parameters:
      aStringBuffer - StringBuffer to modify.
      aChar - Char to remove.
    • doStripRight

      protected static void doStripRight​(StringBuffer aStringBuffer, char aChar)
      Removes all rear chars identical with specified char ch. E.g. if str=AAABBBAAABBB and ch=B str will become AAABBBAAA.
      Parameters:
      aStringBuffer - StringBuffer to modify.
      aChar - Char to remove.
    • doStrip

      protected static void doStrip​(StringBuffer aStringBuffer, char aChar)
      Removes all leading and trailing chars identical with specified char ch. E.g. if str=BAABBBAAABBB and ch=B str will become AABBBAAA.
      Parameters:
      aStringBuffer - StringBuffer to modify.
      aChar - Char to remove.
    • toStrip

      protected static String toStrip​(String aText, char[] aChars)
      Returns a new String without leading nor trailing chars.
      Parameters:
      aText - The text to be stripped.
      aChars - the chars
      Returns:
      The stripped text.
    • getText

      public String[] getText()
      Retrieves the text from the text property.
      Specified by:
      getText in interface TextAccessor
      Returns:
      The text stored by the text property.
    • setText

      public void setText​(String... aText)
      Sets the text for the text property.
      Specified by:
      setText in interface TextAccessor.TextMutator
      Parameters:
      aText - The text to be stored by the text property.
    • withText

      public TruncateTextBuilder withText​(Collection<String> aText)
      With text.
      Specified by:
      withText in interface TextAccessor.TextBuilder<B extends Text<B>>
      Parameters:
      aText - the text
      Returns:
      the b
    • toString

      public String toString​(String... aText)
      Race condition safe shortcut for using Text.withText(String...) followed by TextAccessor.TextProvider.toString(). Implementation requirements: This method must not(!) be implemented by calling Text.withText(String...) followed by TextAccessor.TextProvider.toString() (do not change the text property) as this would not be thread safe!
      Specified by:
      toString in interface Text<B extends Text<B>>
      Parameters:
      aText - The text to be processed.
      Returns:
      The according resulting String