/** * Put a map of (key, value) pair into the store. The value could be any type * that supported by {@link ValueObject} * @param kvMap a map of {key, value} pair */ @Override public KVStore putValues(Map<String, Object> kvMap) { for (String key : kvMap.keySet()) { put(key, ValueObject.of(kvMap.get(key))); } return this; }
/** * Create a {@code KVStore} by coping another {@code KVStore} * @param copy the KVStore in which all (K,V) pairs will be copied into the new KVStore instance */ public KVStore(KVStore copy) { putAll(copy); }
/** * Create a {@code KVStore} with a (String, Object) map * @param values the map in which all entries will be stored into the new KVStore instance */ public KVStore(Map<String, Object> values) { putValues(values); }
public List<KVStore> distinct(MorphiaQuery q, String field, String... fields) { List<Group> id = C.listOf(fields).prepend(field).map(new $.Transformer<String, Group>() { @Override public Group transform(String s) { return Group.grouping(s); } }); AggregationPipeline pipeline = ds().createAggregation(modelType()); if (null != q) { pipeline.match(q.morphiaQuery()); } Iterator<DistinctResult> result = pipeline.group(id).out(DistinctResult.class); List<KVStore> retList = C.newList(); while (result.hasNext()) { DistinctResult dr = result.next(); retList.add(new KVStore(dr._id)); } return retList; }
/** * Returns a `Map` contains (key, value) pairs that stored in this * `KVStore`. The value in the pair should be the {@link ValueObject#value()} * stored in the {@link ValueObject} in this `KVStore` * * @return the map of key and raw value stored in this store */ @Override public Map<String, Object> toMap() { Map<String, Object> map = C.newMap(); for (Map.Entry<String, ValueObject> entry : entrySet()) { map.put(entry.getKey(), entry.getValue().value()); } return map; }
/** * Get {@link ValueObject#value() value object value} by key from the * store. * @param key the key * @param <T> the generic type of the return value * @return the value stored in the value object associated with the key * @see ValueObject#value() */ @Override public <T> T getValue(String key) { ValueObject vo = get(key); if (null == vo) { return null; } return vo.value(); }
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { final JSONLexer lexer = parser.lexer; if (lexer.token() == JSONToken.NULL) { lexer.nextToken(JSONToken.COMMA); return null; } KV map = new KVStore(); ParseContext context = parser.getContext(); try { parser.setContext(context, map, fieldName); return (T) parseMap(parser, map, fieldName); } finally { parser.setContext(context); } }
/** * Returns a `Map` contains (key, value) pairs that stored in this * `KVStore`. The value in the pair should be the {@link ValueObject#value()} * stored in the {@link ValueObject} in this `KVStore` * * @return the map of key and raw value stored in this store */ @Override public Map<String, Object> toMap() { Map<String, Object> map = C.newMap(); for (Map.Entry<String, ValueObject> entry : entrySet()) { map.put(entry.getKey(), entry.getValue().value()); } return map; }
/** * Get {@link ValueObject#value() value object value} by key from the * store. * @param key the key * @param <T> the generic type of the return value * @return the value stored in the value object associated with the key * @see ValueObject#value() */ @Override public <T> T getValue(String key) { ValueObject vo = get(key); if (null == vo) { return null; } return vo.value(); }
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { final JSONLexer lexer = parser.lexer; if (lexer.token() == JSONToken.NULL) { lexer.nextToken(JSONToken.COMMA); return null; } KV map = new KVStore(); ParseContext context = parser.getContext(); try { parser.setContext(context, map, fieldName); return (T) parseMap(parser, map, fieldName); } finally { parser.setContext(context); } }
/** * Put a map of (key, value) pair into the store. The value could be any type * that supported by {@link ValueObject} * @param kvMap a map of {key, value} pair */ @Override public KVStore putValues(Map<String, Object> kvMap) { for (String key : kvMap.keySet()) { put(key, ValueObject.of(kvMap.get(key))); } return this; }
/** * Create a {@code KVStore} with a (String, Object) map * @param values the map in which all entries will be stored into the new KVStore instance */ public KVStore(Map<String, Object> values) { putValues(values); }
/** * Create a {@code KVStore} by coping another {@code KVStore} * @param copy the KVStore in which all (K,V) pairs will be copied into the new KVStore instance */ public KVStore(KVStore copy) { putAll(copy); }
@Override public Object decode(Class<?> aClass, Object fromDB, MappedField mappedField) { final KV store = new KVStore(); boolean isStore = aClass.isInstance(store); if (null == fromDB) {
/** * Put a simple data into the store with a key. The type of simple data * should be allowed by {@link ValueObject} * @param key the key * @param val the value * @return this store instance after the put operation finished * @see ValueObject */ @Override public KVStore putValue(String key, Object val) { put(key, ValueObject.of(val)); return this; }
if (value instanceof Map) { Map tmp = (Map)value; value = new KVStore(tmp);
/** * Put a simple data into the store with a key. The type of simple data * should be allowed by {@link ValueObject} * @param key the key * @param val the value * @return this store instance after the put operation finished * @see ValueObject */ @Override public KVStore putValue(String key, Object val) { put(key, ValueObject.of(val)); return this; }
if (value instanceof Map) { Map tmp = (Map)value; value = new KVStore(tmp);