001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.util.text;
016
017 /**
018 * Combine a set of character matchers. A given character will be matched if any
019 * of the provided objects matches it.
020 *
021 * @author mb
022 * @since 4.0
023 */
024 public class CompoundMatcher implements ICharacterMatcher
025 {
026 private ICharacterMatcher[] _matchers;
027
028 /**
029 * Create a new object that will match a character if any of the provided objects matches it.
030 *
031 * @param matchers the array of objects that will be queried if a character matches
032 */
033 public CompoundMatcher(ICharacterMatcher[] matchers) {
034 _matchers = matchers;
035 }
036
037 /**
038 * Match the character if any of the provided objects matches it.
039 *
040 * @see org.apache.tapestry.util.text.ICharacterMatcher#matches(char)
041 */
042 public boolean matches(char ch)
043 {
044 for (int i = 0; i < _matchers.length; i++) {
045 if (_matchers[i].matches(ch))
046 return true;
047 }
048 return false;
049 }
050 }