Package 

Class Stringifier


  • 
    public abstract class Stringifier
    
                        

    The Stringifier class provides the ability to define Class -> String conversions using the Definition DSL.

    A subclass of Stringifier should only ever be instantiated once, which is when it is loaded. This is because it is preferable to declare a subclass as an object instead of a class, as it reduces the redundancy caused by running the configuration constructor property more than once.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private String indent
    • Method Summary

      Modifier and Type Method Description
      final String getIndent() The indentation string that is appended before every print in a Definition if the indentation level is higher than 0.
      final Unit setIndent(String indent) The indentation string that is appended before every print in a Definition if the indentation level is higher than 0.
      final <T extends Any> Unit define(Function2<Definition, T, String> conversion) Defines a new conversion for this Stringifier.
      final <T extends Any> String convert(T obj, Definition definition) Converts an object to a String using a conversion gotten from the object's type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Stringifier

        Stringifier(Function1<Stringifier, Unit> configuration)
        Parameters:
        configuration - The configuration for this stringifier, allows declaring conversions upon class initialization.
    • Method Detail

      • getIndent

         final String getIndent()

        The indentation string that is appended before every print in a Definition if the indentation level is higher than 0.

        By default, this string is a single tab character, \t.

      • setIndent

         final Unit setIndent(String indent)

        The indentation string that is appended before every print in a Definition if the indentation level is higher than 0.

        By default, this string is a single tab character, \t.

      • define

         final <T extends Any> Unit define(Function2<Definition, T, String> conversion)

        Defines a new conversion for this Stringifier.

        A conversion produces a String, given an object with the type of the specified type parameter, and the receiver type of a conversion is a Definition.

        Parameters:
        conversion - the conversion to be defined
      • convert

         final <T extends Any> String convert(T obj, Definition definition)

        Converts an object to a String using a conversion gotten from the object's type.

        Parameters:
        obj - the object to be converted based upon its class
        definition - a Definition instance that is used to convert the object to a String