File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,7 @@ public LRUCache() {
1414
1515 boolean add (E item ) {
1616 boolean newItem = !this .linkedHashSet .remove (item );
17- if (newItem ) {
18- this .linkedHashSet .add (item );
19- }
17+ this .linkedHashSet .add (item );
2018
2119 if (this .linkedHashSet .size () >= MAX_SIZE ) {
2220 Iterator <E > it = this .linkedHashSet .iterator ();
Original file line number Diff line number Diff line change @@ -26,6 +26,16 @@ public void addReturnsFalseForExistingItem() {
2626 assertThat (added , is (false ));
2727 }
2828
29+ @ Category (UnitTest .class )
30+ public void addReturnsFalseForExistingItemMultipleTimes () {
31+ LRUCache <Integer > lru = new LRUCache <Integer >();
32+ lru .add (1 );
33+ lru .add (1 );
34+ boolean added = lru .add (1 );
35+
36+ assertThat (added , is (false ));
37+ }
38+
2939 @ Test
3040 @ Category (UnitTest .class )
3141 public void addRemovesOldestItemWhenMaxSizeIsReached () {
You can’t perform that action at this time.
0 commit comments