-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathGraphEntity.java
More file actions
104 lines (82 loc) · 2.27 KB
/
GraphEntity.java
File metadata and controls
104 lines (82 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.redislabs.redisgraph.graph_entities;
import java.util.*;
/**
* This is an abstract class for representing a graph entity.
* A graph entity has an id and a set of properties. The properties are mapped and accessed by their names.
*/
public abstract class GraphEntity {
//members
protected long id;
protected final Map<String, Property<?>> propertyMap = new HashMap<>();
//setters & getters
public Map<String, Property<?>> getPropertyMap() {
return propertyMap;
}
/**
* @return entity id
*/
public long getId() {
return id;
}
/**
* @param id - entity id to be set
*/
public void setId(long id) {
this.id = id;
}
/**
* Adds a property to the entity, by composing name, type and value to a property object
*
* @param name
* @param value
*/
public void addProperty(String name, Object value) {
addProperty(new Property(name, value));
}
/**
* @return Entity's property names, as a Set
*/
public Set<String> getEntityPropertyNames() {
return propertyMap.keySet();
}
/**
* Add a property to the entity
*
* @param property
*/
public void addProperty(Property property) {
propertyMap.put(property.getName(), property);
}
/**
* @return number of properties
*/
public int getNumberOfProperties() {
return propertyMap.size();
}
/**
* @param propertyName - property name as lookup key (String)
* @return property object, or null if key is not found
*/
public Property getProperty(String propertyName) {
return propertyMap.get(propertyName);
}
/**
* @param name - the name of the property to be removed
*/
public void removeProperty(String name) {
propertyMap.remove(name);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GraphEntity)) return false;
GraphEntity that = (GraphEntity) o;
return id == that.id &&
Objects.equals(propertyMap, that.propertyMap);
}
@Override
public int hashCode() {
return Objects.hash(id, propertyMap);
}
public abstract String toString();
}