Skip to content

Commit 2da3306

Browse files
committed
Mostly cleanup. But I also changed the DiffNode.Visitor interface (accept => node)
1 parent 514bc67 commit 2da3306

File tree

17 files changed

+352
-367
lines changed

17 files changed

+352
-367
lines changed

src/integration-test/java/de/danielbechler/diff/example/MapEntryValueAccessExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 Daniel Bechler
2+
* Copyright 2014 Daniel Bechler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public static void main(final String[] args)
4747
final DiffNode mapNode = ObjectDifferBuilder.buildDefault().compare(working, base);
4848
mapNode.visitChildren(new DiffNode.Visitor()
4949
{
50-
public void accept(final DiffNode node, final Visit visit)
50+
public void node(final DiffNode node, final Visit visit)
5151
{
5252
final Object key = ((MapKeyElementSelector) node.getElementSelector()).getKey();
5353
// ^^^ I do not encourage this, but currently it's the only way

src/integration-test/java/de/danielbechler/diff/issues/issue66/MainApp.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 Daniel Bechler
2+
* Copyright 2014 Daniel Bechler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
1616

1717
package de.danielbechler.diff.issues.issue66;
1818

19-
import de.danielbechler.diff.node.Visit;
2019
import de.danielbechler.diff.ObjectDiffer;
2120
import de.danielbechler.diff.ObjectDifferBuilder;
2221
import de.danielbechler.diff.node.DiffNode;
22+
import de.danielbechler.diff.node.Visit;
2323

2424
public class MainApp
2525
{
@@ -41,7 +41,7 @@ public static void main(final String[] args)
4141

4242
root.visit(new DiffNode.Visitor()
4343
{
44-
public void accept(final DiffNode node, final Visit visit)
44+
public void node(final DiffNode node, final Visit visit)
4545
{
4646
System.out.print(node.getPath() + " :: ");
4747
System.out.print(node.canonicalGet(p1));

src/main/java/de/danielbechler/diff/ObjectMerger.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 Daniel Bechler
2+
* Copyright 2014 Daniel Bechler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package de.danielbechler.diff;
1818

19-
import de.danielbechler.diff.node.Visit;
2019
import de.danielbechler.diff.node.DiffNode;
20+
import de.danielbechler.diff.node.Visit;
2121

2222
/**
2323
* Careful: This class has not yet been tested very thoroughly and serves more as an example for your own
@@ -60,7 +60,7 @@ public MergingDifferenceVisitor(final T head, final T modified)
6060
this.modified = modified;
6161
}
6262

63-
public void accept(final DiffNode node, final Visit visit)
63+
public void node(final DiffNode node, final Visit visit)
6464
{
6565
if (node.getState() == DiffNode.State.ADDED)
6666
{
@@ -70,10 +70,6 @@ else if (node.getState() == DiffNode.State.REMOVED)
7070
{
7171
node.canonicalUnset(head);
7272
}
73-
else if (node.getState() == DiffNode.State.UNTOUCHED)
74-
{
75-
// not touched - nothing to do
76-
}
7773
else if (node.getState() == DiffNode.State.CHANGED)
7874
{
7975
if (node.hasChildren())

src/main/java/de/danielbechler/diff/access/Instances.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 Daniel Bechler
2+
* Copyright 2014 Daniel Bechler
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,10 +36,10 @@ public class Instances
3636
private final Object base;
3737
private final Object fresh;
3838

39-
public Instances(final Accessor sourceAccessor,
40-
final Object working,
41-
final Object base,
42-
final Object fresh)
39+
Instances(final Accessor sourceAccessor,
40+
final Object working,
41+
final Object base,
42+
final Object fresh)
4343
{
4444
Assert.notNull(sourceAccessor, "sourceAccessor");
4545
this.sourceAccessor = sourceAccessor;
@@ -160,40 +160,6 @@ public boolean isPrimitiveWrapperType()
160160
return Classes.isPrimitiveWrapperType(getType());
161161
}
162162

163-
public boolean isPrimitiveNumericType()
164-
{
165-
return Classes.isPrimitiveNumericType(getType());
166-
}
167-
168-
private boolean isPrimitiveBooleanType()
169-
{
170-
return getType() == boolean.class;
171-
}
172-
173-
public boolean areEqual()
174-
{
175-
return isEqual(base, working);
176-
}
177-
178-
public boolean areSame()
179-
{
180-
return working == base;
181-
}
182-
183-
public boolean areNull()
184-
{
185-
return working == null && base == null;
186-
}
187-
188-
private Class<?> tryToGetTypeFromSourceAccessor()
189-
{
190-
if (sourceAccessor instanceof TypeAwareAccessor)
191-
{
192-
return ((TypeAwareAccessor) sourceAccessor).getType();
193-
}
194-
return null;
195-
}
196-
197163
public Class<?> getType()
198164
{
199165
final Set<Class<?>> types = Classes.typesOf(working, base, fresh);
@@ -264,4 +230,38 @@ else if (sourceAccessorType != null)
264230
"Instances must either be null or have the exact same type.");
265231
}
266232

233+
private Class<?> tryToGetTypeFromSourceAccessor()
234+
{
235+
if (sourceAccessor instanceof TypeAwareAccessor)
236+
{
237+
return ((TypeAwareAccessor) sourceAccessor).getType();
238+
}
239+
return null;
240+
}
241+
242+
public boolean isPrimitiveNumericType()
243+
{
244+
return Classes.isPrimitiveNumericType(getType());
245+
}
246+
247+
private boolean isPrimitiveBooleanType()
248+
{
249+
return getType() == boolean.class;
250+
}
251+
252+
public boolean areEqual()
253+
{
254+
return isEqual(base, working);
255+
}
256+
257+
public boolean areSame()
258+
{
259+
return working == base;
260+
}
261+
262+
public boolean areNull()
263+
{
264+
return working == null && base == null;
265+
}
266+
267267
}

src/main/java/de/danielbechler/diff/comparison/ComparisonStrategyAware.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/de/danielbechler/diff/comparison/EqualsOnlyComparisonStrategy.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,6 @@ public EqualsOnlyComparisonStrategy(final String equalsValueProviderMethod)
4343
this.equalsValueProviderMethod = equalsValueProviderMethod;
4444
}
4545

46-
private static Object access(final Object target, final String methodName)
47-
{
48-
if (target == null)
49-
{
50-
return null;
51-
}
52-
try
53-
{
54-
final Method method = target.getClass().getMethod(methodName);
55-
method.setAccessible(true);
56-
return method.invoke(target);
57-
}
58-
catch (final NoSuchMethodException e)
59-
{
60-
throw Exceptions.escalate(e);
61-
}
62-
catch (final InvocationTargetException e)
63-
{
64-
throw Exceptions.escalate(e);
65-
}
66-
catch (final IllegalAccessException e)
67-
{
68-
throw Exceptions.escalate(e);
69-
}
70-
}
71-
7246
public void compare(final DiffNode node, final Class<?> type, final Object working, final Object base)
7347
{
7448
final boolean result;
@@ -92,8 +66,29 @@ public void compare(final DiffNode node, final Class<?> type, final Object worki
9266
}
9367
}
9468

95-
public String getEqualsValueProviderMethod()
69+
private static Object access(final Object target, final String methodName)
9670
{
97-
return equalsValueProviderMethod;
71+
if (target == null)
72+
{
73+
return null;
74+
}
75+
try
76+
{
77+
final Method method = target.getClass().getMethod(methodName);
78+
method.setAccessible(true);
79+
return method.invoke(target);
80+
}
81+
catch (final NoSuchMethodException e)
82+
{
83+
throw Exceptions.escalate(e);
84+
}
85+
catch (final InvocationTargetException e)
86+
{
87+
throw Exceptions.escalate(e);
88+
}
89+
catch (final IllegalAccessException e)
90+
{
91+
throw Exceptions.escalate(e);
92+
}
9893
}
9994
}

0 commit comments

Comments
 (0)