src/share/classes/javax/management/ObjectName.java

Print this page




 812                 prop_len = prop._key_length + prop._value_length + 1;
 813                 System.arraycopy(specified_chars, prop._key_index,
 814                                  canonical_chars, prop_index, prop_len);
 815                 prop.setKeyIndex(prop_index);
 816                 prop_index += prop_len;
 817                 if (i != last_index) {
 818                     canonical_chars[prop_index] = ',';
 819                     prop_index++;
 820                 }
 821             }
 822         }
 823 
 824         // terminate canonicalname with '*' in case of pattern
 825         if (_property_list_pattern) {
 826             if (_kp_array != _Empty_property_array)
 827                 canonical_chars[prop_index++] = ',';
 828             canonical_chars[prop_index++] = '*';
 829         }
 830 
 831         // we now build the canonicalname string
 832         _canonicalName = (new String(canonical_chars, 0, prop_index)).intern();
 833     }
 834 
 835     /**
 836      * Parse a key.
 837      * <pre>final int endKey=parseKey(s,startKey);</pre>
 838      * <p>key starts at startKey (included), and ends at endKey (excluded).
 839      * If (startKey == endKey), then the key is empty.
 840      *
 841      * @param s The char array of the original string.
 842      * @param startKey index at which to begin parsing.
 843      * @return The index following the last character of the key.
 844      **/
 845     private static int parseKey(final char[] s, final int startKey)
 846         throws MalformedObjectNameException {
 847         int next   = startKey;
 848         int endKey = startKey;
 849         final int len = s.length;
 850         while (next < len) {
 851             final char k = s[next++];
 852             switch (k) {


1761      * Compares the current object name with another object name.  Two
1762      * ObjectName instances are equal if and only if their canonical
1763      * forms are equal.  The canonical form is the string described
1764      * for {@link #getCanonicalName()}.
1765      *
1766      * @param object  The object name that the current object name is to be
1767      *        compared with.
1768      *
1769      * @return True if <code>object</code> is an ObjectName whose
1770      * canonical form is equal to that of this ObjectName.
1771      */
1772     @Override
1773     public boolean equals(Object object)  {
1774 
1775         // same object case
1776         if (this == object) return true;
1777 
1778         // object is not an object name case
1779         if (!(object instanceof ObjectName)) return false;
1780 
1781         // equality when canonical names are the same
1782         // (because usage of intern())
1783         ObjectName on = (ObjectName) object;
1784         String on_string = on._canonicalName;
1785         if (_canonicalName == on_string) return true;  // ES: OK
1786 
1787         // Because we are sharing canonical form between object names,
1788         // we have finished the comparison at this stage ==> unequal
1789         return false;
1790    }
1791 
1792     /**
1793      * Returns a hash code for this object name.
1794      *
1795      */
1796     @Override
1797     public int hashCode() {
1798         return _canonicalName.hashCode();
1799     }
1800 
1801     /**
1802      * <p>Returns a quoted form of the given String, suitable for
1803      * inclusion in an ObjectName.  The returned value can be used as
1804      * the value associated with a key in an ObjectName.  The String
1805      * <code>s</code> may contain any character.  Appropriate quoting
1806      * ensures that the returned value is legal in an ObjectName.</p>
1807      *
1808      * <p>The returned value consists of a quote ('"'), a sequence of




 812                 prop_len = prop._key_length + prop._value_length + 1;
 813                 System.arraycopy(specified_chars, prop._key_index,
 814                                  canonical_chars, prop_index, prop_len);
 815                 prop.setKeyIndex(prop_index);
 816                 prop_index += prop_len;
 817                 if (i != last_index) {
 818                     canonical_chars[prop_index] = ',';
 819                     prop_index++;
 820                 }
 821             }
 822         }
 823 
 824         // terminate canonicalname with '*' in case of pattern
 825         if (_property_list_pattern) {
 826             if (_kp_array != _Empty_property_array)
 827                 canonical_chars[prop_index++] = ',';
 828             canonical_chars[prop_index++] = '*';
 829         }
 830 
 831         // we now build the canonicalname string
 832         _canonicalName = (new String(canonical_chars, 0, prop_index));
 833     }
 834 
 835     /**
 836      * Parse a key.
 837      * <pre>final int endKey=parseKey(s,startKey);</pre>
 838      * <p>key starts at startKey (included), and ends at endKey (excluded).
 839      * If (startKey == endKey), then the key is empty.
 840      *
 841      * @param s The char array of the original string.
 842      * @param startKey index at which to begin parsing.
 843      * @return The index following the last character of the key.
 844      **/
 845     private static int parseKey(final char[] s, final int startKey)
 846         throws MalformedObjectNameException {
 847         int next   = startKey;
 848         int endKey = startKey;
 849         final int len = s.length;
 850         while (next < len) {
 851             final char k = s[next++];
 852             switch (k) {


1761      * Compares the current object name with another object name.  Two
1762      * ObjectName instances are equal if and only if their canonical
1763      * forms are equal.  The canonical form is the string described
1764      * for {@link #getCanonicalName()}.
1765      *
1766      * @param object  The object name that the current object name is to be
1767      *        compared with.
1768      *
1769      * @return True if <code>object</code> is an ObjectName whose
1770      * canonical form is equal to that of this ObjectName.
1771      */
1772     @Override
1773     public boolean equals(Object object)  {
1774 
1775         // same object case
1776         if (this == object) return true;
1777 
1778         // object is not an object name case
1779         if (!(object instanceof ObjectName)) return false;
1780 


1781         ObjectName on = (ObjectName) object;
1782         String on_string = on._canonicalName;
1783         if(_canonicalName.compareTo(on_string) == 0) return true;
1784 


1785         return false;
1786    }
1787 
1788     /**
1789      * Returns a hash code for this object name.
1790      *
1791      */
1792     @Override
1793     public int hashCode() {
1794         return _canonicalName.hashCode();
1795     }
1796 
1797     /**
1798      * <p>Returns a quoted form of the given String, suitable for
1799      * inclusion in an ObjectName.  The returned value can be used as
1800      * the value associated with a key in an ObjectName.  The String
1801      * <code>s</code> may contain any character.  Appropriate quoting
1802      * ensures that the returned value is legal in an ObjectName.</p>
1803      *
1804      * <p>The returned value consists of a quote ('"'), a sequence of