From aed6ed909ee81beecac2836cb86654efe29e154b Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Wed, 15 Apr 2020 15:09:41 -0400 Subject: [Update] Version 0.5.1 More documentation, and an updated list of packets --- .../net/transit/network/packet/IStaticPacket.java | 23 +++++++ .../net/transit/network/packet/MetaPacket.java | 34 +++++----- .../net/transit/network/packet/StaticPacket.java | 13 +++- .../network/packet/dynamic/ArrayPacket.java | 74 ++++++++++++++++++++++ .../network/packet/dynamic/DynamicPacket.java | 43 +++++++++++++ .../network/packet/dynamic/IDynamicPacket.java | 16 +++++ .../network/packet/dynamic/MetaDynamicPacket.java | 44 +++++++++++++ 7 files changed, 230 insertions(+), 17 deletions(-) create mode 100644 src/main/java/net/transit/network/packet/IStaticPacket.java create mode 100644 src/main/java/net/transit/network/packet/dynamic/ArrayPacket.java create mode 100644 src/main/java/net/transit/network/packet/dynamic/DynamicPacket.java create mode 100644 src/main/java/net/transit/network/packet/dynamic/IDynamicPacket.java create mode 100644 src/main/java/net/transit/network/packet/dynamic/MetaDynamicPacket.java (limited to 'src/main/java/net/transit/network/packet') diff --git a/src/main/java/net/transit/network/packet/IStaticPacket.java b/src/main/java/net/transit/network/packet/IStaticPacket.java new file mode 100644 index 0000000..01073d3 --- /dev/null +++ b/src/main/java/net/transit/network/packet/IStaticPacket.java @@ -0,0 +1,23 @@ +package net.transit.network.packet; + +import net.transit.type.Type; + +/** Interface describing an unchanging packet. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public interface IStaticPacket +{ + /**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 0240519..7e49318 100644 --- a/src/main/java/net/transit/network/packet/MetaPacket.java +++ b/src/main/java/net/transit/network/packet/MetaPacket.java @@ -2,32 +2,34 @@ package net.transit.network.packet; import net.transit.type.Type; -public class MetaPacket implements Packet +/** 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 D data; private M metaData; - private Type type; + /** 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) { - data = dat; - type = t; + super(dat, t); metaData = meta; } - - public D getData() - { - return data; - } + /** Get the metadata of the packet. + * + * @return The packet's metadata + */ public M getMetaData() { return metaData; } - - @Override - public Type getType() { - return type; - } } diff --git a/src/main/java/net/transit/network/packet/StaticPacket.java b/src/main/java/net/transit/network/packet/StaticPacket.java index b14e442..eeeae3f 100644 --- a/src/main/java/net/transit/network/packet/StaticPacket.java +++ b/src/main/java/net/transit/network/packet/StaticPacket.java @@ -2,17 +2,28 @@ package net.transit.network.packet; import net.transit.type.Type; -public class StaticPacket implements Packet +/** Simple packet which stores an unchanging value. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public class StaticPacket implements IStaticPacket { private D data; private Type 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 t) { data = dat; type = t; } + @Override public D getData() { return data; diff --git a/src/main/java/net/transit/network/packet/dynamic/ArrayPacket.java b/src/main/java/net/transit/network/packet/dynamic/ArrayPacket.java new file mode 100644 index 0000000..0c27c80 --- /dev/null +++ b/src/main/java/net/transit/network/packet/dynamic/ArrayPacket.java @@ -0,0 +1,74 @@ +package net.transit.network.packet.dynamic; + +import java.util.ArrayList; + +import net.transit.type.Type; + +/** A packet type which stores multiple values which can be accessed. When getting data, pop and shift from the array. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + */ +public class ArrayPacket implements IDynamicPacket +{ + private ArrayList arrayData; + private Type type; + + /** Constructor + * Create an array packet. Adds the starting value. + * @param startValue The starting value + * @param t The type of the packet + */ + public ArrayPacket(D startValue, Type t) + { + arrayData = new ArrayList(0); + arrayData.add(startValue); + type = t; + } + + /** + * Create an empty array packet of the desired type. + * @param t The type of the packet + */ + public ArrayPacket(Type t) + { + arrayData = new ArrayList(0); + type = t; + } + + /** Pop and shift data from the array. + */ + @Override + public D getData() + { + D temp = null; + + if(arrayData.size() > 0) + { + temp = arrayData.remove(0); + } + + return temp; + } + + /** Add data to the array. + * @param data The data to push + */ + public void setData(D data) + { + arrayData.add(data); + } + + /** + * @return The ammount of data the packet holds + */ + public int dataStored() + { + return arrayData.size(); + } + + @Override + public Type getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/dynamic/DynamicPacket.java b/src/main/java/net/transit/network/packet/dynamic/DynamicPacket.java new file mode 100644 index 0000000..0860487 --- /dev/null +++ b/src/main/java/net/transit/network/packet/dynamic/DynamicPacket.java @@ -0,0 +1,43 @@ +package net.transit.network.packet.dynamic; + +import net.transit.type.Type; + +/** + * Simple packet which stores a fluid value. + * + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + */ +public class DynamicPacket implements IDynamicPacket { + private D data; + private Type 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 t) + { + data = dat; + type = t; + } + + @Override + public D getData() + { + return data; + } + + @Override + public void setData(D dat) + { + data = dat; + } + + @Override + public Type getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/dynamic/IDynamicPacket.java b/src/main/java/net/transit/network/packet/dynamic/IDynamicPacket.java new file mode 100644 index 0000000..51b3c13 --- /dev/null +++ b/src/main/java/net/transit/network/packet/dynamic/IDynamicPacket.java @@ -0,0 +1,16 @@ +package net.transit.network.packet.dynamic; + +import net.transit.network.packet.IStaticPacket; + +/** Interface describing a fluid packet. + * @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); +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/dynamic/MetaDynamicPacket.java b/src/main/java/net/transit/network/packet/dynamic/MetaDynamicPacket.java new file mode 100644 index 0000000..b6a3ec6 --- /dev/null +++ b/src/main/java/net/transit/network/packet/dynamic/MetaDynamicPacket.java @@ -0,0 +1,44 @@ +package net.transit.network.packet.dynamic; + +import net.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; + } +} -- cgit v1.2.3