MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Cache

Class Cache

src/main/java/fieldbox/ui/Compositor.java:128–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126 }
127
128 static public class Cache<T> {
129 private final Function<T, Long> getMod;
130 private final Consumer<T> update;
131 T target;
132 long mod;
133 boolean lock = false;
134
135 public Cache(T target, Function<T, Long> getMod, Consumer<T> update) {
136 this.target = target;
137 this.mod = getMod.apply(target) - 1;
138 this.getMod = getMod;
139 this.update = update;
140 }
141
142 public void update() {
143 if (lock) return;
144 try {
145 lock = true;
146 long m = getMod.apply(target);
147 if (m != mod) {
148 update.accept(target);
149 mod = getMod.apply(target);
150 }
151 } finally {
152 lock = false;
153 }
154 }
155 }
156
157 public class Layer {
158 public Map<Layer, Cache<Layer>> dependsOn = new HashMap<>();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected