View Javadoc
1   package de.dlr.shepard.neo4Core.entities;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.neo4j.ogm.annotation.NodeEntity;
7   import org.neo4j.ogm.annotation.Relationship;
8   
9   import de.dlr.shepard.util.Constants;
10  import de.dlr.shepard.util.HasId;
11  import lombok.Data;
12  import lombok.NoArgsConstructor;
13  import lombok.ToString;
14  
15  @NodeEntity
16  @Data
17  @ToString(callSuper = true)
18  @NoArgsConstructor
19  public class DataObject extends AbstractDataObject {
20  
21  	@Relationship(type = Constants.HAS_DATAOBJECT, direction = Relationship.INCOMING)
22  	private Collection collection;
23  
24  	@Relationship(type = Constants.HAS_REFERENCE)
25  	private List<BasicReference> references = new ArrayList<>();
26  
27  	@Relationship(type = Constants.HAS_SUCCESSOR)
28  	private List<DataObject> successors = new ArrayList<>();
29  
30  	@Relationship(type = Constants.HAS_SUCCESSOR, direction = Relationship.INCOMING)
31  	private List<DataObject> predecessors = new ArrayList<>();
32  
33  	@Relationship(type = Constants.HAS_CHILD)
34  	private List<DataObject> children = new ArrayList<>();
35  
36  	@Relationship(type = Constants.HAS_CHILD, direction = Relationship.INCOMING)
37  	private DataObject parent;
38  
39  	@ToString.Exclude
40  	@Relationship(type = Constants.POINTS_TO, direction = Relationship.INCOMING)
41  	private List<DataObjectReference> incoming = new ArrayList<>();
42  
43  	/**
44  	 * For testing purposes only
45  	 *
46  	 * @param id identifies the entity
47  	 */
48  	public DataObject(long id) {
49  		super(id);
50  	}
51  
52  	public void addReference(BasicReference reference) {
53  		references.add(reference);
54  	}
55  
56  	public void addSuccessor(DataObject successor) {
57  		successors.add(successor);
58  	}
59  
60  	public void addPredecessor(DataObject predecessor) {
61  		predecessors.add(predecessor);
62  	}
63  
64  	public void addChild(DataObject child) {
65  		children.add(child);
66  	}
67  
68  	public void addIncoming(DataObjectReference dataObjectReference) {
69  		incoming.add(dataObjectReference);
70  	}
71  
72  	@Override
73  	public int hashCode() {
74  		final int prime = 31;
75  		int result = super.hashCode();
76  		result = prime * result + HasId.hashcodeHelper(collection);
77  		result = prime * result + HasId.hashcodeHelper(references);
78  		result = prime * result + HasId.hashcodeHelper(successors);
79  		result = prime * result + HasId.hashcodeHelper(predecessors);
80  		result = prime * result + HasId.hashcodeHelper(children);
81  		result = prime * result + HasId.hashcodeHelper(parent);
82  		result = prime * result + HasId.hashcodeHelper(incoming);
83  		return result;
84  	}
85  
86  	@Override
87  	public boolean equals(Object obj) {
88  		if (this == obj)
89  			return true;
90  		if (!super.equals(obj))
91  			return false;
92  		if (!(obj instanceof DataObject))
93  			return false;
94  		DataObject other = (DataObject) obj;
95  		return HasId.equalsHelper(collection, other.collection) && HasId.equalsHelper(references, other.references)
96  				&& HasId.equalsHelper(predecessors, other.predecessors)
97  				&& HasId.equalsHelper(successors, other.successors) && HasId.equalsHelper(parent, other.parent)
98  				&& HasId.equalsHelper(children, other.children) && HasId.equalsHelper(incoming, other.incoming);
99  	}
100 }