View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.configuration2.tree;
18  
19  /**
20   * <p>
21   * An interface for matching nodes based on specific criteria.
22   * </p>
23   * <p>
24   * This interface is used by {@link NodeHandler} to support advanced filtering on the child nodes of a given parent
25   * node. This is useful for instance for special {@link ExpressionEngine} implementations which do no direct or strict
26   * matches based on node names. An example could be an expression engine that treats the passed in node keys in a
27   * case-insensitive manner. Such an engine would use a special case-insensitive matcher when resolving configuration
28   * keys.
29   * </p>
30   * <p>
31   * The idea behind this interface is that a matcher has to match a property of a node against a given criterion. This
32   * criterion is passed to the matching function so that matchers can be implemented in a state-less fashion and shared
33   * between multiple components.
34   * </p>
35   *
36   * @since 2.0
37   * @param <C> the type of the criterion evaluated by this matcher
38   */
39  public interface NodeMatcher<C> {
40      /**
41       * Tests whether the passed in node matches the given criterion.
42       *
43       * @param node the node to be tested
44       * @param handler the corresponding {@code NodeHandler}
45       * @param criterion the criterion to match against
46       * @param <T> the type of the node
47       * @return <b>true</b> if this node matches the criterion, <b>false</b> otherwise
48       */
49      <T> boolean matches(T node, NodeHandler<T> handler, C criterion);
50  }