summaryrefslogtreecommitdiff
path: root/src/main/java/net/cshift/transit/network
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-01-16 01:12:04 -0500
committerKyle Gunger <kgunger12@gmail.com>2021-01-16 01:12:04 -0500
commite0a6cfb0aba631d3a1cd27971f87b0d4a677f294 (patch)
treec87a18f10a1cb7b0cab4b278a4b6b424cefcebc7 /src/main/java/net/cshift/transit/network
parentbfe0005433f5fd84d47a310578e6d4da4cfcc43d (diff)
Update include paths
Diffstat (limited to 'src/main/java/net/cshift/transit/network')
-rw-r--r--src/main/java/net/cshift/transit/network/packet/IStaticPacket.java23
-rw-r--r--src/main/java/net/cshift/transit/network/packet/MetaPacket.java35
-rw-r--r--src/main/java/net/cshift/transit/network/packet/StaticPacket.java36
-rw-r--r--src/main/java/net/cshift/transit/network/packet/dynamic/DynamicPacket.java43
-rw-r--r--src/main/java/net/cshift/transit/network/packet/dynamic/IDynamicPacket.java16
-rw-r--r--src/main/java/net/cshift/transit/network/packet/dynamic/MetaDynamicPacket.java44
-rw-r--r--src/main/java/net/cshift/transit/network/system/Connection.java49
-rw-r--r--src/main/java/net/cshift/transit/network/system/INode.java53
-rw-r--r--src/main/java/net/cshift/transit/network/system/ISystem.java15
-rw-r--r--src/main/java/net/cshift/transit/network/system/swap/IAcceptorNode.java37
-rw-r--r--src/main/java/net/cshift/transit/network/system/swap/IProviderNode.java27
11 files changed, 378 insertions, 0 deletions
diff --git a/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java b/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java
new file mode 100644
index 0000000..bac8745
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java
@@ -0,0 +1,23 @@
+package net.cshift.transit.network.packet;
+
+import net.cshift.transit.type.*;
+
+/** Interface describing an unchanging packet.
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers.
+ */
+public interface IStaticPacket<D>
+{
+ /**Get the packet's data.
+ *
+ * @return <D> The packet's data
+ */
+ public D getData();
+
+ /**Get the packet's type.
+ *
+ * @return IType<<D>> The type of the packet
+ */
+ public Type<D> getType();
+}
diff --git a/src/main/java/net/cshift/transit/network/packet/MetaPacket.java b/src/main/java/net/cshift/transit/network/packet/MetaPacket.java
new file mode 100644
index 0000000..99be83c
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/packet/MetaPacket.java
@@ -0,0 +1,35 @@
+package net.cshift.transit.network.packet;
+
+import net.cshift.transit.type.*;
+
+/** Static packet with extra data attached.
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers
+ * @param <M> The type of metadata
+*/
+public class MetaPacket<D, M> extends StaticPacket<D>
+{
+ 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<D> 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/transit/network/packet/StaticPacket.java b/src/main/java/net/cshift/transit/network/packet/StaticPacket.java
new file mode 100644
index 0000000..7c95108
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/packet/StaticPacket.java
@@ -0,0 +1,36 @@
+package net.cshift.transit.network.packet;
+
+import net.cshift.transit.type.*;
+
+/** Simple packet which stores an unchanging value.
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers.
+ */
+public class StaticPacket<D> implements IStaticPacket<D>
+{
+ private D data;
+ private Type<D> type;
+
+ /** Constructor. Stores the given data and uses the given type.
+ *
+ * @param dat The packet's data
+ * @param t The packet's type
+ */
+ public StaticPacket(D dat, Type<D> t)
+ {
+ data = dat;
+ type = t;
+ }
+
+ @Override
+ public D getData()
+ {
+ return data;
+ }
+
+ @Override
+ public Type<D> getType() {
+ return type;
+ }
+}
diff --git a/src/main/java/net/cshift/transit/network/packet/dynamic/DynamicPacket.java b/src/main/java/net/cshift/transit/network/packet/dynamic/DynamicPacket.java
new file mode 100644
index 0000000..d5feb92
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/packet/dynamic/DynamicPacket.java
@@ -0,0 +1,43 @@
+package net.cshift.transit.network.packet.dynamic;
+
+import net.cshift.transit.type.Type;
+
+/**
+ * Simple packet which stores a fluid value.
+ *
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers
+ */
+public class DynamicPacket<D> implements IDynamicPacket<D> {
+ private D data;
+ private Type<D> type;
+
+ /** Constructor. Stores the given data and uses the given type.
+ *
+ * @param dat The packet's data
+ * @param t The packet's type
+ */
+ public DynamicPacket(D dat, Type<D> t)
+ {
+ data = dat;
+ type = t;
+ }
+
+ @Override
+ public D getData()
+ {
+ return data;
+ }
+
+ @Override
+ public void setData(D dat)
+ {
+ data = dat;
+ }
+
+ @Override
+ public Type<D> getType() {
+ return type;
+ }
+}
diff --git a/src/main/java/net/cshift/transit/network/packet/dynamic/IDynamicPacket.java b/src/main/java/net/cshift/transit/network/packet/dynamic/IDynamicPacket.java
new file mode 100644
index 0000000..ffb68a3
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/packet/dynamic/IDynamicPacket.java
@@ -0,0 +1,16 @@
+package net.cshift.transit.network.packet.dynamic;
+
+import net.cshift.transit.network.packet.IStaticPacket;
+
+/** Interface describing a fluid packet.
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers
+ */
+public interface IDynamicPacket<D> extends IStaticPacket<D>{
+ /**Set the packet's data.
+ *
+ * @return <D> The packet's data
+ */
+ public void setData(D dat);
+}
diff --git a/src/main/java/net/cshift/transit/network/packet/dynamic/MetaDynamicPacket.java b/src/main/java/net/cshift/transit/network/packet/dynamic/MetaDynamicPacket.java
new file mode 100644
index 0000000..9e7d293
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/packet/dynamic/MetaDynamicPacket.java
@@ -0,0 +1,44 @@
+package net.cshift.transit.network.packet.dynamic;
+
+import net.cshift.transit.type.Type;
+
+/** Static packet with extra data attached.
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers
+ * @param <M> The type of metadata
+*/
+public class MetaDynamicPacket<D, M> extends DynamicPacket<D>
+{
+ 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<D> 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/transit/network/system/Connection.java b/src/main/java/net/cshift/transit/network/system/Connection.java
new file mode 100644
index 0000000..a111795
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/system/Connection.java
@@ -0,0 +1,49 @@
+package net.cshift.transit.network.system;
+
+public class Connection {
+ INode node;
+ short mask;
+
+ public Connection(INode n)
+ {
+ node = n;
+ mask = 0;
+ }
+
+ public Connection(INode n, short m)
+ {
+ node = n;
+ mask = m;
+ }
+
+ public INode getNode()
+ {
+ return node;
+ }
+
+ public boolean isAccepting()
+ {
+ return (mask & 1) == 1;
+ }
+
+ public void setAccepting(boolean value)
+ {
+ if(isAccepting() && value == false)
+ mask -= 1;
+ else if(!isAccepting() && value == true)
+ mask += 1;
+ }
+
+ public boolean isProviding()
+ {
+ return (mask & 2) == 2;
+ }
+
+ public void setProviding(boolean value)
+ {
+ if(isProviding() && value == false)
+ mask -= 2;
+ else if(!isProviding() && value == true)
+ mask += 2;
+ }
+}
diff --git a/src/main/java/net/cshift/transit/network/system/INode.java b/src/main/java/net/cshift/transit/network/system/INode.java
new file mode 100644
index 0000000..5c901a9
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/system/INode.java
@@ -0,0 +1,53 @@
+package net.cshift.transit.network.system;
+
+/**
+ * @author Kyle Gunger
+ * @apiNote A node inside or outside a system.
+ */
+public interface INode
+{
+
+ /**Returns true if the group given is used by the node
+ *
+ * @param groupID the group to querry
+ * @return bool
+ */
+ public boolean hasGroup(String groupID);
+
+
+ /**Get the system managing the node or {@code null} if there isn't one
+ *
+ * @return System
+ */
+ public ISystem getSystem();
+
+
+ /** Get the data of one of the TypeGroups the Node supports
+ *
+ * @param groupID
+ * @return
+ */
+ public Object getData(String groupID);
+
+
+ /** Set the group data for the node
+ *
+ * @param dat
+ * @param groupID
+ */
+ public void setData(Object dat, String groupID);
+
+
+ /** Get the nodes that this node is connected to
+ *
+ * @return Node[]
+ */
+ public Connection[] getConnections();
+
+
+ /** Get the number of nodes that this node is connected to
+ *
+ * @return int
+ */
+ public int connectionCount();
+}
diff --git a/src/main/java/net/cshift/transit/network/system/ISystem.java b/src/main/java/net/cshift/transit/network/system/ISystem.java
new file mode 100644
index 0000000..9e01645
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/system/ISystem.java
@@ -0,0 +1,15 @@
+package net.cshift.transit.network.system;
+
+
+/**
+ * @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/transit/network/system/swap/IAcceptorNode.java b/src/main/java/net/cshift/transit/network/system/swap/IAcceptorNode.java
new file mode 100644
index 0000000..b64d4cc
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/system/swap/IAcceptorNode.java
@@ -0,0 +1,37 @@
+package net.cshift.transit.network.system.swap;
+
+import net.cshift.transit.network.packet.IStaticPacket;
+import net.cshift.transit.network.system.INode;
+
+/**
+ * @author Kyle Gunger
+ * @apiNote A node which can accept packets of specific types
+ */
+public interface IAcceptorNode extends INode
+{
+
+ /** Link another node as a provider
+ *
+ * @param requester The object to be a provider
+ * @param group
+ * @return
+ */
+ public boolean linkProvider(IProviderNode requestor, String group);
+
+
+ /** Unlink a provider from the acceptor
+ *
+ * @param requestor
+ * @return
+ */
+ public boolean unlinkProvider(IProviderNode requestor);
+
+
+ /** Accept a packet from a provider
+ *
+ * @param packet
+ * @param group
+ * @return
+ */
+ public <T> boolean accept(IStaticPacket<T> packet, String group);
+}
diff --git a/src/main/java/net/cshift/transit/network/system/swap/IProviderNode.java b/src/main/java/net/cshift/transit/network/system/swap/IProviderNode.java
new file mode 100644
index 0000000..5a3bd80
--- /dev/null
+++ b/src/main/java/net/cshift/transit/network/system/swap/IProviderNode.java
@@ -0,0 +1,27 @@
+package net.cshift.transit.network.system.swap;
+
+import net.cshift.transit.network.system.INode;
+
+/**
+ * @author Kyle Gunger
+ * @apiNote A node which can provide packets of specific types
+ */
+public interface IProviderNode extends INode{
+
+ /** Link another node as an acceptor
+ *
+ * @param requester The object requesting the Acceptor
+ * @param group
+ * @return boolean
+ */
+ public boolean linkAcceptor(IAcceptorNode requestor, String group);
+
+
+ /** Unlink a provider from the acceptor
+ *
+ * @param requestor
+ * @return
+ */
+ public boolean unlinkAcceptor(IAcceptorNode requestor);
+
+}