01: /*
02: * $Id: IntegerGroup.java 1492 2005-03-29 07:03:48 +0000 (Tue, 29 Mar 2005)
03: * jonathanlocke $ $Revision: 1492 $ $Date: 2005-03-29 07:03:48 +0000 (Tue, 29
04: * Mar 2005) $
05: *
06: * ==============================================================================
07: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
08: * use this file except in compliance with the License. You may obtain a copy of
09: * the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16: * License for the specific language governing permissions and limitations under
17: * the License.
18: */
19: package wicket.util.parse.metapattern;
20:
21: import java.util.regex.Matcher;
22:
23: /**
24: * A Group that captures case-sensitive boolean values "true" or "false".
25: *
26: * @author Jonathan Locke
27: */
28: public final class BooleanGroup extends Group {
29: /**
30: * Constructs an IntegerGroup that parses Strings that match the INTEGER
31: * pattern in base 10.
32: *
33: * @see MetaPattern#INTEGER
34: */
35: public BooleanGroup() {
36: super (new MetaPattern("true|false"));
37: }
38:
39: /**
40: * @param matcher
41: * The matcher
42: * @return The value
43: * @see BooleanGroup#getInt(Matcher, int)
44: */
45: public boolean getBoolean(final Matcher matcher) {
46: return getBoolean(matcher, false);
47: }
48:
49: /**
50: * Gets a boolean by parsing the String matched by this capturing group.
51: *
52: * @param matcher
53: * The matcher
54: * @param defaultValue
55: * The default value to use if this group is omitted because it
56: * is optional
57: * @return The parsed int value
58: */
59: public boolean getBoolean(final Matcher matcher,
60: final boolean defaultValue) {
61: final String value = get(matcher);
62: return value == null ? defaultValue : value.equals("true");
63: }
64: }
|