Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code cleanups #1888

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Expand Up @@ -283,7 +283,7 @@ public void hsetnx(final byte[] key, final byte[] field, final byte[] value) {
}

public void hmset(final byte[] key, final Map<byte[], byte[]> hash) {
final List<byte[]> params = new ArrayList<byte[]>();
final List<byte[]> params = new ArrayList<>();
params.add(key);

for (final Entry<byte[], byte[]> entry : hash.entrySet()) {
Expand Down Expand Up @@ -439,7 +439,7 @@ public void zadd(final byte[] key, final double score, final byte[] member,
}

public void zadd(final byte[] key, final Map<byte[], Double> scoreMembers) {
ArrayList<byte[]> args = new ArrayList<byte[]>(scoreMembers.size() * 2 + 1);
ArrayList<byte[]> args = new ArrayList<>(scoreMembers.size() * 2 + 1);
args.add(key);
args.addAll(convertScoreMembersToByteArrays(scoreMembers));

Expand Down Expand Up @@ -535,7 +535,7 @@ public void sort(final byte[] key) {
}

public void sort(final byte[] key, final SortingParams sortingParameters) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(key);
args.addAll(sortingParameters.getParams());
sendCommand(SORT, args.toArray(new byte[args.size()][]));
Expand All @@ -546,7 +546,7 @@ public void blpop(final byte[][] args) {
}

public void blpop(final int timeout, final byte[]... keys) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
for (final byte[] arg : keys) {
args.add(arg);
}
Expand All @@ -555,7 +555,7 @@ public void blpop(final int timeout, final byte[]... keys) {
}

public void sort(final byte[] key, final SortingParams sortingParameters, final byte[] dstkey) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(key);
args.addAll(sortingParameters.getParams());
args.add(STORE.raw);
Expand All @@ -572,7 +572,7 @@ public void brpop(final byte[][] args) {
}

public void brpop(final int timeout, final byte[]... keys) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
for (final byte[] arg : keys) {
args.add(arg);
}
Expand Down Expand Up @@ -720,7 +720,7 @@ public void zunionstore(final byte[] dstkey, final byte[]... sets) {
}

public void zunionstore(final byte[] dstkey, final ZParams params, final byte[]... sets) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(dstkey);
args.add(Protocol.toByteArray(sets.length));
for (final byte[] set : sets) {
Expand All @@ -735,7 +735,7 @@ public void zinterstore(final byte[] dstkey, final byte[]... sets) {
}

public void zinterstore(final byte[] dstkey, final ZParams params, final byte[]... sets) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(dstkey);
args.add(Protocol.toByteArray(sets.length));
for (final byte[] set : sets) {
Expand Down Expand Up @@ -877,7 +877,7 @@ public void getbit(final byte[] key, final long offset) {
}

public void bitpos(final byte[] key, final boolean value, final BitPosParams params) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(key);
args.add(toByteArray(value));
args.addAll(params.getParams());
Expand Down Expand Up @@ -1088,30 +1088,30 @@ public void hincrByFloat(final byte[] key, final byte[] field, final double incr
}

public void scan(final byte[] cursor, final ScanParams params) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(cursor);
args.addAll(params.getParams());
sendCommand(SCAN, args.toArray(new byte[args.size()][]));
}

public void hscan(final byte[] key, final byte[] cursor, final ScanParams params) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(key);
args.add(cursor);
args.addAll(params.getParams());
sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
}

public void sscan(final byte[] key, final byte[] cursor, final ScanParams params) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(key);
args.add(cursor);
args.addAll(params.getParams());
sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
}

public void zscan(final byte[] key, final byte[] cursor, final ScanParams params) {
final List<byte[]> args = new ArrayList<byte[]>();
final List<byte[]> args = new ArrayList<>();
args.add(key);
args.add(cursor);
args.addAll(params.getParams());
Expand Down Expand Up @@ -1155,7 +1155,7 @@ public void geoadd(final byte[] key, final double longitude, final double latitu
}

public void geoadd(final byte[] key, final Map<byte[], GeoCoordinate> memberCoordinateMap) {
List<byte[]> args = new ArrayList<byte[]>(memberCoordinateMap.size() * 3 + 1);
List<byte[]> args = new ArrayList<>(memberCoordinateMap.size() * 3 + 1);
args.add(key);
args.addAll(convertGeoCoordinateMapToByteArrays(memberCoordinateMap));

Expand Down Expand Up @@ -1234,7 +1234,7 @@ public void moduleUnload(final byte[] name) {
}

private ArrayList<byte[]> convertScoreMembersToByteArrays(final Map<byte[], Double> scoreMembers) {
ArrayList<byte[]> args = new ArrayList<byte[]>(scoreMembers.size() * 2);
ArrayList<byte[]> args = new ArrayList<>(scoreMembers.size() * 2);

for (Map.Entry<byte[], Double> entry : scoreMembers.entrySet()) {
args.add(toByteArray(entry.getValue()));
Expand All @@ -1246,7 +1246,7 @@ private ArrayList<byte[]> convertScoreMembersToByteArrays(final Map<byte[], Doub

private List<byte[]> convertGeoCoordinateMapToByteArrays(
final Map<byte[], GeoCoordinate> memberCoordinateMap) {
List<byte[]> args = new ArrayList<byte[]>(memberCoordinateMap.size() * 3);
List<byte[]> args = new ArrayList<>(memberCoordinateMap.size() * 3);

for (Entry<byte[], GeoCoordinate> entry : memberCoordinateMap.entrySet()) {
GeoCoordinate coordinate = entry.getValue();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Expand Up @@ -3652,7 +3652,7 @@ public ScanResult<byte[]> scan(final byte[] cursor, final ScanParams params) {
List<Object> result = client.getObjectMultiBulkReply();
byte[] newcursor = (byte[]) result.get(0);
List<byte[]> rawResults = (List<byte[]>) result.get(1);
return new ScanResult<byte[]>(newcursor, rawResults);
return new ScanResult<>(newcursor, rawResults);
}

@Override
Expand All @@ -3667,7 +3667,7 @@ public ScanResult<Map.Entry<byte[], byte[]>> hscan(final byte[] key, final byte[
client.hscan(key, cursor, params);
List<Object> result = client.getObjectMultiBulkReply();
byte[] newcursor = (byte[]) result.get(0);
List<Map.Entry<byte[], byte[]>> results = new ArrayList<Map.Entry<byte[], byte[]>>();
List<Map.Entry<byte[], byte[]>> results = new ArrayList<>();
List<byte[]> rawResults = (List<byte[]>) result.get(1);
Iterator<byte[]> iterator = rawResults.iterator();
while (iterator.hasNext()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Expand Up @@ -30,7 +30,7 @@ public class BinaryJedisCluster implements BinaryJedisClusterCommands,
protected static final int DEFAULT_TIMEOUT = 2000;
protected static final int DEFAULT_MAX_ATTEMPTS = 5;

protected int maxAttempts;
protected final int maxAttempts;

protected JedisClusterConnectionHandler connectionHandler;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/BitPosParams.java
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public class BitPosParams {
private List<byte[]> params = new ArrayList<byte[]>();
private final List<byte[]> params = new ArrayList<>();

protected BitPosParams() {
}
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Expand Up @@ -87,7 +87,7 @@ public List<String> build(Object data) {
return null;
}
List<byte[]> l = (List<byte[]>) data;
final ArrayList<String> result = new ArrayList<String>(l.size());
final ArrayList<String> result = new ArrayList<>(l.size());
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
Expand All @@ -109,7 +109,7 @@ public String toString() {
@SuppressWarnings("unchecked")
public Map<String, String> build(Object data) {
final List<byte[]> flatHash = (List<byte[]>) data;
final Map<String, String> hash = new HashMap<String, String>(flatHash.size()/2, 1);
final Map<String, String> hash = new HashMap<>(flatHash.size()/2, 1);
final Iterator<byte[]> iterator = flatHash.iterator();
while (iterator.hasNext()) {
hash.put(SafeEncoder.encode(iterator.next()), SafeEncoder.encode(iterator.next()));
Expand All @@ -130,7 +130,7 @@ public String toString() {
@SuppressWarnings("unchecked")
public Map<String, String> build(Object data) {
final List<Object> flatHash = (List<Object>) data;
final Map<String, String> hash = new HashMap<String, String>(flatHash.size()/2, 1);
final Map<String, String> hash = new HashMap<>(flatHash.size()/2, 1);
final Iterator<Object> iterator = flatHash.iterator();
while (iterator.hasNext()) {
hash.put(SafeEncoder.encode((byte[]) iterator.next()),
Expand All @@ -155,7 +155,7 @@ public Set<String> build(Object data) {
return null;
}
List<byte[]> l = (List<byte[]>) data;
final Set<String> result = new HashSet<String>(l.size(), 1);
final Set<String> result = new HashSet<>(l.size(), 1);
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
Expand All @@ -180,9 +180,7 @@ public List<byte[]> build(Object data) {
if (null == data) {
return null;
}
List<byte[]> l = (List<byte[]>) data;

return l;
return (List<byte[]>) data;
}

@Override
Expand All @@ -199,7 +197,7 @@ public Set<byte[]> build(Object data) {
return null;
}
List<byte[]> l = (List<byte[]>) data;
final Set<byte[]> result = new LinkedHashSet<byte[]>(l);
final Set<byte[]> result = new LinkedHashSet<>(l);
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
Expand Down Expand Up @@ -244,7 +242,7 @@ public Set<String> build(Object data) {
return null;
}
List<byte[]> l = (List<byte[]>) data;
final Set<String> result = new LinkedHashSet<String>(l.size(), 1);
final Set<String> result = new LinkedHashSet<>(l.size(), 1);
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
Expand All @@ -270,7 +268,7 @@ public Set<Tuple> build(Object data) {
return null;
}
List<byte[]> l = (List<byte[]>) data;
final Set<Tuple> result = new LinkedHashSet<Tuple>(l.size()/2, 1);
final Set<Tuple> result = new LinkedHashSet<>(l.size()/2, 1);
Iterator<byte[]> iterator = l.iterator();
while (iterator.hasNext()) {
result.add(new Tuple(iterator.next(), DOUBLE.build(iterator.next())));
Expand Down Expand Up @@ -302,7 +300,7 @@ private Object evalResult(Object result) {

if (result instanceof List<?>) {
List<?> list = (List<?>) result;
List<Object> listResult = new ArrayList<Object>(list.size());
List<Object> listResult = new ArrayList<>(list.size());
for (Object bin : list) {
listResult.add(evalResult(bin));
}
Expand Down Expand Up @@ -330,7 +328,7 @@ public String toString() {
private Object evalResult(Object result) {
if (result instanceof List<?>) {
List<?> list = (List<?>) result;
List<Object> listResult = new ArrayList<Object>(list.size());
List<Object> listResult = new ArrayList<>(list.size());
for (Object bin : list) {
listResult.add(evalResult(bin));
}
Expand All @@ -345,6 +343,7 @@ private Object evalResult(Object result) {

public static final Builder<List<GeoCoordinate>> GEO_COORDINATE_LIST = new Builder<List<GeoCoordinate>>() {
@Override
@SuppressWarnings("unchecked")
public List<GeoCoordinate> build(Object data) {
if (null == data) {
return null;
Expand All @@ -358,7 +357,7 @@ public String toString() {
}

private List<GeoCoordinate> interpretGeoposResult(List<Object> responses) {
List<GeoCoordinate> responseCoordinate = new ArrayList<GeoCoordinate>(responses.size());
List<GeoCoordinate> responseCoordinate = new ArrayList<>(responses.size());
for (Object response : responses) {
if (response == null) {
responseCoordinate.add(null);
Expand All @@ -375,14 +374,15 @@ private List<GeoCoordinate> interpretGeoposResult(List<Object> responses) {

public static final Builder<List<GeoRadiusResponse>> GEORADIUS_WITH_PARAMS_RESULT = new Builder<List<GeoRadiusResponse>>() {
@Override
@SuppressWarnings("unchecked")
public List<GeoRadiusResponse> build(Object data) {
if (data == null) {
return null;
}

List<Object> objectList = (List<Object>) data;

List<GeoRadiusResponse> responses = new ArrayList<GeoRadiusResponse>(objectList.size());
List<GeoRadiusResponse> responses = new ArrayList<>(objectList.size());
if (objectList.isEmpty()) {
return responses;
}
Expand Down Expand Up @@ -431,14 +431,15 @@ public String toString() {

public static final Builder<List<Module>> MODULE_LIST = new Builder<List<Module>>() {
@Override
@SuppressWarnings("unchecked")
public List<Module> build(Object data) {
if (data == null) {
return null;
}

List<List<Object>> objectList = (List<List<Object>>) data;

List<Module> responses = new ArrayList<Module>(objectList.size());
List<Module> responses = new ArrayList<>(objectList.size());
if (objectList.isEmpty()) {
return responses;
}
Expand Down Expand Up @@ -566,8 +567,6 @@ public String toString() {
}
};



private BuilderFactory() {
throw new InstantiationError( "Must not instantiate this class" );
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/redis/clients/jedis/Client.java
Expand Up @@ -191,7 +191,7 @@ public void hset(final String key, final String field, final String value) {

@Override
public void hset(final String key, final Map<String, String> hash) {
final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash.size());
final Map<byte[], byte[]> bhash = new HashMap<>(hash.size());
for (final Entry<String, String> entry : hash.entrySet()) {
bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder.encode(entry.getValue()));
}
Expand All @@ -210,7 +210,7 @@ public void hsetnx(final String key, final String field, final String value) {

@Override
public void hmset(final String key, final Map<String, String> hash) {
final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash.size());
final Map<byte[], byte[]> bhash = new HashMap<>(hash.size());
for (final Entry<String, String> entry : hash.entrySet()) {
bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder.encode(entry.getValue()));
}
Expand Down Expand Up @@ -487,7 +487,7 @@ public void blpop(final String[] args) {

public void blpop(final int timeout, final String... keys) {
final int size = keys.length + 1;
List<String> args = new ArrayList<String>(size);
List<String> args = new ArrayList<>(size);
for (String arg : keys) {
args.add(arg);
}
Expand All @@ -512,7 +512,7 @@ public void brpop(final String[] args) {

public void brpop(final int timeout, final String... keys) {
final int size = keys.length + 1;
List<String> args = new ArrayList<String>(size);
List<String> args = new ArrayList<>(size);
for (String arg : keys) {
args.add(arg);
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public void moduleUnload(final String name) {
}

private HashMap<byte[], Double> convertScoreMembersToBinary(final Map<String, Double> scoreMembers) {
HashMap<byte[], Double> binaryScoreMembers = new HashMap<byte[], Double>();
HashMap<byte[], Double> binaryScoreMembers = new HashMap<>();
for (Entry<String, Double> entry : scoreMembers.entrySet()) {
binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()), entry.getValue());
}
Expand All @@ -1141,7 +1141,7 @@ private HashMap<byte[], Double> convertScoreMembersToBinary(final Map<String, Do

private HashMap<byte[], GeoCoordinate> convertMemberCoordinateMapToBinary(
final Map<String, GeoCoordinate> memberCoordinateMap) {
HashMap<byte[], GeoCoordinate> binaryMemberCoordinateMap = new HashMap<byte[], GeoCoordinate>();
HashMap<byte[], GeoCoordinate> binaryMemberCoordinateMap = new HashMap<>();
for (Entry<String, GeoCoordinate> entry : memberCoordinateMap.entrySet()) {
binaryMemberCoordinateMap.put(SafeEncoder.encode(entry.getKey()), entry.getValue());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Connection.java
Expand Up @@ -324,7 +324,7 @@ protected Object readProtocolWithCheckingBroken() {

public List<Object> getMany(final int count) {
flush();
final List<Object> responses = new ArrayList<Object>(count);
final List<Object> responses = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
try {
responses.add(readProtocolWithCheckingBroken());
Expand Down