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