Skip to content

Commit

Permalink
Fix peak and head methods for LRU
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Apr 5, 2024
1 parent f5d7a1e commit e8f9f64
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/mekanism/common/lib/collection/LRU.java
Expand Up @@ -91,10 +91,11 @@ public void reverseIterate(Consumer<T> callback) {
*/
@NotNull
public T head() {
if (head.value == null) {
//head.next is never null as it will be tail when empty
if (head.next.value == null) {
throw new NoSuchElementException("No entries");
}
return head.value;
return head.next.value;
}

/**
Expand All @@ -104,7 +105,7 @@ public T head() {
*/
@Nullable
public T peek() {
return head.value;
return head.next.value;
}

private static class LRUEntry<T> {
Expand Down

0 comments on commit e8f9f64

Please sign in to comment.