From 20f2c0836b309a95cfcf0d9c13fafeefc5c1d5e7 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 16 Nov 2023 13:24:49 -0500 Subject: Change how GroupRegistry deals with Wildcard Generics --- .../net/cshift/api/transit/network/Channel.java | 12 ++++-- .../java/net/cshift/api/transit/network/INode.java | 20 ++++++---- .../net/cshift/api/transit/network/ISystem.java | 15 -------- .../cshift/api/transit/network/PoolManifest.java | 28 +++++++------- .../api/transit/network/packet/DynamicPacket.java | 14 +++---- .../api/transit/network/packet/IDynamicPacket.java | 13 +++---- .../api/transit/network/packet/IStaticPacket.java | 10 ++--- .../transit/network/packet/MetaDynamicPacket.java | 44 ---------------------- .../api/transit/network/packet/MetaPacket.java | 35 ----------------- .../api/transit/network/packet/StaticPacket.java | 6 +-- 10 files changed, 55 insertions(+), 142 deletions(-) delete mode 100644 src/main/java/net/cshift/api/transit/network/ISystem.java delete mode 100644 src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java delete mode 100644 src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java (limited to 'src/main/java/net/cshift/api/transit/network') diff --git a/src/main/java/net/cshift/api/transit/network/Channel.java b/src/main/java/net/cshift/api/transit/network/Channel.java index bd4cdf2..3fdae88 100644 --- a/src/main/java/net/cshift/api/transit/network/Channel.java +++ b/src/main/java/net/cshift/api/transit/network/Channel.java @@ -25,6 +25,8 @@ package net.cshift.api.transit.network; import net.cshift.api.transit.network.packet.IStaticPacket; +import net.cshift.api.transit.type.group.GroupRegistry; +import net.cshift.api.transit.type.group.TypeGroup; /** * @author Kyle Gunger @@ -35,6 +37,7 @@ public final class Channel { private INode to; private int id; private String group; + private Class baseClass; /** This constructor should be called by a node approving a connection. The approving node can give the connection an ID and group. * Negative IDs indicate a terminated connection, so do not initialize the class with a negative ID. @@ -43,11 +46,12 @@ public final class Channel { * @param id The channel's id, as assigned by the recieving node. In most cases, this will match the pool ID as a way to match channels to pools. * @param group */ - public Channel(INode node, int id, String group) + public Channel(INode node, int id, String group, Class baseClass) { to = node; this.id = id; this.group = group; + this.baseClass = baseClass; } @@ -78,8 +82,8 @@ public final class Channel { * * @return */ - public String getGroup() { - return group; + public TypeGroup getGroup() { + return GroupRegistry.groupByID(group, baseClass); } /** Returns true if the connection has been terminated @@ -135,7 +139,7 @@ public final class Channel { * @param packet the packet to send * @return The overflow data if the packet is only partially accepted. {@code null} otherwise. */ - public IStaticPacket send(IStaticPacket packet) + public IStaticPacket send(IStaticPacket packet) { return to.accept(packet, this); } diff --git a/src/main/java/net/cshift/api/transit/network/INode.java b/src/main/java/net/cshift/api/transit/network/INode.java index 54701e7..6653e40 100644 --- a/src/main/java/net/cshift/api/transit/network/INode.java +++ b/src/main/java/net/cshift/api/transit/network/INode.java @@ -13,25 +13,29 @@ public interface INode */ public PoolManifest getManifest(); - /** Get the system managing the node or {@code null} if there isn't one - * - */ - public ISystem getSystem(); - // ############### // # Connections # // ############### - /** Call this function to establish a connection with a node. + /** Call this function to establish a specific connection with a node. * * @param The type of connection being asked for * @param poolID The ID of the pool the channel will interface with (see PoolManifest) * @param asker The asking node * @return A channel if the node accepts the request, {@code null} otherwise */ - public Channel connect(int poolID, INode asker); + public Channel connect(int poolID, String group, INode asker); + + /** Call this function to establish a default connection with a node. + * + * @param The type of connection being asked for + * @param group The group that is being connected to + * @param asker The asking node + * @return A channel if the node accepts the request, {@code null} otherwise + */ + public Channel connectDefault(String group, INode asker); /** Accept a packet from a channel (or not). * @@ -41,7 +45,7 @@ public interface INode * @param channel The channel which the packet is coming through * @return The overflow data if the packet is only partially accepted. {@code null} otherwise. */ - public IStaticPacket accept(IStaticPacket packet, Channel channel); + public IStaticPacket accept(IStaticPacket packet, Channel channel); /** Pressure * diff --git a/src/main/java/net/cshift/api/transit/network/ISystem.java b/src/main/java/net/cshift/api/transit/network/ISystem.java deleted file mode 100644 index b7ab9bf..0000000 --- a/src/main/java/net/cshift/api/transit/network/ISystem.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.cshift.api.transit.network; - - -/** - * @author Kyle Gunger - * @apiNote An ISystem represents a system of nodes which has been optimized for performance. A node can exist on its own, but an ISystem can't exist without a node. - */ -public interface ISystem -{ - /**The nodes stored by the system - * - * @return INode[] - */ - public INode[] getNodes(); -} diff --git a/src/main/java/net/cshift/api/transit/network/PoolManifest.java b/src/main/java/net/cshift/api/transit/network/PoolManifest.java index 26cbece..e539ee1 100644 --- a/src/main/java/net/cshift/api/transit/network/PoolManifest.java +++ b/src/main/java/net/cshift/api/transit/network/PoolManifest.java @@ -6,35 +6,37 @@ package net.cshift.api.transit.network; */ public abstract class PoolManifest { - /** Represents the number of pools that the node has access to for the specified resource. - * @apiNote A "pool" in this context represents an independant network of resources. + /** Represents the number of pools that the node has access to. + * @apiNote A "pool" in this context represents an independent network of resources. + * Each network in the pool may represent a different TypeGroup. * Pool zero should be the default group that simple nodes will attempt to connect to. * @param group The TypeGroup that the pool belongs to */ - public abstract int poolCount(String group); + public abstract int poolCount(); - /** The ID of the pool. The INode will use this in a connection attempt with the other INode. - * - * @param group The TypeGroup the pool belongs to - * @param pool Array-like index for pool (gotten from poolCount) - */ - public abstract int poolID(String group, int pool); - - /** If the mod supports named pools, the names can be querried through this function. + /** If the mod supports named pools, the names can be queried through this function. * * @param group The TypeGroup the pool belongs to * @param pool Array-like index for pool (gotten from poolCount) */ - public String poolName(String group, int pool) { + public String poolName(int pool) { return ""; } + + /** Returns true if the pool with the given id supports the given group + * + * @param pool The pool ID to query + * @param group The TypeGroup to query + * @return {@code true} if the pool supports the specified group, {@code false} otherwise + */ + public abstract boolean poolProvides(int pool, String group); /** If the mod supports pool descriptions, they can be accessed by this method. * * @param group The TypeGroup the pool belongs to * @param pool Array-like index for pool (gotten from poolCount) */ - public String poolDescription(String group, int pool) { + public String poolDescription(int pool) { return ""; } } diff --git a/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java index f3a6c47..3a57227 100644 --- a/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java @@ -3,14 +3,14 @@ package net.cshift.api.transit.network.packet; import net.cshift.api.transit.type.Type; /** - * Simple packet which stores a fluid value. + * Simple packet which stores a value which can change. * + * @param The type parameter of the Type being transported * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers + * */ public class DynamicPacket implements IDynamicPacket { - private D data; + private Object data; private Type type; /** Constructor. Stores the given data and uses the given type. @@ -18,20 +18,20 @@ public class DynamicPacket implements IDynamicPacket { * @param dat The packet's data * @param t The packet's type */ - public DynamicPacket(D dat, Type t) + public DynamicPacket(Object dat, Type t) { data = dat; type = t; } @Override - public D getData() + public Object getData() { return data; } @Override - public void setData(D dat) + public void setData(Object dat) { data = dat; } diff --git a/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java index 334d5f6..6d80b3b 100644 --- a/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java @@ -1,14 +1,11 @@ package net.cshift.api.transit.network.packet; -/** Interface describing a fluid packet. +/** Interface describing a packet where the data can change as it's transferred. + * + * @param The type parameter of the Type being transported * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers */ public interface IDynamicPacket extends IStaticPacket{ - /**Set the packet's data. - * - * @return The packet's data - */ - public void setData(D dat); + /** Set the packet's data. */ + public void setData(Object dat); } diff --git a/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java index ba1b17f..cdad90a 100644 --- a/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java @@ -3,21 +3,21 @@ package net.cshift.api.transit.network.packet; import net.cshift.api.transit.type.*; /** Interface describing an unchanging packet. - * @author Kyle Gunger * - * @param The data type (Object) that the packet transfers. + * @param The type parameter of the Type being transported + * @author Kyle Gunger */ public interface IStaticPacket { /**Get the packet's data. * - * @return The packet's data + * @return The packet's data */ - public D getData(); + public Object getData(); /**Get the packet's type. * - * @return IType<> The type of the packet + * @return IType The type of the packet */ public Type getType(); } diff --git a/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java deleted file mode 100644 index d382645..0000000 --- a/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.cshift.api.transit.network.packet; - -import net.cshift.api.transit.type.Type; - -/** Static packet with extra data attached. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - * @param The type of metadata -*/ -public class MetaDynamicPacket extends DynamicPacket -{ - private M metaData; - - /** Constructor - * - * @param dat The data to store - * @param t The Type of the data - * @param meta The metadata to store - */ - public MetaDynamicPacket(D dat, Type t, M meta) - { - super(dat, t); - metaData = meta; - } - - /** Get the metadata of the packet. - * - * @return The packet's metadata - */ - public M getMetaData() - { - return metaData; - } - - /** Set the metadata of the packet. - * - * @param meta The packet's new metadata - */ - public void setMetaData(M meta) - { - metaData = meta; - } -} diff --git a/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java deleted file mode 100644 index aea1b83..0000000 --- a/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.cshift.api.transit.network.packet; - -import net.cshift.api.transit.type.*; - -/** Static packet with extra data attached. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - * @param The type of metadata -*/ -public class MetaPacket extends StaticPacket -{ - private M metaData; - - /** Constructor - * - * @param dat The data to store - * @param t The Type of the data - * @param meta The metadata to store - */ - public MetaPacket(D dat, Type t, M meta) - { - super(dat, t); - metaData = meta; - } - - /** Get the metadata of the packet. - * - * @return The packet's metadata - */ - public M getMetaData() - { - return metaData; - } -} diff --git a/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java index 2c6a16a..5ffed26 100644 --- a/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java @@ -9,7 +9,7 @@ import net.cshift.api.transit.type.*; */ public class StaticPacket implements IStaticPacket { - private D data; + private Object data; private Type type; /** Constructor. Stores the given data and uses the given type. @@ -17,14 +17,14 @@ public class StaticPacket implements IStaticPacket * @param dat The packet's data * @param t The packet's type */ - public StaticPacket(D dat, Type t) + public StaticPacket(Object dat, Type t) { data = dat; type = t; } @Override - public D getData() + public Object getData() { return data; } -- cgit v1.2.3