/** * 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); } }
@SuppressWarnings("deprecation") @Override public void start() { ValueOption<?>[] vs = values; for (int i = 0; i < vs.length; i++) { ValueOption<?> v = vs[i]; if (v != null) { v.setNull(); } } }
private boolean emitNull(ValueOption<?> option) { if (option.isNull()) { lineBuffer.append(ESCAPE_CHAR); lineBuffer.append(ESCAPE_NULL_COLUMN); return true; } return false; }
@SuppressWarnings("deprecation") static <V extends ValueOption<V>> V update(V property, V newValue) { property.copyFrom(newValue); return property; }
/** * 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; }
@SuppressWarnings("deprecation") @Override public void absent(T property) { property.setNull(); }
@Override public Timestamp getPrimitiveJavaObject(Object o) { ValueOption<?> object = (ValueOption<?>) o; if (object == null || object.isNull()) { return null; } return toTimestamp(object); }
@SuppressWarnings("deprecation") @Override public E set(int index, E element) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } E result = get(index); result.copyFrom(element); return result; }
@SuppressWarnings("deprecation") @Override public void clear(T property) { property.setNull(); }
/** * 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); } } }
@Override public String getPrimitiveJavaObject(Object o) { ValueOption<?> object = (ValueOption<?>) o; if (object == null || object.isNull()) { return null; } return toString(object); }
@SuppressWarnings("deprecation") private void set(T instance, Method property, Object value) { assert instance != null; assert property != null; ValueOption<?> holder = getHolder(instance, property); if (value == null) { holder.setNull(); } else { ValueDriver<?> driver = VALUE_DRIVERS.get(property.getReturnType()); assert driver != null : property; driver.modifyUnsafe(holder, value); } }
@Override public Object getStructFieldData(Object data, StructField field) { PropertyDescriptor propertyDescriptor = (PropertyDescriptor) field; ValueOption<?> property = propertyDescriptor.extract(data); return property.isNull() ? null : property; }
@SuppressWarnings("deprecation") @Override public void set(ValueOption<?> target, Object value) { if (value == null) { target.setNull(); } else { ((BooleanOption) target).modify(inspector.get(value)); } }
@Override public Object resolveRawValue(Object value) { if (value == null) { return null; } Class<?> type = value.getClass(); ValueDriver<?> driver = VALUE_DRIVERS.get(type); if (driver == null) { throw new IllegalArgumentException(MessageFormat.format( "unsupported property type: {0} ({1})", value, type.getSimpleName())); } if (((ValueOption<?>) value).isNull()) { return null; } return driver.extractUnsafe(value); }
@SuppressWarnings("deprecation") @Override public void set(ValueOption<?> target, Object value) { if (value == null) { target.setNull(); } else { ((IntOption) target).modify(inspector.get(value)); } } }
private Object get(T instance, Method property) { assert instance != null; assert property != null; ValueOption<?> holder = getHolder(instance, property); if (holder.isNull()) { return null; } ValueDriver<?> driver = VALUE_DRIVERS.get(property.getReturnType()); assert driver != null : property; return driver.extractUnsafe(holder); }
@SuppressWarnings("deprecation") @Override public void set(ValueOption<?> target, Object value) { if (value == null) { target.setNull(); } else { ((FloatOption) target).modify(inspector.get(value)); } } }
@Override final void set(Object propertyValue) { @SuppressWarnings("unchecked") T option = (T) propertyValue; if (option.isNull()) { setNull(); } else { doUpdate(option); } }