Skip to content

Commit

Permalink
use static final
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 7, 2024
1 parent 99c1539 commit a2dc7fd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public final class ExpiringSet<E> {

private final Cache<E, Object> cache;
private final Object PRESENT = new Object(); // Dummy value to associate with an Object in the backing Cache
private static final Object PRESENT = new Object(); // Dummy value to associate with an Object in the backing Cache

public ExpiringSet(long duration, TimeUnit unit) {
this.cache = Caffeine.newBuilder().expireAfterWrite(duration, unit).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ final class Default implements TPSCache {

private final Server server;
private final Cache<Object, Double> cached_tps;
private final Object TPS_KEY;
private static final Object TPS_KEY = new Object(); // Dummy value to associate with tps in the backing Cache

Default(JavaPlugin plugin, long checkDelayMillis) {
this.server = plugin.getServer();
this.cached_tps = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(checkDelayMillis)).build();
this.TPS_KEY = new Object(); // Dummy value to associate with tps in the backing Cache
}

@Override
public double getGlobalTPS() {
Double tps = this.cached_tps.getIfPresent(this.TPS_KEY);
Double tps = this.cached_tps.getIfPresent(TPS_KEY);
if (tps == null) {
tps = this.server.getTPS()[0];
this.cached_tps.put(this.TPS_KEY, tps);
this.cached_tps.put(TPS_KEY, tps);
}
return tps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public final class ExpiringSet<E> {

private final Cache<E, Object> cache;
private final Object PRESENT = new Object(); // Dummy value to associate with an Object in the backing Cache
private static final Object PRESENT = new Object(); // Dummy value to associate with an Object in the backing Cache

public ExpiringSet(long duration, TimeUnit unit) {
this.cache = Caffeine.newBuilder().expireAfterWrite(duration, unit).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ public final class TPSCache {

private final Server server;
private final Cache<Object, Double> cached_tps;
private final Object TPS_KEY;
private static final Object TPS_KEY = new Object();

TPSCache(Server server, long checkDelayMillis) {
this.server = server;
this.cached_tps = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(checkDelayMillis)).build();
this.TPS_KEY = new Object(); // Dummy value to associate with tps in the backing Cache
}

public static TPSCache create(long checkDelayMillis) {
return new TPSCache(AnarchyExploitFixes.getInstance().getServer(), checkDelayMillis);
}

public double getTPS() {
Double tps = this.cached_tps.getIfPresent(this.TPS_KEY);
Double tps = this.cached_tps.getIfPresent(TPS_KEY);
if (tps == null) {
tps = this.server.getTPS()[0];
this.cached_tps.put(this.TPS_KEY, tps);
this.cached_tps.put(TPS_KEY, tps);
}
return tps;
}
Expand Down

0 comments on commit a2dc7fd

Please sign in to comment.