diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2019-11-21 18:35:14 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2019-11-21 18:35:14 -0500 |
commit | d08cbf6b8705df234077c49608de3c2f7ff0e3fa (patch) | |
tree | 6e8705d65e4e0f0c1cafe9736980504b5b6f9cde /src/main/java/net/transit/network | |
parent | df044930bca4252ff6e4814c654a612c6aee2136 (diff) |
[Update] Codebase updated to 0.2.8
~ Rewrote files and documentation for cohesion
~ Removed I from the start of interface names
Diffstat (limited to 'src/main/java/net/transit/network')
-rw-r--r-- | src/main/java/net/transit/network/packet/ArrayPacket.java | 11 | ||||
-rw-r--r-- | src/main/java/net/transit/network/packet/MetaPacket.java | 2 | ||||
-rw-r--r-- | src/main/java/net/transit/network/packet/Packet.java (renamed from src/main/java/net/transit/network/packet/IPacket.java) | 2 | ||||
-rw-r--r-- | src/main/java/net/transit/network/packet/StaticPacket.java | 2 | ||||
-rw-r--r-- | src/main/java/net/transit/network/swap/Acceptor.java | 44 | ||||
-rw-r--r-- | src/main/java/net/transit/network/swap/IAcceptor.java | 31 | ||||
-rw-r--r-- | src/main/java/net/transit/network/swap/IProvider.java | 37 | ||||
-rw-r--r-- | src/main/java/net/transit/network/swap/Provider.java | 50 | ||||
-rw-r--r-- | src/main/java/net/transit/network/system/INode.java | 50 | ||||
-rw-r--r-- | src/main/java/net/transit/network/system/Node.java | 50 | ||||
-rw-r--r-- | src/main/java/net/transit/network/system/System.java (renamed from src/main/java/net/transit/network/system/ISystem.java) | 4 |
11 files changed, 158 insertions, 125 deletions
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<D> implements IPacket<D> +public class ArrayPacket<D> implements Packet<D> { private ArrayList<D> arrayData; private Type<D> type; @@ -13,8 +13,10 @@ public class ArrayPacket<D> implements IPacket<D> { arrayData = new ArrayList<D>(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<D> implements IPacket<D> { arrayData.add(data); } + + public int dataStored() + { + return arrayData.size(); + } public D popAndShift() { 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<D, M> implements IPacket<D> +public class MetaPacket<D, M> implements Packet<D> { private D data; diff --git a/src/main/java/net/transit/network/packet/IPacket.java b/src/main/java/net/transit/network/packet/Packet.java index deafdf8..0b7c832 100644 --- a/src/main/java/net/transit/network/packet/IPacket.java +++ b/src/main/java/net/transit/network/packet/Packet.java @@ -7,7 +7,7 @@ import net.transit.type.Type; * * @param <D> The data type (Object) that the packet transfers. */ -public interface IPacket<D> +public interface Packet<D> { /**Get the packet's data * 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<D> implements IPacket<D> +public class StaticPacket<D> implements Packet<D> { private D data; private Type<D> 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 <T> The type of data accepted (in IPacket<<T>> form) + */ +public interface Acceptor<T> +{ + /** 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 <b>True</b> if the Acceptor can accept packets. + */ + public boolean canAccept(); + + /** + * @param provided The packet provided. + * @return <b>True</b> if the Acceptor accepted the packet. + */ + public boolean accept(Packet<T> provided); + + /** + * @return <b>True</b> 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<T> 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<T> 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 <T> The type of data accepted (in IPacket<<T>> form) - */ -public interface IAcceptor<T> -{ - /** - * @return <b>True</b> if the acceptor can accept packets. - */ - public boolean canAccept(); - - /** - * @param provided The packet provided. - * @return <b>True</b> if the acceptor accepted the packet. - */ - public boolean accept(IPacket<T> provided); - - /** - * @return <b>True</b> 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<T> 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 <T> The type of data provided (in IPacket<<T>> form) - */ -public interface IProvider<T> -{ - /** - * @return <b>True</b> if the provider can provide a packet. - */ - public boolean canProvide(); - - /**Get the next packet from the provider - * - * @return IPacket<<T>> - */ - public IPacket<T> provide(); - - /**Retain the packet if the acceptor did not accept the packet. - * - * @param rejected The rejected packet - */ - public void retain(IPacket<T> rejected); - - /** - * @return <b>True</b> 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 <T> The type of data provided (in IPacket<<T>> form) + */ +public interface Provider<T> +{ + /** 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 <b>True</b> if the Provider can provide a packet. + */ + public boolean canProvide(); + + /**Get the next packet from the Provider + * + * @return IPacket<<T>> + */ + public Packet<T> provide(); + + /**Retain the packet if the Acceptor did not accept the packet. + * + * @param rejected The rejected packet + */ + public void retain(Packet<T> rejected); + + /** + * @return <b>True</b> 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<T> 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<T> 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/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/ISystem.java b/src/main/java/net/transit/network/system/System.java index fd2fa51..c70292a 100644 --- a/src/main/java/net/transit/network/system/ISystem.java +++ b/src/main/java/net/transit/network/system/System.java @@ -7,11 +7,11 @@ package net.transit.network.system; * * @param T The object type stored in the system. */ -public interface ISystem +public interface System { /**The nodes stored by the system * * @return INode[] */ - public INode[] getNodes(); + public Node[] getNodes(); } |