Package com.firefly.utils.ReflectUtils

Examples of com.firefly.utils.ReflectUtils.ArrayProxy


  @Override
  public ArrayProxy getArrayProxy(Class<?> clazz) throws Throwable {
    if(!clazz.isArray())
      throw new IllegalArgumentException("type error, it's not array");
     
    ArrayProxy ret = arrayCache.get(clazz);
    if(ret != null)
      return ret;
   
    synchronized(arrayCache) {
      ret = arrayCache.get(clazz);
View Full Code Here


   
    Class<?> arrayProxyClazz = CompilerUtils.compileSource(completeClassName, source);
    if(arrayProxyClazz == null)
      return null;
   
    ArrayProxy obj = (ArrayProxy)arrayProxyClazz.newInstance();
//    long end = System.currentTimeMillis();
//    System.out.println("Java compiler generates class proxy time -> " + (end - start));
    return obj;
  }
View Full Code Here

    ArrayProxyFactoryUsingJavaCompiler arrayProxyFactory = ArrayProxyFactoryUsingJavaCompiler.INSTANCE;
   
    int[] intArr = new int[5];
    Integer[] intArr2 = new Integer[10];
   
    ArrayProxy intArrProxy = arrayProxyFactory.getArrayProxy(intArr.getClass());
    ArrayProxy intArr2Proxy = arrayProxyFactory.getArrayProxy(intArr2.getClass());
   
    Assert.assertThat(ReflectUtils.arraySize(intArr), is(5));
    Assert.assertThat(ReflectUtils.arraySize(intArr2), is(10));
   
    Assert.assertThat(intArrProxy.size(intArr), is(5));
    Assert.assertThat(intArr2Proxy.size(intArr2), is(10));
   
    ReflectUtils.arraySet(intArr, 0, 33);
    Assert.assertThat((Integer)ReflectUtils.arrayGet(intArr, 0), is(33));
   
    ReflectUtils.arraySet(intArr2, intArr2.length - 1, 55);
    Assert.assertThat((Integer)ReflectUtils.arrayGet(intArr2, 9), is(55));
   
    intArrProxy.set(intArr, 1, 23);
    Assert.assertThat((Integer)intArrProxy.get(intArr, 1), is(23));
   
    intArr2Proxy.set(intArr2, intArr2.length - 1, 65);
    Assert.assertThat((Integer)intArr2Proxy.get(intArr2, 9), is(65));
  }
View Full Code Here

  }
 
  public static void main5(String[] args) throws Throwable {
    Integer[] array = new Integer[]{77, 88, 99, 0, 11};
    int[] array2 = new int[]{15, 44, 55, 66};
    ArrayProxy arrayProxy = ArrayProxyFactoryUsingJavaCompiler.INSTANCE.getArrayProxy(array.getClass());
    ArrayProxy arrayProxy2 = ArrayProxyFactoryUsingJavaCompiler.INSTANCE.getArrayProxy(array2.getClass());
    System.out.println(arrayProxy.get(array, 2));
    System.out.println(arrayProxy2.get(array2, 3));
   
    ArrayProxy arrayProxy3 = ReflectUtils.getArrayProxy(array.getClass());
    ArrayProxy arrayProxy4 = ReflectUtils.getArrayProxy(array2.getClass());
    System.out.println(arrayProxy3.get(array, 2));
    System.out.println(arrayProxy4.get(array2, 3));
   
    int times = 1000 * 1000 * 1000;
    long start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      arrayProxy2.get(array2, 3);
    }
    long end = System.currentTimeMillis();
    System.out.println("java compiler -> " + (end - start));
   
    start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      arrayProxy4.get(array2, 3);
    }
    end = System.currentTimeMillis();
    System.out.println("javassist -> " + (end - start));
   
  }
View Full Code Here

  @Override
  public ArrayProxy getArrayProxy(Class<?> clazz) throws Throwable {
    if(!clazz.isArray())
      throw new IllegalArgumentException("type error, it's not array");
     
    ArrayProxy ret = arrayCache.get(clazz);
    if(ret != null)
      return ret;
   
    synchronized(arrayCache) {
      ret = arrayCache.get(clazz);
View Full Code Here

   
    cc.addMethod(CtMethod.make(createArraySizeCode(clazz), cc));
    cc.addMethod(CtMethod.make(createArrayGetCode(clazz), cc));
    cc.addMethod(CtMethod.make(createArraySetCode(clazz), cc));
   
    ArrayProxy ret = (ArrayProxy) cc.toClass().getConstructor().newInstance();
//    long end = System.currentTimeMillis();
//    System.out.println("Javassist generates class proxy time -> " + (end - start));
    return ret;
  }
View Full Code Here

TOP

Related Classes of com.firefly.utils.ReflectUtils.ArrayProxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.