for (Iterator<Entry<String, VPackSlice>> iterator = document.objectIterator(); iterator.hasNext();) { Entry<String, VPackSlice> next = iterator.next(); VPackSlice value = next.getValue(); if (value.isString()) { resultMap.put(next.getKey(), stringToByteIterator(value.getAsString())); } else if (!value.isCustom()) { logger.error("Error! Not the format expected! Actually is {}", value.getClass().getName()); VPackSlice value = document.get(field); if (value.isString()) { resultMap.put(field, stringToByteIterator(value.getAsString())); } else if (!value.isCustom()) { logger.error("Error! Not the format expected! Actually is {}", value.getClass().getName());
while (cursor.hasNext()) { VPackSlice aDocument = cursor.next(); HashMap<String, ByteIterator> aMap = new HashMap<String, ByteIterator>(aDocument.size()); if (!this.fillMap(aMap, aDocument)) { return Status.ERROR;
private Object readSimple(final Class<?> type, final VPackSlice source) { if (source.isNone() || source.isNull()) { return null; if (source.isBoolean()) { return source.getAsBoolean(); if (source.isNumber()) { return source.getAsByte(); return source.getAsShort(); return source.getAsInt(); return source.getAsLong(); return source.getAsFloat(); return source.getAsDouble(); && (source.isSmallInt() || source.isInt() || source.isUInt())) { return source.getAsBigInteger(); else if (BigDecimal.class.isAssignableFrom(type) && source.isDouble()) { return source.getAsBigDecimal(); return source.getAsNumber(); if (source.isString()) {
protected static FieldLink deserializeField(final Entry<String, VPackSlice> field) { final VPackSlice value = field.getValue(); final FieldLink link = FieldLink.on(field.getKey()); final VPackSlice analyzers = value.get("analyzers"); if (analyzers.isArray()) { final Iterator<VPackSlice> analyzerIterator = analyzers.arrayIterator(); for (; analyzerIterator.hasNext();) { link.analyzers(analyzerIterator.next().getAsString()); final VPackSlice includeAllFields = value.get("includeAllFields"); if (includeAllFields.isBoolean()) { link.includeAllFields(includeAllFields.getAsBoolean()); final VPackSlice trackListPositions = value.get("trackListPositions"); if (trackListPositions.isBoolean()) { link.trackListPositions(trackListPositions.getAsBoolean()); final VPackSlice storeValues = value.get("storeValues"); if (storeValues.isString()) { link.storeValues(StoreValuesType.valueOf(storeValues.getAsString().toUpperCase())); final VPackSlice fields = value.get("fields"); if (fields.isObject()) { final Iterator<Entry<String, VPackSlice>> fieldsIterator = fields.objectIterator(); for (; fieldsIterator.hasNext();) { link.fields(deserializeField(fieldsIterator.next()));
public Alias readAliasFrom(final VPackSlice source) { if (source.isArray()) { return Alias.NONE; } if (source.isObject()) { final VPackSlice typeKey = source.get(this.typeKey); return Alias.ofNullable(typeKey.isString() ? typeKey.getAsString() : null); } throw new IllegalArgumentException("Cannot read alias from VPack type " + source.getType()); }
if (attribute != null) { appendField(attribute, json); deserializer = getDeserializer(attribute, value.getType()); if (value.isObject()) { parseObject(value, json, includeNullValues); } else if (value.isArray()) { parseArray(value, json, includeNullValues); } else if (value.isBoolean()) { json.append(value.getAsBoolean()); } else if (value.isString()) { json.append(toJSONString(value.getAsString())); } else if (value.isDouble()) { json.append(value.getAsDouble()); } else if (value.isInt()) { json.append(value.getAsLong()); } else if (value.isNumber()) { json.append(value.getAsNumber()); } else if (value.isDate()) { json.append(toJSONString(DateUtil.format(value.getAsDate()))); } else if (value.isNull()) { json.append(NULL); } else {
final Collection<Object> documentsAndErrors = new ArrayList<Object>(); final VPackSlice body = response.getBody(); if (body.isArray()) { for (final Iterator<VPackSlice> iterator = body.arrayIterator(); iterator.hasNext();) { final VPackSlice next = iterator.next(); if (next.get(ArangoResponseField.ERROR).isTrue()) { final ErrorEntity error = (ErrorEntity) util().deserialize(next, ErrorEntity.class); errors.add(error); } else { final DocumentDeleteEntity<T> doc = util().deserialize(next, DocumentDeleteEntity.class); final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type));
@Override public ConsolidationPolicy deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { final VPackSlice type = vpack.get("type"); if (type.isString()) { final ConsolidationPolicy consolidate = ConsolidationPolicy .of(ConsolidationType.valueOf(type.getAsString().toUpperCase())); final VPackSlice threshold = vpack.get("threshold"); if (threshold.isNumber()) { consolidate.threshold(threshold.getAsDouble()); } final VPackSlice segmentThreshold = vpack.get("segmentThreshold"); if (segmentThreshold.isInteger()) { consolidate.segmentThreshold(segmentThreshold.getAsLong()); } return consolidate; } return null; } };
private Type getType(final VPackSlice vpack) { final Type type; if (vpack.isObject()) { type = Map.class; } else if (vpack.isString()) { type = String.class; } else if (vpack.isBoolean()) { type = Boolean.class; } else if (vpack.isArray()) { type = Collection.class; } else if (vpack.isDate()) { type = Date.class; } else if (vpack.isDouble()) { type = Double.class; } else if (vpack.isNumber()) { type = Number.class; } else if (vpack.isCustom()) { type = String.class; } else { type = null; } return type; }
private Object readMap(final TypeInformation<?> type, final VPackSlice source) { if (!source.isObject()) { throw new MappingException( String.format("Can't read map type %s from VPack type %s!", type, source.getType())); } final Class<?> keyType = getNonNullComponentType(type).getType(); final TypeInformation<?> valueType = getNonNullMapValueType(type); final Map<Object, Object> map = CollectionFactory.createMap(type.getType(), keyType, source.size()); final Iterator<Entry<String, VPackSlice>> iterator = source.objectIterator(); while (iterator.hasNext()) { final Entry<String, VPackSlice> entry = iterator.next(); if (typeMapper.isTypeKey(entry.getKey())) { continue; } final Object key = convertIfNecessary(entry.getKey(), keyType); final VPackSlice value = entry.getValue(); map.put(key, readInternal(valueType, value)); } return map; }
@Override public byte[] getBinaryValue(final Base64Variant b64variant) throws IOException { if (currentValue.isBinary()) { return currentValue.getAsBinary(); } else if (currentValue.isString()) { return b64variant.decode(currentValue.getAsString()); } return Arrays.copyOfRange(currentValue.getBuffer(), currentValue.getStart(), currentValue.getStart() + currentValue.getByteSize()); }
if (isString()) { length = getStringLength(); } else if (!isArray() && !isObject()) { throw new VPackValueTypeException(ValueType.ARRAY, ValueType.OBJECT, ValueType.STRING); } else { final byte head = head(); if (head == 0x01 || head == 0x0a) { if (head <= 0x05) { final int dataOffset = findDataOffset(); final VPackSlice first = new VPackSlice(vpack, start + dataOffset); length = (end - dataOffset) / first.getByteSize(); } else if (offsetsize < 8) { length = NumberUtil.toLong(vpack, start + 1 + offsetsize, offsetsize);
public BigInteger getAsBigInteger() { if (isString()) { return new BigInteger(getAsString()); } else if (isSmallInt() || isInt()) { return BigInteger.valueOf(getAsLong()); } else if (isUInt()) { return NumberUtil.toBigInteger(vpack, start + 1, length()); } else { throw new VPackValueTypeException(ValueType.STRING, ValueType.INT, ValueType.UINT, ValueType.SMALLINT); } }
/** * Construct a GeoResult from the given object * * @param object * object representing one document in the result * @return GeoResult object */ private GeoResult<?> buildGeoResult(final Object object) { if (object == null || !(object instanceof VPackSlice)) { return null; } final VPackSlice slice = (VPackSlice) object; final VPackSlice distSlice = slice.get("_distance"); final Double distanceInMeters = distSlice.isDouble() ? distSlice.getAsDouble() : null; if (distanceInMeters == null) { return null; } final Object entity = operations.getConverter().read(domainClass, slice); final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS); return new GeoResult<>(entity, distance); }
public ArangoPropertyValueProvider(final ArangoPersistentEntity<?> entity, final VPackSlice source) { this.entity = entity; this.source = source; this.id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; }
private Object readArray(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read array type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final int length = source.getLength(); final Object array = Array.newInstance(componentType.getType(), length); for (int i = 0; i < length; ++i) { Array.set(array, i, readInternal(componentType, source.get(i))); } return array; }
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read collection type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType(); final Collection<Object> collection = CollectionFactory.createCollection(collectionType, componentType.getType(), source.getLength()); final Iterator<VPackSlice> iterator = source.arrayIterator(); while (iterator.hasNext()) { final VPackSlice elem = iterator.next(); collection.add(readInternal(componentType, elem)); } return collection; }
public BigDecimal getAsBigDecimal() { if (isString()) { return new BigDecimal(getAsString()); } else if (isDouble()) { return BigDecimal.valueOf(getAsDouble()); } else { throw new VPackValueTypeException(ValueType.STRING, ValueType.DOUBLE); } }
@SuppressWarnings("unchecked") @Override public DocumentDeleteEntity<T> deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody(); final DocumentDeleteEntity<T> doc = util().deserialize(body, DocumentDeleteEntity.class); final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type)); } return doc; } };
@Override public String deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { return vpack.getAsString(); } };