Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/main/java/dev/shaaf/jgraphlet/CacheKey.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package dev.shaaf.jgraphlet;

import java.util.*;

/**
* Cache key used to uniquely identify the output of a task for a given input.
*
* @param taskName the name of the task
* @param input the input provided to that task
*/
public record CacheKey(String taskName, Object input) {
}
public CacheKey {
Objects.requireNonNull(taskName, "taskName");
input = normalize(input); // snapshot for stable equals/hashCode
}
private static Object normalize(Object o) {
if (o == null) return null;
if (o instanceof Map<?, ?> m) {
// preserve iteration order to keep equals/hash stable
var copy = new LinkedHashMap<>(m);
return Map.copyOf(copy);
}
if (o instanceof List<?> l) return List.copyOf(l);
if (o instanceof Set<?> s) return Set.copyOf(s);
return o; // assume immutable or stable
}
}
Loading