Skip to content

Commit 7ca5507

Browse files
committed
code cleanup
1 parent a119e65 commit 7ca5507

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

src/main/java/com/redislabs/redisgraph/Record.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,46 @@ public interface Record {
1313
* The value at the given field index (represented as String)
1414
*
1515
* @param index
16-
* @return
16+
* @return string representation of the value
1717
*/
1818
String getString(int index);
1919

2020
/**
2121
* The value at the given field (represented as String)
2222
*
23-
* @param key
24-
* @return
23+
* @param key header key
24+
*
25+
* @return string representation of the value
2526
*/
2627
String getString(String key);
2728

2829
/**
2930
* The keys of the record
3031
*
31-
* @return
32+
* @return list of the record key
3233
*/
3334
List<String> keys();
3435

3536
/**
3637
* The values of the record
3738
*
38-
* @return
39+
* @return list of the record values
3940
*/
4041
List<String> values();
4142

4243
/**
43-
* Check if the keys contain the given key
44+
* Check if the record header contains the given key
45+
*
46+
* @param key header key
4447
*
45-
* @param key
46-
* @return
48+
* @return <code>true</code> if the the key exists
4749
*/
4850
boolean containsKey(String key);
4951

5052
/**
5153
* The number of fields in this record
5254
*
53-
* @return
55+
* @return the number of fields
5456
*/
5557
int size();
5658
}

src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*/
1414
public class RedisGraphAPI {
1515

16-
final private Pool<Jedis> client;
17-
final private String graphId;
16+
private final Pool<Jedis> client;
17+
private final String graphId;
1818

1919
/**
2020
* Creates a client to a specific graph running on the local machine
@@ -54,7 +54,7 @@ public RedisGraphAPI(String graphId, Pool<Jedis> jedis) {
5454
* @return a result set
5555
*/
5656
public ResultSet query(String query) {
57-
try (Jedis conn = _conn()) {
57+
try (Jedis conn = getConnection()) {
5858
return new ResultSetImpl(sendCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply());
5959
}
6060
}
@@ -65,19 +65,19 @@ public ResultSet query(String query) {
6565
* @return delete running time statistics
6666
*/
6767
public String deleteGraph() {
68-
try (Jedis conn = _conn()) {
68+
try (Jedis conn = getConnection()) {
6969
return sendCommand(conn, Command.DELETE, graphId).getBulkReply();
7070
}
7171
}
7272

7373

7474
private BinaryClient sendCommand(Jedis conn, ProtocolCommand provider, String ...args) {
75-
BinaryClient client = conn.getClient();
76-
client.sendCommand(provider, args);
77-
return client;
75+
BinaryClient binaryClient = conn.getClient();
76+
binaryClient.sendCommand(provider, args);
77+
return binaryClient;
7878
}
7979

80-
private Jedis _conn() {
80+
private Jedis getConnection() {
8181
return this.client.getResource();
8282
}
8383
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class RecordImpl implements Record {
88

9-
final private List<String> header;
10-
final private List<String> values;
9+
private final List<String> header;
10+
private final List<String> values;
1111

1212
RecordImpl(List<String> header, List<String> values){
1313
this.header=header;

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.NoSuchElementException;
56
import java.util.stream.Collectors;
67

78
import com.redislabs.redisgraph.Record;
@@ -12,10 +13,10 @@
1213

1314
public class ResultSetImpl implements ResultSet{
1415

15-
final private int totalResults;
16-
final private List<String> header;
17-
final private List<Record> results;
18-
final private Statistics statistics;
16+
private final int totalResults;
17+
private final List<String> header;
18+
private final List<Record> results;
19+
private final Statistics statistics;
1920
private int position = 0;
2021

2122
public ResultSetImpl(List<Object> resp) {
@@ -25,21 +26,21 @@ public ResultSetImpl(List<Object> resp) {
2526
ArrayList<ArrayList<byte[]>> result = (ArrayList<ArrayList<byte[]>>) resp.get(0);
2627

2728
// Empty result set
28-
if(result == null || result.size() == 0) {
29+
if(result == null || result.isEmpty()) {
2930
header = new ArrayList<>(0);
3031
totalResults = 0;
31-
results = new ArrayList<Record>(0);
32+
results = new ArrayList<>(0);
3233
} else {
3334
ArrayList<byte[]> headers = result.get(0);
34-
header = headers.stream().map( h -> new String(h)).collect(Collectors.toList());
35+
header = headers.stream().map( String::new).collect(Collectors.toList());
3536

3637
// First row is a header row
3738
totalResults = result.size()-1;
38-
results = new ArrayList<Record>(totalResults);
39+
results = new ArrayList<>(totalResults);
3940
// Skips last row (runtime info)
4041
for (int i = 1; i <= totalResults; i++) {
4142
ArrayList<byte[]> row = result.get(i);
42-
Record record = new RecordImpl(header, row.stream().map( h -> SafeEncoder.encode(h)).collect(Collectors.toList()));
43+
Record record = new RecordImpl(header, row.stream().map( SafeEncoder::encode).collect(Collectors.toList()));
4344
results.add(record);
4445
}
4546
}
@@ -56,6 +57,8 @@ public boolean hasNext() {
5657

5758
@Override
5859
public Record next() {
60+
if (!hasNext())
61+
throw new NoSuchElementException();
5962
return results.get(position++);
6063
}
6164

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.redislabs.redisgraph.impl;
22

3-
import java.util.HashMap;
3+
import java.util.EnumMap;
44
import java.util.List;
55
import java.util.Map;
66

@@ -9,12 +9,12 @@
99
import redis.clients.jedis.util.SafeEncoder;
1010

1111
public class StatisticsImpl implements Statistics {
12-
final private List<byte[]> raw;
13-
final private Map<Statistics.Label, String> statistics;
12+
private final List<byte[]> raw;
13+
private final Map<Statistics.Label, String> statistics;
1414

1515
StatisticsImpl(List<byte[]> raw){
1616
this.raw = raw;
17-
this.statistics = new HashMap<Statistics.Label, String>(raw.size()); // lazy loaded
17+
this.statistics = new EnumMap<>(Statistics.Label.class); // lazy loaded
1818
}
1919

2020
@Override

0 commit comments

Comments
 (0)