org.terracotta.context.query.Matchers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of statistics Show documentation
Show all versions of statistics Show documentation
A statistics framework used inside Ehcache and the Terracotta products
/*
* All content copyright Terracotta, Inc., unless otherwise indicated.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terracotta.context.query;
import org.terracotta.context.ContextElement;
import org.terracotta.context.TreeNode;
import java.util.Map;
/**
* A static library of {@link Matcher} implementations that can be used with the
* {@link QueryBuilder#filter(Matcher)} method.
*/
public final class Matchers {
private Matchers() {
//static class
}
/**
* Returns a matcher that matches tree nodes whose {@link TreeNode#getContext()}
* match against the supplied matcher.
*
* @param matcher {@code ContextElement} matcher
* @return a {@code TreeNode} matcher
*/
public static Matcher context(final Matcher matcher) {
return new Matcher() {
@Override
protected boolean matchesSafely(TreeNode t) {
return matcher.matches(t.getContext());
}
@Override
public String toString() {
return "a context that has " + matcher;
}
};
}
/**
* Returns a matcher that matches context elements whose {@link ContextElement#attributes()}
* match against the supplied matcher.
*
* @param matcher a {@code Map} (attributes) matcher
* @return a {@code ContextElement} matcher
*/
public static Matcher attributes(final Matcher