Skip to content

Commit 0f9ad5f

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents abd8575 + 8607935 commit 0f9ad5f

8 files changed

Lines changed: 230 additions & 306 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.comroid.api.attr;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class NativeObjectContainer<T> {
7+
protected T nativeObject;
8+
}

src/main/java/org/comroid/api/data/Vector.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.EqualsAndHashCode;
77
import lombok.Getter;
88
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
910
import lombok.Value;
1011
import lombok.experimental.FieldDefaults;
1112
import org.comroid.api.info.Assert;
@@ -68,6 +69,22 @@ static Vector of(double... dim) {
6869

6970
Vector setW(double value);
7071

72+
default Vector intCast() {
73+
return map(x -> (int) x);
74+
}
75+
76+
default Vector intRound() {
77+
return map(Math::round);
78+
}
79+
80+
default Vector intFloor() {
81+
return map(Math::floor);
82+
}
83+
84+
default Vector intCeil() {
85+
return map(Math::ceil);
86+
}
87+
7188
default DoubleStream stream() {
7289
return Arrays.stream(toArray());
7390
}
@@ -278,8 +295,8 @@ public final String toString() {
278295
@FieldDefaults(level = AccessLevel.PROTECTED)
279296
class N3 extends N2 {
280297
public static final N3 Zero = new N3();
281-
public static final N3 One = new N3(1, 1, 1);
282-
double z;
298+
public static final N3 One = new N3(1, 1, 1);
299+
@Setter double z;
283300

284301
public N3(double x, double y, double z) {
285302
super(x, y);
@@ -336,9 +353,9 @@ public N3 convertToEntityAttribute(byte[] dbData) {
336353
@EqualsAndHashCode(callSuper = true)
337354
@FieldDefaults(level = AccessLevel.PROTECTED)
338355
class N4 extends N3 {
339-
public static final N4 Zero = new N4();
340-
public static final N4 One = new N4(1, 1, 1, 1);
341-
double w;
356+
public static final N4 Zero = new N4();
357+
public static final N4 One = new N4(1, 1, 1, 1);
358+
@Setter double w;
342359

343360
public N4(double x, double y, double z, double w) {
344361
super(x, y, z);

src/main/java/org/comroid/api/func/util/Command.java

Lines changed: 143 additions & 266 deletions
Large diffs are not rendered by default.

src/main/java/org/comroid/api/func/util/Event.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ public static class Listener<T> extends Container.Base implements Predicate<Even
171171
@NonFinal boolean active = true;
172172

173173
private Listener(@Nullable String key, @NotNull Bus<T> bus, Predicate<Event<T>> requirement, Consumer<Event<T>> action) {
174-
this.name = key;
175-
this.bus = bus;
174+
this.name = key;
175+
this.bus = bus;
176176
this.requirement = requirement;
177-
this.action = action;
178-
this.location = caller(2);
177+
this.action = action;
178+
this.location = caller(2);
179179
}
180180

181181
@Override
@@ -327,7 +327,7 @@ private <I> Bus<T> setDependent(
327327
) {
328328
if (cleanup && this.upstream != null) this.upstream.downstream.remove(this);
329329
this.upstream = parent;
330-
this.function = uncheckedCast(function);
330+
this.function = uncheckedCast(function);
331331
this.keyFunction = keyFunction;
332332
this.upstream.downstream.add(this);
333333
return this;
@@ -407,7 +407,7 @@ public Event<T> publish(@Nullable String key, @Nullable T data) {
407407
@Builder(builderClassName = "Publisher", buildMethodName = "publish", builderMethodName = "publisher")
408408
public Event<T> publish(@Nullable String key, @Nullable Long flag_, @Nullable T data) {
409409
if (!active) return null;
410-
final var flag = flag_ == null ? Subscriber.DefaultFlag : flag_;
410+
final var flag = flag_ == null ? Subscriber.DefaultFlag : flag_;
411411
final var event = factory.apply(data, key, flag);
412412
accept(event);
413413
return event;
@@ -454,7 +454,7 @@ private void publish(Event<T> event) {
454454
private <P> void $publishDownstream(final Event<P> data) {
455455
if (function == null) return;
456456
Function<@NotNull Event<P>, @Nullable Event<T>> func = uncheckedCast(function);
457-
var it = func.apply(data);
457+
var it = func.apply(data);
458458
if (it == null) return;
459459
accept(it);
460460
}
@@ -464,7 +464,7 @@ private class SubscriberImpl implements Predicate<Event<T>>, BiConsumer<@Nullabl
464464
String key;
465465
long flag;
466466
Subscriber.FlagMode mode;
467-
Invocable<?> delegate;
467+
Invocable<?> delegate;
468468

469469
@Override
470470
public boolean test(Event<T> event) {
@@ -499,7 +499,7 @@ private class SubscriberListener extends Listener<T> {
499499

500500
public SubscriberListener(@Nullable Object target, Collection<SubscriberImpl> subscribers) {
501501
super(null, Bus.this, $ -> true, $ -> {});
502-
this.target = target;
502+
this.target = target;
503503
this.subscribers = subscribers;
504504
}
505505

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.comroid.api.info;
2+
3+
import lombok.Setter;
4+
import lombok.Value;
5+
import lombok.With;
6+
import lombok.experimental.NonFinal;
7+
import org.jetbrains.annotations.Nullable;
8+
9+
import java.util.Objects;
10+
import java.util.stream.IntStream;
11+
12+
@Value
13+
@Setter
14+
public class Range<T extends Number> {
15+
@With @Nullable T start, end;
16+
@NonFinal @Nullable T lowerBound, upperBound;
17+
18+
@SuppressWarnings("unchecked")
19+
public Range(@Nullable T start, @Nullable T end) {
20+
this(start, end, (T) (Integer) 0, (T) (Integer) 64);
21+
}
22+
23+
public Range(@Nullable T start, @Nullable T end, @Nullable T lowerBound, @Nullable T upperBound) {
24+
this.start = start;
25+
this.end = end;
26+
this.lowerBound = lowerBound;
27+
this.upperBound = upperBound;
28+
}
29+
30+
public IntStream asIndices() {
31+
var low = Objects.requireNonNullElse(start, lowerBound);
32+
var high = Objects.requireNonNullElse(end, upperBound);
33+
return IntStream.range((int) low, (int) high);
34+
}
35+
36+
public IntStream asEntries() {
37+
return asIndices().map(x -> x + 1);
38+
}
39+
}

src/main/java/org/comroid/api/java/ResourceLoader.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ static ResourceLoader ofCallerClassLoader() {
3131
}
3232

3333
static ResourceLoader ofDirectory(final File dir) {
34-
if (!dir.isDirectory())
35-
throw new IllegalArgumentException("File is not a directory: " + dir);
36-
if (!dir.exists())
37-
throw new IllegalArgumentException("Directory does not exist");
34+
if (!dir.isDirectory()) throw new IllegalArgumentException("File is not a directory: " + dir);
35+
if (!dir.exists()) throw new IllegalArgumentException("Directory does not exist");
3836
return name -> {
3937
try {
4038
return new FileInputStream(new File(dir, name));
@@ -45,23 +43,20 @@ static ResourceLoader ofDirectory(final File dir) {
4543
}
4644

4745
static InputStream fromResourceString(String string) throws FileNotFoundException {
48-
if (string.startsWith("@:"))
49-
return ClassLoader.getSystemClassLoader()
50-
.getResourceAsStream(PathUtil.sanitize(string.substring(2)));
51-
if (string.startsWith("@"))
52-
return new FileInputStream(PathUtil.sanitize(string.substring(1)));
46+
if (string.startsWith("@:")) return ClassLoader.getSystemClassLoader().getResourceAsStream(PathUtil.sanitize(string.substring(2)));
47+
if (string.startsWith("@")) return new FileInputStream(PathUtil.sanitize(string.substring(1)));
5348
return new ByteArrayInputStream(PathUtil.sanitize(string).getBytes());
5449
}
5550

5651
static void assertFile(Class<?> resourceContext, String resource, File file, @Nullable Supplier<String> fallback) throws IOException {
57-
if (file.exists()) return;
52+
var dir = file.getParentFile();
53+
if (!dir.exists() && !dir.mkdirs()) return;
54+
if (file.exists() || !file.createNewFile()) return;
5855
try (
59-
var res = resourceContext.getResourceAsStream(resource);
60-
var fos = new FileOutputStream(file)
56+
var res = resourceContext.getResourceAsStream(resource); var fos = new FileOutputStream(file, false)
6157
) {
6258
if (res == null) {
63-
if (fallback != null)
64-
fos.write(fallback.get().getBytes(StandardCharsets.US_ASCII));
59+
if (fallback != null) fos.write(fallback.get().getBytes(StandardCharsets.US_ASCII));
6560
} else res.transferTo(fos);
6661
}
6762
}

src/test/java/org/comroid/test/config/ConfigTest.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/test/java/org/comroid/test/config/TestConfiguration.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)