- 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.textual.TextAccessor
TextAccessor.TextBuilder<B extends TextAccessor.TextBuilder<B>>, TextAccessor.TextMutator, TextAccessor.TextProperty, TextAccessor.TextProvider
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.TruncateModeAccessor
org.refcodes.mixin.TruncateModeAccessor.TruncateModeBuilder<B extends org.refcodes.mixin.TruncateModeAccessor.TruncateModeBuilder<B>>, org.refcodes.mixin.TruncateModeAccessor.TruncateModeMutator, org.refcodes.mixin.TruncateModeAccessor.TruncateModeProperty
-
-
Constructor Summary
Constructors Constructor Description TruncateTextBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
asTruncated(String aText, org.refcodes.mixin.TruncateMode aTruncateTextMode)
Returns a newString
without the according leading and/or trailing whitespaces as ofCharSet.WHITE_SPACES
.static String
asTruncated(String aText, org.refcodes.mixin.TruncateMode aTruncateTextMode, char... aChars)
Returns a newString
without the according leading and/or trailing chars.static String
asTruncatedLeft(String aText)
Returns a newString
without the according leading whitespaces as ofCharSet.WHITE_SPACES
.static String
asTruncatedLeft(String aText, char... aChars)
Returns a newString
without the according leading chars.static String
asTruncatedRight(String aText)
Returns a newString
without the according trailing whitespaces as ofCharSet.WHITE_SPACES
.static String
asTruncatedRight(String aText, char... aChars)
Returns a newString
without the according trailing chars.protected static void
doStrip(StringBuffer aStringBuffer, char aChar)
Removes all leading and trailing chars identical with specified char ch.protected static void
doStripLeft(StringBuffer aStringBuffer, char aChar)
Removes all leading chars identical with specified char.protected static void
doStripRight(StringBuffer aStringBuffer, char aChar)
Removes all rear chars identical with specified char ch.String[]
getText()
Retrieves the text from the text property.char[]
getTruncateChars()
Retrieves the truncate chars from the truncate chars property.org.refcodes.mixin.TruncateMode
getTruncateMode()
Retrieves the truncate text mode from the truncate text mode property.void
setText(String... aText)
Sets the text for the text property.void
setTruncateChars(char... aTruncateChars)
Sets the truncate chars for the truncate chars property.void
setTruncateMode(org.refcodes.mixin.TruncateMode aTruncateTextMode)
Sets the truncate text mode for the truncate text mode property.String
toString()
TheString
being build by the builder upon the settings of the attributes.String
toString(String... aText)
Race condition safe shortcut for usingText.withText(String...)
followed byTextAccessor.TextProvider.toString()
.String[]
toStrings()
TheString
s being build by the builder upon the settings of the attributes.String[]
toStrings(String... aText)
Race condition safe shortcut for usingText.withText(String...)
followed byTextAccessor.TextProvider.toStrings()
.protected static String
toStrip(String aText, char[] aChars)
Returns a new String without leading nor trailing chars.TruncateTextBuilder
withStripChars(char... aStripChars)
Sets the truncate chars for the truncate chars property.TruncateTextBuilder
withText(String... aTextLines)
Sets theString
array for the text property.B
withText(Collection<String> aText)
With text.TruncateTextBuilder
withTruncateMode(org.refcodes.mixin.TruncateMode aTruncateTextMode)
Sets the truncate text mode for the truncate text mode property.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.textual.TextAccessor
getText
-
Methods inherited from interface org.refcodes.textual.TextAccessor.TextBuilder
withText
-
Methods inherited from interface org.refcodes.textual.TextAccessor.TextMutator
setText, setText
-
Methods inherited from interface org.refcodes.textual.TextAccessor.TextProperty
letText, letText
-
-
-
-
Method Detail
-
getTruncateMode
public org.refcodes.mixin.TruncateMode getTruncateMode()
Retrieves the truncate text mode from the truncate text mode property.- Specified by:
getTruncateMode
in interfaceorg.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 interfaceorg.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()
TheString
s being build by the builder upon the settings of the attributes.- Specified by:
toStrings
in interfaceTextAccessor.TextProvider
- Returns:
- The according resulting
String
array
-
toStrings
public String[] toStrings(String... aText)
Race condition safe shortcut for usingText.withText(String...)
followed byTextAccessor.TextProvider.toStrings()
. Implementation requirements: This method must not(!) be implemented by callingText.withText(String...)
followed byTextAccessor.TextProvider.toStrings()
(do not change the text property) as this would not be thread safe!- Specified by:
toStrings
in interfaceText<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 interfaceorg.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 theString
array for the text property.- Specified by:
withText
in interfaceText<TruncateTextBuilder>
- Specified by:
withText
in interfaceTextAccessor.TextBuilder<Text<TruncateTextBuilder>>
- Parameters:
aTextLines
- TheString
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
TheString
being build by the builder upon the settings of the attributes.- Specified by:
toString
in interfaceTextAccessor.TextProvider
- Returns:
- The according resulting
String
- Throws:
IllegalStateException
- Thrown in case more than one text line has been set via thewithText(String...)
orTextAccessor.TextMutator.setText(String...)
methods.
-
asTruncated
public static String asTruncated(String aText, org.refcodes.mixin.TruncateMode aTruncateTextMode)
Returns a newString
without the according leading and/or trailing whitespaces as ofCharSet.WHITE_SPACES
.- Parameters:
aText
- The text to truncate.aTruncateTextMode
- TheTruncateMode
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 newString
without the according leading and/or trailing chars.- Parameters:
aText
- The text to truncate.aTruncateTextMode
- TheTruncateMode
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 newString
without the according leading whitespaces as ofCharSet.WHITE_SPACES
.- Parameters:
aText
- The text to truncate.- Returns:
- The accordingly truncated
String
.
-
asTruncatedLeft
public static String asTruncatedLeft(String aText, char... aChars)
Returns a newString
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 newString
without the according trailing whitespaces as ofCharSet.WHITE_SPACES
.- Parameters:
aText
- The text to truncate.- Returns:
- The accordingly truncated
String
.
-
asTruncatedRight
public static String asTruncatedRight(String aText, char... aChars)
Returns a newString
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 returnedString
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 interfaceTextAccessor
- 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 interfaceTextAccessor.TextMutator
- Parameters:
aText
- The text to be stored by the text property.
-
withText
public B withText(Collection<String> aText)
With text.- Specified by:
withText
in interfaceTextAccessor.TextBuilder<B extends Text<B>>
- Parameters:
aText
- the text- Returns:
- the b
-
toString
public String toString(String... aText)
Race condition safe shortcut for usingText.withText(String...)
followed byTextAccessor.TextProvider.toString()
. Implementation requirements: This method must not(!) be implemented by callingText.withText(String...)
followed byTextAccessor.TextProvider.toString()
(do not change the text property) as this would not be thread safe!
-
-