Skip to content

Commit 3e828d7

Browse files
author
DvirDukhan
committed
Added documentation, equals, hashCode, toString for StatisticsImpl
1 parent 3fc3655 commit 3e828d7

File tree

1 file changed

+84
-13
lines changed

1 file changed

+84
-13
lines changed

src/main/java/com/redislabs/redisgraph/impl/StatisticsImpl.java

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,155 @@
33
import java.util.EnumMap;
44
import java.util.List;
55
import java.util.Map;
6+
import java.util.Objects;
67

78
import com.redislabs.redisgraph.Statistics;
89

910
import redis.clients.jedis.util.SafeEncoder;
1011

12+
/**
13+
* Query result statistics interface implementation
14+
*/
1115
public class StatisticsImpl implements Statistics {
16+
//members
1217
private final List<byte[]> raw;
1318
private final Map<Statistics.Label, String> statistics;
14-
19+
20+
/**
21+
* A raw representation of query exection statistics is a list of strings
22+
* (byte arrays which need to be de-serialized).
23+
* Each string is built in the form of "K:V" where K is statistics label and V is its value.
24+
* @param raw a raw representation of the query execution statistics
25+
*/
1526
StatisticsImpl(List<byte[]> raw){
1627
this.raw = raw;
1728
this.statistics = new EnumMap<>(Statistics.Label.class); // lazy loaded
1829
}
19-
30+
31+
32+
public List<byte[]> getRaw() {
33+
return raw;
34+
}
35+
36+
/**
37+
*
38+
* @param label the requested statistic label as key
39+
* @return a string with the value, if key exists, null otherwise
40+
*/
2041
@Override
2142
public String getStringValue(Statistics.Label label) {
2243
return getStatistics().get(label);
2344
}
2445

2546
private Map<Statistics.Label, String> getStatistics(){
2647
if(statistics.size() == 0) {
27-
for(byte[] touple : this.raw) {
28-
String text = SafeEncoder.encode(touple);
29-
String[] rowTouple = text.split(":");
30-
if(rowTouple.length == 2) {
31-
Statistics.Label label = Statistics.Label.getEnum(rowTouple[0]);
48+
for(byte[] tuple : this.raw) {
49+
String text = SafeEncoder.encode(tuple);
50+
String[] rowTuple = text.split(":");
51+
if(rowTuple.length == 2) {
52+
Statistics.Label label = Statistics.Label.getEnum(rowTuple[0]);
3253
if(label != null) {
33-
this.statistics.put( label, rowTouple[1].trim());
54+
this.statistics.put( label, rowTuple[1].trim());
3455
}
3556
}
3657
}
3758
}
3859
return statistics;
3960
}
40-
61+
62+
/**
63+
*
64+
* @param label the requested statistic label as key
65+
* @return a string with the value, if key exists, 0 otherwise
66+
*/
4167
public int getIntValue(Statistics.Label label) {
4268
String value = getStringValue(label);
4369
return value==null ? 0 : Integer.parseInt(value);
4470
}
4571

72+
/**
73+
*
74+
* @return number of nodes created after query execution
75+
*/
4676
@Override
4777
public int nodesCreated() {
4878
return getIntValue(Label.NODES_CREATED);
4979
}
5080

81+
/**
82+
*
83+
* @return number of nodes deleted after query execution
84+
*/
5185
@Override
5286
public int nodesDeleted() {
5387
return getIntValue(Label.NODES_DELETED);
5488
}
5589

90+
/**
91+
*
92+
* @return number of indices added after query execution
93+
*/
5694
@Override
5795
public int indicesAdded() {
5896
return getIntValue(Label.INDICES_ADDED);
5997
}
60-
61-
98+
99+
100+
/**
101+
*
102+
* @return number of lables added after query execution
103+
*/
62104
@Override
63105
public int labelsAdded() {
64106
return getIntValue(Label.LABELS_ADDED);
65107
}
66108

109+
/**
110+
*
111+
* @return number of relationship deleted after query execution
112+
*/
67113
@Override
68114
public int relationshipsDeleted() {
69115
return getIntValue(Label.RELATIONSHIPS_DELETED);
70116
}
71117

118+
/**
119+
*
120+
* @return number of relationship created after query execution
121+
*/
72122
@Override
73123
public int relationshipsCreated() {
74124
return getIntValue(Label.RELATIONSHIPS_CREATED);
75125
}
76126

127+
/**
128+
*
129+
* @return number of properties set after query execution
130+
*/
77131
@Override
78132
public int propertiesSet() {
79133
return getIntValue(Label.PROPERTIES_SET);
80134
}
81-
135+
136+
@Override
137+
public boolean equals(Object o) {
138+
if (this == o) return true;
139+
if (!(o instanceof StatisticsImpl)) return false;
140+
StatisticsImpl that = (StatisticsImpl) o;
141+
return Objects.equals(getRaw(), that.getRaw()) &&
142+
Objects.equals(getStatistics(), that.getStatistics());
143+
}
144+
145+
@Override
146+
public int hashCode() {
147+
return Objects.hash(getRaw(), getStatistics());
148+
}
149+
82150
@Override
83151
public String toString() {
84-
return getStatistics().toString();
152+
final StringBuilder sb = new StringBuilder("StatisticsImpl{");
153+
sb.append("statistics=").append(getStatistics());
154+
sb.append('}');
155+
return sb.toString();
85156
}
86157
}

0 commit comments

Comments
 (0)