Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
This file is part of Niowire. Niowire is free software: you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Niowire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with Niowire. If not, see <http://www.gnu.org/licenses/>.
 
 package io.niowire.data;

This class represents a packet containing an object. They are used as the internal communication objects between the various services. They are created from the raw byte stream coming into the serializer/deserializer.

Author(s):
Trent Houliston
 
 public class NioPacket implements Comparable<NioPacket>
 {

The time this packet was created
 
 	private final long timestamp = System.currentTimeMillis();
The ID of the source of this packet (the ID given by NIO connection)
 
 	private final String source;
The data contained in this packet
 
 	private final Object data;

Construct a new NioPacket containing this data from the source (the UID of the connection)

Parameters:
uid the unique identifier for the NioConnection which made this object
data the Object which this packet contains
 
 	public NioPacket(String uidObject data)
 	{
 		this. = data;
 		this. = uid;
 	}

Gets the UID of the NioConnection which created this packet

Returns:
the source of the packet
 
 	public String getSource()
 	{
 		return ;
 	}

Gets the data object which is contained in this packet

Returns:
the data object contained in this packet
 
 	public Object getData()
 	{
 		return ;
 	}

Gets the timestamp that this packet was created

Returns:
the timestamp this packet was created
 
 	public long getTimestamp()
 	{
 		return ;
 	}

Compares this packet to another packed based on their timestamps

Parameters:
o the other NioPacket to compare to
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.NullPointerException if the specified object is null
java.lang.ClassCastException if the specified object's type prevents it from being compared to this object.
 
 	public int compareTo(NioPacket o)
	{
		return Long.compare(this.getTimestamp(), o.getTimestamp());
	}

Generates a HashCode for this object based on the data contained in it.

Returns:
a hash code for this object
	public int hashCode()
	{
		//Build our hashcode
		int hash = 7;
		hash = 97 * hash + (int) (this. ^ (this. >>> 32));
		hash = 97 * hash + (this. != null ? this..hashCode() : 0);
		hash = 97 * hash + (this. != null ? this..hashCode() : 0);
		//Return our hashcode
		return hash;
	}

Checks for equality with the passed object

Parameters:
obj the object to check
Returns:
true if the other object is equal to this object, false otherwise.
	public boolean equals(Object obj)
	{
		//Check fo nulls and classes
		if (obj == null)
		{
			return false;
		}
		if (getClass() != obj.getClass())
		{
			return false;
		}
		//Cast our object
		final NioPacket other = (NioPacketobj;
		//Check the member variables
		if (this. != other.timestamp)
		{
			return false;
		}
		if ((this. == null) ? (other.source != null) : !this..equals(other.source))
		{
			return false;
		}
		if (this. != other.data && (this. == null || !this..equals(other.data)))
		{
			return false;
		}
		//return true if we haven't already returned false
		return true;
	}

Returns a String representation of this object

Returns:
a string representation of this object
	public String toString()
	{
		//Build our string
		return "NioPacket{" + "timestamp=" +  + ", source=" +  + ", data=" +  + '}';
	}
New to GrepCode? Check out our FAQ X