1 8 13 package jfun.parsec; 14 15 16 17 23 public final class Maps { 24 private static final Unary<Object > _id = new Unary<Object >(){ 25 public Object map(Object v) { 26 return v; 27 } 28 public String toString(){return "id";} 29 }; 30 private static final Mapn<Object []> _idn = new Mapn<Object []>(){ 31 public Object [] map(Object ... v){ 32 return v; 33 } 34 }; 35 39 public static <x> Unary<x> id(){return (Unary<x>)_id;} 40 45 public static <R> Unary<R> id(Class <R> type){ 46 return id(); 47 } 48 52 public static Mapn<Object []> idn(){return _idn;} 53 58 public static <x, V> Map<x, V> cnst(final V v){ 59 return new Map<x,V>(){ 60 public V map(final x from){return v;} 61 }; 62 } 63 68 public static <From,To> Map<From,To> jmap(final java.util.Map <From, To> m){ 69 return new Map<From,To>(){ 70 public To map(final From k){ 71 return m.get(k); 72 } 73 }; 74 } 75 76 80 public static <T> Map<Tok, T> toToken(){ 81 return new Map<Tok, T>(){ 82 public T map(final Tok o){ 83 return (T)o.getToken(); 84 } 85 }; 86 } 87 private static final Map2 _id2 = new Map2(){ 88 public Object map(Object o1, Object o2){ 89 return new Pair(o1, o2); 90 } 91 }; 92 private static final Map3 _id3 = new Map3(){ 93 public Object map(Object o1, Object o2, Object o3){ 94 return new Tuple3(o1, o2, o3); 95 } 96 }; 97 private static final Map4 _id4 = new Map4(){ 98 public Object map(Object o1, Object o2, Object o3, Object o4){ 99 return new Tuple4(o1, o2, o3, o4); 100 } 101 }; 102 private static final Map5 _id5 = new Map5(){ 103 public Object map(Object o1, Object o2, Object o3, Object o4, Object o5){ 104 return new Tuple5(o1, o2, o3, o4, o5); 105 } 106 }; 107 110 public static <A,B> Map2<A,B,Pair<A,B>> id2(){ 111 return _id2; 112 } 113 116 public static <A,B,C> Map3<A,B,C,Tuple3<A,B,C>> id3(){ 117 return _id3; 118 } 119 122 public static <A,B,C,D> Map4<A,B,C,D,Tuple4<A,B,C,D>> id4(){ 123 return _id4; 124 } 125 128 public static <A,B,C,D,E> Map5<A,B,C,D,E,Tuple5<A,B,C,D,E>> id5(){ 129 return _id5; 130 } 131 } 132 | Popular Tags |