All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.securegraph.accumulo.LazyPropertyMetadata Maven / Gradle / Ivy

The newest version!
package org.securegraph.accumulo;

import org.securegraph.Metadata;
import org.securegraph.SecureGraphException;
import org.securegraph.Visibility;
import org.securegraph.accumulo.serializer.ValueSerializer;

import java.util.HashMap;
import java.util.Map;

public class LazyPropertyMetadata {
    private Map entries = new HashMap();

    public Metadata toMetadata(ValueSerializer valueSerializer) {
        Metadata metadata = new Metadata();
        for (Map.Entry metadataItem : this.entries.entrySet()) {
            String metadataKey = metadataItem.getValue().getMetadataKey();
            Visibility metadataVisibility = metadataItem.getValue().getMetadataVisibility();
            Object metadataValue = valueSerializer.valueToObject(metadataItem.getValue().getValue());
            if (metadataValue == null) {
                throw new SecureGraphException("Invalid metadata found.");
            }
            metadata.add(metadataKey, metadataValue, metadataVisibility);
        }
        return metadata;
    }

    public void add(String metadataKey, Visibility metadataVisibility, byte[] value) {
        this.entries.put(metadataKey + metadataVisibility.getVisibilityString(), new Entry(metadataKey, metadataVisibility, value));
    }

    private static class Entry {
        private final String metadataKey;
        private final Visibility metadataVisibility;
        private final byte[] value;

        public Entry(String metadataKey, Visibility metadataVisibility, byte[] value) {
            this.metadataKey = metadataKey;
            this.metadataVisibility = metadataVisibility;
            this.value = value;
        }

        public String getMetadataKey() {
            return metadataKey;
        }

        public Visibility getMetadataVisibility() {
            return metadataVisibility;
        }

        public byte[] getValue() {
            return value;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy