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

io.permazen.core.MapValueStorageInfo Maven / Gradle / Ivy


/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.core;

import io.permazen.kv.KVPairIterator;
import io.permazen.util.ByteReader;

import java.util.Set;
import java.util.function.Predicate;

class MapValueStorageInfo extends ComplexSubFieldStorageInfo> {

    final FieldType keyFieldType;

    MapValueStorageInfo(MapField field) {
        super(field.valueField, field);
        this.keyFieldType = field.keyField.fieldType.genericizeForIndex();
    }

    CoreIndex2 getValueIndex(Transaction tx) {
        return new CoreIndex2<>(tx.kvt,
          new Index2View<>(this.storageId, this.fieldType, FieldTypeRegistry.OBJ_ID, this.keyFieldType));
    }

    @Override
    CoreIndex getIndex(Transaction tx) {
        return this.getValueIndex(tx).asIndex();
    }

    @Override
    void unreference(Transaction tx, ObjId target, ObjId referrer, byte[] prefix) {
        final FieldTypeMap fieldMap
          = (FieldTypeMap)tx.readMapField(referrer, this.parentRepresentative.storageId, false);
        for (KVPairIterator i = new KVPairIterator(tx.kvt, prefix); i.hasNext(); ) {
            final ByteReader reader = new ByteReader(i.next().getKey());
            reader.skip(prefix.length);
            fieldMap.remove(fieldMap.keyFieldType.read(reader));
        }
    }

    @Override
    void readAllNonNull(Transaction tx, ObjId target, Set values, Predicate filter) {
        for (V value : this.parentRepresentative.getValueInternal(tx, target).values()) {
            if (value != null && (filter == null || filter.test(value)))
                values.add(value);
        }
    }

// Object

    @Override
    public String toString() {
        return "map value field with " + this.fieldType;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (!super.equals(obj))
            return false;
        final MapValueStorageInfo that = (MapValueStorageInfo)obj;
        return this.keyFieldType.equals(that.keyFieldType);
    }

    @Override
    public int hashCode() {
        return super.hashCode() ^ this.keyFieldType.hashCode();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy