Skip to content

Commit 290cc8c

Browse files
Artem LabazinArtem Labazin
authored andcommitted
Add LRU cache
1 parent 07f4856 commit 290cc8c

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Add more tests.
1313
- Add `JavaDoc`.
1414

15+
## [1.9.0](https://github.com/appulse-projects/utils-java/releases/tag/1.9.0) - 2018-09-11
16+
17+
### Added
18+
19+
- Created `LruCache` implementation.
20+
1521
## [1.8.0](https://github.com/appulse-projects/utils-java/releases/tag/1.8.0) - 2018-05-25
1622

1723
Created SerializationUtils helper class and RoundRobin collection wrapper.

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424

2525
<groupId>io.appulse</groupId>
2626
<artifactId>utils-java</artifactId>
27-
<version>1.8.0</version>
27+
<version>1.9.0</version>
2828
<packaging>jar</packaging>
2929

3030
<properties>
@@ -62,7 +62,7 @@ limitations under the License.
6262
<url>https://github.com/appulse-projects/utils-java</url>
6363
<connection>scm:git:https://github.com/appulse-projects/utils-java.git</connection>
6464
<developerConnection>scm:git:https://github.com/appulse-projects/utils-java.git</developerConnection>
65-
<tag>1.8.0</tag>
65+
<tag>1.9.0</tag>
6666
</scm>
6767

6868
<distributionManagement>
@@ -98,7 +98,7 @@ limitations under the License.
9898
<dependency>
9999
<groupId>org.projectlombok</groupId>
100100
<artifactId>lombok</artifactId>
101-
<version>1.16.20</version>
101+
<version>1.18.2</version>
102102
<scope>provided</scope>
103103
</dependency>
104104

@@ -110,7 +110,7 @@ limitations under the License.
110110
<dependency>
111111
<groupId>io.appulse</groupId>
112112
<artifactId>logging-java</artifactId>
113-
<version>1.0.2</version>
113+
<version>1.1.0</version>
114114
<scope>provided</scope>
115115
</dependency>
116116

@@ -124,7 +124,7 @@ limitations under the License.
124124
<dependency>
125125
<groupId>com.google.code.findbugs</groupId>
126126
<artifactId>annotations</artifactId>
127-
<version>3.0.1</version>
127+
<version>3.0.1u2</version>
128128
<scope>provided</scope>
129129
</dependency>
130130
<dependency>
@@ -137,7 +137,7 @@ limitations under the License.
137137
<dependency>
138138
<groupId>org.assertj</groupId>
139139
<artifactId>assertj-core</artifactId>
140-
<version>3.9.1</version>
140+
<version>3.11.1</version>
141141
<scope>test</scope>
142142
</dependency>
143143
</dependencies>
@@ -277,7 +277,7 @@ limitations under the License.
277277
<dependency>
278278
<groupId>com.puppycrawl.tools</groupId>
279279
<artifactId>checkstyle</artifactId>
280-
<version>8.8</version>
280+
<version>8.12</version>
281281
</dependency>
282282
</dependencies>
283283
<executions>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appulse.utils;
18+
19+
import java.util.LinkedHashMap;
20+
import java.util.Map.Entry;
21+
22+
/**
23+
* LRU cache implementation based on {@code LinkedHashMap}
24+
*
25+
* @author Artem Labazin
26+
* @since 1.9.0
27+
*/
28+
public class LruCache<K, V> extends LinkedHashMap<K, V> {
29+
30+
private static final long serialVersionUID = -1100634446524987320L;
31+
32+
private final int maxSize;
33+
34+
public LruCache (int maxSize) {
35+
super(maxSize + 1, 1.0F, true);
36+
this.maxSize = maxSize;
37+
}
38+
39+
@Override
40+
protected boolean removeEldestEntry (Entry<K, V> eldest) {
41+
return size() > maxSize;
42+
}
43+
}

0 commit comments

Comments
 (0)