View Javadoc

1   package net.sf.snmpadaptor4j;
2   
3   import java.io.Serializable;
4   
5   /**
6    * Object containing all parameters to connect to a SNMP manager for trap sending.
7    * @author <a href="http://fr.linkedin.com/in/jpminetti/">Jean-Philippe MINETTI</a>
8    */
9   public final class SnmpManagerConfiguration
10  		implements Serializable {
11  
12  	/**
13  	 * Serial number.
14  	 */
15  	private static final long serialVersionUID = 923122651757199428L;
16  
17  	/**
18  	 * IP address of SNMP manager responsible of traps handling.
19  	 */
20  	private final String address;
21  
22  	/**
23  	 * UDP port of SNMP manager responsible of traps handling.
24  	 */
25  	private final int port;
26  
27  	/**
28  	 * Protocol version of SNMP manager.
29  	 */
30  	private final int version;
31  
32  	/**
33  	 * Community of SNMP manager.
34  	 */
35  	private final String community;
36  
37  	/**
38  	 * Constructor.
39  	 * @param address IP address of SNMP manager responsible of traps handling.
40  	 * @param port UDP port of SNMP manager responsible of traps handling.
41  	 * @param version Protocol version of SNMP manager.
42  	 * @param community Community of SNMP manager.
43  	 */
44  	public SnmpManagerConfiguration (final String address, final int port, final int version, final String community) {
45  		super();
46  		this.address = address;
47  		this.port = port;
48  		this.version = version;
49  		this.community = community;
50  	}
51  
52  	/**
53  	 * Returns the IP address of SNMP manager responsible of traps handling.
54  	 * @return IP address of SNMP manager.
55  	 */
56  	public String getAddress () {
57  		return this.address;
58  	}
59  
60  	/**
61  	 * Returns the UDP port of SNMP manager responsible of traps handling.
62  	 * @return UDP port of SNMP manager.
63  	 */
64  	public int getPort () {
65  		return this.port;
66  	}
67  
68  	/**
69  	 * Returns the protocol version of SNMP manager.
70  	 * @return Protocol version of SNMP manager.
71  	 */
72  	public int getVersion () {
73  		return this.version;
74  	}
75  
76  	/**
77  	 * Returns the community of SNMP manager.
78  	 * @return Community of SNMP manager.
79  	 */
80  	public String getCommunity () {
81  		return this.community;
82  	}
83  
84  	/*
85  	 * {@inheritDoc}
86  	 * @see java.lang.Object#hashCode()
87  	 */
88  	@Override
89  	public int hashCode () {
90  		final int prime = 31;
91  		int result = 1;
92  		result = prime * result + ((this.address == null) ? 0 : this.address.hashCode());
93  		result = prime * result + ((this.community == null) ? 0 : this.community.hashCode());
94  		result = prime * result + this.port;
95  		result = prime * result + this.version;
96  		return result;
97  	}
98  
99  	/*
100 	 * {@inheritDoc}
101 	 * @see java.lang.Object#equals(java.lang.Object)
102 	 */
103 	@Override
104 	public boolean equals (final Object obj) {
105 		boolean result = false;
106 		if (obj == this) {
107 			result = true;
108 		}
109 		else if ((obj != null) && (getClass().equals(obj.getClass()))) {
110 			final SnmpManagerConfiguration other = (SnmpManagerConfiguration) obj;
111 			result = (this.address != null ? this.address.equals(other.address) : (other.address == null));
112 			if (result) {
113 				result = (this.port == other.port);
114 			}
115 			if (result) {
116 				result = (this.version == other.version);
117 			}
118 			if (result) {
119 				result = (this.community != null ? this.community.equals(other.community) : (other.community == null));
120 			}
121 		}
122 		return result;
123 	}
124 
125 	/*
126 	 * {@inheritDoc}
127 	 * @see java.lang.Object#toString()
128 	 */
129 	@Override
130 	public String toString () {
131 		return this.address + ":" + this.port + "/" + this.community;
132 	}
133 
134 }