@Test public void testMatches5() { Subtopic s1 = new Subtopic("*", DEFAULT_SEPERATOR); Subtopic s2 = new Subtopic("foo.bar.foo", DEFAULT_SEPERATOR); boolean result = s1.matches(s2); Assert.assertTrue(result); }
public boolean matches(Subtopic other) { if (!hasSubtopicWildcard && !other.hasSubtopicWildcard) { return (subtopic.equals(other.subtopic)) ? true : false; } else { if (hierarchical && other.hierarchical && !separator.equals(other.separator)) return false; StringTokenizer t1 = new StringTokenizer(subtopic, separator); StringTokenizer t2 = new StringTokenizer(other.subtopic, other.separator); int n = t1.countTokens(); int difference = n - t2.countTokens(); String tok1 = null; String tok2 = null; boolean matchToken; while (n-- > 0) { tok1 = t1.nextToken(); matchToken = !tok1.equals(SUBTOPIC_WILDCARD); if (t2.hasMoreTokens()) { tok2 = t2.nextToken(); if (tok2.equals(SUBTOPIC_WILDCARD)) continue; } else { break; } if (matchToken && !tok1.equals(tok2)) return false; } if (difference == 0) return true; else if ((difference < 0) && tok1.equals(SUBTOPIC_WILDCARD)) return true; else return (difference > 0) && tok2.equals(SUBTOPIC_WILDCARD); } }
Subtopic { public boolean matches(Subtopic other) { if (!hasSubtopicWildcard && !other.hasSubtopicWildcard) { return (subtopic.equals(other.subtopic)) ? true : false; } else { if (hierarchical && other.hierarchical && !separator.equals(other.separator)) return false; StringTokenizer t1 = new StringTokenizer(subtopic, separator); StringTokenizer t2 = new StringTokenizer(other.subtopic, other.separator); int n = t1.countTokens(); int difference = n - t2.countTokens(); String tok1 = null; String tok2 = null; boolean matchToken; while (n-- > 0) { tok1 = t1.nextToken(); matchToken = !tok1.equals(SUBTOPIC_WILDCARD); if (t2.hasMoreTokens()) { tok2 = t2.nextToken(); if (tok2.equals(SUBTOPIC_WILDCARD)) continue; } else { break; } if (matchToken && !tok1.equals(tok2)) return false; } if (difference == 0) return true; else if ((difference < 0) && tok1.equals(SUBTOPIC_WILDCARD)) return true; else return (difference > 0) && tok2.equals(SUBTOPIC_WILDCARD); } } }
Subtopic { public boolean matches(Subtopic other) { if (!hasSubtopicWildcard && !other.hasSubtopicWildcard) { return (subtopic.equals(other.subtopic)) ? true : false; } else { if (hierarchical && other.hierarchical && !separator.equals(other.separator)) return false; StringTokenizer t1 = new StringTokenizer(subtopic, separator); StringTokenizer t2 = new StringTokenizer(other.subtopic, other.separator); int n = t1.countTokens(); int difference = n - t2.countTokens(); String tok1 = null; String tok2 = null; boolean matchToken; while (n-- > 0) { tok1 = t1.nextToken(); matchToken = !tok1.equals(SUBTOPIC_WILDCARD); if (t2.hasMoreTokens()) { tok2 = t2.nextToken(); if (tok2.equals(SUBTOPIC_WILDCARD)) continue; } else { break; } if (matchToken && !tok1.equals(tok2)) return false; } if (difference == 0) return true; else if ((difference < 0) && tok1.equals(SUBTOPIC_WILDCARD)) return true; else return (difference > 0) && tok2.equals(SUBTOPIC_WILDCARD); } } Subtopic(String subtopic, String separator); }
Subtopic { public boolean matches(Subtopic other) { if (!hasSubtopicWildcard && !other.hasSubtopicWildcard) { return (subtopic.equals(other.subtopic)) ? true : false; } else { if (hierarchical && other.hierarchical && !separator.equals(other.separator)) return false; StringTokenizer t1 = new StringTokenizer(subtopic, separator); StringTokenizer t2 = new StringTokenizer(other.subtopic, other.separator); int n = t1.countTokens(); int difference = n - t2.countTokens(); String tok1 = null; String tok2 = null; boolean matchToken; while (n-- > 0) { tok1 = t1.nextToken(); matchToken = !tok1.equals(SUBTOPIC_WILDCARD); if (t2.hasMoreTokens()) { tok2 = t2.nextToken(); if (tok2.equals(SUBTOPIC_WILDCARD)) continue; } else { break; } if (matchToken && !tok1.equals(tok2)) return false; } if (difference == 0) return true; else if ((difference < 0) && tok1.equals(SUBTOPIC_WILDCARD)) return true; else return (difference > 0) && tok2.equals(SUBTOPIC_WILDCARD); } } Subtopic(String subtopic, String separator); boolean containsSubtopicWildcard(); boolean equals(Object other); String getSeparator(); String getValue(); int hashCode(); boolean isHierarchical(); boolean matches(Subtopic other); String toString(); }
Subtopic { public boolean matches(Subtopic other) { if (!hasSubtopicWildcard && !other.hasSubtopicWildcard) { return (subtopic.equals(other.subtopic)) ? true : false; } else { if (hierarchical && other.hierarchical && !separator.equals(other.separator)) return false; StringTokenizer t1 = new StringTokenizer(subtopic, separator); StringTokenizer t2 = new StringTokenizer(other.subtopic, other.separator); int n = t1.countTokens(); int difference = n - t2.countTokens(); String tok1 = null; String tok2 = null; boolean matchToken; while (n-- > 0) { tok1 = t1.nextToken(); matchToken = !tok1.equals(SUBTOPIC_WILDCARD); if (t2.hasMoreTokens()) { tok2 = t2.nextToken(); if (tok2.equals(SUBTOPIC_WILDCARD)) continue; } else { break; } if (matchToken && !tok1.equals(tok2)) return false; } if (difference == 0) return true; else if ((difference < 0) && tok1.equals(SUBTOPIC_WILDCARD)) return true; else return (difference > 0) && tok2.equals(SUBTOPIC_WILDCARD); } } Subtopic(String subtopic, String separator); boolean containsSubtopicWildcard(); boolean equals(Object other); String getSeparator(); String getValue(); int hashCode(); boolean isHierarchical(); boolean matches(Subtopic other); String toString(); static final String SUBTOPIC_WILDCARD; }