From d08cbf6b8705df234077c49608de3c2f7ff0e3fa Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 21 Nov 2019 18:35:14 -0500 Subject: [Update] Codebase updated to 0.2.8 ~ Rewrote files and documentation for cohesion ~ Removed I from the start of interface names --- .../net/transit/network/packet/ArrayPacket.java | 11 ++++- .../java/net/transit/network/packet/IPacket.java | 23 ---------- .../net/transit/network/packet/MetaPacket.java | 2 +- .../java/net/transit/network/packet/Packet.java | 23 ++++++++++ .../net/transit/network/packet/StaticPacket.java | 2 +- .../java/net/transit/network/swap/Acceptor.java | 44 +++++++++++++++++++ .../java/net/transit/network/swap/IAcceptor.java | 31 -------------- .../java/net/transit/network/swap/IProvider.java | 37 ---------------- .../java/net/transit/network/swap/Provider.java | 50 ++++++++++++++++++++++ .../java/net/transit/network/system/INode.java | 50 ---------------------- .../java/net/transit/network/system/ISystem.java | 17 -------- src/main/java/net/transit/network/system/Node.java | 50 ++++++++++++++++++++++ .../java/net/transit/network/system/System.java | 17 ++++++++ 13 files changed, 195 insertions(+), 162 deletions(-) delete mode 100644 src/main/java/net/transit/network/packet/IPacket.java create mode 100644 src/main/java/net/transit/network/packet/Packet.java create mode 100644 src/main/java/net/transit/network/swap/Acceptor.java delete mode 100644 src/main/java/net/transit/network/swap/IAcceptor.java delete mode 100644 src/main/java/net/transit/network/swap/IProvider.java create mode 100644 src/main/java/net/transit/network/swap/Provider.java delete mode 100644 src/main/java/net/transit/network/system/INode.java delete mode 100644 src/main/java/net/transit/network/system/ISystem.java create mode 100644 src/main/java/net/transit/network/system/Node.java create mode 100644 src/main/java/net/transit/network/system/System.java (limited to 'src/main/java/net/transit/network') diff --git a/src/main/java/net/transit/network/packet/ArrayPacket.java b/src/main/java/net/transit/network/packet/ArrayPacket.java index 9cbd300..fbea811 100644 --- a/src/main/java/net/transit/network/packet/ArrayPacket.java +++ b/src/main/java/net/transit/network/packet/ArrayPacket.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import net.transit.type.Type; -public class ArrayPacket implements IPacket +public class ArrayPacket implements Packet { private ArrayList arrayData; private Type type; @@ -13,8 +13,10 @@ public class ArrayPacket implements IPacket { arrayData = new ArrayList(0); arrayData.add(startValue); + type = t; } - + + @Override public D getData() { if(arrayData.size() > 0) return arrayData.get(0); @@ -25,6 +27,11 @@ public class ArrayPacket implements IPacket { arrayData.add(data); } + + public int dataStored() + { + return arrayData.size(); + } public D popAndShift() { diff --git a/src/main/java/net/transit/network/packet/IPacket.java b/src/main/java/net/transit/network/packet/IPacket.java deleted file mode 100644 index deafdf8..0000000 --- a/src/main/java/net/transit/network/packet/IPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.transit.network.packet; - -import net.transit.type.Type; - -/** - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers. - */ -public interface IPacket -{ - /**Get the packet's data - * - * @return The packet's data - */ - public D getData(); - - /**Get the packet's type - * - * @return IType<> The type of the packet - */ - public Type getType(); -} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/MetaPacket.java b/src/main/java/net/transit/network/packet/MetaPacket.java index e4cffdf..0240519 100644 --- a/src/main/java/net/transit/network/packet/MetaPacket.java +++ b/src/main/java/net/transit/network/packet/MetaPacket.java @@ -2,7 +2,7 @@ package net.transit.network.packet; import net.transit.type.Type; -public class MetaPacket implements IPacket +public class MetaPacket implements Packet { private D data; diff --git a/src/main/java/net/transit/network/packet/Packet.java b/src/main/java/net/transit/network/packet/Packet.java new file mode 100644 index 0000000..0b7c832 --- /dev/null +++ b/src/main/java/net/transit/network/packet/Packet.java @@ -0,0 +1,23 @@ +package net.transit.network.packet; + +import net.transit.type.Type; + +/** + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public interface Packet +{ + /**Get the packet's data + * + * @return The packet's data + */ + public D getData(); + + /**Get the packet's type + * + * @return IType<> The type of the packet + */ + public Type getType(); +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/StaticPacket.java b/src/main/java/net/transit/network/packet/StaticPacket.java index 8399041..b14e442 100644 --- a/src/main/java/net/transit/network/packet/StaticPacket.java +++ b/src/main/java/net/transit/network/packet/StaticPacket.java @@ -2,7 +2,7 @@ package net.transit.network.packet; import net.transit.type.Type; -public class StaticPacket implements IPacket +public class StaticPacket implements Packet { private D data; private Type type; diff --git a/src/main/java/net/transit/network/swap/Acceptor.java b/src/main/java/net/transit/network/swap/Acceptor.java new file mode 100644 index 0000000..9778095 --- /dev/null +++ b/src/main/java/net/transit/network/swap/Acceptor.java @@ -0,0 +1,44 @@ +package net.transit.network.swap; + +import net.transit.network.packet.Packet; +import net.transit.network.system.Node; + +/** + * @author Kyle Gunger + * + * @param The type of data accepted (in IPacket<> form) + */ +public interface Acceptor +{ + /** Returns the INode this Acceptor is attached to. All Acceptors and Provider must be attached to an INode to function. + * + * @return INode + */ + public Node getNode(); + + /** + * @return True if the Acceptor can accept packets. + */ + public boolean canAccept(); + + /** + * @param provided The packet provided. + * @return True if the Acceptor accepted the packet. + */ + public boolean accept(Packet provided); + + /** + * @return True if the Acceptor has a Provider assigned to it. + */ + public boolean hasProvider(); + + /**Set the provider of the Acceptor. The Acceptor can decide if it wants to adopt the Provider. + */ + public void setProvider(Provider provider); + + /** Request that the Acceptor close it's connection to a Provider. The Acceptor may also shut itself down if no more Providers are attached. + * + * @param provider The Provider + */ + public void shutdown(Provider provider); +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/swap/IAcceptor.java b/src/main/java/net/transit/network/swap/IAcceptor.java deleted file mode 100644 index 6966b9a..0000000 --- a/src/main/java/net/transit/network/swap/IAcceptor.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.transit.network.swap; - -import net.transit.network.packet.IPacket; - -/** - * @author Kyle Gunger - * - * @param The type of data accepted (in IPacket<> form) - */ -public interface IAcceptor -{ - /** - * @return True if the acceptor can accept packets. - */ - public boolean canAccept(); - - /** - * @param provided The packet provided. - * @return True if the acceptor accepted the packet. - */ - public boolean accept(IPacket provided); - - /** - * @return True if the acceptor has a provider assigned to it. - */ - public boolean hasProvider(); - - /**Set the provider of the acceptor. The acceptor can decide if it wants to adopt the provider. - */ - public void setProvider(IProvider provider); -} \ No newline at end of file diff --git a/src/main/java/net/transit/network/swap/IProvider.java b/src/main/java/net/transit/network/swap/IProvider.java deleted file mode 100644 index 03c9ca9..0000000 --- a/src/main/java/net/transit/network/swap/IProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.transit.network.swap; - -import net.transit.network.packet.IPacket; - -/** - * @author Kyle Gunger - * - * @param The type of data provided (in IPacket<> form) - */ -public interface IProvider -{ - /** - * @return True if the provider can provide a packet. - */ - public boolean canProvide(); - - /**Get the next packet from the provider - * - * @return IPacket<> - */ - public IPacket provide(); - - /**Retain the packet if the acceptor did not accept the packet. - * - * @param rejected The rejected packet - */ - public void retain(IPacket rejected); - - /** - * @return True if the acceptor has a provider assigned to it - */ - public boolean hasAcceptor(); - - /**Set the acceptor of the provider. The provider can decide if it wants to adopt the acceptor. - */ - public void setAcceptor(); -} \ No newline at end of file diff --git a/src/main/java/net/transit/network/swap/Provider.java b/src/main/java/net/transit/network/swap/Provider.java new file mode 100644 index 0000000..20656b8 --- /dev/null +++ b/src/main/java/net/transit/network/swap/Provider.java @@ -0,0 +1,50 @@ +package net.transit.network.swap; + +import net.transit.network.packet.Packet; +import net.transit.network.system.Node; + +/** + * @author Kyle Gunger + * + * @param The type of data provided (in IPacket<> form) + */ +public interface Provider +{ + /** Returns the INode this Provider is attached to. All Acceptors and Providers must be attached to an INode to function. + * + * @return INode + */ + public Node getNode(); + + /** + * @return True if the Provider can provide a packet. + */ + public boolean canProvide(); + + /**Get the next packet from the Provider + * + * @return IPacket<> + */ + public Packet provide(); + + /**Retain the packet if the Acceptor did not accept the packet. + * + * @param rejected The rejected packet + */ + public void retain(Packet rejected); + + /** + * @return True if the Provider has an Acceptor assigned to it + */ + public boolean hasAcceptor(); + + /**Set the Acceptor of the Provider. The Provider can decide if it wants to adopt the Acceptor. + */ + public void setAcceptor(Acceptor acceptor); + + /** Request that the Provider close it's connection to a Acceptor. The Provider may also shut itself down if no more Acceptors are attached. + * + * @param acceptor The Acceptor + */ + public void shutdown(Acceptor acceptor); +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/system/INode.java b/src/main/java/net/transit/network/system/INode.java deleted file mode 100644 index 2dc3686..0000000 --- a/src/main/java/net/transit/network/system/INode.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.transit.network.system; - -import net.transit.network.swap.IAcceptor; -import net.transit.network.swap.IProvider; - -/** - * @author Kyle Gunger - * @apiNote A node inside or outside a system. Provides acceptors and providers to other nodes. - */ -public interface INode -{ - /**Returns the groupIDs of groups the node provide - * - * @return String[] - */ - public String[] groupsProvided(); - - /**Get the system managing the node or {@code null} if there isn't one - * - * @return ISystem - */ - public ISystem getSystem(); - - /**Returns {@code true} if the node provides IAcceptors - * - * @return boolean - */ - public boolean isAcceptor(); - - /**Returns an IAcceptor or {@code null} depending on the requester and group - * - * @param requester The object requesting the IAcceptor - * @param group - * @return IAcceptor - */ - public IAcceptor requestAcceptor(Object requester, String group); - - /**Returns {@code true} if the node provides IProviders - * - */ - public boolean isProvider(); - - /**Returns an IProvider or {@code null} depending on the requester and group - * - * @param requester The object requesting the IProvider - * @param group - * @return IProvider - */ - public IProvider requestProvider(Object requestor, String group); -} diff --git a/src/main/java/net/transit/network/system/ISystem.java b/src/main/java/net/transit/network/system/ISystem.java deleted file mode 100644 index fd2fa51..0000000 --- a/src/main/java/net/transit/network/system/ISystem.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.transit.network.system; - - -/**ISystem - a group of nodes optimized for performance - * - * A node can exist without a system, but a system can not exist without at least one root node. - * - * @param T The object type stored in the system. - */ -public interface ISystem -{ - /**The nodes stored by the system - * - * @return INode[] - */ - public INode[] getNodes(); -} diff --git a/src/main/java/net/transit/network/system/Node.java b/src/main/java/net/transit/network/system/Node.java new file mode 100644 index 0000000..8e0fcbb --- /dev/null +++ b/src/main/java/net/transit/network/system/Node.java @@ -0,0 +1,50 @@ +package net.transit.network.system; + +import net.transit.network.swap.Acceptor; +import net.transit.network.swap.Provider; + +/** + * @author Kyle Gunger + * @apiNote A node inside or outside a system. Provides acceptors and providers to other nodes. + */ +public interface Node +{ + /**Returns the groupIDs of groups the node provide + * + * @return String[] + */ + public String[] groupsProvided(); + + /**Get the system managing the node or {@code null} if there isn't one + * + * @return ISystem + */ + public System getSystem(); + + /**Returns {@code true} if the node provides Acceptors + * + * @return boolean + */ + public boolean isAcceptor(); + + /**Returns an Acceptor or {@code null} depending on the requester and group + * + * @param requester The object requesting the Acceptor + * @param group + * @return Acceptor + */ + public Acceptor requestAcceptor(Object requester, String group); + + /**Returns {@code true} if the node provides Providers + * + */ + public boolean isProvider(); + + /**Returns an Provider or {@code null} depending on the requester and group + * + * @param requester The object requesting the Provider + * @param group + * @return Provider + */ + public Provider requestProvider(Object requestor, String group); +} diff --git a/src/main/java/net/transit/network/system/System.java b/src/main/java/net/transit/network/system/System.java new file mode 100644 index 0000000..c70292a --- /dev/null +++ b/src/main/java/net/transit/network/system/System.java @@ -0,0 +1,17 @@ +package net.transit.network.system; + + +/**ISystem - a group of nodes optimized for performance + * + * A node can exist without a system, but a system can not exist without at least one root node. + * + * @param T The object type stored in the system. + */ +public interface System +{ + /**The nodes stored by the system + * + * @return INode[] + */ + public Node[] getNodes(); +} -- cgit v1.2.3