01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.wicket.util.parse.metapattern;
18:
19: import java.util.regex.Matcher;
20:
21: /**
22: * A Group that captures case-sensitive boolean values "true" or "false".
23: *
24: * @author Jonathan Locke
25: */
26: public final class BooleanGroup extends Group {
27: private static final long serialVersionUID = 1L;
28:
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: }
|