KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > ConstTokenizer


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on 2004-11-15
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15 /**
16  * This tokenizer will always return the same token regardless of the input range.
17  * @author Ben Yu
18  *
19  * 2004-11-15
20  */

21 public final class ConstTokenizer implements Tokenizer, java.io.Serializable JavaDoc {
22
23   /*
24    * @see jfun.parsec.scanner.Tokenizer#toToken(java.lang.CharSequence, int, int)
25    */

26   public Object JavaDoc toToken(CharSequence JavaDoc cs, int from, int len) {
27     return tok;
28   }
29   private final Object JavaDoc tok;
30   private ConstTokenizer(final Object JavaDoc t){this.tok = t;}
31   /**
32    * Creates the Tokenizer instance.
33    * @param t the token to be returned by the tokenizer.
34    * @return the tokenizer instance.
35    */

36   public static Tokenizer instance(final Object JavaDoc t){
37     return new ConstTokenizer(t);
38   }
39 }
40
Popular Tags