Package com.deco2800.game.utils
Class StringDecorator<T>
java.lang.Object
com.deco2800.game.utils.StringDecorator<T>
- Type Parameters:
T
- Class to decorate
public class StringDecorator<T>
extends java.lang.Object
Apply a custom toString() for a class without overriding the class, using a decorator.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description StringDecorator(T object, java.util.function.Function<T,java.lang.String> printFn)
Create a string-decorated object. -
Method Summary
Modifier and Type Method Description java.lang.String
toString()
-
Field Details
-
Constructor Details
-
StringDecorator
Create a string-decorated object.- Parameters:
object
- Object to decorate.printFn
- Function which takes the object and returns the desired string representation.
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-