public Text apply(Object in) { if (in instanceof String) { return null==in ? null : new Text((String) in); } return (Text)in; } };
/** * Returns {@code com.google.appengine.api.datastore.Text} value as string * representation. */ @Override protected String convertToString(Object value) throws Throwable { Text text = (Text) value; return text.getValue(); }
@Test public void testTextType() { String propertyName = "textProp"; List<Entity> elist = doQuery(kindName, propertyName, null, false); Text text = (Text) elist.get(0).getProperty(propertyName); Text sameDat = (Text) elist.get(0).getProperty(propertyName); Text diffDat = (Text) elist.get(1).getProperty(propertyName); assertTrue(text.equals(sameDat)); assertFalse(text.equals(diffDat)); String getText = text.getValue(); assertTrue(getText.equals("english") || getText.equals("chinese") || getText.equals("japanese")); assertEquals(text.hashCode(), text.hashCode()); }
/** * Converts the specified value to * {@code com.google.appengine.api.datastore.Text}. * * @see org.apache.commons.beanutils.converters.AbstractConverter#convertToType(java.lang.Class, java.lang.Object) */ @SuppressWarnings("rawtypes") @Override protected Object convertToType(Class type, Object value) throws Throwable { return new Text(value.toString()); }
@Override public Object forPojo(Object value, Class<?> fieldType, ConverterLoadContext ctx, Object onPojo) { if (fieldType != String.class) return null; if (value instanceof Text) return ((Text)value).getValue(); else return value.toString(); } }
@Override public Object getCellEditorValue() { return new Text(button.getText()); }
private <T> void setTextProperty(T object, Field field, Object value) throws IllegalAccessException { field.set(object, ((Text) value).getValue()); }
public static Text instantiate(SerializationStreamReader streamReader) throws SerializationException { return new Text(streamReader.readString()); }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value != null) { Text text = (Text) value; button.setText(text.getValue()); } else { button.setText(null); } return button; }
@Override public Object toHrdProperty(NarrativeValue value) { return new Text(value.getText()); }
@Override public NarrativeValue toFieldValue(Object hrdValue) { if(hrdValue instanceof Text) { return NarrativeValue.valueOf(((Text) hrdValue).getValue()); } else { return null; } } };
@Override public Object forDatastore(Object value, ConverterSaveContext ctx) { if (!(value instanceof String)) return null; // Check to see if it's too long and needs to be Text instead if (((String)value).length() > 500) { if (ctx.inEmbeddedCollection()) throw new IllegalStateException("Objectify cannot autoconvert Strings greater than 500 characters to Text within @Embedded collections." + " You must use Text for the field type instead." + " This is what you tried to save into " + ctx.getField() + ": " + value); return new Text((String)value); } else return value; }
private <T> void setJsonProperty(Repository r, T object, Field field, Object value) throws IllegalAccessException { String json = ((Text) value).getValue(); field.set(object, JsonUtils.from(r, json, field.getGenericType())); }
private static Object typedObjectFromJson(ObjectNode node) throws LeanException { // must have 'type' field String type = node.get("type").getTextValue(); if (type == null) throw new LeanException(LeanException.Error.ValueToJSON, " Missing 'type' field."); if ("date".equals(type)) { return new Date(getLongFromValueNode("value", node)); } else if ("text".equals(type)) { return new Text(getStringFromValueNode("value", node)); } else if ("geopt".equals(type)) { throw new IllegalArgumentException("Value nodes of type 'geopt' are not yet implemented."); } else if ("geohash".equals(type)) { throw new IllegalArgumentException("Value nodes of type 'geohash' are not yet implemented."); } else if ("blob".equals(type)) { throw new IllegalArgumentException("Value nodes of type 'blob' are not yet implemented."); } else if ("shortblob".equals(type)) { throw new IllegalArgumentException("Value nodes of type 'shortblob' are not yet implemented."); } else if ("reference".equals(type)) { throw new IllegalArgumentException("Value nodes of type 'reference' are not yet implemented."); } else { //unknown node type throw new LeanException(LeanException.Error.ValueToJSON, " Unknown type '" + type + "'."); } }
public static void serialize(SerializationStreamWriter streamWriter, Text instance) throws SerializationException { streamWriter.writeString(instance.getValue()); } }
return new Text(label);
private <T> void setLazyJsonProperty(T object, Field field, Object value) throws IllegalAccessException { String json = ((Text) value).getValue(); Type type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; field.set(object, LazyJson.$create(type, json)); }
public void map(Long index) { String name = String.valueOf(random.nextLong() & Long.MAX_VALUE); Entity e = new Entity(kind, name); e.setProperty("payload", new Text(payloads.get((int) (index % payloads.size())))); pool.put(e); } }