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; 018 019import java.util.List; 020 021/** 022 * Makes any MetaPattern optional by enclosing the pattern in an optionality expression. The 023 * expression will be something equivalent to "(?:<pattern>)?". 024 * 025 * @author Jonathan Locke 026 */ 027public final class OptionalMetaPattern extends MetaPattern 028{ 029 private static final long serialVersionUID = 1L; 030 031 /** 032 * Constructor 033 * 034 * @param pattern 035 */ 036 public OptionalMetaPattern(final String pattern) 037 { 038 super(pattern); 039 } 040 041 /** 042 * Constructor 043 * 044 * @param pattern 045 * MetaPattern to make optional 046 */ 047 public OptionalMetaPattern(final MetaPattern pattern) 048 { 049 super(pattern); 050 } 051 052 /** 053 * Constructor 054 * 055 * @param patterns 056 */ 057 public OptionalMetaPattern(final List<MetaPattern> patterns) 058 { 059 super(patterns); 060 } 061 062 /** 063 * Constructor 064 * 065 * @param patterns 066 */ 067 public OptionalMetaPattern(final MetaPattern[] patterns) 068 { 069 super(patterns); 070 } 071 072 /** 073 * @return String representation of this pattern 074 */ 075 @Override 076 public String toString() 077 { 078 return "(?:" + super.toString() + ")?"; 079 } 080}