MetricFiltering { public static boolean matchesScope(String actualScope, Set<String> scopes) { if (scopes.isEmpty() || scopes.contains(actualScope)) { return true; } for (String scope : scopes) { if (subPathMatches(actualScope, scope)) { return true; } } return false; } private  MetricFiltering(); static boolean matches(MetricsFilter filter, MetricKey key); static boolean subPathMatches(String haystack, String needle); static boolean matchesScope(String actualScope, Set<String> scopes);  }
@Test public void testMatchesScope() { assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1")); assertTrue( matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1/Bottom1")); assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1")); assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1")); assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Inner1")); assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inn")); }
@Test public void testMatchesScope() { assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1")); assertTrue(matchesScopeWithSingleFilter( "Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1/Bottom1")); assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1")); assertTrue(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inner1")); assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Inner1")); assertFalse(matchesScopeWithSingleFilter("Top1/Outer1/Inner1/Bottom1", "Top1/Outer1/Inn")); }