Skip to content

Commit

Permalink
Makes cache attempt unlabeled if labeled was not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Nov 26, 2024
1 parent abb1125 commit 89108b1
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ public boolean contains(Class<?> type, String label) {
@SuppressWarnings("unchecked")
@Override
public <T> Optional<Tuple<T>> provide(TypeTag tag, Attributes attributes) {
Key key = Key.of(tag.getType(), attributes.label);
if (cache.containsKey(key)) {
return Optional.of((Tuple<T>) cache.get(key));
Key first = Key.of(tag.getType(), attributes.label);
if (cache.containsKey(first)) {
return Optional.of((Tuple<T>) cache.get(first));
}
Key second = first.removeLabel();
if (cache.containsKey(second)) {
return Optional.of((Tuple<T>) cache.get(second));
}
return Optional.empty();
}
Expand All @@ -61,6 +65,10 @@ public static Key of(Class<?> type, String label) {
return new Key(type, label);
}

public Key removeLabel() {
return Key.of(type, null);
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Key)) {
Expand Down

0 comments on commit 89108b1

Please sign in to comment.