boxesruntime.java
来自「JAVA 语言的函数式编程扩展」· Java 代码 · 共 846 行 · 第 1/3 页
JAVA
846 行
return boxToBoolean(((Boolean) arg1).booleanValue() | ((Boolean) arg2).booleanValue()); } int code1 = typeCode(arg1); int code2 = typeCode(arg2); int maxcode = (code1 < code2) ? code2 : code1; if (maxcode <= INT) { int val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).intValue(); int val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).intValue(); return boxToInteger(val1 | val2); } if (maxcode <= LONG) { long val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).longValue(); long val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).longValue(); return boxToLong(val1 | val2); } throw new NoSuchMethodException(); } /** arg1 ^ arg2 */ public static Object takeXor(Object arg1, Object arg2) throws NoSuchMethodException { if ((arg1 instanceof Boolean) || (arg2 instanceof Boolean)) { if (!((arg1 instanceof Boolean) && (arg2 instanceof Boolean))) { throw new NoSuchMethodException(); } return boxToBoolean(((Boolean) arg1).booleanValue() ^ ((Boolean) arg2).booleanValue()); } int code1 = typeCode(arg1); int code2 = typeCode(arg2); int maxcode = (code1 < code2) ? code2 : code1; if (maxcode <= INT) { int val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).intValue(); int val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).intValue(); return boxToInteger(val1 ^ val2); } if (maxcode <= LONG) { long val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).longValue(); long val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).longValue(); return boxToLong(val1 ^ val2); } throw new NoSuchMethodException(); } /** arg1 && arg2 */ public static Object takeConditionalAnd(Object arg1, Object arg2) throws NoSuchMethodException { if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) { return boxToBoolean(((Boolean) arg1).booleanValue() && ((Boolean) arg2).booleanValue()); } throw new NoSuchMethodException(); } /** arg1 || arg2 */ public static Object takeConditionalOr(Object arg1, Object arg2) throws NoSuchMethodException { if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) { return boxToBoolean(((Boolean) arg1).booleanValue() || ((Boolean) arg2).booleanValue()); } throw new NoSuchMethodException(); } /** ~arg */ public static Object complement(Object arg) throws NoSuchMethodException { int code = typeCode(arg); if (code <= INT) { int val = (code == CHAR) ? ((Character) arg).charValue() : ((Number) arg).intValue(); return boxToInteger(~val); } if (code <= LONG) { long val = (code == CHAR) ? ((Character) arg).charValue() : ((Number) arg).longValue(); return boxToLong(~val); } throw new NoSuchMethodException(); } /** !arg */ public static Object takeNot(Object arg) throws NoSuchMethodException { if (arg instanceof Boolean) { return boxToBoolean(!((Boolean) arg).booleanValue()); } throw new NoSuchMethodException(); } public static Object testEqual(Object arg1, Object arg2) throws NoSuchMethodException { return boxToBoolean(arg1 == arg2); } public static Object testNotEqual(Object arg1, Object arg2) throws NoSuchMethodException { return boxToBoolean(arg1 != arg2); } public static Object testLessThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); int maxcode = (code1 < code2) ? code2 : code1; if (maxcode <= INT) { int val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).intValue(); int val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).intValue(); return boxToBoolean(val1 < val2); } if (maxcode <= LONG) { long val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).longValue(); long val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).longValue(); return boxToBoolean(val1 < val2); } if (maxcode <= FLOAT) { float val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).floatValue(); float val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).floatValue(); return boxToBoolean(val1 < val2); } if (maxcode <= DOUBLE) { double val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).doubleValue(); double val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).doubleValue(); return boxToBoolean(val1 < val2); } throw new NoSuchMethodException(); } public static Object testLessOrEqualThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); int maxcode = (code1 < code2) ? code2 : code1; if (maxcode <= INT) { int val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).intValue(); int val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).intValue(); return boxToBoolean(val1 <= val2); } if (maxcode <= LONG) { long val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).longValue(); long val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).longValue(); return boxToBoolean(val1 <= val2); } if (maxcode <= FLOAT) { float val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).floatValue(); float val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).floatValue(); return boxToBoolean(val1 <= val2); } if (maxcode <= DOUBLE) { double val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).doubleValue(); double val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).doubleValue(); return boxToBoolean(val1 <= val2); } throw new NoSuchMethodException(); } public static Object testGreaterOrEqualThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); int maxcode = (code1 < code2) ? code2 : code1; if (maxcode <= INT) { int val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).intValue(); int val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).intValue(); return boxToBoolean(val1 >= val2); } if (maxcode <= LONG) { long val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).longValue(); long val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).longValue(); return boxToBoolean(val1 >= val2); } if (maxcode <= FLOAT) { float val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).floatValue(); float val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).floatValue(); return boxToBoolean(val1 >= val2); } if (maxcode <= DOUBLE) { double val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).doubleValue(); double val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).doubleValue(); return boxToBoolean(val1 >= val2); } throw new NoSuchMethodException(); } public static Object testGreaterThan(Object arg1, Object arg2) throws NoSuchMethodException { int code1 = typeCode(arg1); int code2 = typeCode(arg2); int maxcode = (code1 < code2) ? code2 : code1; if (maxcode <= INT) { int val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).intValue(); int val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).intValue(); return boxToBoolean(val1 > val2); } if (maxcode <= LONG) { long val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).longValue(); long val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).longValue(); return boxToBoolean(val1 > val2); } if (maxcode <= FLOAT) { float val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).floatValue(); float val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).floatValue(); return boxToBoolean(val1 > val2); } if (maxcode <= DOUBLE) { double val1 = (code1 == CHAR) ? ((Character) arg1).charValue() : ((Number) arg1).doubleValue(); double val2 = (code2 == CHAR) ? ((Character) arg2).charValue() : ((Number) arg2).doubleValue(); return boxToBoolean(val1 > val2); } throw new NoSuchMethodException(); } /** arg.toChar */ public static Character toCharacter(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return (Character)arg; if (arg instanceof Byte) return boxToCharacter((char)unboxToByte(arg)); if (arg instanceof Short) return boxToCharacter((char)unboxToShort(arg)); if (arg instanceof Integer) return boxToCharacter((char)unboxToInt(arg)); if (arg instanceof Long) return boxToCharacter((char)unboxToLong(arg)); if (arg instanceof Float) return boxToCharacter((char)unboxToFloat(arg)); if (arg instanceof Double) return boxToCharacter((char)unboxToDouble(arg)); throw new NoSuchMethodException(); } /** arg.toByte */ public static Byte toByte(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return boxToByte((byte)unboxToChar(arg)); if (arg instanceof Byte) return (Byte)arg; if (arg instanceof Short) return boxToByte((byte)unboxToShort(arg)); if (arg instanceof Integer) return boxToByte((byte)unboxToInt(arg)); if (arg instanceof Long) return boxToByte((byte)unboxToLong(arg)); if (arg instanceof Float) return boxToByte((byte)unboxToFloat(arg)); if (arg instanceof Double) return boxToByte((byte)unboxToDouble(arg)); throw new NoSuchMethodException(); } /** arg.toShort */ public static Short toShort(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return boxToShort((short)unboxToChar(arg)); if (arg instanceof Byte) return boxToShort((short)unboxToByte(arg)); if (arg instanceof Short) return (Short)arg; if (arg instanceof Integer) return boxToShort((short)unboxToInt(arg)); if (arg instanceof Long) return boxToShort((short)unboxToLong(arg)); if (arg instanceof Float) return boxToShort((short)unboxToFloat(arg)); if (arg instanceof Double) return boxToShort((short)unboxToDouble(arg)); throw new NoSuchMethodException(); } /** arg.toInt */ public static Integer toInteger(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return boxToInteger((int)unboxToChar(arg)); if (arg instanceof Byte) return boxToInteger((int)unboxToByte(arg)); if (arg instanceof Short) return boxToInteger((int)unboxToShort(arg)); if (arg instanceof Integer) return (Integer)arg; if (arg instanceof Long) return boxToInteger((int)unboxToLong(arg)); if (arg instanceof Float) return boxToInteger((int)unboxToFloat(arg)); if (arg instanceof Double) return boxToInteger((int)unboxToDouble(arg)); throw new NoSuchMethodException(); } /** arg.toLong */ public static Long toLong(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return boxToLong((long)unboxToChar(arg)); if (arg instanceof Byte) return boxToLong((long)unboxToByte(arg)); if (arg instanceof Short) return boxToLong((long)unboxToShort(arg)); if (arg instanceof Integer) return boxToLong((long)unboxToInt(arg)); if (arg instanceof Long) return (Long)arg; if (arg instanceof Float) return boxToLong((long)unboxToFloat(arg)); if (arg instanceof Double) return boxToLong((long)unboxToDouble(arg)); throw new NoSuchMethodException(); } /** arg.toFloat */ public static Float toFloat(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return boxToFloat((float)unboxToChar(arg)); if (arg instanceof Byte) return boxToFloat((float)unboxToByte(arg)); if (arg instanceof Short) return boxToFloat((float)unboxToShort(arg)); if (arg instanceof Integer) return boxToFloat((float)unboxToInt(arg)); if (arg instanceof Long) return boxToFloat((float)unboxToLong(arg)); if (arg instanceof Float) return (Float)arg; if (arg instanceof Double) return boxToFloat((float)unboxToDouble(arg)); throw new NoSuchMethodException(); } /** arg.toDouble */ public static Double toDouble(Object arg) throws NoSuchMethodException { if (arg instanceof Character) return boxToDouble((double)unboxToChar(arg)); if (arg instanceof Byte) return boxToDouble((double)unboxToByte(arg)); if (arg instanceof Short) return boxToDouble((double)unboxToShort(arg)); if (arg instanceof Integer) return boxToDouble((double)unboxToInt(arg)); if (arg instanceof Long) return boxToDouble((double)unboxToLong(arg)); if (arg instanceof Float) return boxToDouble((double)unboxToFloat(arg)); if (arg instanceof Double) return (Double)arg; throw new NoSuchMethodException(); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?