001: /*_############################################################################
002: _##
003: _## SNMP4J - PduHandle.java
004: _##
005: _## Copyright (C) 2003-2008 Frank Fock and Jochen Katz (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.mp;
022:
023: /**
024: * The <code>PduHandle</code> class represents an unique key for a SNMP PDU.
025: * It uses an unique transaction ID (request ID) to identify the PDUs.
026: *
027: * @author Frank Fock
028: * @version 1.0.3
029: * @since 1.0
030: */
031: public class PduHandle {
032:
033: private static final long serialVersionUID = -6365764428974409942L;
034:
035: public static final int NONE = Integer.MIN_VALUE;
036: private int transactionID = NONE;
037:
038: /**
039: * Creates a <code>PduHandle</code> with a transaction ID set to {@link #NONE}.
040: */
041: public PduHandle() {
042: }
043:
044: /**
045: * Creates a <code>PduHandle</code> for the supplied transaction ID.
046: * @param transactionID
047: * an unqiue transaction ID.
048: */
049: public PduHandle(int transactionID) {
050: setTransactionID(transactionID);
051: }
052:
053: /**
054: * Gets the transaction ID of this handle.
055: * @return
056: * the transaction ID.
057: */
058: public int getTransactionID() {
059: return transactionID;
060: }
061:
062: /**
063: * Sets the transaction ID which is typically the request ID of the PDU.
064: * @param transactionID
065: * an unqiue transaction ID.
066: */
067: public void setTransactionID(int transactionID) {
068: this .transactionID = transactionID;
069: }
070:
071: /**
072: * Copy all members from the supplied <code>PduHandle</code>.
073: * @param other
074: * a PduHandle.
075: */
076: public void copyFrom(PduHandle other) {
077: setTransactionID(other.transactionID);
078: }
079:
080: /**
081: * Indicates whether some other object is "equal to" this one.
082: *
083: * @param obj the reference object with which to compare.
084: * @return <code>true</code> if this object is the same as the obj argument;
085: * <code>false</code> otherwise.
086: */
087: public boolean equals(Object obj) {
088: if (obj instanceof PduHandle) {
089: return (transactionID == ((PduHandle) obj).transactionID);
090: }
091: return false;
092: }
093:
094: /**
095: * Returns a hash code value for the object.
096: *
097: * @return a hash code value for this object.
098: */
099: public int hashCode() {
100: return transactionID;
101: }
102:
103: public String toString() {
104: return "PduHandle[" + transactionID + "]";
105: }
106:
107: }
|