View Javadoc
1   package de.dlr.shepard.common.neo4j.entities;
2   
3   import de.dlr.shepard.common.util.Constants;
4   import de.dlr.shepard.common.util.HasId;
5   import de.dlr.shepard.context.semantic.entities.SemanticAnnotation;
6   import java.util.ArrayList;
7   import java.util.List;
8   import java.util.Objects;
9   import lombok.Getter;
10  import lombok.NoArgsConstructor;
11  import lombok.Setter;
12  import lombok.ToString;
13  import org.neo4j.ogm.annotation.Relationship;
14  
15  @Getter
16  @Setter
17  @ToString
18  @NoArgsConstructor
19  public class BasicEntity extends AbstractEntity {
20  
21    protected String name;
22  
23    @ToString.Exclude
24    @Relationship(type = Constants.HAS_ANNOTATION)
25    private List<SemanticAnnotation> annotations = new ArrayList<>();
26  
27    /**
28     * For testing purposes only
29     *
30     * @param id identifies the entity
31     */
32    public BasicEntity(long id) {
33      super(id);
34    }
35  
36    public void addAnnotation(SemanticAnnotation annotation) {
37      annotations.add(annotation);
38    }
39  
40    public long getNumericId() {
41      return getId();
42    }
43  
44    @Override
45    public int hashCode() {
46      final int prime = 31;
47      int result = 1;
48      result = prime * result + Objects.hash(id, deleted, createdAt, updatedAt, name);
49      result = prime * result + HasId.hashcodeHelper(createdBy);
50      result = prime * result + HasId.hashcodeHelper(updatedBy);
51      result = prime * result + HasId.hashcodeHelper(annotations);
52      return result;
53    }
54  
55    @Override
56    public boolean equals(Object obj) {
57      if (this == obj) return true;
58      if (!(obj instanceof BasicEntity)) return false;
59      BasicEntity other = (BasicEntity) obj;
60      return (
61        Objects.equals(id, other.id) &&
62        deleted == other.deleted &&
63        Objects.equals(createdAt, other.createdAt) &&
64        Objects.equals(updatedAt, other.updatedAt) &&
65        HasId.equalsHelper(createdBy, other.createdBy) &&
66        HasId.equalsHelper(updatedBy, other.updatedBy) &&
67        Objects.equals(name, other.name) &&
68        HasId.areEqualSetsByUniqueId(annotations, other.annotations)
69      );
70    }
71  }