Class DiffImpl

  • All Implemented Interfaces:
    Diff, java.lang.Comparable<DiffImpl>, java.util.Formattable

    public class DiffImpl
    extends java.lang.Object
    implements Diff, java.lang.Comparable<DiffImpl>, java.util.Formattable
    A DiffImpl class compares a newer Element to an older Element. The Element classes hide all the low level details. A Element class is either either Structured (has children) or it is a Leaf, it only has a value. The constructor will first build its children (if any) and then calculate the delta. Each comparable element is translated to an Element. If necessary the Element can be sub classed to provide special behavior.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.Collection<DiffImpl> children  
      (package private) Delta delta  
      (package private) Tree newer  
      (package private) Tree older  
      (package private) static Delta[][] TRANSITIONS
      The transitions table defines how the state is escalated depending on the children.
    • Constructor Summary

      Constructors 
      Constructor Description
      DiffImpl​(Tree newer, Tree older)
      Compares the newer against the older, traversing the children if necessary.
    • Field Detail

      • older

        final Tree older
      • newer

        final Tree newer
      • children

        final java.util.Collection<DiffImpl> children
      • delta

        final Delta delta
      • TRANSITIONS

        static final Delta[][] TRANSITIONS
        The transitions table defines how the state is escalated depending on the children. horizontally is the current delta and this is indexed with the child delta for each child. This escalates deltas from below up.
    • Constructor Detail

      • DiffImpl

        public DiffImpl​(Tree newer,
                        Tree older)
        Compares the newer against the older, traversing the children if necessary.
        Parameters:
        newer - The newer Element
        older - The older Element
    • Method Detail

      • getDelta

        public Delta getDelta​(Diff.Ignore ignore)
        This getDelta calculates the delta but allows the caller to ignore certain Diff objects by calling back the ignore call back parameter. This can be useful to ignore warnings/errors.
        Specified by:
        getDelta in interface Diff
      • getType

        public Type getType()
        Specified by:
        getType in interface Diff
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface Diff
      • getChildren

        public java.util.Collection<? extends Diff> getChildren()
        Specified by:
        getChildren in interface Diff
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(DiffImpl other)
        Specified by:
        compareTo in interface java.lang.Comparable<DiffImpl>
      • get

        public Diff get​(java.lang.String name)
        Specified by:
        get in interface Diff
      • formatTo

        public void formatTo​(java.util.Formatter formatter,
                             int flags,
                             int width,
                             int precision)
        Specified by:
        formatTo in interface java.util.Formattable
      • format

        private static void format​(java.util.Formatter formatter,
                                   Diff diff,
                                   java.util.List<java.lang.String> formats,
                                   java.util.Set<Delta> deltas,
                                   int indent,
                                   int depth)