Package com.iizix

Class CircularReferenceFinder<INPUT,TARGET>

java.lang.Object
com.iizix.CircularReferenceFinder<INPUT,TARGET>
Direct Known Subclasses:
ExtendsCircularReferenceFinder

public class CircularReferenceFinder<INPUT,TARGET> extends Object
Helper class to find circular references.
Author:
Christopher Mindus
  • Constructor Details

    • CircularReferenceFinder

      public CircularReferenceFinder(INPUT input, ICircularReference<INPUT,TARGET> finder)
      Constructs the circular reference finder.
      Parameters:
      input - The input reference.
      finder - The finder implementing instance.
  • Method Details

    • isValid

      public boolean isValid()
      Checks if the reference is valid and that it is not circular.
      Returns:
      true if no error is set, i.e. error is null.
    • getError

      public String getError()
      Gets the error message.
      Returns:
      Error string for circular finder check, or null for no error.
    • getFirstTarget

      public TARGET getFirstTarget()
      Gets the first target found.

      This target is ONLY set if there was a single target reference found, and is null if there are more than one.

      Returns:
      The first target found, or null for none.
    • getLastTarget

      public TARGET getLastTarget()
      Gets the last target found, it is the same value as the first if just one reference chain exists. In case of a circular reference error, the last target is the circular reference error cause.
      Returns:
      The last target found, or null for none.
    • getChainCount

      public int getChainCount()
      Gets the count of chains for all references. This value is an indication to the complexity of the references, and is only really useful if there can be only one reference target per input.
      Returns:
      The chain count.
    • hasMultipleTargets

      public boolean hasMultipleTargets()
      Checks if at least one input caused multiple targets. If this method returns true, the methods getFirstTarget(), getLastTarget() and getChainCount() should not be used.
      Returns:
      true if a problem exists with multiple targets, false otherwise.
    • inputToString

      protected String inputToString(INPUT input)
      Converts an input to a String.

      Override to provide a method for input.toString().

      Parameters:
      input - The input reference.
      Returns:
      The input String representation, "null" for null input.
    • outputToString

      protected String outputToString(TARGET target)
      Converts a target to a String.

      Override to provide a method for target.toString().

      Parameters:
      target - The target reference (i.e. getFirstTarget() or getLastTarget()).
      Returns:
      The target String representation, "null" for null target.
    • toString

      public String toString()
      Converts to a String representation.
      Overrides:
      toString in class Object
    • paramString

      protected String paramString()
      The parameter string. Subclasses can override to provide additional parameters, normally appended at the end of the string.
      Returns:
      The parameter string.