VirtualRelationship.java
4.57 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.util.Text
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
*/
package com.adobe.granite.socialgraph.impl;
import com.adobe.granite.socialgraph.GraphNode;
import com.adobe.granite.socialgraph.Relationship;
import com.adobe.granite.socialgraph.impl.JcrSocialGraph;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class VirtualRelationship
implements Relationship {
private final JcrSocialGraph graph;
private final String startId;
private final String endId;
private final String type;
private final String signature;
private final ValueMap properties = new ValueMapDecorator(new HashMap());
public VirtualRelationship(JcrSocialGraph graph, String startId, String endId, String type) {
this.graph = graph;
this.startId = startId;
this.endId = endId;
this.type = type;
this.signature = Text.escape((String)startId) + ":" + Text.escape((String)type) + ":" + Text.escape((String)endId);
}
@Override
public GraphNode getStartNode() {
return this.graph.getNode(this.startId);
}
@Override
public GraphNode getEndNode() {
return this.graph.getNode(this.endId);
}
@Override
public GraphNode getOtherNode(GraphNode node) {
String id = node.getId();
if (id.equals(this.startId)) {
return this.getEndNode();
}
if (id.equals(this.endId)) {
return this.getStartNode();
}
throw new IllegalArgumentException("Neither start- or end node given.");
}
@Override
public boolean isBidirectional() {
return true;
}
@Override
public String getType() {
return this.type;
}
@Override
public void delete() {
throw new UnsupportedOperationException("Deleting virtual relationships is not supported.");
}
@Override
public String signature() {
return this.signature;
}
@Override
public boolean isVirtual() {
return true;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Relationship)) {
return false;
}
Relationship that = (Relationship)o;
return this.signature.equals(that.signature());
}
@Override
public int hashCode() {
return this.signature.hashCode();
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("VirtualRelationship");
sb.append("{startId='").append(this.startId).append('\'');
sb.append(", endId='").append(this.endId).append('\'');
sb.append(", type='").append(this.type).append('\'');
sb.append('}');
return sb.toString();
}
@Override
public <T> T get(String s, Class<T> tClass) {
return (T)this.properties.get(s, tClass);
}
@Override
public <T> T get(String s, T t) {
return (T)this.properties.get(s, t);
}
@Override
public int size() {
return this.properties.size();
}
@Override
public boolean isEmpty() {
return this.properties.isEmpty();
}
@Override
public boolean containsKey(Object o) {
return this.properties.containsKey(o);
}
@Override
public boolean containsValue(Object o) {
return this.properties.containsValue(o);
}
@Override
public Object get(Object o) {
return this.properties.get(o);
}
@Override
public Object put(String s, Object o) {
return this.properties.put((Object)s, o);
}
@Override
public Object remove(Object o) {
return this.properties.remove(o);
}
@Override
public void putAll(Map<? extends String, ? extends Object> map) {
this.properties.putAll(map);
}
@Override
public void clear() {
this.properties.clear();
}
@Override
public Set<String> keySet() {
return this.properties.keySet();
}
@Override
public Collection<Object> values() {
return this.properties.values();
}
@Override
public Set<Map.Entry<String, Object>> entrySet() {
return this.properties.entrySet();
}
}