Interface Delta

All Known Subinterfaces:
DeltaNode, DeltaRange

public interface Delta
A difference found by a comparison: one or more pairs of comparable items - files and folders, blocks of text - together with the Delta.Kind of difference within each pair. DeltaNode (folder comparisons) and DeltaRange (text comparisons) are the two kinds of Delta.

A two-way comparison has a single pair, also called a relation: the item with Role.REF and the item with Role.ONE, and so a single Kind. A three-way comparison has three relations, each with its own Kind:

  • Role.ONE and Role.REF
  • Role.REF and Role.TWO
  • Role.ONE and Role.TWO

In a three-way comparison it therefore makes sense to talk about the overall result, the combination of the kinds of the individual relations. For instance, if Role.ONE and Role.REF differ by Delta.Kind.ADDED and there is no difference between Role.REF and Role.TWO, the overall result is Kind.ADDED. When more than one relation has a difference, the overall result can be a conflict or a pseudo-conflict.

The is...() methods test the overall result; kind(Role[]) returns the kind of a single relation.


 const node = nodes[i];
 if (node.isAdded()) { ... }
 else if (node.isConflict()) { ... }
 const kind = node.kind([Role.ONE, Role.REF]);
 
Since:
2.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    The kinds of difference between the two items of a relation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the children of this delta.
    Returns the parent of this delta: a DeltaNode in folder comparisons, a DeltaRange in text comparisons.
    boolean
    Answers whether this delta has children, based on the information available so far; this method does not start, or wait for, a comparison.
    boolean
    Checks whether the overall result represented by this Delta is Delta.Kind.ADDED, that is, whether every relation is either ADDED or Delta.Kind.SAME, and at least one is ADDED.
    boolean
    Checks whether the overall result represented by this Delta is Delta.Kind.CHANGED, that is, whether every relation is either CHANGED or Delta.Kind.SAME, and at least one is CHANGED.
    boolean
    Checks whether the overall result represented by this Delta is a conflict.
    boolean
    Checks whether the overall result represented by this Delta is Delta.Kind.DELETED, that is, whether every relation is either DELETED or Delta.Kind.SAME, and at least one is DELETED.
    boolean
    Checks whether the overall result is of the specified Delta.Kind: whether every relation is either of that kind or Delta.Kind.SAME, and at least one is of that kind.
    boolean
    Answers whether the overall result represented by this Delta is a pseudo-conflict: Role.ONE and Role.TWO both differ from Role.REF but are the same as each other.
    boolean
    Checks whether the overall result represented by this Delta is Delta.Kind.SAME, that is, whether there is no difference in any relation.
    kind(Role[] relation)
    Returns the Delta.Kind of difference within the specified relation, that is, pair of roles.
  • Method Details

    • getChildren

      Delta[] getChildren()
      Returns the children of this delta. In a text comparison the children are DeltaRanges representing differences within a block of text, also known as inline differences. In a folder comparison they are DeltaNodes representing the files and folders inside this folder.
      Returns:
      an array of child deltas; empty, never null, when there are no children
    • getParent

      Delta getParent()
      Returns the parent of this delta: a DeltaNode in folder comparisons, a DeltaRange in text comparisons.

      The parent is null in these cases:

      • in folder comparisons, for the root node;
      • in text comparisons, for top-level blocks of text. Only inline differences have a parent: the block of text that contains them.
      Returns:
      the parent of this Delta, or null
      Since:
      2.0
    • hasChildren

      boolean hasChildren()
      Answers whether this delta has children, based on the information available so far; this method does not start, or wait for, a comparison.
      Returns:
      true if this delta has children, false otherwise
      Since:
      2.0
    • isAdded

      boolean isAdded()
      Checks whether the overall result represented by this Delta is Delta.Kind.ADDED, that is, whether every relation is either ADDED or Delta.Kind.SAME, and at least one is ADDED.
      Returns:
      true if this difference is of type Kind#ADDED, false otherwise.
      Since:
      2.0
      See Also:
    • isChanged

      boolean isChanged()
      Checks whether the overall result represented by this Delta is Delta.Kind.CHANGED, that is, whether every relation is either CHANGED or Delta.Kind.SAME, and at least one is CHANGED.
      Returns:
      true if this difference is of type Kind#CHANGED, false otherwise.
      Since:
      2.0
      See Also:
    • isConflict

      boolean isConflict()
      Checks whether the overall result represented by this Delta is a conflict. In addition to the four Delta.Kinds, the overall result of a three-way comparison can be a conflict or a pseudo-conflict. In a conflict, both Role.ONE and Role.TWO differ from Role.REF and also differ from each other. In a pseudo-conflict, Role.ONE and Role.TWO have changed in the same way relative to Role.REF, so they are the same when compared with each other.

      Always false in a two-way comparison.

      Returns:
      true if this difference is a conflict, false otherwise.
      Since:
      2.0
    • isDeleted

      boolean isDeleted()
      Checks whether the overall result represented by this Delta is Delta.Kind.DELETED, that is, whether every relation is either DELETED or Delta.Kind.SAME, and at least one is DELETED.
      Returns:
      true if this difference is of type Kind#DELETED, false otherwise.
      Since:
      2.0
      See Also:
    • isOverallKind

      boolean isOverallKind(Delta.Kind kind)
      Checks whether the overall result is of the specified Delta.Kind: whether every relation is either of that kind or Delta.Kind.SAME, and at least one is of that kind.

      Most of the time it is the overall result that matters. In a three-way comparison with a conflict or pseudo-conflict this method returns false for every kind other than SAME, because the relations differ in more than one way.

      To get the exact Delta.Kind of a single relation, use kind(Role[]).

      Parameters:
      kind - the kind to check for
      Returns:
      true if the 'overall' Kind of this Delta is the same as the specified kind.
      Since:
      2.0
      See Also:
    • isPseudoConflict

      boolean isPseudoConflict()
      Answers whether the overall result represented by this Delta is a pseudo-conflict: Role.ONE and Role.TWO both differ from Role.REF but are the same as each other. Always false in a two-way comparison.
      Returns:
      true if this difference is a pseudo-conflict, false otherwise.
      Since:
      2.0
      See Also:
    • isSame

      boolean isSame()
      Checks whether the overall result represented by this Delta is Delta.Kind.SAME, that is, whether there is no difference in any relation.
      Returns:
      true if this difference is of type Kind#SAME, false otherwise.
      Since:
      2.0
      See Also:
    • kind

      Delta.Kind kind(Role[] relation)
      Returns the Delta.Kind of difference within the specified relation, that is, pair of roles. A two-way comparison has a single relation, Role.REF and Role.ONE. A three-way comparison has three: Role.REF and Role.ONE, Role.REF and Role.TWO, and Role.ONE and Role.TWO.
      
       const kind = delta.kind([Role.ONE, Role.REF]);
       if (kind == Delta.Kind.ADDED) { ... }
       

      Most of the time, however, it is the overall kind that matters: the kind that results from all relations together, which is also what the DeltaWalker UI shows. Use the is...() methods for that.

      A relation does not depend on the order of its roles: the kind of [Role.REF, Role.ONE] is the same as that of [Role.ONE, Role.REF]. When one of the roles is Role.REF, Delta.Kind.ADDED and Delta.Kind.DELETED are reported relative to that reference role. When a relation does not include Role.REF, for instance Role.ONE and Role.TWO, any difference is reported as Delta.Kind.CHANGED; whether content was added or deleted can be worked out from the other two relations.

      Parameters:
      relation - the two roles of the relation, in any order
      Returns:
      the Kind of the specified relation
      Since:
      2.0
      See Also: