@@ -65,7 +65,17 @@ public class DiffNode
6565 private Class <?> valueType ;
6666 private TypeInfo valueTypeInfo ;
6767
68- public DiffNode (final Accessor accessor , final Class <?> valueType )
68+ public static DiffNode newRootNode ()
69+ {
70+ return new DiffNode ();
71+ }
72+
73+ /**
74+ * @deprecated Only used in tests. Doesn't really make sense in the real world, as no parent node implies the
75+ * RootAccessor
76+ */
77+ @ Deprecated
78+ DiffNode (final Accessor accessor , final Class <?> valueType )
6979 {
7080 this (ROOT , accessor , valueType );
7181 }
@@ -78,12 +88,26 @@ public DiffNode(final DiffNode parentNode, final Accessor accessor, final Class<
7888 setParentNode (parentNode );
7989 }
8090
91+ public DiffNode (final DiffNode parentNode , final Accessor accessor )
92+ {
93+ this (parentNode , accessor , null );
94+ }
95+
96+ public DiffNode (final Accessor accessor )
97+ {
98+ this (null , accessor , null );
99+ }
100+
101+ /**
102+ * @deprecated Only used in tests
103+ */
104+ @ Deprecated
81105 public DiffNode (final Class <?> valueType )
82106 {
83107 this (ROOT , RootAccessor .getInstance (), valueType );
84108 }
85109
86- public DiffNode ()
110+ private DiffNode ()
87111 {
88112 this (ROOT , RootAccessor .getInstance (), null );
89113 }
@@ -336,43 +360,33 @@ else if (selectors.size() > 1)
336360 *
337361 * @param node The node to add.
338362 */
339- public boolean addChild (final DiffNode node )
363+ public void addChild (final DiffNode node )
340364 {
341- if (node .isRootNode ())
342- {
343- throw new IllegalArgumentException ("Detected attempt to add root node as child. " +
344- "This is not allowed and must be a mistake." );
345- }
346- else if (node == this )
365+ if (node == this )
347366 {
348367 throw new IllegalArgumentException ("Detected attempt to add a node to itself. " +
349368 "This would cause inifite loops and must never happen." );
350369 }
370+ else if (node .isRootNode ())
371+ {
372+ throw new IllegalArgumentException ("Detected attempt to add root node as child. " +
373+ "This is not allowed and must be a mistake." );
374+ }
351375 else if (node .getParentNode () != null && node .getParentNode () != this )
352376 {
353377 throw new IllegalArgumentException ("Detected attempt to add child node that is already the " +
354378 "child of another node. Adding nodes multiple times is not allowed, since it could " +
355379 "cause infinite loops." );
356380 }
357- final ElementSelector pathElementSelector = node .getElementSelector ();
358381 if (node .getParentNode () == null )
359382 {
360383 node .setParentNode (this );
361- children .put (pathElementSelector , node );
362- }
363- else if (node .getParentNode () == this )
364- {
365- children .put (pathElementSelector , node );
366- }
367- else
368- {
369- throw new IllegalStateException ("Detected attempt to replace the parent node of node at path '" + getPath () + "'" );
370384 }
385+ children .put (node .getElementSelector (), node );
371386 if (state == State .UNTOUCHED && node .hasChanges ())
372387 {
373388 state = State .CHANGED ;
374389 }
375- return true ;
376390 }
377391
378392 /**
0 commit comments