Move WiredNode default methods to the impl

This commit is contained in:
Jonathan Coates 2024-03-10 10:00:52 +00:00
parent d38b1da974
commit 451a2593ce
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
4 changed files with 27 additions and 24 deletions

View File

@ -53,9 +53,7 @@ public interface WiredNode extends PacketNetwork {
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
* @see WiredNode#disconnectFrom(WiredNode)
*/
default boolean connectTo(WiredNode node) {
return getNetwork().connect(this, node);
}
boolean connectTo(WiredNode node);
/**
* Destroy a connection between this node and another.
@ -66,9 +64,7 @@ default boolean connectTo(WiredNode node) {
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
* @see WiredNode#connectTo(WiredNode)
*/
default boolean disconnectFrom(WiredNode node) {
return getNetwork() == node.getNetwork() && getNetwork().disconnect(this, node);
}
boolean disconnectFrom(WiredNode node);
/**
* Sever all connections this node has, removing it from this network.
@ -80,9 +76,7 @@ default boolean disconnectFrom(WiredNode node) {
* only element.
* @throws IllegalArgumentException If the node is not in the network.
*/
default boolean remove() {
return getNetwork().remove(this);
}
boolean remove();
/**
* Mark this node's peripherals as having changed.
@ -92,7 +86,5 @@ default boolean remove() {
*
* @param peripherals The new peripherals for this node.
*/
default void updatePeripherals(Map<String, IPeripheral> peripherals) {
getNetwork().updatePeripherals(this, peripherals);
}
void updatePeripherals(Map<String, IPeripheral> peripherals);
}

View File

@ -40,6 +40,26 @@ public WiredNodeImpl(WiredElement element) {
network = new WiredNetworkImpl(this);
}
@Override
public boolean connectTo(WiredNode node) {
return network.connect(this, node);
}
@Override
public boolean disconnectFrom(WiredNode node) {
return network == ((WiredNodeImpl) node).network && network.disconnect(this, node);
}
@Override
public boolean remove() {
return network.remove(this);
}
@Override
public void updatePeripherals(Map<String, IPeripheral> peripherals) {
network.updatePeripherals(this, peripherals);
}
@Override
public synchronized void addReceiver(PacketReceiver receiver) {
if (receivers == null) receivers = new HashSet<>();

View File

@ -15,7 +15,6 @@
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Map;
import static dan200.computercraft.core.util.Nullability.assertNonNull;
@ -86,11 +85,6 @@ public String getConnectedName() {
return peripheral != null ? type + "_" + id : null;
}
@Nullable
public IPeripheral getPeripheral() {
return peripheral;
}
public boolean hasPeripheral() {
return peripheral != null;
}
@ -100,9 +94,7 @@ public void extendMap(Map<String, IPeripheral> peripherals) {
}
public Map<String, IPeripheral> toMap() {
return peripheral == null
? Map.of()
: Collections.singletonMap(type + "_" + id, peripheral);
return peripheral == null ? Map.of() : Map.of(type + "_" + id, peripheral);
}
public void write(CompoundTag tag, String suffix) {

View File

@ -4,14 +4,13 @@
package dan200.computercraft.core.apis.http.options;
import com.google.errorprone.annotations.Immutable;
import com.google.errorprone.annotations.concurrent.LazyInit;
import javax.annotation.Nullable;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
@Immutable
public final class PartialOptions {
public static final PartialOptions DEFAULT = new PartialOptions(
null, OptionalLong.empty(), OptionalLong.empty(), OptionalInt.empty(), Optional.empty()
@ -23,7 +22,7 @@ public final class PartialOptions {
private final OptionalInt websocketMessage;
private final Optional<Boolean> useProxy;
@SuppressWarnings("Immutable") // Lazily initialised, so this mutation is invisible in the public API
@LazyInit
private @Nullable Options options;
public PartialOptions(@Nullable Action action, OptionalLong maxUpload, OptionalLong maxDownload, OptionalInt websocketMessage, Optional<Boolean> useProxy) {