mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 09:20:28 +00:00
Move WiredNode default methods to the impl
This commit is contained in:
parent
d38b1da974
commit
451a2593ce
@ -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.
|
* @return {@code true} if a connection was created or {@code false} if the connection already exists.
|
||||||
* @see WiredNode#disconnectFrom(WiredNode)
|
* @see WiredNode#disconnectFrom(WiredNode)
|
||||||
*/
|
*/
|
||||||
default boolean connectTo(WiredNode node) {
|
boolean connectTo(WiredNode node);
|
||||||
return getNetwork().connect(this, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a connection between this node and another.
|
* Destroy a connection between this node and another.
|
||||||
@ -66,9 +64,7 @@ public interface WiredNode extends PacketNetwork {
|
|||||||
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
|
* @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
|
||||||
* @see WiredNode#connectTo(WiredNode)
|
* @see WiredNode#connectTo(WiredNode)
|
||||||
*/
|
*/
|
||||||
default boolean disconnectFrom(WiredNode node) {
|
boolean disconnectFrom(WiredNode node);
|
||||||
return getNetwork() == node.getNetwork() && getNetwork().disconnect(this, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sever all connections this node has, removing it from this network.
|
* Sever all connections this node has, removing it from this network.
|
||||||
@ -80,9 +76,7 @@ public interface WiredNode extends PacketNetwork {
|
|||||||
* only element.
|
* only element.
|
||||||
* @throws IllegalArgumentException If the node is not in the network.
|
* @throws IllegalArgumentException If the node is not in the network.
|
||||||
*/
|
*/
|
||||||
default boolean remove() {
|
boolean remove();
|
||||||
return getNetwork().remove(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark this node's peripherals as having changed.
|
* Mark this node's peripherals as having changed.
|
||||||
@ -92,7 +86,5 @@ public interface WiredNode extends PacketNetwork {
|
|||||||
*
|
*
|
||||||
* @param peripherals The new peripherals for this node.
|
* @param peripherals The new peripherals for this node.
|
||||||
*/
|
*/
|
||||||
default void updatePeripherals(Map<String, IPeripheral> peripherals) {
|
void updatePeripherals(Map<String, IPeripheral> peripherals);
|
||||||
getNetwork().updatePeripherals(this, peripherals);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,26 @@ public final class WiredNodeImpl implements WiredNode {
|
|||||||
network = new WiredNetworkImpl(this);
|
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
|
@Override
|
||||||
public synchronized void addReceiver(PacketReceiver receiver) {
|
public synchronized void addReceiver(PacketReceiver receiver) {
|
||||||
if (receivers == null) receivers = new HashSet<>();
|
if (receivers == null) receivers = new HashSet<>();
|
||||||
|
@ -15,7 +15,6 @@ import net.minecraft.nbt.Tag;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||||
@ -86,11 +85,6 @@ public final class WiredModemLocalPeripheral {
|
|||||||
return peripheral != null ? type + "_" + id : null;
|
return peripheral != null ? type + "_" + id : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public IPeripheral getPeripheral() {
|
|
||||||
return peripheral;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPeripheral() {
|
public boolean hasPeripheral() {
|
||||||
return peripheral != null;
|
return peripheral != null;
|
||||||
}
|
}
|
||||||
@ -100,9 +94,7 @@ public final class WiredModemLocalPeripheral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, IPeripheral> toMap() {
|
public Map<String, IPeripheral> toMap() {
|
||||||
return peripheral == null
|
return peripheral == null ? Map.of() : Map.of(type + "_" + id, peripheral);
|
||||||
? Map.of()
|
|
||||||
: Collections.singletonMap(type + "_" + id, peripheral);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(CompoundTag tag, String suffix) {
|
public void write(CompoundTag tag, String suffix) {
|
||||||
|
@ -4,14 +4,13 @@
|
|||||||
|
|
||||||
package dan200.computercraft.core.apis.http.options;
|
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 javax.annotation.Nullable;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.OptionalLong;
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
@Immutable
|
|
||||||
public final class PartialOptions {
|
public final class PartialOptions {
|
||||||
public static final PartialOptions DEFAULT = new PartialOptions(
|
public static final PartialOptions DEFAULT = new PartialOptions(
|
||||||
null, OptionalLong.empty(), OptionalLong.empty(), OptionalInt.empty(), Optional.empty()
|
null, OptionalLong.empty(), OptionalLong.empty(), OptionalInt.empty(), Optional.empty()
|
||||||
@ -23,7 +22,7 @@ public final class PartialOptions {
|
|||||||
private final OptionalInt websocketMessage;
|
private final OptionalInt websocketMessage;
|
||||||
private final Optional<Boolean> useProxy;
|
private final Optional<Boolean> useProxy;
|
||||||
|
|
||||||
@SuppressWarnings("Immutable") // Lazily initialised, so this mutation is invisible in the public API
|
@LazyInit
|
||||||
private @Nullable Options options;
|
private @Nullable Options options;
|
||||||
|
|
||||||
public PartialOptions(@Nullable Action action, OptionalLong maxUpload, OptionalLong maxDownload, OptionalInt websocketMessage, Optional<Boolean> useProxy) {
|
public PartialOptions(@Nullable Action action, OptionalLong maxUpload, OptionalLong maxDownload, OptionalInt websocketMessage, Optional<Boolean> useProxy) {
|
||||||
|
Loading…
Reference in New Issue
Block a user