Skip to content

Commit 3d4b7a0

Browse files
authored
pre-release clean up (#103)
* refactor: remove unused method * refactor: use java.util.Optional over Google's Guava * refactor: consecutive AssertJ 'assertThat' statements should be chained (Sonarlint java:S5853) * refactor: null check
1 parent 12d41c1 commit 3d4b7a0

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

redis-om-spring/src/main/java/com/redis/om/spring/RedisJSONKeyValueAdapter.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Collections;
1010
import java.util.Date;
1111
import java.util.List;
12+
import java.util.Optional;
1213
import java.util.Set;
1314
import java.util.concurrent.TimeUnit;
1415

@@ -29,7 +30,6 @@
2930
import org.springframework.util.ReflectionUtils;
3031
import org.springframework.util.StringUtils;
3132

32-
import com.google.common.base.Optional;
3333
import com.redis.om.spring.convert.RedisOMCustomConversions;
3434
import com.redis.om.spring.ops.json.JSONOperations;
3535
import com.redis.om.spring.util.ObjectUtils;
@@ -57,7 +57,7 @@ public RedisJSONKeyValueAdapter(RedisOperations<?, ?> redisOps, JSONOperations<?
5757
}
5858

5959
/* (non-Javadoc)
60-
*
60+
*
6161
* @see
6262
* org.springframework.data.keyvalue.core.KeyValueAdapter#put(java.lang.Object,
6363
* java.lang.Object, java.lang.String) */
@@ -87,7 +87,7 @@ public Object put(Object id, Object item, String keyspace) {
8787
}
8888

8989
/* (non-Javadoc)
90-
*
90+
*
9191
* @see
9292
* org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.lang.Object,
9393
* java.lang.String, java.lang.Class) */
@@ -121,6 +121,10 @@ public <T> List<T> getAllOf(String keyspace, Class<T> type, long offset, int row
121121
byte[] binKeyspace = toBytes(keyspace);
122122
Set<byte[]> ids = redisOperations
123123
.execute((RedisCallback<Set<byte[]>>) connection -> connection.sMembers(binKeyspace));
124+
125+
if (ids == null || ids.isEmpty()) {
126+
return Collections.emptyList();
127+
}
124128

125129
String[] keys = ids.stream().map(b -> getKey(keyspace, new String(b, StandardCharsets.UTF_8)))
126130
.toArray(String[]::new);
@@ -185,12 +189,12 @@ private Optional<Long> getTTLForEntity(Object entity) {
185189
}
186190
}
187191
} catch (SecurityException | IllegalArgumentException e) {
188-
return Optional.absent();
192+
return Optional.empty();
189193
}
190194
} else if (settings != null && settings.getTimeToLive() != null && settings.getTimeToLive() > 0) {
191195
return Optional.of(settings.getTimeToLive());
192196
}
193197
}
194-
return Optional.absent();
198+
return Optional.empty();
195199
}
196200
}

redis-om-spring/src/main/java/com/redis/om/spring/repository/support/SimpleRedisDocumentRepository.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import java.util.ArrayList;
88
import java.util.Date;
99
import java.util.List;
10+
import java.util.Optional;
1011
import java.util.concurrent.TimeUnit;
1112
import java.util.stream.Collectors;
1213
import java.util.stream.StreamSupport;
1314

14-
import com.google.common.base.Optional;
1515
import com.google.gson.Gson;
1616
import com.google.gson.GsonBuilder;
1717
import com.redis.om.spring.convert.MappingRedisOMConverter;
@@ -191,10 +191,6 @@ public byte[] createKey(String keyspace, String id) {
191191
return this.mappingConverter.toBytes(keyspace + ":" + id);
192192
}
193193

194-
private boolean expires(RedisData data) {
195-
return data.getTimeToLive() != null && data.getTimeToLive() > 0L;
196-
}
197-
198194
private void processAuditAnnotations(byte[] redisKey, Object item, boolean isNew) {
199195
var auditClass = isNew ? CreatedDate.class : LastModifiedDate.class;
200196

@@ -236,13 +232,13 @@ private Optional<Long> getTTLForEntity(Object entity) {
236232
}
237233
}
238234
} catch (SecurityException | IllegalArgumentException e) {
239-
return Optional.absent();
235+
return Optional.empty();
240236
}
241237
} else if (settings != null && settings.getTimeToLive() != null && settings.getTimeToLive() > 0) {
242238
return Optional.of(settings.getTimeToLive());
243239
}
244240
}
245-
return Optional.absent();
241+
return Optional.empty();
246242
}
247243

248244
private enum Command implements ProtocolCommand {

redis-om-spring/src/test/java/com/redis/om/spring/metamodel/MetamodelGeneratorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ void testValidDocumentUnindexed(Results results) throws IOException {
218218
@Classpath("data.metamodel.Address")
219219
void testValidDocumentIndexedNested(Results results) throws IOException {
220220
List<String> warnings = getWarningStrings(results);
221-
assertThat(warnings).hasSize(1);
222-
assertThat(warnings).containsOnly(
221+
assertThat(warnings).hasSize(1).containsOnly(
223222
"Processing class ValidDocumentIndexedNested could not resolve valid.Address while checking for nested indexables");
224223

225224
List<String> errors = getErrorStrings(results);

0 commit comments

Comments
 (0)