private boolean emitNull(ValueOption<?> option) { if (option.isNull()) { lineBuffer.append(ESCAPE_CHAR); lineBuffer.append(ESCAPE_NULL_COLUMN); return true; } return false; }
@Override public Object getStructFieldData(Object data, StructField field) { PropertyDescriptor propertyDescriptor = (PropertyDescriptor) field; ValueOption<?> property = propertyDescriptor.extract(data); return property.isNull() ? null : property; }
@Override public String getPrimitiveJavaObject(Object o) { ValueOption<?> object = (ValueOption<?>) o; if (object == null || object.isNull()) { return null; } return toString(object); }
@Override public Timestamp getPrimitiveJavaObject(Object o) { ValueOption<?> object = (ValueOption<?>) o; if (object == null || object.isNull()) { return null; } return toTimestamp(object); }
@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); }
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); }
/** * 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); } } }
@Override final void set(Object propertyValue) { @SuppressWarnings("unchecked") T option = (T) propertyValue; if (option.isNull()) { setNull(); } else { doUpdate(option); } }
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" }) @Override public final Object copyObject(Object o) { ValueOption<?> object = (ValueOption<?>) o; if (object == null || object.isNull()) { return null; } ValueOption copy = newObject(); copy.copyFrom(object); return copy; }
@Override public void write(T property, ValueWriter writer) throws IOException { if (property.isNull()) { if (nullStyle == NullStyle.VALUE) { writer.writeNull(); } } else { doWrite(property, writer); } }
@Override public void emit(T property, FieldOutput output) { if (property.isNull()) { if (nullFormat == null) { output.putNull(); } else { output.put(nullFormat); } } else { StringBuilder buffer = output.acquireBuffer(); try { doEmit(property, buffer); } finally { output.releaseBuffer(buffer); } } }
@Override public void write(Object value) { RecordConsumer consumer = recordConsumer; String[] ns = names; PropertyExtractor[] ps = properties; ValueWriter[] vs = drivers; consumer.startMessage(); for (int index = 0, n = ns.length; index < n; index++) { ValueOption<?> property = ps[index].extract(value); if (property.isNull() == false) { String name = ns[index]; consumer.startField(name, index); vs[index].write(property, consumer); consumer.endField(name, index); } } consumer.endMessage(); } }