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, onlyExplicitlyIncluded = 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  	@Relationship(type = Constants.POINTS_TO, direction = Relationship.INCOMING)
40  	private List<DataObjectReference> incoming = new ArrayList<>();
41  
42  	/**
43  	 * For testing purposes only
44  	 *
45  	 * @param id identifies the entity
46  	 */
47  	public DataObject(long id) {
48  		super(id);
49  	}
50  
51  	public void addReference(BasicReference reference) {
52  		references.add(reference);
53  	}
54  
55  	public void addSuccessor(DataObject successor) {
56  		successors.add(successor);
57  	}
58  
59  	public void addPredecessor(DataObject predecessor) {
60  		predecessors.add(predecessor);
61  	}
62  
63  	public void addChild(DataObject child) {
64  		children.add(child);
65  	}
66  
67  	public void addIncoming(DataObjectReference dataObjectReference) {
68  		incoming.add(dataObjectReference);
69  	}
70  
71  	@Override
72  	public int hashCode() {
73  		final int prime = 31;
74  		int result = super.hashCode();
75  		result = prime * result + HasId.hashcodeHelper(collection);
76  		result = prime * result + HasId.hashcodeHelper(references);
77  		result = prime * result + HasId.hashcodeHelper(successors);
78  		result = prime * result + HasId.hashcodeHelper(predecessors);
79  		result = prime * result + HasId.hashcodeHelper(children);
80  		result = prime * result + HasId.hashcodeHelper(parent);
81  		result = prime * result + HasId.hashcodeHelper(incoming);
82  		return result;
83  	}
84  
85  	@Override
86  	public boolean equals(Object obj) {
87  		if (this == obj)
88  			return true;
89  		if (!super.equals(obj))
90  			return false;
91  		if (!(obj instanceof DataObject))
92  			return false;
93  		DataObject other = (DataObject) obj;
94  		return HasId.equalsHelper(collection, other.collection) && HasId.equalsHelper(references, other.references)
95  				&& HasId.equalsHelper(predecessors, other.predecessors)
96  				&& HasId.equalsHelper(successors, other.successors) && HasId.equalsHelper(parent, other.parent)
97  				&& HasId.equalsHelper(children, other.children) && HasId.equalsHelper(incoming, other.incoming);
98  	}
99  }