diff options
Diffstat (limited to 'libjava/classpath/javax/management/ObjectName.java')
-rw-r--r-- | libjava/classpath/javax/management/ObjectName.java | 135 |
1 files changed, 72 insertions, 63 deletions
diff --git a/libjava/classpath/javax/management/ObjectName.java b/libjava/classpath/javax/management/ObjectName.java index 757b80f..8259eab 100644 --- a/libjava/classpath/javax/management/ObjectName.java +++ b/libjava/classpath/javax/management/ObjectName.java @@ -105,7 +105,7 @@ public class ObjectName /** * The properties, as key-value pairs. */ - private TreeMap properties; + private TreeMap<String,String> properties = new TreeMap<String,String>(); /** * The properties as a string (stored for ordering). @@ -164,7 +164,6 @@ public class ObjectName throw new MalformedObjectNameException("A name that is not a " + "pattern must contain at " + "least one key-value pair."); - properties = new TreeMap(); for (int a = 0; a < pairs.length; ++a) { int sep = pairs[a].indexOf('='); @@ -197,7 +196,6 @@ public class ObjectName throws MalformedObjectNameException { this.domain = domain; - properties = new TreeMap(); properties.put(key, value); checkComponents(); } @@ -216,7 +214,7 @@ public class ObjectName * @throws NullPointerException if one of the parameters is * <code>null</code>. */ - public ObjectName(String domain, Hashtable properties) + public ObjectName(String domain, Hashtable<String,String> properties) throws MalformedObjectNameException { this.domain = domain; @@ -305,70 +303,80 @@ public class ObjectName { if (name.isPattern()) return false; - if (isPattern()) + + if (!isPattern()) + return equals(name); + + if (isDomainPattern()) { - boolean domainMatch, propMatch; - if (isDomainPattern()) + if (!domainMatches(domain, 0, name.getDomain(), 0)) + return false; + } + else + { + if (!domain.equals(name.getDomain())) + return false; + } + + if (isPropertyPattern()) + { + Hashtable oProps = name.getKeyPropertyList(); + Iterator i = properties.entrySet().iterator(); + while (i.hasNext()) { - String oDomain = name.getDomain(); - int oLength = oDomain.length(); - for (int a = 0; a < domain.length(); ++a) - { - char n = domain.charAt(a); - if (oLength == a && n != '*') - return false; - if (n == '?') - continue; - if (n == '*') - if ((a + 1) < domain.length()) - { - if (oLength == a) - return false; - char next; - do - { - next = domain.charAt(a + 1); - } while (next == '*'); - if (next == '?') - continue; - int pos = a; - while (oDomain.charAt(pos) != next) - { - ++pos; - if (pos == oLength) - return false; - } - } - if (n != oDomain.charAt(a)) - return false; - } - domainMatch = true; + Map.Entry entry = (Map.Entry) i.next(); + String key = (String) entry.getKey(); + if (!(oProps.containsKey(key))) + return false; + String val = (String) entry.getValue(); + if (!(val.equals(oProps.get(key)))) + return false; } - else - domainMatch = domain.equals(name.getDomain()); - if (isPropertyPattern()) + } + else + { + if (!getCanonicalKeyPropertyListString().equals + (name.getCanonicalKeyPropertyListString())) + return false; + } + return true; + } + + /** + * Returns true if the domain matches the pattern. + * + * @param pattern the pattern to match against. + * @param patternindex the index into the pattern to start matching. + * @param domain the domain to match. + * @param domainindex the index into the domain to start matching. + * @return true if the domain matches the pattern. + */ + private static boolean domainMatches(String pattern, int patternindex, + String domain, int domainindex) + { + while (patternindex < pattern.length()) + { + char c = pattern.charAt(patternindex++); + + if (c == '*') { - Hashtable oProps = name.getKeyPropertyList(); - Iterator i = properties.entrySet().iterator(); - while (i.hasNext()) + for (int i = domain.length(); i >= domainindex; i--) { - Map.Entry entry = (Map.Entry) i.next(); - String key = (String) entry.getKey(); - if (!(oProps.containsKey(key))) - return false; - String val = (String) entry.getValue(); - if (!(val.equals(oProps.get(key)))) - return false; + if (domainMatches(pattern, patternindex, domain, i)) + return true; } - propMatch = true; + return false; } - else - propMatch = - getCanonicalKeyPropertyListString().equals - (name.getCanonicalKeyPropertyListString()); - return domainMatch && propMatch; + + if (domainindex >= domain.length()) + return false; + + if (c != '?' && c != domain.charAt(domainindex)) + return false; + + domainindex++; } - return equals(name); + return true; } /** @@ -542,7 +550,8 @@ public class ObjectName * specifications. * @throws NullPointerException if <code>name</code> is <code>null</code>. */ - public static ObjectName getInstance(String domain, Hashtable properties) + public static ObjectName getInstance(String domain, + Hashtable<String,String> properties) throws MalformedObjectNameException { return new ObjectName(domain, properties); @@ -571,9 +580,9 @@ public class ObjectName * @return a {@link java.util.Hashtable}, containing each of the object * name's properties. */ - public Hashtable getKeyPropertyList() + public Hashtable<String,String> getKeyPropertyList() { - return new Hashtable(properties); + return new Hashtable<String,String>(properties); } /** |