Package squidpony.panel
Class IColoredString.Impl<T>
java.lang.Object
squidpony.panel.IColoredString.Impl<T>
- Type Parameters:
T- The type of colors
- All Implemented Interfaces:
Iterable<IColoredString.Bucket<T>>,IColoredString<T>
- Enclosing interface:
- IColoredString<T>
public static class IColoredString.Impl<T> extends Object implements IColoredString<T>
A basic implementation of
IColoredString.- Author:
- smelC
-
Nested Class Summary
Nested classes/interfaces inherited from interface squidpony.panel.IColoredString
IColoredString.Bucket<T>, IColoredString.Impl<T> -
Field Summary
Fields Modifier and Type Field Description protected ArrayList<IColoredString.Bucket<T>>fragments -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidappend(char c)A convenience alias forappend(c, null).voidappend(char c, T color)Mutatesthisby appendingcto it.voidappend(String text)A convenience alias forappend(text, null).voidappend(String text, T color)Mutatesthisby appendingtextto it.voidappend(IColoredString.Bucket<T> bucket)voidappend(IColoredString<T> other)Mutatesthisby appendingotherto it.voidappendFloat(float f, T color)Mutatesthisby appendingfto it.voidappendInt(int i, T color)Mutatesthisby appendingito it.charcharAt(int index)voidclear()Emptiesthis.static <T> IColoredString.Impl<T>clone(IColoredString<T> toClone)TcolorAt(int index)static <T> IColoredString.Impl<T>create()A static constructor, to avoid having to write<T>in the caller.static <T> IColoredString.Impl<T>create(String s)A convenience method, equivalent tocreate(s, null).static <T> IColoredString.Impl<T>create(String s, T t)A static constructor, to avoid having to write<T>in the caller.protected static booleanequals(Object o1, Object o2)static <T> booleanequals(IColoredString<T> one, IColoredString<T> two)ArrayList<IColoredString.Bucket<T>>getFragments()Gets the Buckets as an ArrayList, allowing access by index instead of byiterator().booleanisEmpty()ListIterator<IColoredString.Bucket<T>>iterator()IColoredString<T>justify(int width)This method does NOT guarantee that the result's length iswidth.TlastColor()This method is typically more efficient thanIColoredString.colorAt(int).intlength()Stringpresent()StringpresentWithMarkup(IMarkup<T> markup)Given some way of converting from a T value to an in-line markup tag, returns a string representation of this IColoredString with in-line markup representing colors.voidreplaceColor(T old, T new_)Replace coloroldbynew_in all buckets ofthis.voidsetColor(T color)Setcolorin all buckets.voidsetLength(int len)Deletes all content after indexlen(if any).StringtoString()List<IColoredString<T>>wrap(int width)List<IColoredString<T>>wrap(int width, List<IColoredString<T>> buf)
-
Field Details
-
Constructor Details
-
Method Details
-
create
A static constructor, to avoid having to write<T>in the caller.- Returns:
new Impl(s, t).
-
create
A convenience method, equivalent tocreate(s, null).- Parameters:
s-- Returns:
create(s, null)
-
create
A static constructor, to avoid having to write<T>in the caller.- Returns:
new Impl(s, t).
-
clone
-
equals
- Parameters:
one-two-- Returns:
- Whether
onerepresents the same content astwo.
-
append
Description copied from interface:IColoredStringA convenience alias forappend(c, null).- Specified by:
appendin interfaceIColoredString<T>- Parameters:
c- the char to append
-
append
Description copied from interface:IColoredStringMutatesthisby appendingcto it.- Specified by:
appendin interfaceIColoredString<T>- Parameters:
c- The text to append.color-text's color. Ornullto let the panel decide.
-
append
Description copied from interface:IColoredStringA convenience alias forappend(text, null).- Specified by:
appendin interfaceIColoredString<T>
-
append
Description copied from interface:IColoredStringMutatesthisby appendingtextto it. Does nothing iftextisnull.- Specified by:
appendin interfaceIColoredString<T>- Parameters:
text- The text to append.color-text's color. Ornullto let the panel decide.
-
appendInt
Description copied from interface:IColoredStringMutatesthisby appendingito it.- Specified by:
appendIntin interfaceIColoredString<T>- Parameters:
i- The int to append.color-text's color. Ornullto let the panel decide.
-
appendFloat
Description copied from interface:IColoredStringMutatesthisby appendingfto it.- Specified by:
appendFloatin interfaceIColoredString<T>- Parameters:
f- The float to append.color-text's color. Ornullto let the panel decide.
-
append
Description copied from interface:IColoredStringMutatesthisby appendingotherto it.- Specified by:
appendin interfaceIColoredString<T>
-
replaceColor
Description copied from interface:IColoredStringReplace coloroldbynew_in all buckets ofthis.- Specified by:
replaceColorin interfaceIColoredString<T>- Parameters:
old- The color to replace.new_- The replacing color.
-
setColor
Description copied from interface:IColoredStringSetcolorin all buckets.- Specified by:
setColorin interfaceIColoredString<T>
-
append
-
setLength
Description copied from interface:IColoredStringDeletes all content after indexlen(if any).- Specified by:
setLengthin interfaceIColoredString<T>
-
wrap
- Specified by:
wrapin interfaceIColoredString<T>- Parameters:
width- A positive integer- Returns:
thissplit in pieces that would fit in a display withwidthcolumns (if all words inthisare smaller or equal in length towidth, otherwise wrapping will fail for these words).
-
wrap
- Specified by:
wrapin interfaceIColoredString<T>- Parameters:
width- A positive integerbuf- A List of IColoredString with the same T type as this; will have the wrapped contents appended to it. Cannot be null, and if it has existing contents, they will be left as-is.- Returns:
bufcontainingthissplit in pieces that would fit in a display withwidthcolumns (if all words inthisare smaller or equal in length towidth, otherwise wrapping will fail for these words).
-
justify
Description copied from interface:IColoredStringThis method does NOT guarantee that the result's length iswidth. It is impossible to do correct justifying ifthis's length is greater thanwidthor ifthishas no space character.- Specified by:
justifyin interfaceIColoredString<T>- Returns:
- A variant of
thiswhere spaces have been introduced in-between words, so thatthis's length is as close as possible towidth. Orthisitself if unaffected.
-
clear
Description copied from interface:IColoredStringEmptiesthis.- Specified by:
clearin interfaceIColoredString<T>
-
length
- Specified by:
lengthin interfaceIColoredString<T>- Returns:
- The length of text.
-
isEmpty
- Specified by:
isEmptyin interfaceIColoredString<T>- Returns:
trueifIColoredString.present()is"".
-
lastColor
Description copied from interface:IColoredStringThis method is typically more efficient thanIColoredString.colorAt(int).- Specified by:
lastColorin interfaceIColoredString<T>- Returns:
- The color of the last bucket, if any.
-
colorAt
- Specified by:
colorAtin interfaceIColoredString<T>- Returns:
- The color at
index, if any.
-
charAt
- Specified by:
charAtin interfaceIColoredString<T>- Returns:
- The character at
index, if any.
-
present
- Specified by:
presentin interfaceIColoredString<T>- Returns:
- The text that
thisrepresents.
-
presentWithMarkup
Given some way of converting from a T value to an in-line markup tag, returns a string representation of this IColoredString with in-line markup representing colors.- Specified by:
presentWithMarkupin interfaceIColoredString<T>- Parameters:
markup- an IMarkup implementation- Returns:
- a String with markup inserted inside.
-
iterator
-
toString
-
equals
-
getFragments
Gets the Buckets as an ArrayList, allowing access by index instead of byiterator().- Specified by:
getFragmentsin interfaceIColoredString<T>- Returns:
- the Buckets that would be returned by
iterator(), but in an ArrayList.
-