@Test public void testDiffListOnAnnotationNodesWithAnnotationArrayValue() throws Exception { AnnotationNode original = new AnnotationNode("Ltest/SomeAnnotation;"); AnnotationVisitor arrayVisitor = original.visitArray("test"); AnnotationVisitor newAnnotation = arrayVisitor.visitAnnotation("InnerAnnotation", "LTest;"); newAnnotation.visit("innerEntry", "innerValue"); newAnnotation.visitEnd(); newAnnotation = arrayVisitor.visitAnnotation("InnerAnnotation", "LTest;"); newAnnotation.visit("innerEntry", "innerValue"); newAnnotation.visitEnd(); arrayVisitor.visitEnd(); AnnotationNode updated = new AnnotationNode("Ltest/SomeAnnotation;"); arrayVisitor = updated.visitArray("test"); newAnnotation = arrayVisitor.visitAnnotation("InnerAnnotation", "LTest;"); newAnnotation.visit("innerEntry", "innerValue"); newAnnotation.visitEnd(); newAnnotation = arrayVisitor.visitAnnotation("InnerAnnotation", "LTest;"); newAnnotation.visit("innerEntry", "innerValue"); newAnnotation.visitEnd(); arrayVisitor.visitEnd(); assertEquals( InstantRunVerifier.Diff.NONE, InstantRunVerifier.diffList( Lists.newArrayList(original), Lists.newArrayList(updated), InstantRunVerifier.ANNOTATION_COMPARATOR)); }
@VisibleForTesting @NonNull static <T> Diff diffList( @Nullable List<T> one, @Nullable List<T> two, @NonNull Comparator<T> comparator) { if (one == null && two == null) { return Diff.NONE; } if (one == null) { return Diff.ADDITION; } if (two == null) { return Diff.REMOVAL; } List<T> copyOfOne = new ArrayList<T>(one); List<T> copyOfTwo = new ArrayList<T>(two); for (T elementOfTwo : two) { T commonElement = getElementOf(copyOfOne, elementOfTwo, comparator); if (commonElement != null) { copyOfOne.remove(commonElement); } } for (T elementOfOne : one) { T commonElement = getElementOf(copyOfTwo, elementOfOne, comparator); if (commonElement != null) { copyOfTwo.remove(commonElement); } } if ((!copyOfOne.isEmpty()) && (copyOfOne.size() == copyOfTwo.size())) { return Diff.CHANGE; } if (!copyOfOne.isEmpty()) { return Diff.REMOVAL; } return copyOfTwo.isEmpty() ? Diff.NONE : Diff.ADDITION; }
InstantRunVerifier { @VisibleForTesting @NonNull static <T> Diff diffList( @Nullable List<T> one, @Nullable List<T> two, @NonNull Comparator<T> comparator) { if (one == null && two == null) { return Diff.NONE; } if (one == null) { return Diff.ADDITION; } if (two == null) { return Diff.REMOVAL; } List<T> copyOfOne = new ArrayList<T>(one); List<T> copyOfTwo = new ArrayList<T>(two); for (T elementOfTwo : two) { T commonElement = getElementOf(copyOfOne, elementOfTwo, comparator); if (commonElement != null) { copyOfOne.remove(commonElement); } } for (T elementOfOne : one) { T commonElement = getElementOf(copyOfTwo, elementOfOne, comparator); if (commonElement != null) { copyOfTwo.remove(commonElement); } } if ((!copyOfOne.isEmpty()) && (copyOfOne.size() == copyOfTwo.size())) { return Diff.CHANGE; } if (!copyOfOne.isEmpty()) { return Diff.REMOVAL; } return copyOfTwo.isEmpty() ? Diff.NONE : Diff.ADDITION; } }
InstantRunVerifier { @VisibleForTesting @NonNull static <T> Diff diffList( @Nullable List<T> one, @Nullable List<T> two, @NonNull Comparator<T> comparator) { if (one == null && two == null) { return Diff.NONE; } if (one == null) { return Diff.ADDITION; } if (two == null) { return Diff.REMOVAL; } List<T> copyOfOne = new ArrayList<T>(one); List<T> copyOfTwo = new ArrayList<T>(two); for (T elementOfTwo : two) { T commonElement = getElementOf(copyOfOne, elementOfTwo, comparator); if (commonElement != null) { copyOfOne.remove(commonElement); } } for (T elementOfOne : one) { T commonElement = getElementOf(copyOfTwo, elementOfOne, comparator); if (commonElement != null) { copyOfTwo.remove(commonElement); } } if ((!copyOfOne.isEmpty()) && (copyOfOne.size() == copyOfTwo.size())) { return Diff.CHANGE; } if (!copyOfOne.isEmpty()) { return Diff.REMOVAL; } return copyOfTwo.isEmpty() ? Diff.NONE : Diff.ADDITION; } private  InstantRunVerifier(); }
InstantRunVerifier { @VisibleForTesting @NonNull static <T> Diff diffList( @Nullable List<T> one, @Nullable List<T> two, @NonNull Comparator<T> comparator) { if (one == null && two == null) { return Diff.NONE; } if (one == null) { return Diff.ADDITION; } if (two == null) { return Diff.REMOVAL; } List<T> copyOfOne = new ArrayList<T>(one); List<T> copyOfTwo = new ArrayList<T>(two); for (T elementOfTwo : two) { T commonElement = getElementOf(copyOfOne, elementOfTwo, comparator); if (commonElement != null) { copyOfOne.remove(commonElement); } } for (T elementOfOne : one) { T commonElement = getElementOf(copyOfTwo, elementOfOne, comparator); if (commonElement != null) { copyOfTwo.remove(commonElement); } } if ((!copyOfOne.isEmpty()) && (copyOfOne.size() == copyOfTwo.size())) { return Diff.CHANGE; } if (!copyOfOne.isEmpty()) { return Diff.REMOVAL; } return copyOfTwo.isEmpty() ? Diff.NONE : Diff.ADDITION; } private  InstantRunVerifier(); static InstantRunVerifierStatus run(File original, File updated); @SuppressWarnings("unchecked") @NonNull static InstantRunVerifierStatus run(ClassBytesProvider original, ClassBytesProvider updated); @Nullable static T getElementOf(List<T> list, T element, Comparator<T> comparator); }
InstantRunVerifier { @VisibleForTesting @NonNull static <T> Diff diffList( @Nullable List<T> one, @Nullable List<T> two, @NonNull Comparator<T> comparator) { if (one == null && two == null) { return Diff.NONE; } if (one == null) { return Diff.ADDITION; } if (two == null) { return Diff.REMOVAL; } List<T> copyOfOne = new ArrayList<T>(one); List<T> copyOfTwo = new ArrayList<T>(two); for (T elementOfTwo : two) { T commonElement = getElementOf(copyOfOne, elementOfTwo, comparator); if (commonElement != null) { copyOfOne.remove(commonElement); } } for (T elementOfOne : one) { T commonElement = getElementOf(copyOfTwo, elementOfOne, comparator); if (commonElement != null) { copyOfTwo.remove(commonElement); } } if ((!copyOfOne.isEmpty()) && (copyOfOne.size() == copyOfTwo.size())) { return Diff.CHANGE; } if (!copyOfOne.isEmpty()) { return Diff.REMOVAL; } return copyOfTwo.isEmpty() ? Diff.NONE : Diff.ADDITION; } private  InstantRunVerifier(); static InstantRunVerifierStatus run(File original, File updated); @SuppressWarnings("unchecked") @NonNull static InstantRunVerifierStatus run(ClassBytesProvider original, ClassBytesProvider updated); @Nullable static T getElementOf(List<T> list, T element, Comparator<T> comparator);  }