1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact.repository.metadata;
20
21 import java.io.Serializable;
22
23 import static java.util.Objects.requireNonNull;
24
25 public abstract class BaseObject implements Serializable, Cloneable {
26 protected transient ChildrenTracking childrenTracking;
27
28 protected Object delegate;
29
30 public BaseObject() {}
31
32 public BaseObject(Object delegate, BaseObject parent) {
33 this.delegate = requireNonNull(delegate, "delegate cannot be null");
34 this.childrenTracking = parent != null ? parent::replace : null;
35 }
36
37 public BaseObject(Object delegate, ChildrenTracking parent) {
38 this.delegate = requireNonNull(delegate, "delegate cannot be null");
39 this.childrenTracking = parent;
40 }
41
42 public Object getDelegate() {
43 return delegate;
44 }
45
46 public void update(Object newDelegate) {
47 if (delegate != newDelegate) {
48 if (childrenTracking != null) {
49 childrenTracking.replace(delegate, newDelegate);
50 }
51 delegate = newDelegate;
52 }
53 }
54
55 protected boolean replace(Object oldDelegate, Object newDelegate) {
56 return false;
57 }
58
59 @FunctionalInterface
60 protected interface ChildrenTracking {
61 boolean replace(Object oldDelegate, Object newDelegate);
62 }
63 }