Java Code Examples for com.arangodb.velocypack.VPackSlice#objectIterator()

The following examples show how to use com.arangodb.velocypack.VPackSlice#objectIterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultArangoConverter.java    From spring-data with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: VPackExample.java    From arangodb-java-driver-async with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObject() throws VPackException {
	final VPackBuilder builder = new VPackBuilder();
	builder.add(ValueType.OBJECT);// object start
	builder.add("foo", 1); // add field "foo" with value 1
	builder.add("bar", 2); // add field "bar" with value 2
	builder.close();// object end

	final VPackSlice slice = builder.slice(); // create slice
	assertThat(slice.isObject(), is(true));
	assertThat(slice.size(), is(2)); // number of fields

	final VPackSlice foo = slice.get("foo"); // get field "foo"
	assertThat(foo.isInteger(), is(true));
	assertThat(foo.getAsInt(), is(1));

	final VPackSlice bar = slice.get("bar"); // get field "bar"
	assertThat(bar.isInteger(), is(true));
	assertThat(bar.getAsInt(), is(2));

	// iterate over the fields
	for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext();) {
		final Entry<String, VPackSlice> field = iterator.next();
		assertThat(field.getValue().isInteger(), is(true));
	}
}
 
Example 3
Source File: VPackExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObject() throws VPackException {
	final VPackBuilder builder = new VPackBuilder();
	builder.add(ValueType.OBJECT);// object start
	builder.add("foo", 1); // add field "foo" with value 1
	builder.add("bar", 2); // add field "bar" with value 2
	builder.close();// object end

	final VPackSlice slice = builder.slice(); // create slice
	assertThat(slice.isObject(), is(true));
	assertThat(slice.size(), is(2)); // number of fields

	final VPackSlice foo = slice.get("foo"); // get field "foo"
	assertThat(foo.isInteger(), is(true));
	assertThat(foo.getAsInt(), is(1));

	final VPackSlice bar = slice.get("bar"); // get field "bar"
	assertThat(bar.isInteger(), is(true));
	assertThat(bar.getAsInt(), is(2));

	// iterate over the fields
	for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext(); ) {
		final Entry<String, VPackSlice> field = iterator.next();
		assertThat(field.getValue().isInteger(), is(true));
	}
}
 
Example 4
Source File: VPackExample.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void buildObject() throws VPackException {
    final VPackBuilder builder = new VPackBuilder();
    builder.add(ValueType.OBJECT);// object start
    builder.add("foo", 1); // add field "foo" with value 1
    builder.add("bar", 2); // add field "bar" with value 2
    builder.close();// object end

    final VPackSlice slice = builder.slice(); // create slice
    assertThat(slice.isObject(), is(true));
    assertThat(slice.size(), is(2)); // number of fields

    final VPackSlice foo = slice.get("foo"); // get field "foo"
    assertThat(foo.isInteger(), is(true));
    assertThat(foo.getAsInt(), is(1));

    final VPackSlice bar = slice.get("bar"); // get field "bar"
    assertThat(bar.isInteger(), is(true));
    assertThat(bar.getAsInt(), is(2));

    // iterate over the fields
    for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext(); ) {
        final Entry<String, VPackSlice> field = iterator.next();
        assertThat(field.getValue().isInteger(), is(true));
    }
}
 
Example 5
Source File: InternalArangoDB.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
protected ResponseDeserializer<Collection<String>> getAccessibleDatabasesForResponseDeserializer() {
    return response -> {
        final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT);
        final Collection<String> dbs = new ArrayList<>();
        for (final Iterator<Entry<String, VPackSlice>> iterator = result.objectIterator(); iterator
                .hasNext(); ) {
            dbs.add(iterator.next().getKey());
        }
        return dbs;
    };
}
 
Example 6
Source File: VPackDeserializers.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
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()));
        }
    }
    return link;
}