/** * Sets the specified value to this object only if the specified value is less than this object. However, if either * this object or the specified value represents {@code null}, this object will also turn to {@code null}. * @param other the target value */ public final void min(V other) { if (this == other) { return; } if (this.isNull() || other.isNull()) { setNull(); } else if (compareTo(other) > 0) { copyFrom(other); } }
/** * Sets the specified value to this object only if the specified value is greater than this object. However, if * either this object or the specified value represents {@code null}, this object will also turn to {@code null}. * @param other the target value */ public final void max(V other) { if (this == other) { return; } if (this.isNull() || other.isNull()) { setNull(); } else if (compareTo(other) < 0) { copyFrom(other); } } }
/** * compares between two objects. * @param <T> the value type * @param a object 1 * @param b object 2 * @return result */ protected <T extends ValueOption<T>> int compare(T a, T b) { int object = a.compareTo(b); Class<?> klass = a.getClass(); try { byte[] b1 = toBytes(a); byte[] b2 = toBytes(b); Method method = klass.getMethod("compareBytes", byte[].class, int.class, int.class, byte[].class, int.class, int.class); int bytes = (Integer) method.invoke(null, b1, 0, b1.length, b2, 0, b2.length); assertThat(sign(bytes), is(sign(object))); } catch (Exception e) { throw new AssertionError(e); } return object; }