Class Snapshot<T>

java.lang.Object
de.serra.so_dirty.Snapshot<T>
Type Parameters:
T - The type that is being checked for differences.

public class Snapshot<T> extends Object
Creates a snapshot of an java object that can then be compared to another snappshot to check what has changed.
var myObject = new MyObject();
var previous = Snapshot.of(myObject);
// modify myObject here...
var differenceResult = previous.doDiff(myObject);
// depending on MyObject and the modifications you can check for differences
assertTrue(differenceResult.isDifferent("myField"), "Check if myField is different");
Author:
Peter Lamby
  • Method Details

    • doDiff

      public DifferenceNode doDiff(@NonNull T other)
      Diff this against other.

      Convenience method for

      this.doDiff(Snapshot.of(other, this.factory));
      
      Uses the same SnapshotNodeFactory that was used for this.

      If you want to use a different SnapshotNodeFactory use doDiff(Snapshot).

      Parameters:
      other - The object to diff against.
      Returns:
      The differences.
    • doDiff

      public DifferenceNode doDiff(@NonNull Snapshot<T> other)
      Diff this against other.
      Parameters:
      other - The snapshot to diff against.
      Returns:
      The differences.
    • of

      public static <T> Snapshot<T> of(@NonNull T val, SnapshotNodeFactory factory)
      Create a snapshot of val using factory. If val may be null use of(Object, Class) instead of this.
      Type Parameters:
      T - The type of val.
      Parameters:
      val - The value to snapshot.
      factory - The factory that should be used to create the snapshot.
      Returns:
      The snapshot.
    • of

      public static <T> Snapshot<T> of(@NonNull T val)
      Create a snapshot of val.

      Convenience method for

      Type Parameters:
      T - The type of val.
      Parameters:
      val - The value to snapshot.
      Returns:
      The snapshot.
    • of

      public static <T> Snapshot<T> of(@Nullable T val, Class<T> type, SnapshotNodeFactory factory)
      Create a snapshot of val using factory. If val may be null use this instead of of(Object).
      Type Parameters:
      T - The type of val.
      Parameters:
      val - The Instance to snapshot.
      type - The type to snapshot.
      factory - The factory that should be used to create the snapshot.
      Returns:
      The snapshot.
    • of

      public static <T> Snapshot<T> of(@Nullable T val, Class<T> type)
      Create a snapshot of val. If val may be null use this instead of of(Object).

      Convenience method for

      Type Parameters:
      T - The type of val.
      Parameters:
      val - The Instance to snapshot.
      type - The type to snapshot.
      Returns:
      The snapshot.