/** * @return the {@code FieldType} corresponding to the {@link Optional}'s value. * @see #forValue(Object) */ public static FieldType forValue(Optional<Object> field) { return forValue(field.orNull()); }
/** * @return the {@code FieldType} corresponding to the {@link Optional}'s value. * @see #forValue(Object) */ public static FieldType forValue(Optional<Object> field) { return forValue(field.orNull()); }
private static Map<Object, Object> recursiveSafeCopy(Map<?, ?> m) { Map<Object, Object> copy = new HashMap<>(m.size()); m.forEach((k, v) -> copy.put(k, FieldType.forValue(v).safeCopy(v))); return copy; }
private static Object safeCopy(Object v) { Object safeCopy = FieldType.forValue(v).safeCopy(v); return safeCopy; } }
public static String asString(@Nullable Object value) { final FieldType type = FieldType.forValue(value); if (serializers.containsKey(type)) { return serializers.get(type).toString(value); } else { throw new IllegalArgumentException("The specified type is not supported: " + type); } }
default public void encode(Object value, DataOutput out) throws IOException { final FieldType type = FieldType.forValue(value); encode(type, value, out); }
private static Object safeCopy(Object v) { Object safeCopy = FieldType.forValue(v).safeCopy(v); return safeCopy; } }
default public void encode(Object value, DataOutput out) throws IOException { final FieldType type = FieldType.forValue(value); encode(type, value, out); }
private @Nullable Object safeCopy(@Nullable Object value) { return FieldType.forValue(value).safeCopy(value); } }
private @Nullable Object safeCopy(@Nullable Object value) { return FieldType.forValue(value).safeCopy(value); } }
public static String asString(@Nullable Object value) { final FieldType type = FieldType.forValue(value); if (serializers.containsKey(type)) { return serializers.get(type).toString(value); } else { throw new IllegalArgumentException("The specified type is not supported: " + type); } }
private Object safeCopy(@Nullable Object value) { FieldType fieldType = FieldType.forValue(value); if (FieldType.UNKNOWN.equals(fieldType)) { throw new IllegalArgumentException(String.format( "Objects of class %s are not supported as RevFeature attributes: ", value.getClass().getName())); } value = fieldType.safeCopy(value); return value; }
public static @Nullable Object safeCopy(@Nullable Object value) { if (value == null) { return null; } FieldType fieldType = FieldType.forValue(value); if (FieldType.UNKNOWN.equals(fieldType)) { throw new IllegalArgumentException(String.format( "Objects of class %s are not supported as RevFeature attributes: ", value.getClass().getName())); } value = fieldType.safeCopy(value); return value; }
@Override public void writeMap(Map<String, Object> map, DataOutput data) throws IOException { data.writeInt(map.size()); for (Entry<String, Object> e : map.entrySet()) { String key = e.getKey(); writeString(key, data); Object value = e.getValue(); FieldType fieldType = FieldType.forValue(value); data.writeByte(fieldType.getTag()); encode(fieldType, value, data); } }
@Override public void writeMap(Map<String, Object> map, DataOutput data) throws IOException { data.writeInt(map.size()); for (Entry<String, Object> e : map.entrySet()) { String key = e.getKey(); writeString(key, data); Object value = e.getValue(); FieldType fieldType = FieldType.forValue(value); data.writeByte(fieldType.getTag()); encode(fieldType, value, data); } }
public static void write(NodeId id, DataOutput out) throws IOException { checkNotNull(id); checkNotNull(out); final String name = id.name(); @Nullable final Object value = id.value(); final FieldType valueType = FieldType.forValue((Object) id.value()); out.writeUTF(name); out.writeByte(valueType.ordinal()); DataStreamValueSerializerV2.INSTANCE.encode(valueType, value, out); }
public void writeFeature(RevFeature feature, DataOutput data) throws IOException { writeUnsignedVarInt(feature.size(), data); for (int i = 0; i < feature.size(); i++) { Object field = feature.get(i).orNull(); FieldType type = FieldType.forValue(field); data.writeByte(type.getTag()); valueEncoder.encode(type, field, data); } }
public void writeFeature(RevFeature feature, DataOutput data) throws IOException { writeUnsignedVarInt(feature.size(), data); for (int i = 0; i < feature.size(); i++) { Object field = feature.get(i).orNull(); FieldType type = FieldType.forValue(field); data.writeByte(type.getTag()); valueEncoder.encode(type, field, data); } }
@Override protected void print(RevFeature feature, Writer w) throws IOException { for (int i = 0; i < feature.size(); i++) { Optional<Object> opt = feature.get(i); final FieldType type = FieldType.forValue(opt); String valueString = TextValueSerializer.asString(opt); println(w, type.toString() + "\t" + valueString); } w.flush(); }
@Override protected void print(RevFeature feature, Writer w) throws IOException { for (int i = 0; i < feature.size(); i++) { Optional<Object> opt = feature.get(i); final FieldType type = FieldType.forValue(opt); String valueString = TextValueSerializer.asString(opt); println(w, type.toString() + "\t" + valueString); } w.flush(); }