Search in sources :

Example 26 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class StringSetSerializer method fromJson.

public Set<String> fromJson(byte[] data) {
    Inspector inspector = SlimeUtils.jsonToSlime(data).get();
    Set<String> stringSet = new HashSet<>();
    inspector.traverse((ArrayTraverser) (index, name) -> stringSet.add(name.asString()));
    return stringSet;
}
Also used : HashSet(java.util.HashSet) Cursor(com.yahoo.slime.Cursor) Inspector(com.yahoo.slime.Inspector) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) ArrayTraverser(com.yahoo.slime.ArrayTraverser) Slime(com.yahoo.slime.Slime) Set(java.util.Set) IOException(java.io.IOException) Inspector(com.yahoo.slime.Inspector) HashSet(java.util.HashSet)

Example 27 with Inspector

use of com.yahoo.slime.Inspector in project vespa by vespa-engine.

the class NodePatcher method asStringSet.

private Set<String> asStringSet(Inspector field) {
    if (!field.type().equals(Type.ARRAY))
        throw new IllegalArgumentException("Expected an ARRAY value, got a " + field.type());
    TreeSet<String> strings = new TreeSet<>();
    for (int i = 0; i < field.entries(); i++) {
        Inspector entry = field.entry(i);
        if (!entry.type().equals(Type.STRING))
            throw new IllegalArgumentException("Expected a STRING value, got a " + entry.type());
        strings.add(entry.asString());
    }
    return strings;
}
Also used : TreeSet(java.util.TreeSet) Inspector(com.yahoo.slime.Inspector)

Aggregations

Inspector (com.yahoo.slime.Inspector)27 ArrayTraverser (com.yahoo.slime.ArrayTraverser)10 Slime (com.yahoo.slime.Slime)10 IOException (java.io.IOException)6 Cursor (com.yahoo.slime.Cursor)4 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)4 CompressionType (com.yahoo.compress.CompressionType)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 JsonDecoder (com.yahoo.slime.JsonDecoder)3 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)3 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Version (com.yahoo.component.Version)2 ObjectTraverser (com.yahoo.slime.ObjectTraverser)2 Utf8Array (com.yahoo.text.Utf8Array)2 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)2 Change (com.yahoo.vespa.hosted.controller.application.Change)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2