diff --git a/.lycheeignore b/.lycheeignore index 39c854fd..0b991c43 100644 --- a/.lycheeignore +++ b/.lycheeignore @@ -2,3 +2,4 @@ file:///* https://querydsl.com/* https://uel.java.net/ https://www.openapis.org/ +https://jcp.org/* diff --git a/src/main/java/com/qubitpi/ws/jersey/template/cache/LruCache.java b/src/main/java/com/qubitpi/ws/jersey/template/cache/LruCache.java deleted file mode 100755 index 97f9e712..00000000 --- a/src/main/java/com/qubitpi/ws/jersey/template/cache/LruCache.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Jiaqi Liu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.qubitpi.ws.jersey.template.cache; - -import jakarta.validation.constraints.NotNull; -import net.jcip.annotations.NotThreadSafe; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * LRU Cache. - * - * @param The type of keys maintained by this cache - * @param The type of cached values - */ -@NotThreadSafe -public class LruCache extends LinkedHashMap { - - private static final long serialVersionUID = -5727315380707628908L; - - private final int cacheSize; - - /** - * Constructs an empty {@link LruCache} instance with the provided maximum number of entries hold in the cache. - * - * @param cacheSize Maximum number of entries in cache - */ - private LruCache(final int cacheSize) { - super(cacheSize * 4 / 3, 0.75f, true); - this.cacheSize = cacheSize; - } - - /** - * Creates a new instance of {@link LruCache} with the provided maximum number of entries hold in the cache. - * - * @param cacheSize Maximum number of entries in cache - * - * @param The type of keys maintained by this cache - * @param The type of cached values - * - * @return a new initialized {@link LruCache} instance - */ - @NotNull - public static LruCache ofSize(final int cacheSize) { - return new LruCache<>(cacheSize); - } - - @Override - protected boolean removeEldestEntry(final Map.Entry eldest) { - return size() > getCacheSize(); - } - - private int getCacheSize() { - return cacheSize; - } -} diff --git a/src/test/groovy/com/qubitpi/ws/jersey/template/cache/LruCacheSpec.groovy b/src/test/groovy/com/qubitpi/ws/jersey/template/cache/LruCacheSpec.groovy deleted file mode 100644 index f7d30fe3..00000000 --- a/src/test/groovy/com/qubitpi/ws/jersey/template/cache/LruCacheSpec.groovy +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright Jiaqi Liu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.qubitpi.ws.jersey.template.cache - -import spock.lang.Specification - -class LruCacheSpec extends Specification { - - @SuppressWarnings(["GroovyAccessibility"]) - def "the least frequently used cache entry is removed when cache is full"() { - given: "a cache with cache size of 2" - LruCache cache = new LruCache<>(2) - - when: "inserting 2 entries into cache to make it full" - cache.put("foo", "bar") - cache.put("bat", "baz") - - then: "all inserted entries are there" - cache.toString() == "[foo:bar, bat:baz]" - - when: "outdate an entry and putting a new cache entry into the cache" - cache.get("bat") - cache.put("new", "new") - - then: "the outdated entry is reomved" - cache.toString() == "[bat:baz, new:new]" - } - - def "static factory method produces a new instances"() { - given: "two instance produced by the same static factory method" - LruCache first = LruCache.ofSize(3) - LruCache second = LruCache.ofSize(3) - - expect: "the two instances are different objects" - ! first.is(second) - } -}