Package it.unimi.di.prog2.h15
Class StringFormatter
java.lang.Object
it.unimi.di.prog2.h15.StringFormatter
A class to collect a sequence of strings and format them.
This class collects strings and null
s and can return the sequence both via toString()
that concatenates non-null strings with a space, inserting a newline for each
null
, and via an iterator that returns just the non-null strings.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a string, or null, to the formatter.iterator()
Returns an iterator over the non-null strings in this formatter.toString()
Returns a string version of this formatter, non-null strings will be concatenated with a space, and a newline will be inserted for each null.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
string
The list of added strings.
-
-
Constructor Details
-
StringFormatter
public StringFormatter()Creates an empty formatter.
-
-
Method Details
-
add
Adds a string, or null, to the formatter.- Parameters:
s
- the string to add, or null.
-
toString
Returns a string version of this formatter, non-null strings will be concatenated with a space, and a newline will be inserted for each null. -
iterator
Returns an iterator over the non-null strings in this formatter.
-