equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. |
2 * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Sun designates this |
7 * published by the Free Software Foundation. Sun designates this |
23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
25 |
25 |
26 package javax.management; |
26 package javax.management; |
27 |
27 |
|
28 import com.sun.jmx.mbeanserver.Util; |
28 import java.io.InvalidObjectException; |
29 import java.io.InvalidObjectException; |
29 import java.lang.reflect.Array; |
30 import java.lang.reflect.Array; |
30 import java.util.Arrays; |
31 import java.util.Arrays; |
31 import java.util.Comparator; |
32 import java.util.Comparator; |
32 import java.util.Map; |
33 import java.util.Map; |
360 * otherwise. |
361 * otherwise. |
361 * |
362 * |
362 */ |
363 */ |
363 // Note: this Javadoc is copied from javax.management.Descriptor |
364 // Note: this Javadoc is copied from javax.management.Descriptor |
364 // due to 6369229. |
365 // due to 6369229. |
|
366 @Override |
365 public boolean equals(Object o) { |
367 public boolean equals(Object o) { |
366 if (o == this) |
368 if (o == this) |
367 return true; |
369 return true; |
368 if (!(o instanceof Descriptor)) |
370 if (!(o instanceof Descriptor)) |
369 return false; |
371 return false; |
408 * @return A hash code value for this object. |
410 * @return A hash code value for this object. |
409 * |
411 * |
410 */ |
412 */ |
411 // Note: this Javadoc is copied from javax.management.Descriptor |
413 // Note: this Javadoc is copied from javax.management.Descriptor |
412 // due to 6369229. |
414 // due to 6369229. |
|
415 @Override |
413 public int hashCode() { |
416 public int hashCode() { |
414 if (hashCode == -1) { |
417 if (hashCode == -1) { |
415 int hash = 0; |
418 hashCode = Util.hashCode(names, values); |
416 for (int i = 0; i < names.length; i++) { |
|
417 Object v = values[i]; |
|
418 int h; |
|
419 if (v == null) |
|
420 h = 0; |
|
421 else if (v instanceof Object[]) |
|
422 h = Arrays.deepHashCode((Object[]) v); |
|
423 else if (v.getClass().isArray()) { |
|
424 h = Arrays.deepHashCode(new Object[] {v}) - 31; |
|
425 // hashcode of a list containing just v is |
|
426 // v.hashCode() + 31, see List.hashCode() |
|
427 } else |
|
428 h = v.hashCode(); |
|
429 hash += names[i].toLowerCase().hashCode() ^ h; |
|
430 } |
|
431 hashCode = hash; |
|
432 } |
419 } |
433 return hashCode; |
420 return hashCode; |
434 } |
421 } |
435 |
422 |
|
423 @Override |
436 public String toString() { |
424 public String toString() { |
437 StringBuilder sb = new StringBuilder("{"); |
425 StringBuilder sb = new StringBuilder("{"); |
438 for (int i = 0; i < names.length; i++) { |
426 for (int i = 0; i < names.length; i++) { |
439 if (i > 0) |
427 if (i > 0) |
440 sb.append(", "); |
428 sb.append(", "); |
477 * @exception RuntimeOperationsException for illegal value for field Names |
465 * @exception RuntimeOperationsException for illegal value for field Names |
478 * or field Values. |
466 * or field Values. |
479 * If the descriptor construction fails for any reason, this exception will |
467 * If the descriptor construction fails for any reason, this exception will |
480 * be thrown. |
468 * be thrown. |
481 */ |
469 */ |
|
470 @Override |
482 public Descriptor clone() { |
471 public Descriptor clone() { |
483 return this; |
472 return this; |
484 } |
473 } |
485 |
474 |
486 /** |
475 /** |