Compare two objects for equality, after coercing to the same type if appropriate. If the objects are identical (including both null) return true. If either object is null, return false. If either object is Boolean, coerce both to Boolean and check equality. Similarly for Enum, String
(final ELContext ctx, final Object obj0, final Object obj1)
| 144 | * @throws ELException if one of the coercion fails |
| 145 | */ |
| 146 | public static boolean equals(final ELContext ctx, final Object obj0, final Object obj1) throws ELException { |
| 147 | if (obj0 == obj1) { |
| 148 | return true; |
| 149 | } else if (obj0 == null || obj1 == null) { |
| 150 | return false; |
| 151 | } else if (isBigDecimalOp(obj0, obj1)) { |
| 152 | BigDecimal bd0 = (BigDecimal) coerceToNumber(ctx, obj0, BigDecimal.class); |
| 153 | BigDecimal bd1 = (BigDecimal) coerceToNumber(ctx, obj1, BigDecimal.class); |
| 154 | return bd0.equals(bd1); |
| 155 | } else if (isDoubleOp(obj0, obj1)) { |
| 156 | Double d0 = (Double) coerceToNumber(ctx, obj0, Double.class); |
| 157 | Double d1 = (Double) coerceToNumber(ctx, obj1, Double.class); |
| 158 | return d0.equals(d1); |
| 159 | } else if (isBigIntegerOp(obj0, obj1)) { |
| 160 | BigInteger bi0 = (BigInteger) coerceToNumber(ctx, obj0, BigInteger.class); |
| 161 | BigInteger bi1 = (BigInteger) coerceToNumber(ctx, obj1, BigInteger.class); |
| 162 | return bi0.equals(bi1); |
| 163 | } else if (isLongOp(obj0, obj1)) { |
| 164 | Long l0 = (Long) coerceToNumber(ctx, obj0, Long.class); |
| 165 | Long l1 = (Long) coerceToNumber(ctx, obj1, Long.class); |
| 166 | return l0.equals(l1); |
| 167 | } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) { |
| 168 | return coerceToBoolean(ctx, obj0, false).equals(coerceToBoolean(ctx, obj1, false)); |
| 169 | } else if (obj0.getClass().isEnum()) { |
| 170 | return obj0.equals(coerceToEnum(ctx, obj1, obj0.getClass())); |
| 171 | } else if (obj1.getClass().isEnum()) { |
| 172 | return obj1.equals(coerceToEnum(ctx, obj0, obj1.getClass())); |
| 173 | } else if (obj0 instanceof String || obj1 instanceof String) { |
| 174 | int lexCompare = coerceToString(ctx, obj0).compareTo(coerceToString(ctx, obj1)); |
| 175 | return lexCompare == 0; |
| 176 | } else { |
| 177 | return obj0.equals(obj1); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Coerces an object to an Enum value of the specified type. |