Class DynamicRewriter<C>

java.lang.Object
eu.bandm.tools.util.classes.DynamicRewriter<C>

public abstract class DynamicRewriter<C> extends Object
An abstract base class for reflection-based type case distinctions. Subclasses should overload the rewrite(java.lang.Class<R>, C, boolean) method with a method B rewrite(A x) to match objects of class A, and replace them by objects of class B. Methods of subclasses will only be considered as matches for an input if they have
  • Constructor Details

    • DynamicRewriter

      public DynamicRewriter()
  • Method Details

    • rewrite

      public <R> R rewrite(Class<R> targetClass, C x, boolean total)
      Finds the best-matching rewrite method for the dynamic type of a given object and invokes it.
      Parameters:
      targetClass - the expected class of the result.
      x - the input object.
      total - if true and x is null or no match is found, then x is cast to the class targetClass and returned.
      Throws:
      IllegalArgumentException - if the matching method throws an exception or cannot be invoked for some reason, or if total is false and no match is found.
      ClassCastException - if the result cannot be cast to the class targetClass.
      NullPointerException - if total is false and x is null.