Skip to content

Commit 3558c91

Browse files
committed
Refactor and fix compiler warnings in FutureResult and JedisResult.
1 parent 4f76fb3 commit 3558c91

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

src/main/java/org/springframework/data/redis/connection/FutureResult.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,25 @@
2121
import org.springframework.lang.Nullable;
2222

2323
/**
24-
* The result of an asynchronous operation
24+
* Result of an asynchronous operation
2525
*
26+
* @param <T> The data type of the object that holds the future result (usually type of the
27+
* {@link java.util.concurrent.Future} or response wrapper).
2628
* @author Jennifer Hickey
2729
* @author Christoph Strobl
2830
* @author Mark Paluch
29-
* @param <T> The data type of the object that holds the future result (usually type of the
30-
* {@link java.util.concurrent.Future} or response wrapper).
31+
* @author John Blum
3132
*/
3233
public abstract class FutureResult<T> {
3334

34-
private T resultHolder;
35+
private boolean status = false;
36+
37+
private final T resultHolder;
38+
3539
private final Supplier<?> defaultConversionResult;
3640

37-
private boolean status = false;
3841

39-
@SuppressWarnings("rawtypes") //
42+
@SuppressWarnings("rawtypes")
4043
protected Converter converter;
4144

4245
/**
@@ -71,23 +74,14 @@ public FutureResult(T resultHolder, @Nullable Converter converter) {
7174
* @param defaultConversionResult must not be {@literal null}.
7275
* @since 2.1
7376
*/
77+
@SuppressWarnings("rawtypes")
7478
public FutureResult(T resultHolder, @Nullable Converter converter, Supplier<?> defaultConversionResult) {
7579

7680
this.resultHolder = resultHolder;
7781
this.converter = converter != null ? converter : val -> val;
7882
this.defaultConversionResult = defaultConversionResult;
7983
}
8084

81-
/**
82-
* Get the object holding the actual result.
83-
*
84-
* @return never {@literal null}.
85-
* @since 1.1
86-
*/
87-
public T getResultHolder() {
88-
return resultHolder;
89-
}
90-
9185
/**
9286
* Converts the given result if a converter is specified, else returns the result
9387
*
@@ -98,11 +92,9 @@ public T getResultHolder() {
9892
@Nullable
9993
public Object convert(@Nullable Object result) {
10094

101-
if (result == null) {
102-
return computeDefaultResult(null);
103-
}
95+
Object resolvedResult = result != null ? getConverter().convert(result) : null;
10496

105-
return computeDefaultResult(converter.convert(result));
97+
return computeDefaultResult(resolvedResult);
10698
}
10799

108100
@Nullable
@@ -112,7 +104,17 @@ private Object computeDefaultResult(@Nullable Object source) {
112104

113105
@SuppressWarnings("rawtypes")
114106
public Converter getConverter() {
115-
return converter;
107+
return this.converter;
108+
}
109+
110+
/**
111+
* Get the object holding the actual result.
112+
*
113+
* @return never {@literal null}.
114+
* @since 1.1
115+
*/
116+
public T getResultHolder() {
117+
return this.resultHolder;
116118
}
117119

118120
/**
@@ -121,7 +123,7 @@ public Converter getConverter() {
121123
* @return true if this is a status result (i.e. OK)
122124
*/
123125
public boolean isStatus() {
124-
return status;
126+
return this.status;
125127
}
126128

127129
/**
@@ -144,4 +146,5 @@ public void setStatus(boolean status) {
144146
* @since 2.1
145147
*/
146148
public abstract boolean conversionRequired();
149+
147150
}

src/main/java/org/springframework/data/redis/connection/jedis/JedisResult.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,21 @@
2424
import org.springframework.lang.Nullable;
2525

2626
/**
27-
* Jedis specific {@link FutureResult} implementation. <br />
27+
* {@link FutureResult} implementation for Jedis.
2828
*
29+
* @param <T> The data type of the object that holds the future result (usually of type Future).
30+
* @param <R> The data type of the result type.
2931
* @author Costin Leau
3032
* @author Jennifer Hickey
3133
* @author Christoph Strobl
3234
* @author Mark Paluch
33-
* @param <T> The data type of the object that holds the future result (usually of type Future).
34-
* @param <R> The data type of the result type.
35+
* @author John Blum
3536
* @since 2.1
3637
*/
3738
class JedisResult<T, R> extends FutureResult<Response<?>> {
3839

3940
private final boolean convertPipelineAndTxResults;
4041

41-
JedisResult(Response<T> resultHolder) {
42-
this(resultHolder, false, null);
43-
}
44-
4542
JedisResult(Response<T> resultHolder, boolean convertPipelineAndTxResults, @Nullable Converter<T, ?> converter) {
4643
this(resultHolder, () -> null, convertPipelineAndTxResults, converter);
4744
}
@@ -50,6 +47,7 @@ class JedisResult<T, R> extends FutureResult<Response<?>> {
5047
@Nullable Converter<T, ?> converter) {
5148

5249
super(resultHolder, converter, defaultReturnValue);
50+
5351
this.convertPipelineAndTxResults = convertPipelineAndTxResults;
5452
}
5553

@@ -61,18 +59,18 @@ public T get() {
6159
}
6260

6361
public boolean conversionRequired() {
64-
return convertPipelineAndTxResults;
62+
return this.convertPipelineAndTxResults;
6563
}
6664

6765
/**
6866
* Jedis specific {@link FutureResult} implementation of a throw away status result.
6967
*/
7068
static class JedisStatusResult<T, R> extends JedisResult<T, R> {
7169

72-
@SuppressWarnings("unchecked")
7370
JedisStatusResult(Response<T> resultHolder, Converter<T, R> converter) {
7471

7572
super(resultHolder, false, converter);
73+
7674
setStatus(true);
7775
}
7876
}
@@ -86,9 +84,12 @@ static class JedisStatusResult<T, R> extends JedisResult<T, R> {
8684
*/
8785
static class JedisResultBuilder<T, R> {
8886

89-
private final Response<T> response;
90-
private Converter<T, R> converter;
9187
private boolean convertPipelineAndTxResults = false;
88+
89+
private Converter<T, R> converter;
90+
91+
private final Response<T> response;
92+
9293
private Supplier<R> nullValueDefault = () -> null;
9394

9495
@SuppressWarnings("unchecked")
@@ -119,6 +120,7 @@ static <T, R> JedisResultBuilder<T, R> forResponse(Response<T> response) {
119120
JedisResultBuilder<T, R> mappedWith(Converter<T, R> converter) {
120121

121122
this.converter = converter;
123+
122124
return this;
123125
}
124126

@@ -131,12 +133,14 @@ JedisResultBuilder<T, R> mappedWith(Converter<T, R> converter) {
131133
JedisResultBuilder<T, R> mapNullTo(Supplier<R> supplier) {
132134

133135
this.nullValueDefault = supplier;
136+
134137
return this;
135138
}
136139

137140
JedisResultBuilder<T, R> convertPipelineAndTxResults(boolean flag) {
138141

139-
convertPipelineAndTxResults = flag;
142+
this.convertPipelineAndTxResults = flag;
143+
140144
return this;
141145
}
142146

0 commit comments

Comments
 (0)