move Construct to FunctionUtils

This commit is contained in:
dfsek
2026-01-02 20:04:00 -07:00
parent e706ef89fc
commit df46c617f2
5 changed files with 13 additions and 23 deletions

View File

@@ -12,13 +12,13 @@ import java.util.Collection;
import java.util.List;
import com.dfsek.terra.api.block.state.properties.Property;
import com.dfsek.terra.api.util.generic.Construct;
import com.dfsek.terra.api.util.function.FunctionUtils;
public interface IntProperty extends Property<Integer> {
static IntProperty of(String name, int min, int max) {
return new IntProperty() {
private final Collection<Integer> collection = Construct.construct(() -> {
private final Collection<Integer> collection = FunctionUtils.construct(() -> {
List<Integer> ints = new ArrayList<>();
for(int i = min; i <= max; i++) {
ints.add(i);

View File

@@ -9,7 +9,7 @@ package com.dfsek.terra.api.block.state.properties.enums;
import com.dfsek.seismic.type.Rotation;
import com.dfsek.terra.api.util.generic.Construct;
import com.dfsek.terra.api.util.function.FunctionUtils;
public enum Direction {
@@ -20,7 +20,7 @@ public enum Direction {
UP(-1, 0, 1, 0),
DOWN(-1, 0, -1, 0);
private static final Direction[] rotations = Construct.construct(() -> new Direction[]{ NORTH, SOUTH, EAST, WEST });
private static final Direction[] rotations = FunctionUtils.construct(() -> new Direction[]{ NORTH, SOUTH, EAST, WEST });
private final int rotation;

View File

@@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public final class FunctionUtils {
@@ -54,4 +55,8 @@ public final class FunctionUtils {
}
};
}
public static <T> T construct(Supplier<T> in) {
return in.get();
}
}

View File

@@ -1,17 +0,0 @@
/*
* Copyright (c) 2020-2025 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.util.generic;
import java.util.function.Supplier;
public final class Construct {
public static <T> T construct(Supplier<T> in) {
return in.get();
}
}

View File

@@ -8,12 +8,10 @@
package com.dfsek.terra.api.util.generic;
import com.dfsek.terra.api.util.generic.control.Monad;
import com.dfsek.terra.api.util.generic.data.Functor;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -31,6 +29,10 @@ public final class Lazy<T> implements Monad<T, Lazy<?>> {
return new Lazy<>(valueSupplier);
}
public static <T> Lazy<T> of(T value) {
return new Lazy<>(() -> value);
}
public T value() {
if(!got.compareAndExchange(false, true)) {
value = valueSupplier.get();