Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions api/src/main/java/com/inrupt/client/spi/NoopCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@
*/
class NoopCache<T, U> implements ClientCache<T, U> {

private static final String KEY_NOT_NULL = "cache key may not be null!";
private static final String VALUE_NOT_NULL = "cache value may not be null!";

@Override
public U get(final T key) {
Objects.requireNonNull(key, "cache key may not be null!");
Objects.requireNonNull(key, KEY_NOT_NULL);
return null;
}

@Override
public void put(final T key, final U value) {
/* no-op */
Objects.requireNonNull(key, "cache key may not be null!");
Objects.requireNonNull(value, "cache value may not be null!");
Objects.requireNonNull(key, KEY_NOT_NULL);
Objects.requireNonNull(value, VALUE_NOT_NULL);
}

@Override
public void invalidate(final T key) {
/* no-op */
Objects.requireNonNull(key, "cache key may not be null!");
Objects.requireNonNull(key, KEY_NOT_NULL);
}

@Override
Expand All @@ -60,7 +63,7 @@ public void invalidateAll() {
public static class NoopCacheBuilder implements CacheBuilderService {
@Override
public <T, U> ClientCache<T, U> build(final int size, final Duration duration) {
return new NoopCache<T, U>();
return new NoopCache<>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public <T, U> ClientCache<T, U> build(final int maximumSize, final Duration dura
* @return a cache suitable for use in the Inrupt Client libraries
*/
public static <T, U> ClientCache<T, U> ofCache(final Cache<T, U> cache) {
return new CaffeineCache<T, U>(cache);
return new CaffeineCache<>(cache);
}
}

Expand Down
13 changes: 8 additions & 5 deletions guava/src/main/java/com/inrupt/client/guava/GuavaCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*/
public class GuavaCache<T, U> implements ClientCache<T, U> {

private static final String KEY_NOT_NULL = "cache key may not be null!";
private static final String VALUE_NOT_NULL = "cache value may not be null!";

private final Cache<T, U> cache;

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

@Override
public U get(final T key) {
Objects.requireNonNull(key, "cache key may not be null!");
Objects.requireNonNull(key, KEY_NOT_NULL);
return cache.getIfPresent(key);
}

@Override
public void put(final T key, final U value) {
Objects.requireNonNull(key, "cache key may not be null!");
Objects.requireNonNull(value, "cache value may not be null!");
Objects.requireNonNull(key, KEY_NOT_NULL);
Objects.requireNonNull(value, VALUE_NOT_NULL);
cache.put(key, value);
}

@Override
public void invalidate(final T key) {
Objects.requireNonNull(key, "cache key may not be null!");
Objects.requireNonNull(key, KEY_NOT_NULL);
cache.invalidate(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public <T, U> ClientCache<T, U> build(final int maximumSize, final Duration dura
* @return a cache suitable for use in the Inrupt Client libraries
*/
public static <T, U> ClientCache<T, U> ofCache(final Cache<T, U> cache) {
return new GuavaCache<T, U>(cache);
return new GuavaCache<>(cache);
}
}

Expand Down