Class Mutaters

java.lang.Object
org.apache.juneau.reflect.Mutaters

public class Mutaters extends Object
Cache of object that convert POJOs to and from common types such as strings, readers, and input streams.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Mutater<Object,Object>
    Represents a non-existent transform.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    add(Class<?> ic, Class<?> oc, Mutater<?,?> t)
    Adds a transform for the specified input/output types.
    static <T> T
    Constructs a new instance of the specified class from the specified string.
    static <I, O> Mutater<I,O>
    get(Class<I> ic, Class<O> oc)
    Returns the transform for converting the specified input type to the specified output type.
    static <I, O> boolean
    hasMutate(Class<I> ic, Class<O> oc)
    Returns the transform for converting the specified input type to the specified output type.
    static String
    Converts an object to a string.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • add

      public static void add(Class<?> ic, Class<?> oc, Mutater<?,?> t)
      Adds a transform for the specified input/output types.
      Parameters:
      ic - The input type.
      oc - The output type.
      t - The transform for converting the input to the output.
    • get

      public static <I, O> Mutater<I,O> get(Class<I> ic, Class<O> oc)
      Returns the transform for converting the specified input type to the specified output type.
      Type Parameters:
      I - The input type.
      O - The output type.
      Parameters:
      ic - The input type.
      oc - The output type.
      Returns:
      The transform for performing the conversion, or null if the conversion cannot be made.
    • hasMutate

      public static <I, O> boolean hasMutate(Class<I> ic, Class<O> oc)
      Returns the transform for converting the specified input type to the specified output type.
      Type Parameters:
      I - The input type.
      O - The output type.
      Parameters:
      ic - The input type.
      oc - The output type.
      Returns:
      The transform for performing the conversion, or null if the conversion cannot be made.
    • fromString

      public static <T> T fromString(Class<T> c, String s)
      Constructs a new instance of the specified class from the specified string.

      Class must be one of the following:

      • Have a public constructor that takes in a single String argument.
      • Have a static fromString(String) (or related) method.
      • Be an enum.
      Type Parameters:
      T - The class type.
      Parameters:
      c - The class type.
      s - The string to create the instance from.
      Returns:
      A new object instance, or null if a method for converting the string to an object could not be found.
    • toString

      public static String toString(Object o)
      Converts an object to a string.

      Normally, this is just going to call toString() on the object. However, the Locale and TimeZone objects are treated special so that the returned value works with the fromString(Class, String) method.

      Parameters:
      o - The object to convert to a string.
      Returns:
      The stringified object, or null if the object was null.