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 ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
/*
* 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 java.util.Map;
import org.terracotta.context.ContextElement;
import org.terracotta.context.TreeNode;
/**
* 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