|
1 | 1 | package com.googlecode.jmxtrans.model.output;
|
2 | 2 |
|
3 | 3 | import java.io.IOException;
|
4 |
| -import java.net.*; |
| 4 | +import java.net.DatagramPacket; |
| 5 | +import java.net.DatagramSocket; |
| 6 | +import java.net.InetAddress; |
| 7 | +import java.net.InetSocketAddress; |
| 8 | +import java.net.UnknownHostException; |
5 | 9 | import java.util.HashSet;
|
6 | 10 | import java.util.List;
|
7 | 11 | import java.util.Map;
|
|
11 | 15 | import java.util.regex.Pattern;
|
12 | 16 |
|
13 | 17 | import org.apache.commons.lang.StringUtils;
|
| 18 | +import org.apache.commons.lang.builder.EqualsBuilder; |
| 19 | +import org.apache.commons.lang.builder.HashCodeBuilder; |
14 | 20 | import org.apache.commons.pool.KeyedObjectPool;
|
15 | 21 | import org.slf4j.Logger;
|
16 | 22 | import org.slf4j.LoggerFactory;
|
@@ -290,26 +296,26 @@ private void sendMetricMetadata(DatagramSocket socket, MetricMetaData metaData)
|
290 | 296 | /**
|
291 | 297 | * Puts a string into the buffer by first writing the size of the string as
|
292 | 298 | * an int, followed by the bytes of the string, padded if necessary to a
|
293 |
| - * multiple of 4. |
294 |
| - * If the String value exceeds the available length of the buffer, this will |
295 |
| - * trim the String to fit and add an ellipsis at the end. |
| 299 | + * multiple of 4. If the String value exceeds the available length of the |
| 300 | + * buffer, this will trim the String to fit and add an ellipsis at the end. |
296 | 301 | */
|
297 | 302 | protected void xdr_string(String s) {
|
298 | 303 | byte[] bytes = s.getBytes();
|
299 | 304 | int len = bytes.length;
|
300 |
| - // The available buffer is equal to the total buffer size, minus our current offset, minus 4 bytes |
| 305 | + // The available buffer is equal to the total buffer size, minus our |
| 306 | + // current offset, minus 4 bytes |
301 | 307 | // to write the xdr integer length value
|
302 | 308 | int availableBuffer = BUFFER_SIZE - offset - 4;
|
303 |
| - if( len < availableBuffer ) { |
| 309 | + if (len < availableBuffer) { |
304 | 310 | xdr_int(len);
|
305 | 311 | System.arraycopy(bytes, 0, buffer, offset, len);
|
306 | 312 | offset += len;
|
307 | 313 | } else {
|
308 |
| - xdr_int( availableBuffer ); |
309 |
| - bytes[ availableBuffer - 1 ] = '.'; |
310 |
| - bytes[ availableBuffer - 2 ] = '.'; |
311 |
| - bytes[ availableBuffer - 3 ] = '.'; |
312 |
| - System.arraycopy( bytes, 0, buffer, offset, availableBuffer ); |
| 314 | + xdr_int(availableBuffer); |
| 315 | + bytes[availableBuffer - 1] = '.'; |
| 316 | + bytes[availableBuffer - 2] = '.'; |
| 317 | + bytes[availableBuffer - 3] = '.'; |
| 318 | + System.arraycopy(bytes, 0, buffer, offset, availableBuffer); |
313 | 319 | offset += availableBuffer;
|
314 | 320 | }
|
315 | 321 | pad();
|
@@ -348,25 +354,28 @@ private MetricMetaData(String hostName, String metricName, DataType type) {
|
348 | 354 | }
|
349 | 355 |
|
350 | 356 | public boolean equals(Object o) {
|
351 |
| - if (this == o) |
352 |
| - return true; |
353 |
| - if (o == null || getClass() != o.getClass()) |
354 |
| - return false; |
355 |
| - MetricMetaData that = (MetricMetaData) o; |
356 |
| - if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) |
| 357 | + if (o == null) { |
357 | 358 | return false;
|
358 |
| - if (metricName != null ? !metricName.equals(that.metricName) : that.metricName != null) |
| 359 | + } |
| 360 | + if (o == this) { |
| 361 | + return true; |
| 362 | + } |
| 363 | + if (o.getClass() != this.getClass()) { |
359 | 364 | return false;
|
360 |
| - if (type != that.type) |
| 365 | + } |
| 366 | + |
| 367 | + if (!(o instanceof MetricMetaData)) { |
361 | 368 | return false;
|
362 |
| - return true; |
| 369 | + } |
| 370 | + |
| 371 | + MetricMetaData other = (MetricMetaData) o; |
| 372 | + |
| 373 | + return new EqualsBuilder().append(this.hostName, other.hostName).append(this.metricName, other.metricName).append(this.type, other.type) |
| 374 | + .isEquals(); |
363 | 375 | }
|
364 | 376 |
|
365 | 377 | public int hashCode() {
|
366 |
| - int result = hostName != null ? hostName.hashCode() : 0; |
367 |
| - result = 31 * result + (metricName != null ? metricName.hashCode() : 0); |
368 |
| - result = 31 * result + (type != null ? type.hashCode() : 0); |
369 |
| - return result; |
| 378 | + return new HashCodeBuilder(41, 97).append(hostName).append(metricName).append(type).toHashCode(); |
370 | 379 | }
|
371 | 380 |
|
372 | 381 | public String toString() {
|
|
0 commit comments