@Override public void set(T value) { fieldMetadata.setValue(target, value); } }
@Override public void set(Float value) { fieldMetadata.setValue(target, value); } };
@Override public void setValue(Float value) { field.setValue(target, value); }
@Override public void set(Float value) { fieldMetadata.setValue(target, value.intValue()); } };
@Override public void set(Float value) { fieldMetadata.setValue(target, value.doubleValue()); } };
/** * @param object The instance of this class to copy * @return A copy of the given object */ public T copy(T object) { T result = constructor.construct(); if (result != null) { for (FIELD field : fields.values()) { field.setValue(result, field.getCopyOfValue(object)); } } return result; }
private void cloneAndSet(String group, Object value) { Component comp = worldConfig.getProperties().get(group); Component clone = compLib.copy(comp); fieldMetadata.setValue(clone, value); // notify the world generator about the new component worldConfig.setProperty(label, clone); } }
private void cloneAndSet(String group, Object value) { Component comp = worldConfig.getProperties().get(group); Component clone = compLib.copy(comp); fieldMetadata.setValue(clone, value); // notify the world generator about the new component worldConfig.setProperty(label, clone); } }
@Override public T deserialize(PersistedData data, DeserializationContext context) { try { T result = clazz.newInstance(); for (Map.Entry<String, PersistedData> entry : data.getAsValueMap().entrySet()) { FieldMetadata fieldInfo = fieldByName.get(UriUtil.normalise(entry.getKey())); if (fieldInfo != null) { TypeHandler handler = mappedFields.get(fieldInfo); Object val = handler.deserialize(entry.getValue(), context); fieldInfo.setValue(result, val); } } return result; } catch (Exception e) { logger.error("Unable to deserialize {}", data, e); } return null; }
/** * Deserializes a value onto an object * * @param target The object to deserialize the field onto * @param fieldMetadata The metadata of the field * @param data The serialized value of the field * @param context The deserialization context */ public void deserializeOnto(Object target, FieldMetadata<?, ?> fieldMetadata, PersistedData data, DeserializationContext context) { TypeHandler<?> handler = getHandlerFor(fieldMetadata); if (handler == null) { logger.error("No type handler for type {} used by {}::{}", fieldMetadata.getType(), target.getClass(), fieldMetadata); } else { try { Object deserializedValue = handler.deserialize(data, context); fieldMetadata.setValue(target, deserializedValue); } catch (DeserializationException e) { logger.error("Unable to deserialize field '{}' from '{}'", fieldMetadata.getName(), data.toString(), e); } } }
logger.warn("UIWidget type {} lacks id field", elementMetadata.getUri()); } else { fieldMetadata.setValue(element, id); result.add(context.deserialize(item, contentType)); field.setValue(element, result); field.setValue(element, context.deserialize(jsonObject.get(field.getSerializationName()), field.getType()));
private <T extends Component> void updateComponent(EntityRef blockEntity, ComponentMetadata<T> metadata, T targetComponent) { T currentComp = blockEntity.getComponent(metadata.getType()); if (currentComp != null) { boolean changed = false; for (FieldMetadata<T, ?> field : metadata.getFields()) { Object newVal = field.getValue(targetComponent); if (!Objects.equal(field.getValue(currentComp), newVal)) { field.setValue(currentComp, newVal); changed = true; } } if (changed) { blockEntity.saveComponent(currentComp); } } }
Object expected = field.getValue(comp); if (!Objects.equal(expected, field.getValue(currentComp))) { field.setValue(currentComp, expected); changed = true;