|
16 | 16 |
|
17 | 17 | package de.danielbechler.diff; |
18 | 18 |
|
19 | | -import java.util.ArrayList; |
20 | | -import java.util.Collection; |
21 | | -import java.util.Set; |
22 | | - |
23 | 19 | import de.danielbechler.diff.category.CategoryConfigurer; |
24 | 20 | import de.danielbechler.diff.category.CategoryService; |
25 | 21 | import de.danielbechler.diff.circular.CircularReferenceConfigurer; |
|
38 | 34 | import de.danielbechler.diff.differ.PrimitiveDiffer; |
39 | 35 | import de.danielbechler.diff.filtering.FilteringConfigurer; |
40 | 36 | import de.danielbechler.diff.filtering.ReturnableNodeService; |
41 | | -import de.danielbechler.diff.identity.IdentityConfigurer; |
42 | | -import de.danielbechler.diff.identity.IdentityService; |
43 | 37 | import de.danielbechler.diff.inclusion.InclusionConfigurer; |
44 | 38 | import de.danielbechler.diff.inclusion.InclusionService; |
45 | 39 | import de.danielbechler.diff.introspection.IntrospectionConfigurer; |
46 | 40 | import de.danielbechler.diff.introspection.IntrospectionService; |
47 | 41 | import de.danielbechler.diff.node.DiffNode; |
48 | 42 |
|
| 43 | +import java.util.ArrayList; |
| 44 | +import java.util.Collection; |
| 45 | +import java.util.Set; |
| 46 | + |
49 | 47 | /** |
50 | 48 | * This is the entry point of every diffing operation. It acts as a factory to |
51 | 49 | * get hold of an actual {@link ObjectDiffer} instance and exposes a |
52 | 50 | * configuration API to customize its behavior to suit your needs. |
53 | 51 | * |
54 | 52 | * @author Daniel Bechler |
55 | 53 | */ |
56 | | -public class ObjectDifferBuilder { |
57 | | -privatefinalIntrospectionServiceintrospectionService = newIntrospectionService( |
58 | | - this); |
| 54 | +public class ObjectDifferBuilder |
| 55 | +{ |
| 56 | + privatefinalIntrospectionServiceintrospectionService = newIntrospectionService(this); |
59 | 57 | private final CategoryService categoryService = new CategoryService(this); |
60 | | - private final InclusionService inclusionService = new InclusionService( |
61 | | - categoryService, this); |
62 | | - private final ComparisonService comparisonService = new ComparisonService( |
63 | | - this); |
64 | | - private final IdentityService identityService = new IdentityService(this); |
65 | | - private final ReturnableNodeService returnableNodeService = new ReturnableNodeService( |
66 | | - this); |
67 | | - private final CircularReferenceService circularReferenceService = new CircularReferenceService( |
68 | | - this); |
| 58 | + private final InclusionService inclusionService = new InclusionService(categoryService, this); |
| 59 | + private final ComparisonService comparisonService = new ComparisonService(this); |
| 60 | + private final ReturnableNodeService returnableNodeService = new ReturnableNodeService(this); |
| 61 | + private final CircularReferenceService circularReferenceService = new CircularReferenceService(this); |
69 | 62 | private final DifferConfigurer differConfigurer = new DifferConfigurerImpl(); |
70 | 63 | private final NodeQueryService nodeQueryService = new NodeQueryServiceImpl(); |
71 | 64 | private final Collection<DifferFactory> differFactories = new ArrayList<DifferFactory>(); |
72 | 65 |
|
73 | | - private ObjectDifferBuilder() { |
74 | | - } |
75 | | - |
76 | | - public static ObjectDiffer buildDefault() { |
77 | | - return startBuilding().build(); |
78 | | - } |
79 | | - |
80 | | - public ObjectDiffer build() { |
81 | | - final DifferProvider differProvider = new DifferProvider(); |
82 | | - final DifferDispatcher differDispatcher = new DifferDispatcher( |
83 | | - differProvider, circularReferenceService, |
84 | | - circularReferenceService, inclusionService, |
85 | | - returnableNodeService, introspectionService); |
86 | | - differProvider.push(new BeanDiffer(differDispatcher, |
87 | | - introspectionService, returnableNodeService, comparisonService, |
88 | | - introspectionService)); |
89 | | - differProvider.push(new CollectionDiffer(differDispatcher, |
90 | | - comparisonService, identityService)); |
91 | | - differProvider.push(new MapDiffer(differDispatcher, comparisonService)); |
92 | | - differProvider.push(new PrimitiveDiffer(comparisonService)); |
93 | | - for (final DifferFactory differFactory : differFactories) { |
94 | | - differProvider.push(differFactory.createDiffer(differDispatcher, |
95 | | - nodeQueryService)); |
96 | | - } |
97 | | - return new ObjectDiffer(differDispatcher); |
98 | | - } |
99 | | - |
100 | | - public static ObjectDifferBuilder startBuilding() { |
101 | | - return new ObjectDifferBuilder(); |
| 66 | + private ObjectDifferBuilder() |
| 67 | + { |
102 | 68 | } |
103 | 69 |
|
104 | 70 | /** |
105 | 71 | * Allows to exclude nodes from being added to the object graph based on |
106 | 72 | * criteria that are only known after the diff for the affected node and all |
107 | 73 | * its children has been determined. |
108 | 74 | */ |
109 | | - public FilteringConfigurer filtering() { |
| 75 | + public FilteringConfigurer filtering() |
| 76 | + { |
110 | 77 | return returnableNodeService; |
111 | 78 | } |
112 | 79 |
|
113 | 80 | /** |
114 | 81 | * Allows to replace the default bean introspector with a custom |
115 | 82 | * implementation. |
116 | 83 | */ |
117 | | - public IntrospectionConfigurer introspection() { |
| 84 | + public IntrospectionConfigurer introspection() |
| 85 | + { |
118 | 86 | return introspectionService; |
119 | 87 | } |
120 | 88 |
|
121 | 89 | /** |
122 | 90 | * Allows to define how the circular reference detector compares object |
123 | 91 | * instances. |
124 | 92 | */ |
125 | | - public CircularReferenceConfigurer circularReferenceHandling() { |
| 93 | + public CircularReferenceConfigurer circularReferenceHandling() |
| 94 | + { |
126 | 95 | return circularReferenceService; |
127 | 96 | } |
128 | 97 |
|
129 | 98 | /** |
130 | 99 | * Allows to in- or exclude nodes based on property name, object type, |
131 | 100 | * category or location in the object graph. |
132 | 101 | */ |
133 | | - public InclusionConfigurer inclusion() { |
| 102 | + public InclusionConfigurer inclusion() |
| 103 | + { |
134 | 104 | return inclusionService; |
135 | 105 | } |
136 | 106 |
|
137 | 107 | /** |
138 | 108 | * Allows to configure the way objects are compared. |
139 | 109 | */ |
140 | | - public ComparisonConfigurer comparison() { |
| 110 | + public ComparisonConfigurer comparison() |
| 111 | + { |
141 | 112 | return comparisonService; |
142 | 113 | } |
143 | 114 |
|
144 | | - /** |
145 | | - * Allows to configure the way objects identities are established when |
146 | | - * comparing collections by CollectionDiffer. |
147 | | - */ |
148 | | - public IdentityConfigurer identity() { |
149 | | - return identityService; |
150 | | - } |
151 | | - |
152 | 115 | /** |
153 | 116 | * Allows to assign custom categories (or tags) to entire types or selected |
154 | 117 | * elements and properties. |
155 | 118 | */ |
156 | | - public CategoryConfigurer categories() { |
| 119 | + public CategoryConfigurer categories() |
| 120 | + { |
157 | 121 | return categoryService; |
158 | 122 | } |
159 | 123 |
|
160 | | - public DifferConfigurer differs() { |
| 124 | + public DifferConfigurer differs() |
| 125 | + { |
161 | 126 | return differConfigurer; |
162 | 127 | } |
163 | 128 |
|
164 | | - public class DifferConfigurerImpl implements DifferConfigurer { |
165 | | - public ObjectDifferBuilder register(final DifferFactory differFactory) { |
| 129 | + public static ObjectDiffer buildDefault() |
| 130 | + { |
| 131 | + return startBuilding().build(); |
| 132 | + } |
| 133 | + |
| 134 | + public ObjectDiffer build() |
| 135 | + { |
| 136 | + final DifferProvider differProvider = new DifferProvider(); |
| 137 | + final DifferDispatcher differDispatcher = new DifferDispatcher( |
| 138 | + differProvider, |
| 139 | + circularReferenceService, |
| 140 | + circularReferenceService, |
| 141 | + inclusionService, |
| 142 | + returnableNodeService, |
| 143 | + introspectionService); |
| 144 | + differProvider.push(new BeanDiffer( |
| 145 | + differDispatcher, |
| 146 | + introspectionService, |
| 147 | + returnableNodeService, |
| 148 | + comparisonService, |
| 149 | + introspectionService)); |
| 150 | + differProvider.push(new CollectionDiffer(differDispatcher, comparisonService, comparisonService)); |
| 151 | + differProvider.push(new MapDiffer(differDispatcher, comparisonService)); |
| 152 | + differProvider.push(new PrimitiveDiffer(comparisonService)); |
| 153 | + for (final DifferFactory differFactory : differFactories) |
| 154 | + { |
| 155 | + differProvider.push(differFactory.createDiffer(differDispatcher, nodeQueryService)); |
| 156 | + } |
| 157 | + return new ObjectDiffer(differDispatcher); |
| 158 | + } |
| 159 | + |
| 160 | + public static ObjectDifferBuilder startBuilding() |
| 161 | + { |
| 162 | + return new ObjectDifferBuilder(); |
| 163 | + } |
| 164 | + |
| 165 | + public class DifferConfigurerImpl implements DifferConfigurer |
| 166 | + { |
| 167 | + public ObjectDifferBuilder register(final DifferFactory differFactory) |
| 168 | + { |
166 | 169 | differFactories.add(differFactory); |
167 | 170 | return ObjectDifferBuilder.this; |
168 | 171 | } |
169 | 172 |
|
170 | 173 | } |
171 | 174 |
|
172 | | - private class NodeQueryServiceImpl implements NodeQueryService { |
173 | | - public Set<String> resolveCategories(final DiffNode node) { |
| 175 | + private class NodeQueryServiceImpl implements NodeQueryService |
| 176 | + { |
| 177 | + public Set<String> resolveCategories(final DiffNode node) |
| 178 | + { |
174 | 179 | return categoryService.resolveCategories(node); |
175 | 180 | } |
176 | 181 |
|
177 | | - public boolean isIntrospectable(final DiffNode node) { |
| 182 | + public boolean isIntrospectable(final DiffNode node) |
| 183 | + { |
178 | 184 | return introspectionService.isIntrospectable(node); |
179 | 185 | } |
180 | 186 |
|
181 | | - public boolean isIgnored(final DiffNode node) { |
| 187 | + public boolean isIgnored(final DiffNode node) |
| 188 | + { |
182 | 189 | return inclusionService.isIgnored(node); |
183 | 190 | } |
184 | 191 |
|
185 | | - public boolean isReturnable(final DiffNode node) { |
| 192 | + public boolean isReturnable(final DiffNode node) |
| 193 | + { |
186 | 194 | return returnableNodeService.isReturnable(node); |
187 | 195 | } |
188 | 196 |
|
189 | | - public ComparisonStrategy resolveComparisonStrategy(final DiffNode node) { |
| 197 | + public ComparisonStrategy resolveComparisonStrategy(final DiffNode node) |
| 198 | + { |
190 | 199 | return comparisonService.resolveComparisonStrategy(node); |
191 | 200 | } |
192 | 201 |
|
193 | 202 | public PrimitiveDefaultValueMode resolvePrimitiveDefaultValueMode( |
194 | | - final DiffNode node) { |
| 203 | + final DiffNode node) |
| 204 | + { |
195 | 205 | return comparisonService.resolvePrimitiveDefaultValueMode(node); |
196 | 206 | } |
197 | 207 | } |
|
0 commit comments