@Test public void testDiffListOnAnnotationNodesWithArrayValues() throws Exception { AnnotationNode original = new AnnotationNode("Ltest/SomeAnnotation;"); original.visit("byteArray", new byte[] {1, 2, 3}); original.visit("booleanArray", new boolean[] {false, true, false}); original.visit("shortArray", new short[] {1, 2, 3}); original.visit("charArray", new char[] {'a', 'b', 'c'}); original.visit("intArray", new int[] {1, 2, 3}); original.visit("longArray", new long[] {1, 2, 3}); original.visit("floatArray", new float[] {1, 2, 3}); original.visit("doubleArray", new double[] {1, 2, 3}); original.visit("stringArray", new String[] {"1", "2", "3"}); AnnotationNode updated = new AnnotationNode("Ltest/SomeAnnotation;"); updated.visit("byteArray", new byte[] {1, 2, 3}); updated.visit("booleanArray", new boolean[] {false, true, false}); updated.visit("shortArray", new short[] {1, 2, 3}); updated.visit("charArray", new char[] {'a', 'b', 'c'}); updated.visit("intArray", new int[] {1, 2, 3}); updated.visit("longArray", new long[] {1, 2, 3}); updated.visit("floatArray", new float[] {1, 2, 3}); updated.visit("doubleArray", new double[] {1, 2, 3}); updated.visit("stringArray", new String[] {"1", "2", "3"}); 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);  }