KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > String2Value


1 package jfun.parsec;
2
3 import jfun.util.Misc;
4
5 /**
6  * This implementation of FromString simply returns an object for any parameter.
7  * <p>
8  * @author Ben Yu
9  * Mar 29, 2006 9:57:03 PM
10  */

11 public class String2Value implements FromString {
12   private final Object JavaDoc val;
13   
14   /**
15    * Create a String2Value instance.
16    * @param val the value to be returned by {@link #fromString(int, int, String)}
17    */

18   public String2Value(Object JavaDoc val) {
19     this.val = val;
20   }
21   public Object JavaDoc fromString(int from, int len, String JavaDoc s) {
22     return val;
23   }
24   public String JavaDoc toString(){
25     return ""+val;
26   }
27   public boolean equals(Object JavaDoc obj) {
28     if(obj instanceof String2Value){
29       final String2Value other = (String2Value)obj;
30       return Misc.equals(val, other.val);
31     }
32     else return false;
33   }
34   public int hashCode() {
35     return Misc.hashcode(val);
36   }
37   
38 }
39
Popular Tags