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.wicket.util.parse.metapattern.parsers; 018 019import org.apache.wicket.util.parse.metapattern.Group; 020import org.apache.wicket.util.parse.metapattern.IntegerGroup; 021import org.apache.wicket.util.parse.metapattern.MetaPattern; 022 023/** 024 * Parses integer variable assignments, such as "x = 9" or "x=9". 025 * 026 * @author Jonathan Locke 027 */ 028public final class IntegerVariableAssignmentParser extends MetaPatternParser 029{ 030 /** Parse "variable = <number>". */ 031 private static final Group variable = new Group(MetaPattern.VARIABLE_NAME); 032 033 /** Group value. */ 034 private static final IntegerGroup value = new IntegerGroup(); 035 036 /** Meta pattern. */ 037 private static final MetaPattern pattern = new MetaPattern(variable, 038 MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS, MetaPattern.OPTIONAL_WHITESPACE, value); 039 040 /** 041 * Construct. 042 * 043 * @param input 044 * to parse 045 */ 046 public IntegerVariableAssignmentParser(final CharSequence input) 047 { 048 super(pattern, input); 049 } 050 051 /** 052 * Gets the variable part (eg the 'x' from 'x = 9'). 053 * 054 * @return the variable part 055 */ 056 public String getVariable() 057 { 058 return variable.get(matcher()); 059 } 060 061 /** 062 * Gets the int part (eg the '9' from 'x = 9'). 063 * 064 * @return the int part. 065 */ 066 public int getIntValue() 067 { 068 return value.getInt(matcher()); 069 } 070 071 /** 072 * Gets the int part as a long. 073 * 074 * @return the int part as a long 075 */ 076 public long getLongValue() 077 { 078 return value.getLong(matcher()); 079 } 080}