Skip to content

Commit c72226a

Browse files
committed
What am I doing
More util
1 parent 8191cc7 commit c72226a

4 files changed

Lines changed: 90 additions & 2 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package survivalblock.atmosphere.atmospheric_api.not_mixin.util;
2+
3+
import com.mojang.serialization.Codec;
4+
import net.minecraft.util.StringRepresentable;
5+
import survivalblock.atmosphere.atmospheric_api.not_mixin.funny.IsThisEvenNecessary;
6+
7+
import java.util.Locale;
8+
import java.util.function.BinaryOperator;
9+
10+
@IsThisEvenNecessary(IsThisEvenNecessary.Levels.PROBABLY_NOT)
11+
@SuppressWarnings("unused")
12+
public enum BooleanOperations implements StringRepresentable {
13+
/**
14+
* Represents the logical AND ({@code &&}) operator
15+
*/
16+
AND((one, two) -> one && two),
17+
/**
18+
* Represents the logical OR ({@code ||}) operator
19+
*/
20+
OR((one, two) -> one || two),
21+
/**
22+
* Represents the bitwise AND ({@code &}) operator
23+
*/
24+
BAND((one, two) -> one & two),
25+
/**
26+
* Represents the bitwise OR ({@code |}) operator
27+
*/
28+
BOR((one, two) -> one | two),
29+
/**
30+
* Represents the exclusive OR ({@code ^} or ⊕) operator
31+
*/
32+
XOR((one, two) -> one ^ two);
33+
34+
public static final Codec<BooleanOperations> CODEC = StringRepresentable.fromEnum(BooleanOperations::values);
35+
36+
private final BinaryOperator<Boolean> applicator;
37+
private final BinaryOperator<Boolean> negator;
38+
39+
BooleanOperations(BinaryOperator<Boolean> applicator) {
40+
this.applicator = applicator;
41+
this.negator = ((one, two) -> !applicator.apply(one, two));
42+
}
43+
44+
/**
45+
* @return the {@linkplain BinaryOperator} associated with this operation
46+
*/
47+
public BinaryOperator<Boolean> applicator() {
48+
return this.applicator;
49+
}
50+
51+
/**
52+
* Returns a {@linkplain BinaryOperator} that is the opposite of the original operation.
53+
* For example, this would return XNOR for {@linkplain BooleanOperations#XOR}.
54+
* @return the inverse of the {@linkplain BooleanOperations#applicator()}
55+
*/
56+
public BinaryOperator<Boolean> negator() {
57+
return this.negator;
58+
}
59+
60+
@Override
61+
public String getSerializedName() {
62+
return this.name().toLowerCase(Locale.ROOT);
63+
}
64+
}

src/main/java/survivalblock/atmosphere/atmospheric_api/not_mixin/util/FunctionOperations.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.world.entity.Entity;
1111
import net.minecraft.world.entity.SpawnPlacements.SpawnPredicate;
1212
import org.apache.commons.lang3.function.Consumers;
13+
import survivalblock.atmosphere.atmospheric_api.not_mixin.funny.IsThisEvenNecessary;
1314

1415
import java.util.ArrayList;
1516
import java.util.List;
@@ -33,20 +34,24 @@ public final class FunctionOperations {
3334
private FunctionOperations() {
3435
}
3536

37+
@IsThisEvenNecessary(IsThisEvenNecessary.Levels.PROBABLY_NOT)
3638
public static <T> Consumer<T> voidConsumer() {
3739
return Consumers.nop();
3840
}
3941

42+
@IsThisEvenNecessary(IsThisEvenNecessary.Levels.PROBABLY_NOT)
4043
@SuppressWarnings("unchecked")
4144
public static <T> Function<T, T> identityFunction() {
4245
return IDENTITY_FUNCTION;
4346
}
4447

48+
@IsThisEvenNecessary(IsThisEvenNecessary.Levels.PROBABLY_NOT)
4549
@SuppressWarnings("unchecked")
4650
public static <T> Supplier<T> nullSupplier() {
4751
return NULL_SUPPLIER;
4852
}
4953

54+
@IsThisEvenNecessary
5055
public static <T> Supplier<T> lazySupplier(T obj) {
5156
return () -> obj;
5257
}

src/main/java/survivalblock/atmosphere/atmospheric_api/not_mixin/util/FunctionUnlimited.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
/**
99
* @see com.llamalad7.mixinextras.injector.wrapoperation.Operation
10-
* @param <R> the return type
10+
* @param <R> the return type of the function
1111
*/
1212
@FunctionalInterface
1313
public interface FunctionUnlimited<R> {
14-
1514
R apply(Object[] args);
1615
}

src/main/java/survivalblock/atmosphere/atmospheric_api/not_mixin/util/ReflectionCacher.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Objects;
1818
import java.util.WeakHashMap;
1919
import java.util.function.Function;
20+
import java.util.stream.Collectors;
2021

2122
@SuppressWarnings("unused")
2223
public final class ReflectionCacher {
@@ -127,6 +128,17 @@ public int hashCode() {
127128
Arrays.hashCode(this.parameterTypes)
128129
);
129130
}
131+
132+
@Override
133+
public String toString() {
134+
return this.getClass().getName()
135+
+ "{reference='" + this.clazz.getName() + "." + this.name + "'"
136+
+ ", returnType=" + (this.returnType == null ? "null" : this.returnType.getName())
137+
+ ", parameterTypes=" + Arrays.stream(this.parameterTypes)
138+
.map(Class::getName)
139+
.collect(Collectors.joining(", "))
140+
+ '}';
141+
}
130142
}
131143

132144
/**
@@ -153,5 +165,13 @@ public int hashCode() {
153165
this.explicit
154166
);
155167
}
168+
169+
@Override
170+
public String toString() {
171+
return this.getClass().getName()
172+
+ "{reference='" + this.clazz.getName() + "." + this.name + "'"
173+
+ ", explicit=" + this.explicit
174+
+ '}';
175+
}
156176
}
157177
}

0 commit comments

Comments
 (0)