View Javadoc
1   package de.dlr.shepard.context.references.structureddata.entities;
2   
3   import de.dlr.shepard.common.util.Constants;
4   import de.dlr.shepard.common.util.HasId;
5   import de.dlr.shepard.context.references.basicreference.entities.BasicReference;
6   import de.dlr.shepard.data.structureddata.entities.StructuredData;
7   import de.dlr.shepard.data.structureddata.entities.StructuredDataContainer;
8   import java.util.ArrayList;
9   import java.util.List;
10  import java.util.Objects;
11  import lombok.Data;
12  import lombok.NoArgsConstructor;
13  import lombok.ToString;
14  import org.neo4j.ogm.annotation.NodeEntity;
15  import org.neo4j.ogm.annotation.Relationship;
16  
17  @NodeEntity
18  @Data
19  @NoArgsConstructor
20  public class StructuredDataReference extends BasicReference {
21  
22    @Relationship(type = Constants.HAS_PAYLOAD)
23    private List<StructuredData> structuredDatas = new ArrayList<>();
24  
25    @ToString.Exclude
26    @Relationship(type = Constants.IS_IN_CONTAINER)
27    private StructuredDataContainer structuredDataContainer;
28  
29    /**
30     * For testing purposes only
31     *
32     * @param id identifies the entity
33     */
34    public StructuredDataReference(long id) {
35      super(id);
36    }
37  
38    public void addStructuredData(StructuredData structuredData) {
39      structuredDatas.add(structuredData);
40    }
41  
42    @Override
43    public int hashCode() {
44      final int prime = 31;
45      int result = super.hashCode();
46      result = prime * result + Objects.hash(structuredDatas);
47      result = prime * result + HasId.hashcodeHelper(structuredDataContainer);
48      return result;
49    }
50  
51    @Override
52    public boolean equals(Object obj) {
53      if (this == obj) return true;
54      if (!super.equals(obj)) return false;
55      if (!(obj instanceof StructuredDataReference)) return false;
56      StructuredDataReference other = (StructuredDataReference) obj;
57      return (
58        HasId.equalsHelper(structuredDataContainer, other.structuredDataContainer) &&
59        Objects.equals(structuredDatas, other.structuredDatas)
60      );
61    }
62  }