@Test public void testNumberCompare() { ASMSupportClassLoader classLoader = CachedThreadLocalClassLoader.getInstance(); Value[] values = new Value[14]; values[0] = Value.value(classLoader, (byte)1); values[1] = Value.value(classLoader, (byte)2); values[2] = Value.value(classLoader, (short)1); values[3] = Value.value(classLoader, (short)2); values[4] = Value.value(classLoader, 1); values[5] = Value.value(classLoader, 2); values[6] = Value.value(classLoader, 1F); values[7] = Value.value(classLoader, 2F); values[8] = Value.value(classLoader, 1L); values[9] = Value.value(classLoader, 2L); values[10] = Value.value(classLoader, 1D); values[11] = Value.value(classLoader, 2D); for(int i=0; i<11; i++) { Value vi = values[i]; for(int j=0; j<11; j++) { Value vj = values[j]; if(i%2 == j%2) { Assert.assertEquals(0, vi.numberCompare(vj)); Assert.assertEquals(0, vj.numberCompare(vi)); } else { if(i%2 == 1) { Assert.assertEquals(1, vi.numberCompare(vj)); Assert.assertEquals(-1, vj.numberCompare(vi)); } else { Assert.assertEquals(-1, vi.numberCompare(vj)); Assert.assertEquals(1, vj.numberCompare(vi)); } } } } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public int numberCompare(Value comp) { if (!isNumber()) throw new ASMSupportException(this + " is not a number value."); if (!comp.isNumber()) throw new ASMSupportException(comp + " is not a number value."); int compOrder = cls.getCastOrder() - comp.cls.getCastOrder(); Object v1; Object v2; if (compOrder == 0) { v1 = value; v2 = comp.value; } else if (compOrder > 0) { v1 = value; v2 = comp.getConvert(cls).value; } else { v1 = getConvert(comp.cls).value; v2 = comp.value; } return ((Comparable) v1).compareTo(v2); }
Value implements IValue { @SuppressWarnings({ "unchecked", "rawtypes" }) public int numberCompare(Value comp) { if (!isNumber()) throw new ASMSupportException(this + " is not a number value."); if (!comp.isNumber()) throw new ASMSupportException(comp + " is not a number value."); int compOrder = cls.getCastOrder() - comp.cls.getCastOrder(); Object v1; Object v2; if (compOrder == 0) { v1 = value; v2 = comp.value; } else if (compOrder > 0) { v1 = value; v2 = comp.getConvert(cls).value; } else { v1 = getConvert(comp.cls).value; v2 = comp.value; } return ((Comparable) v1).compareTo(v2); } }
Value implements IValue { @SuppressWarnings({ "unchecked", "rawtypes" }) public int numberCompare(Value comp) { if (!isNumber()) throw new ASMSupportException(this + " is not a number value."); if (!comp.isNumber()) throw new ASMSupportException(comp + " is not a number value."); int compOrder = cls.getCastOrder() - comp.cls.getCastOrder(); Object v1; Object v2; if (compOrder == 0) { v1 = value; v2 = comp.value; } else if (compOrder > 0) { v1 = value; v2 = comp.getConvert(cls).value; } else { v1 = getConvert(comp.cls).value; v2 = comp.value; } return ((Comparable) v1).compareTo(v2); } private  Value(ClassHolder holder, Boolean value); private  Value(ClassHolder holder, Byte value); private  Value(ClassHolder holder, Short value); private  Value(ClassHolder holder, Character value); private  Value(ClassHolder holder, Integer value); private  Value(ClassHolder holder, Long value); private  Value(ClassHolder holder, Float value); private  Value(ClassHolder holder, Double value); private  Value(ClassHolder holder, String value); private  Value(); private  Value(IClass aclass); }
Value implements IValue { @SuppressWarnings({ "unchecked", "rawtypes" }) public int numberCompare(Value comp) { if (!isNumber()) throw new ASMSupportException(this + " is not a number value."); if (!comp.isNumber()) throw new ASMSupportException(comp + " is not a number value."); int compOrder = cls.getCastOrder() - comp.cls.getCastOrder(); Object v1; Object v2; if (compOrder == 0) { v1 = value; v2 = comp.value; } else if (compOrder > 0) { v1 = value; v2 = comp.getConvert(cls).value; } else { v1 = getConvert(comp.cls).value; v2 = comp.value; } return ((Comparable) v1).compareTo(v2); } private  Value(ClassHolder holder, Boolean value); private  Value(ClassHolder holder, Byte value); private  Value(ClassHolder holder, Short value); private  Value(ClassHolder holder, Character value); private  Value(ClassHolder holder, Integer value); private  Value(ClassHolder holder, Long value); private  Value(ClassHolder holder, Float value); private  Value(ClassHolder holder, Double value); private  Value(ClassHolder holder, String value); private  Value(); private  Value(IClass aclass); static Value defaultValue(IClass aclass); static Value getNullValue(ClassHolder holder, Class<?> type); static Value getNullValue(IClass type); static Value value(ClassHolder holder, Integer obj); static Value value(ClassHolder holder, Short obj); static Value value(ClassHolder holder, Byte obj); static Value value(ClassHolder holder, Boolean obj); static Value value(ClassHolder holder, Long obj); static Value value(ClassHolder holder, Double obj); static Value value(ClassHolder holder, Character obj); static Value value(ClassHolder holder, Float obj); static Value value(ClassHolder holder, IClass obj); static Value value(ClassHolder holder, Class<?> obj); static Value value(ClassHolder holder, String obj); static Value number(IClass type, int val); void convert(IClass type); Value getConvert(IClass type); @SuppressWarnings({ "unchecked", "rawtypes" }) int numberCompare(Value comp); boolean isNumber(); boolean isBoolean(); @Override void push(MethodExecuteContext context); @Override void asArgument(); @Override boolean equals(Object obj); @Override int hashCode(); Type getType(); Object getValue(); @Override IClass getResultType(); @Override String toString(); @Override GlobalVariable field(String name); }
Value implements IValue { @SuppressWarnings({ "unchecked", "rawtypes" }) public int numberCompare(Value comp) { if (!isNumber()) throw new ASMSupportException(this + " is not a number value."); if (!comp.isNumber()) throw new ASMSupportException(comp + " is not a number value."); int compOrder = cls.getCastOrder() - comp.cls.getCastOrder(); Object v1; Object v2; if (compOrder == 0) { v1 = value; v2 = comp.value; } else if (compOrder > 0) { v1 = value; v2 = comp.getConvert(cls).value; } else { v1 = getConvert(comp.cls).value; v2 = comp.value; } return ((Comparable) v1).compareTo(v2); } private  Value(ClassHolder holder, Boolean value); private  Value(ClassHolder holder, Byte value); private  Value(ClassHolder holder, Short value); private  Value(ClassHolder holder, Character value); private  Value(ClassHolder holder, Integer value); private  Value(ClassHolder holder, Long value); private  Value(ClassHolder holder, Float value); private  Value(ClassHolder holder, Double value); private  Value(ClassHolder holder, String value); private  Value(); private  Value(IClass aclass); static Value defaultValue(IClass aclass); static Value getNullValue(ClassHolder holder, Class<?> type); static Value getNullValue(IClass type); static Value value(ClassHolder holder, Integer obj); static Value value(ClassHolder holder, Short obj); static Value value(ClassHolder holder, Byte obj); static Value value(ClassHolder holder, Boolean obj); static Value value(ClassHolder holder, Long obj); static Value value(ClassHolder holder, Double obj); static Value value(ClassHolder holder, Character obj); static Value value(ClassHolder holder, Float obj); static Value value(ClassHolder holder, IClass obj); static Value value(ClassHolder holder, Class<?> obj); static Value value(ClassHolder holder, String obj); static Value number(IClass type, int val); void convert(IClass type); Value getConvert(IClass type); @SuppressWarnings({ "unchecked", "rawtypes" }) int numberCompare(Value comp); boolean isNumber(); boolean isBoolean(); @Override void push(MethodExecuteContext context); @Override void asArgument(); @Override boolean equals(Object obj); @Override int hashCode(); Type getType(); Object getValue(); @Override IClass getResultType(); @Override String toString(); @Override GlobalVariable field(String name);  }