KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > IsToken


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-14
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15
16 /**
17  * Tests if the token is the same token expected.
18  * @author Ben Yu
19  *
20  * 2004-11-14
21  */

22 public final class IsToken implements FromToken<Tok> {
23
24   /**
25    * return the token if the token is the same object that we are expecting.
26    * null otherwise.
27    */

28   public Tok fromToken(Tok tok) {
29     if(tok != null && tok.getToken() == target) return tok;
30     else return null;
31   }
32   private final Object JavaDoc target;
33   
34   /**
35    * @param target
36    */

37   private IsToken(final Object JavaDoc target) {
38     this.target = target;
39   }
40   /**
41    * Creates a FromToken instance using the given expected token t.
42    * @param t the expected token object.
43    * @return the FromToken instance.
44    */

45   public static FromToken<Tok> instance(final Object JavaDoc t){
46     return new IsToken(t);
47   }
48 }
49
Popular Tags