Skip to content

Commit 38c079b

Browse files
jonpereiradevJonathan Pereira
authored andcommitted
Refactory.
1 parent 1da9a2e commit 38c079b

3 files changed

Lines changed: 7 additions & 23 deletions

File tree

src/main/java/com/github/jonpereiradev/diffobjects/DiffObjects.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ public static <T> List<DiffResult<?>> diff(T beforeState, T afterState) {
2525
Objects.requireNonNull(beforeState, "Before state is required.");
2626
Objects.requireNonNull(afterState, "After state is required.");
2727

28-
List<DiffResult<?>> results = new LinkedList<>();
29-
List<DiffMetadata> metadatas = DiffReflections.mapAnnotations(beforeState.getClass());
30-
31-
for (DiffMetadata metadata : metadatas) {
32-
results.add(metadata.getStrategy().diff(beforeState, afterState, metadata));
33-
}
34-
35-
return results;
28+
return diff(beforeState, afterState, DiffReflections.mapAnnotations(beforeState.getClass()));
3629
}
3730

3831
/**
@@ -46,17 +39,8 @@ public static <T> List<DiffResult<?>> diff(T beforeState, T afterState) {
4639
public static <T> boolean isEquals(T beforeState, T afterState) {
4740
Objects.requireNonNull(beforeState, "Before state is required.");
4841
Objects.requireNonNull(afterState, "After state is required.");
49-
List<DiffMetadata> metadatas = DiffReflections.mapAnnotations(beforeState.getClass());
50-
51-
for (DiffMetadata metadata : metadatas) {
52-
DiffResult<T> result = metadata.getStrategy().diff(beforeState, afterState, metadata);
5342

54-
if (!result.isEquals()) {
55-
return false;
56-
}
57-
}
58-
59-
return true;
43+
return isEquals(beforeState, afterState, DiffReflections.mapAnnotations(beforeState.getClass()));
6044
}
6145

6246
/**

src/main/java/com/github/jonpereiradev/diffobjects/strategy/DiffReflections.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import com.github.jonpereiradev.diffobjects.annotation.DiffMapping;
55
import com.github.jonpereiradev.diffobjects.annotation.DiffMappings;
66
import com.github.jonpereiradev.diffobjects.builder.DiffBuilder;
7+
import com.github.jonpereiradev.diffobjects.builder.DiffConfigurationBuilder;
78
import com.github.jonpereiradev.diffobjects.builder.DiffInstanceBuilder;
89
import org.apache.commons.lang.StringUtils;
910
import org.apache.commons.lang.reflect.MethodUtils;
1011

1112
import java.lang.reflect.InvocationTargetException;
1213
import java.lang.reflect.Method;
13-
import java.util.List;
1414
import java.util.Map;
1515
import java.util.concurrent.ConcurrentHashMap;
1616

@@ -21,15 +21,15 @@
2121
*/
2222
public final class DiffReflections {
2323

24-
private static final Map<String, List<DiffMetadata>> CACHE_MAP = new ConcurrentHashMap<>();
24+
private static final Map<String, DiffConfigurationBuilder> CACHE_MAP = new ConcurrentHashMap<>();
2525

2626
/**
2727
* Map the methods of the object that has the annotations for diff and stores in cache.
2828
*
2929
* @param diffClass class that have the diff annotations.
3030
* @return the diff mappings of the class.
3131
*/
32-
public static List<DiffMetadata> mapAnnotations(Class<?> diffClass) {
32+
public static DiffConfigurationBuilder mapAnnotations(Class<?> diffClass) {
3333
if (!CACHE_MAP.containsKey(diffClass.getName())) {
3434
DiffInstanceBuilder builder = DiffBuilder.map(diffClass);
3535

@@ -44,7 +44,7 @@ public static List<DiffMetadata> mapAnnotations(Class<?> diffClass) {
4444
}
4545
}
4646

47-
CACHE_MAP.put(diffClass.getName(), builder.configuration().build());
47+
CACHE_MAP.put(diffClass.getName(), builder.configuration());
4848
}
4949

5050
return CACHE_MAP.get(diffClass.getName());

src/test/java/com/github/jonpereiradev/diffobjects/strategy/BaseStrategyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public abstract class BaseStrategyTest {
44

55
protected DiffMetadata discoverByName(Class<?> classMap, String name) {
6-
for (DiffMetadata metadata : DiffReflections.mapAnnotations(classMap)) {
6+
for (DiffMetadata metadata : DiffReflections.mapAnnotations(classMap).build()) {
77
if (metadata.getMethod().getName().equals(name)) {
88
return metadata;
99
}

0 commit comments

Comments
 (0)