Copyright test
[jalview.git] / src / com / stevesoft / pat / Validator.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $(date) The Jalview Authors
4  *
5  * This file is part of Jalview.
6  *  
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *   
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  *******************************************************************************/
21 //
22 // This software is now distributed according to
23 // the Lesser Gnu Public License.  Please see
24 // http://www.gnu.org/copyleft/lesser.txt for
25 // the details.
26 //    -- Happy Computing!
27 //
28 package com.stevesoft.pat;
29
30 /**
31  * This class makes it easy to create your own patterns and integrate them into
32  * Regex. For more detail, see the example file <a
33  * href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a> or <a
34  * href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a>.
35  */
36
37 public class Validator
38 {
39   String argsave = null;
40
41   String pattern = ".";
42
43   /**
44    * This method does extra checking on a matched section of a String beginning
45    * at position start and ending at end. The idea is that you can do extra
46    * checking with this that you don't know how to do with a standard Regex.
47    * 
48    * If this method is successful, it returns the location of the end of this
49    * pattern element -- that may be the value end provided or some other value.
50    * A negative value signifies that a match failure.
51    * 
52    * By default, this method just returns end and thus does nothing.
53    * 
54    * @see com.stevesoft.pat.Regex#define(java.lang.String,java.lang.String,com.stevesoft.pat.Validator)
55    */
56   public int validate(StringLike src, int start, int end)
57   {
58     return end;
59   }
60
61   /*
62    * This method allows you to modify the behavior of this validator by making a
63    * new Validator object. If a Validator named "foo" is defined, then the
64    * pattern "{??foo:bar}" will cause Regex to first get the Validator given to
65    * Regex.define and then to call its arg method with the string "bar". If this
66    * method returns a null (the default) you get the same behavior as the
67    * pattern "{??foo}" would supply.
68    */
69   public Validator arg(String s)
70   {
71     return null;
72   }
73
74   /**
75    * For optimization it is helpful, but not necessary, that you define the
76    * minimum number of characters this validator will allow to match. To do this
77    * return new patInt(number) where number is the smallest number of characters
78    * that can match.
79    */
80   public patInt minChars()
81   {
82     return new patInt(0);
83   }
84
85   /**
86    * For optimization it is helpful, but not necessary, that you define the
87    * maximum number of characters this validator will allow to match. To do this
88    * either return new patInt(number), or new patInf() if an infinite number of
89    * characters may match.
90    */
91   public patInt maxChars()
92   {
93     return new patInf();
94   }
95 }