    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.tree;
    018
    019import org.apache.commons.lang3.StringUtils;
    020
    021/**
    022 * <p>
    023 * An enumeration class with several pre-defined {@link NodeMatcher}
    024 * implementations based on node names.
    025 * </p>
    026 * <p>
    027 * Filtering nodes by their name is a typical use case. Therefore, some default
    028 * implementations for typical filter algorithms are already provided. They are
    029 * available as constants of this class. Because the algorithms are state-less
    030 * these instances can be shared and accessed concurrently.
    031 * </p>
    032 *
    033 * @version $Id: NodeNameMatchers.java 1842194 2018-09-27 22:24:23Z ggregory $
    034 * @since 2.0
    035 */
    036public enum NodeNameMatchers implements NodeMatcher<String>
    037{
    038    /**
    039     * A matcher for exact node name matches. This matcher returns <b>true</b>
    040     * if and only if the name of the passed in node equals exactly the given
    041     * criterion string.
    042     */
    043    EQUALS
    044    {
    045        @Override
    046        public <T> boolean matches(final T node, final NodeHandler<T> handler,
    047                final String criterion)
    048        {
    049            return StringUtils.equals(criterion, handler.nodeName(node));
    050        }
    051    },
    052
    053    /**
    054     * A matcher for matches on node names which ignores case. For this matcher
    055     * the names {@code node}, {@code NODE}, or {@code NodE} are all the same.
    056     */
    057    EQUALS_IGNORE_CASE
    058    {
    059        @Override
    060        public <T> boolean matches(final T node, final NodeHandler<T> handler,
    061                final String criterion)
    062        {
    063            return StringUtils.equalsIgnoreCase(criterion,
    064                    handler.nodeName(node));
    065        }
    066    }
    067}