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.parsers;
18:
19: import org.apache.wicket.util.parse.metapattern.Group;
20: import org.apache.wicket.util.parse.metapattern.IntegerGroup;
21: import org.apache.wicket.util.parse.metapattern.MetaPattern;
22:
23: /**
24: * Parses integer variable assignments, such as "x = 9" or "x=9".
25: *
26: * @author Jonathan Locke
27: */
28: public final class IntegerVariableAssignmentParser extends
29: MetaPatternParser {
30: /** Parse "variable = <number>". */
31: private static final Group variable = new Group(
32: MetaPattern.VARIABLE_NAME);
33:
34: /** Group value. */
35: private static final IntegerGroup value = new IntegerGroup();
36:
37: /** Meta pattern. */
38: private static final MetaPattern pattern = new MetaPattern(
39: new MetaPattern[] { variable,
40: MetaPattern.OPTIONAL_WHITESPACE,
41: MetaPattern.EQUALS,
42: MetaPattern.OPTIONAL_WHITESPACE, value });
43:
44: /**
45: * Construct.
46: *
47: * @param input
48: * to parse
49: */
50: public IntegerVariableAssignmentParser(final CharSequence input) {
51: super (pattern, input);
52: }
53:
54: /**
55: * Gets the variable part (eg the 'x' from 'x = 9').
56: *
57: * @return the variable part
58: */
59: public String getVariable() {
60: return variable.get(matcher());
61: }
62:
63: /**
64: * Gets the int part (eg the '9' from 'x = 9').
65: *
66: * @return the int part.
67: */
68: public int getIntValue() {
69: return value.getInt(matcher());
70: }
71:
72: /**
73: * Gets the int part as a long.
74: *
75: * @return the int part as a long
76: */
77: public long getLongValue() {
78: return value.getLong(matcher());
79: }
80: }
|