KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > ArrayConstructorFunction


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solution. 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 /*
10  * Created on Apr 18, 2005
11  *
12  * Author Ben Yu
13  * ZBS
14  */

15 package jfun.yan;
16
17 import jfun.yan.function.Function;
18
19 /**
20  * Zephyr Business Solution
21  *
22  * @author Ben Yu
23  *
24  */

25 final class ArrayConstructorFunction<T> implements Function<T> {
26   private final Class JavaDoc<T> array_type;
27   public boolean isConcrete(){
28     return true;
29   }
30   ArrayConstructorFunction(final Class JavaDoc<T> array_type) {
31     this.array_type = array_type;
32   }
33   private static final Class JavaDoc[] ptypes = new Class JavaDoc[]{int.class};
34   public T call(Object JavaDoc[] args) throws Throwable JavaDoc {
35     return (T)java.lang.reflect.Array.newInstance(array_type.getComponentType(),
36         ((Integer JavaDoc)args[0]).intValue());
37   }
38   public Class JavaDoc[] getParameterTypes() {
39     return ptypes;
40   }
41   public Class JavaDoc<T> getReturnType() {
42     return array_type;
43   }
44   public boolean equals(Object JavaDoc obj) {
45     if(obj instanceof ArrayConstructorFunction){
46       final ArrayConstructorFunction other = (ArrayConstructorFunction)obj;
47       return array_type.equals(other.array_type);
48     }
49     else return false;
50   }
51   public int hashCode() {
52     return array_type.hashCode();
53   }
54   public String JavaDoc toString() {
55     return jfun.util.Misc.getTypeName(array_type)+".new";
56   }
57   public String JavaDoc getName(){
58     return "new[]";
59   }
60 }
61
Popular Tags