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

    Fields 
    Modifier and Type Field Description
    T object  
    java.util.function.Function<T,​java.lang.String> printFn  
  • 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()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • object

      public T object
    • printFn

      public java.util.function.Function<T,​java.lang.String> printFn
  • Constructor Details

    • StringDecorator

      public StringDecorator​(T object, java.util.function.Function<T,​java.lang.String> printFn)
      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 class java.lang.Object