View Javadoc

1   package net.sf.snmpadaptor4j.object;
2   
3   import java.io.Serializable;
4   
5   /**
6    * Object representing a data of a SNMP trap.
7    * @author <a href="http://fr.linkedin.com/in/jpminetti/">Jean-Philippe MINETTI</a>
8    */
9   public final class SnmpTrapData
10  		implements Serializable {
11  
12  	/**
13  	 * Serial number.
14  	 */
15  	private static final long serialVersionUID = -8267283230287605599L;
16  
17  	/**
18  	 * SNMP data type.
19  	 */
20  	private final SnmpDataType type;
21  
22  	/**
23  	 * Value of data.
24  	 */
25  	private final Object value;
26  
27  	/**
28  	 * Constructor.
29  	 * @param type SNMP data type.
30  	 * @param value Value of data.
31  	 */
32  	public SnmpTrapData (final SnmpDataType type, final Object value) {
33  		super();
34  		this.type = type;
35  		this.value = value;
36  	}
37  
38  	/**
39  	 * Returns the SNMP data type.
40  	 * @return SNMP data type.
41  	 */
42  	public SnmpDataType getType () {
43  		return this.type;
44  	}
45  
46  	/**
47  	 * Returns the value of data.
48  	 * @return Value of data.
49  	 */
50  	public Object getValue () {
51  		return this.value;
52  	}
53  
54  	/*
55  	 * {@inheritDoc}
56  	 * @see java.lang.Object#hashCode()
57  	 */
58  	@Override
59  	public int hashCode () {
60  		final int prime = 31;
61  		int result = 1;
62  		result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
63  		result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
64  		return result;
65  	}
66  
67  	/*
68  	 * {@inheritDoc}
69  	 * @see java.lang.Object#equals(java.lang.Object)
70  	 */
71  	@Override
72  	public boolean equals (final Object obj) {
73  		boolean result = false;
74  		if (obj == this) {
75  			result = true;
76  		}
77  		else if ((obj != null) && (obj.getClass() == getClass())) {
78  			final SnmpTrapData other = (SnmpTrapData) obj;
79  			if (other.type == this.type) {
80  				result = (this.value != null ? this.value.equals(other.value) : (other.value == null));
81  			}
82  		}
83  		return result;
84  	}
85  
86  	/*
87  	 * {@inheritDoc}
88  	 * @see java.lang.Object#toString()
89  	 */
90  	@Override
91  	public String toString () {
92  		return "(" + this.type + ") " + this.value;
93  	}
94  
95  }