chore: fmt

This commit is contained in:
Orion Kindel 2023-04-04 15:37:28 -07:00
parent ecf9086b35
commit 36f708b514
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
12 changed files with 73 additions and 24 deletions

View File

@ -4,11 +4,13 @@ import java.time.Duration;
import java.util.Optional;
public abstract sealed class RetryStrategy {
@Override
public boolean equals(Object other) {
return switch (this) {
case Exponential self -> switch (other) {
case Exponential e -> e.initMin == self.initMin && e.initMax == self.initMax;
case Exponential e -> e.initMin == self.initMin &&
e.initMax == self.initMax;
default -> false;
};
case Linear self -> switch (other) {
@ -20,10 +22,12 @@ public abstract sealed class RetryStrategy {
}
public final class Exponential extends RetryStrategy {
public final Duration initMin;
public final Duration initMax;
private static native Exponential fromRust(byte[] mem);
private native byte[] toRust();
public Exponential(Duration initMin, Duration initMax) {
@ -33,10 +37,12 @@ public abstract sealed class RetryStrategy {
}
public final class Linear extends RetryStrategy {
public final Duration min;
public final Duration max;
private static native Linear fromRust(byte[] mem);
private native byte[] toRust();
public Linear(Duration min, Duration max) {

View File

@ -1,6 +1,7 @@
package dev.toad;
public class Runtime {
public static native void init(RuntimeOptions o);
private Runtime() {}

View File

@ -4,10 +4,16 @@ import java.util.List;
public interface Message {
public int id();
public byte[] token();
public MessageCode code();
public MessageType type();
public List<MessageOption> options();
public byte[] payloadBytes();
public String payloadString();
}

View File

@ -4,5 +4,6 @@ import java.util.List;
public interface MessageOption {
public long number();
public List<MessageOptionValue> values();
}

View File

@ -6,17 +6,25 @@ import java.util.List;
import java.util.stream.Collectors;
public class MessageOptionOwned implements MessageOption {
public final long number;
public final List<MessageOptionValue> values;
public MessageOptionOwned(MessageOptionRef ref) {
this.number = ref.number();
this.values = Arrays.asList(ref.valueRefs())
.stream()
.map(MessageOptionValueRef::clone)
.collect(Collectors.toList());
this.values =
Arrays
.asList(ref.valueRefs())
.stream()
.map(MessageOptionValueRef::clone)
.collect(Collectors.toList());
}
public long number() {return this.number;}
public List<MessageOptionValue> values() {return this.values;}
public long number() {
return this.number;
}
public List<MessageOptionValue> values() {
return this.values;
}
}

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List;
public class MessageOptionRef implements MessageOption {
private final long addr;
private final long number;

View File

@ -2,5 +2,6 @@ package dev.toad.msg;
public interface MessageOptionValue {
public byte[] asBytes();
public String asString();
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.stream.Collectors;
public class MessageOptionValueOwned implements MessageOptionValue {
public final byte[] bytes;
public MessageOptionValueOwned(MessageOptionValueRef ref) {

View File

@ -1,7 +1,9 @@
package dev.toad.msg;
public class MessageOptionValueRef implements MessageOptionValue {
private final long addr;
private native byte[] bytes(long addr);
public MessageOptionValueRef(long addr) {

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.stream.Collectors;
public class MessageOwned implements Message {
private static int id;
private static byte[] token;
private static byte[] payload;
@ -20,10 +21,12 @@ public class MessageOwned implements Message {
this.type = ref.type();
this.payload = ref.payloadBytes().clone();
this.opts = Arrays.asList(ref.optionRefs())
.stream()
.map(MessageOptionRef::clone)
.collect(Collectors.toList());
this.opts =
Arrays
.asList(ref.optionRefs())
.stream()
.map(MessageOptionRef::clone)
.collect(Collectors.toList());
}
public int id() {

View File

@ -11,13 +11,19 @@ import java.util.List;
* MessageRef should never be stored in state; invoke `.clone()` first.
*/
public class MessageRef implements Message {
private final long addr;
private static native int id(long addr);
private static native byte[] token(long addr);
private static native byte[] payload(long addr);
private static native MessageCode code(long addr);
private static native MessageType type(long addr);
private static native MessageOptionRef[] opts(long addr);
public MessageRef(long addr) {

View File

@ -1,27 +1,40 @@
package dev.toad.msg;
public enum MessageType {
CON(1), NON(2), ACK(3), RESET(4);
CON(1),
NON(2),
ACK(3),
RESET(4);
private MessageType(int val) {}
public String toString() {
switch(this) {
case CON: return "CON";
case NON: return "NON";
case ACK: return "ACK";
case RESET: return "RESET";
default: throw new Error();
switch (this) {
case CON:
return "CON";
case NON:
return "NON";
case ACK:
return "ACK";
case RESET:
return "RESET";
default:
throw new Error();
}
}
public static MessageType fromString(String s) {
switch(s.toLowerCase().trim()) {
case "con": return CON;
case "non": return NON;
case "ack": return ACK;
case "reset": return RESET;
default: throw new Error();
switch (s.toLowerCase().trim()) {
case "con":
return CON;
case "non":
return NON;
case "ack":
return ACK;
case "reset":
return RESET;
default:
throw new Error();
}
}
}