Skip to content

Commit b188909

Browse files
authored
Fix minor sonar issues (#478)
1 parent 6cbc8b6 commit b188909

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

api/src/main/java/com/inrupt/client/spi/NoopCache.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,26 @@
3333
*/
3434
class NoopCache<T, U> implements ClientCache<T, U> {
3535

36+
private static final String KEY_NOT_NULL = "cache key may not be null!";
37+
private static final String VALUE_NOT_NULL = "cache value may not be null!";
38+
3639
@Override
3740
public U get(final T key) {
38-
Objects.requireNonNull(key, "cache key may not be null!");
41+
Objects.requireNonNull(key, KEY_NOT_NULL);
3942
return null;
4043
}
4144

4245
@Override
4346
public void put(final T key, final U value) {
4447
/* no-op */
45-
Objects.requireNonNull(key, "cache key may not be null!");
46-
Objects.requireNonNull(value, "cache value may not be null!");
48+
Objects.requireNonNull(key, KEY_NOT_NULL);
49+
Objects.requireNonNull(value, VALUE_NOT_NULL);
4750
}
4851

4952
@Override
5053
public void invalidate(final T key) {
5154
/* no-op */
52-
Objects.requireNonNull(key, "cache key may not be null!");
55+
Objects.requireNonNull(key, KEY_NOT_NULL);
5356
}
5457

5558
@Override
@@ -60,7 +63,7 @@ public void invalidateAll() {
6063
public static class NoopCacheBuilder implements CacheBuilderService {
6164
@Override
6265
public <T, U> ClientCache<T, U> build(final int size, final Duration duration) {
63-
return new NoopCache<T, U>();
66+
return new NoopCache<>();
6467
}
6568
}
6669
}

caffeine/src/main/java/com/inrupt/client/caffeine/CaffeineCacheBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public <T, U> ClientCache<T, U> build(final int maximumSize, final Duration dura
4949
* @return a cache suitable for use in the Inrupt Client libraries
5050
*/
5151
public static <T, U> ClientCache<T, U> ofCache(final Cache<T, U> cache) {
52-
return new CaffeineCache<T, U>(cache);
52+
return new CaffeineCache<>(cache);
5353
}
5454
}
5555

guava/src/main/java/com/inrupt/client/guava/GuavaCache.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
*/
3434
public class GuavaCache<T, U> implements ClientCache<T, U> {
3535

36+
private static final String KEY_NOT_NULL = "cache key may not be null!";
37+
private static final String VALUE_NOT_NULL = "cache value may not be null!";
38+
3639
private final Cache<T, U> cache;
3740

3841
/**
@@ -41,25 +44,25 @@ public class GuavaCache<T, U> implements ClientCache<T, U> {
4144
* @param cache the guava cache
4245
*/
4346
public GuavaCache(final Cache<T, U> cache) {
44-
this.cache = Objects.requireNonNull(cache, "cache may not be null!");
47+
this.cache = Objects.requireNonNull(cache, KEY_NOT_NULL);
4548
}
4649

4750
@Override
4851
public U get(final T key) {
49-
Objects.requireNonNull(key, "cache key may not be null!");
52+
Objects.requireNonNull(key, KEY_NOT_NULL);
5053
return cache.getIfPresent(key);
5154
}
5255

5356
@Override
5457
public void put(final T key, final U value) {
55-
Objects.requireNonNull(key, "cache key may not be null!");
56-
Objects.requireNonNull(value, "cache value may not be null!");
58+
Objects.requireNonNull(key, KEY_NOT_NULL);
59+
Objects.requireNonNull(value, VALUE_NOT_NULL);
5760
cache.put(key, value);
5861
}
5962

6063
@Override
6164
public void invalidate(final T key) {
62-
Objects.requireNonNull(key, "cache key may not be null!");
65+
Objects.requireNonNull(key, KEY_NOT_NULL);
6366
cache.invalidate(key);
6467
}
6568

guava/src/main/java/com/inrupt/client/guava/GuavaCacheBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public <T, U> ClientCache<T, U> build(final int maximumSize, final Duration dura
5050
* @return a cache suitable for use in the Inrupt Client libraries
5151
*/
5252
public static <T, U> ClientCache<T, U> ofCache(final Cache<T, U> cache) {
53-
return new GuavaCache<T, U>(cache);
53+
return new GuavaCache<>(cache);
5454
}
5555
}
5656

0 commit comments

Comments
 (0)