mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
rename Lazy to Memo
This commit is contained in:
@@ -17,7 +17,7 @@ import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.image.SuppliedImage;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.generic.Memo;
|
||||
|
||||
import static com.dfsek.terra.api.util.cache.CacheUtils.CACHE_EXECUTOR;
|
||||
|
||||
@@ -41,7 +41,7 @@ record ImageCache(LoadingCache<String, Image> cache) implements Properties {
|
||||
return new SuppliedImage(() -> images.cache.get(path));
|
||||
} else {
|
||||
// If images do not time out, image can be lazily loaded once instead of performing cache lookups for each image operation
|
||||
Lazy<Image> lazyImage = Lazy.lazy(() -> images.cache.get(path));
|
||||
Memo<Image> lazyImage = Memo.lazy(() -> images.cache.get(path));
|
||||
return new SuppliedImage(lazyImage::value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.generic.Memo;
|
||||
|
||||
|
||||
public interface EnumProperty<T extends Enum<T>> extends Property<T> {
|
||||
static <T extends Enum<T>> EnumProperty<T> of(String name, Class<T> clazz) {
|
||||
return new EnumProperty<>() {
|
||||
private final Lazy<Collection<T>> constants = Lazy.lazy(() -> Arrays.asList(clazz.getEnumConstants()));
|
||||
private final Memo<Collection<T>> constants = Memo.lazy(() -> Arrays.asList(clazz.getEnumConstants()));
|
||||
|
||||
@Override
|
||||
public Collection<T> values() {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.function.BooleanSupplier;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import com.dfsek.terra.api.util.function.IntPredicate;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.generic.Memo;
|
||||
import com.dfsek.terra.api.util.range.Range;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class BinaryColumn {
|
||||
private final IntPredicate data;
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final Lazy<boolean[]> results;
|
||||
private final Memo<boolean[]> results;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link BinaryColumn} with all values initiated to {@code false}
|
||||
@@ -34,7 +34,7 @@ public class BinaryColumn {
|
||||
public BinaryColumn(int minY, int maxY, IntPredicate data) {
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
this.results = Lazy.lazy(() -> {
|
||||
this.results = Memo.lazy(() -> {
|
||||
boolean[] res = new boolean[maxY - minY];
|
||||
for(int y = minY; y < maxY; y++) {
|
||||
res[y - minY] = get(y);
|
||||
@@ -48,7 +48,7 @@ public class BinaryColumn {
|
||||
public BinaryColumn(int minY, int maxY, boolean[] data) {
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
this.results = Lazy.lazy(() -> data);
|
||||
this.results = Memo.lazy(() -> data);
|
||||
if(maxY <= minY) throw new IllegalArgumentException("Max y must be greater than min y");
|
||||
this.data = y -> data[y - minY];
|
||||
}
|
||||
|
||||
@@ -16,21 +16,21 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public final class Lazy<T> implements Monad<T, Lazy<?>> {
|
||||
public final class Memo<T> implements Monad<T, Memo<?>> {
|
||||
private final Supplier<T> valueSupplier;
|
||||
private volatile T value = null;
|
||||
private final AtomicBoolean got = new AtomicBoolean(false);
|
||||
|
||||
private Lazy(Supplier<T> valueSupplier) {
|
||||
private Memo(Supplier<T> valueSupplier) {
|
||||
this.valueSupplier = valueSupplier;
|
||||
}
|
||||
|
||||
public static <T> Lazy<T> lazy(Supplier<T> valueSupplier) {
|
||||
return new Lazy<>(valueSupplier);
|
||||
public static <T> Memo<T> lazy(Supplier<T> valueSupplier) {
|
||||
return new Memo<>(valueSupplier);
|
||||
}
|
||||
|
||||
public static <T> Lazy<T> of(T value) {
|
||||
return new Lazy<>(() -> value);
|
||||
public static <T> Memo<T> of(T value) {
|
||||
return new Memo<>(() -> value);
|
||||
}
|
||||
|
||||
public T value() {
|
||||
@@ -41,17 +41,17 @@ public final class Lazy<T> implements Monad<T, Lazy<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <T2> Lazy<T2> bind(@NotNull Function<T, Monad<T2, Lazy<?>>> map) {
|
||||
return lazy(() -> ((Lazy<T2>) map.apply(value())).value());
|
||||
public @NotNull <T2> Memo<T2> bind(@NotNull Function<T, Monad<T2, Memo<?>>> map) {
|
||||
return lazy(() -> ((Memo<T2>) map.apply(value())).value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <U> Lazy<U> map(@NotNull Function<T, U> map) {
|
||||
public @NotNull <U> Memo<U> map(@NotNull Function<T, U> map) {
|
||||
return lazy(() -> map.apply(value()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <T1> Lazy<T1> pure(@NotNull T1 t) {
|
||||
return new Lazy<>(() -> t);
|
||||
public @NotNull <T1> Memo<T1> pure(@NotNull T1 t) {
|
||||
return new Memo<>(() -> t);
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,21 @@ package com.dfsek.terra.cli.block;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.generic.Memo;
|
||||
|
||||
|
||||
public class CLIBlockType implements BlockType {
|
||||
private final String value;
|
||||
private final boolean solid;
|
||||
private final boolean water;
|
||||
private final Lazy<CLIBlockState> defaultState;
|
||||
private final Memo<CLIBlockState> defaultState;
|
||||
|
||||
public CLIBlockType(String value) {
|
||||
if(value.contains("[")) throw new IllegalArgumentException("Block Type must not contain properties");
|
||||
this.value = value;
|
||||
this.solid = !value.equals("minecraft:air");
|
||||
this.water = value.equals("minecraft:water");
|
||||
this.defaultState = Lazy.lazy(() -> new CLIBlockState(value));
|
||||
this.defaultState = Memo.lazy(() -> new CLIBlockState(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user