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

org.neo4j.kernel.impl.api.state.ValuesMap Maven / Gradle / Ivy

Go to download

Neo4j kernel is a lightweight, embedded Java database designed to store data structured as graphs rather than tables. For more information, see http://neo4j.org.

There is a newer version: 5.25.1
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.kernel.impl.api.state;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.LazyLongIterable;
import org.eclipse.collections.api.LongIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.primitive.MutableBooleanBag;
import org.eclipse.collections.api.bag.primitive.MutableByteBag;
import org.eclipse.collections.api.bag.primitive.MutableCharBag;
import org.eclipse.collections.api.bag.primitive.MutableDoubleBag;
import org.eclipse.collections.api.bag.primitive.MutableFloatBag;
import org.eclipse.collections.api.bag.primitive.MutableIntBag;
import org.eclipse.collections.api.bag.primitive.MutableLongBag;
import org.eclipse.collections.api.bag.primitive.MutableShortBag;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.bimap.MutableBiMap;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.IntObjectToIntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.LongObjectToLongFunction;
import org.eclipse.collections.api.block.function.primitive.LongToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.predicate.primitive.LongObjectPredicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.LongObjectProcedure;
import org.eclipse.collections.api.block.procedure.primitive.LongProcedure;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.collection.primitive.MutableBooleanCollection;
import org.eclipse.collections.api.collection.primitive.MutableByteCollection;
import org.eclipse.collections.api.collection.primitive.MutableCharCollection;
import org.eclipse.collections.api.collection.primitive.MutableDoubleCollection;
import org.eclipse.collections.api.collection.primitive.MutableFloatCollection;
import org.eclipse.collections.api.collection.primitive.MutableIntCollection;
import org.eclipse.collections.api.collection.primitive.MutableLongCollection;
import org.eclipse.collections.api.collection.primitive.MutableShortCollection;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.map.MutableMapIterable;
import org.eclipse.collections.api.map.primitive.ImmutableLongObjectMap;
import org.eclipse.collections.api.map.primitive.LongObjectMap;
import org.eclipse.collections.api.map.primitive.MutableLongLongMap;
import org.eclipse.collections.api.map.primitive.MutableLongObjectMap;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.map.sorted.MutableSortedMap;
import org.eclipse.collections.api.multimap.MutableMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.partition.bag.PartitionMutableBag;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.api.tuple.primitive.LongLongPair;
import org.eclipse.collections.api.tuple.primitive.LongObjectPair;
import org.eclipse.collections.impl.lazy.AbstractLazyIterable;
import org.eclipse.collections.impl.lazy.LazyIterableAdapter;
import org.eclipse.collections.impl.map.mutable.primitive.SynchronizedLongObjectMap;
import org.eclipse.collections.impl.map.mutable.primitive.UnmodifiableLongObjectMap;
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples;
import org.neo4j.values.storable.Value;

public class ValuesMap implements MutableLongObjectMap {
    private static final long NONE = -1L;
    private final MutableLongLongMap refs;
    private final ValuesContainer valuesContainer;

    public ValuesMap(MutableLongLongMap refs, ValuesContainer valuesContainer) {
        this.valuesContainer = valuesContainer;
        this.refs = refs;
    }

    @Override
    public int size() {
        return refs.size();
    }

    @Override
    public boolean isEmpty() {
        return refs.isEmpty();
    }

    @Override
    public Value getFirst() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Value getLast() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean contains(Object object) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean containsAllIterable(Iterable source) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean containsAll(Collection source) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean containsAllArguments(Object... elements) {
        throw new UnsupportedOperationException();
    }

    @Override
    public RichIterable> keyValuesView() {
        return new KeyValuesView();
    }

    @Override
    public Value put(long key, Value value) {
        requireNonNull(value, "Cannot put null values");
        final Value prev = get(key);
        final long ref = valuesContainer.add(value);
        refs.put(key, ref);
        return prev;
    }

    @Override
    public void putAll(LongObjectMap map) {
        map.forEachKeyValue(this::put);
    }

    @Override
    public Value get(long key) {
        final long ref = refs.getIfAbsent(key, NONE);
        return ref == NONE ? null : valuesContainer.get(ref);
    }

    @Override
    public Value getIfAbsentPut(long key, Value value) {
        final Value existing = get(key);
        if (existing != null) {
            return existing;
        }
        put(key, value);
        return value;
    }

    @Override
    public Value getIfAbsentPut(long key, Function0 supplier) {
        final Value existing = get(key);
        if (existing != null) {
            return existing;
        }
        final Value value = supplier.value();
        put(key, value);
        return value;
    }

    @Override
    public Value getIfAbsentPutWithKey(long key, LongToObjectFunction function) {
        final Value existing = get(key);
        if (existing != null) {
            return existing;
        }
        final Value value = function.valueOf(key);
        put(key, value);
        return value;
    }

    @Override
    public 

Value getIfAbsentPutWith(long key, Function function, P parameter) { final Value existing = get(key); if (existing != null) { return existing; } final Value value = function.valueOf(parameter); put(key, value); return value; } @Override public Value updateValue( long key, Function0 factory, Function function) { throw new UnsupportedOperationException(); } @Override public

Value updateValueWith( long key, Function0 factory, Function2 function, P parameter) { throw new UnsupportedOperationException(); } @Override public MutableObjectLongMap flipUniqueValues() { throw new UnsupportedOperationException(); } @Override public MutableLongObjectMap tap(Procedure procedure) { forEachValue(procedure); return this; } @Override public void each(Procedure procedure) { refs.forEachKey(ref -> { final Value value = valuesContainer.get(ref); procedure.value(value); }); } @Override public MutableLongObjectMap select(LongObjectPredicate predicate) { throw new UnsupportedOperationException(); } @Override public MutableLongObjectMap reject(LongObjectPredicate predicate) { throw new UnsupportedOperationException(); } @Override public ImmutableLongObjectMap toImmutable() { throw new UnsupportedOperationException(); } @Override public MutableLongSet keySet() { return refs.keySet().asUnmodifiable(); } @Override public LazyLongIterable keysView() { return refs.keysView(); } @Override public ValuesMap withKeyValue(long key, Value value) { put(key, value); return this; } @Override public ValuesMap withoutKey(long key) { removeKey(key); return this; } @Override public ValuesMap withoutAllKeys(LongIterable keys) { keys.forEach(this::removeKey); return this; } @Override public MutableLongObjectMap asUnmodifiable() { return new UnmodifiableLongObjectMap<>(this); } @Override public MutableLongObjectMap asSynchronized() { return new SynchronizedLongObjectMap<>(this); } @Override public Value getIfAbsent(long key, Function0 ifAbsent) { final Value existing = get(key); if (existing != null) { return existing; } return ifAbsent.value(); } @Override public boolean containsKey(long key) { return refs.containsKey(key); } @Override public Value removeKey(long key) { final long ref = refs.removeKeyIfAbsent(key, NONE); return ref == NONE ? null : valuesContainer.remove(ref); } @Override public Value remove(long key) { return removeKey(key); } @Override public void clear() { refs.clear(); } @Override public MutableMap aggregateInPlaceBy( Function groupBy, Function0 zeroValueFactory, Procedure2 mutatingAggregator) { throw new UnsupportedOperationException(); } @Override public MutableMap aggregateBy( Function groupBy, Function0 zeroValueFactory, Function2 nonMutatingAggregator) { throw new UnsupportedOperationException(); } @Override public MutableBagMultimap groupByEach(Function> function) { throw new UnsupportedOperationException(); } @Override public > R groupByEach( Function> function, R target) { throw new UnsupportedOperationException(); } @Override public MutableBagMultimap groupBy(Function function) { throw new UnsupportedOperationException(); } @Override public > R groupBy(Function function, R target) { throw new UnsupportedOperationException(); } @Override public MutableMap groupByUniqueKey(Function function) { throw new UnsupportedOperationException(); } @Override public > R groupByUniqueKey( Function function, R target) { throw new UnsupportedOperationException(); } @Override public MutableBag collectIf( Predicate predicate, Function function) { throw new UnsupportedOperationException(); } @Override public > R collectIf( Predicate predicate, Function function, R target) { throw new UnsupportedOperationException(); } @Override public MutableBag collect(Function function) { throw new UnsupportedOperationException(); } @Override public > R collect(Function function, R target) { throw new UnsupportedOperationException(); } @Override public MutableBooleanBag collectBoolean(BooleanFunction booleanFunction) { throw new UnsupportedOperationException(); } @Override public R collectBoolean( BooleanFunction booleanFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableByteBag collectByte(ByteFunction byteFunction) { throw new UnsupportedOperationException(); } @Override public R collectByte(ByteFunction byteFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableCharBag collectChar(CharFunction charFunction) { throw new UnsupportedOperationException(); } @Override public R collectChar(CharFunction charFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableDoubleBag collectDouble(DoubleFunction doubleFunction) { throw new UnsupportedOperationException(); } @Override public R collectDouble(DoubleFunction doubleFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableFloatBag collectFloat(FloatFunction floatFunction) { throw new UnsupportedOperationException(); } @Override public R collectFloat(FloatFunction floatFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableIntBag collectInt(IntFunction intFunction) { throw new UnsupportedOperationException(); } @Override public R collectInt(IntFunction intFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableLongBag collectLong(LongFunction longFunction) { throw new UnsupportedOperationException(); } @Override public R collectLong(LongFunction longFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableShortBag collectShort(ShortFunction shortFunction) { throw new UnsupportedOperationException(); } @Override public R collectShort(ShortFunction shortFunction, R target) { throw new UnsupportedOperationException(); } @Override public MutableBag collectWith(Function2 function, P parameter) { throw new UnsupportedOperationException(); } @Override public > R collectWith( Function2 function, P parameter, R targetCollection) { throw new UnsupportedOperationException(); } @Override public MutableBag flatCollect(Function> function) { throw new UnsupportedOperationException(); } @Override public > R flatCollect( Function> function, R target) { throw new UnsupportedOperationException(); } @Override public Value detect(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

Value detectWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public Optional detectOptional(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

Optional detectWithOptional(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public

Value detectWithIfNone( Predicate2 predicate, P parameter, Function0 function) { throw new UnsupportedOperationException(); } @Override public int count(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

int countWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public boolean anySatisfy(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public boolean allSatisfy(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public boolean noneSatisfy(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public IV injectInto(IV injectedValue, Function2 function) { throw new UnsupportedOperationException(); } @Override public int injectInto(int injectedValue, IntObjectToIntFunction function) { throw new UnsupportedOperationException(); } @Override public long injectInto(long injectedValue, LongObjectToLongFunction function) { throw new UnsupportedOperationException(); } @Override public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { throw new UnsupportedOperationException(); } @Override public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { throw new UnsupportedOperationException(); } @Override public > R into(R target) { throw new UnsupportedOperationException(); } @Override public MutableList toList() { throw new UnsupportedOperationException(); } @Override public > MutableList toSortedListBy( Function function) { throw new UnsupportedOperationException(); } @Override public MutableSet toSet() { throw new UnsupportedOperationException(); } @Override public MutableSortedSet toSortedSet() { throw new UnsupportedOperationException(); } @Override public MutableSortedSet toSortedSet(Comparator comparator) { throw new UnsupportedOperationException(); } @Override public > MutableSortedSet toSortedSetBy( Function function) { throw new UnsupportedOperationException(); } @Override public MutableBag toBag() { throw new UnsupportedOperationException(); } @Override public MutableSortedBag toSortedBag() { throw new UnsupportedOperationException(); } @Override public MutableSortedBag toSortedBag(Comparator comparator) { throw new UnsupportedOperationException(); } @Override public > MutableSortedBag toSortedBagBy( Function function) { throw new UnsupportedOperationException(); } @Override public MutableMap toMap( Function keyFunction, Function valueFunction) { throw new UnsupportedOperationException(); } @Override public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { throw new UnsupportedOperationException(); } @Override public MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function valueFunction) { throw new UnsupportedOperationException(); } @Override public MutableBiMap toBiMap( Function keyFunction, Function valueFunction) { throw new UnsupportedOperationException(); } @Override public LazyIterable asLazy() { return new LazyIterableAdapter<>(this); } @Override public Object[] toArray() { throw new UnsupportedOperationException(); } @Override public T[] toArray(T[] target) { throw new UnsupportedOperationException(); } @Override public Value min(Comparator comparator) { throw new UnsupportedOperationException(); } @Override public Value max(Comparator comparator) { throw new UnsupportedOperationException(); } @Override public Value min() { throw new UnsupportedOperationException(); } @Override public Value max() { throw new UnsupportedOperationException(); } @Override public > Value minBy(Function function) { throw new UnsupportedOperationException(); } @Override public > Value maxBy(Function function) { throw new UnsupportedOperationException(); } @Override public long sumOfInt(IntFunction function) { throw new UnsupportedOperationException(); } @Override public double sumOfFloat(FloatFunction function) { throw new UnsupportedOperationException(); } @Override public long sumOfLong(LongFunction function) { throw new UnsupportedOperationException(); } @Override public double sumOfDouble(DoubleFunction function) { throw new UnsupportedOperationException(); } @Override public MutableBag selectInstancesOf(Class clazz) { throw new UnsupportedOperationException(); } @Override public MutableBag select(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public > R select(Predicate predicate, R target) { throw new UnsupportedOperationException(); } @Override public

MutableBag selectWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public > R selectWith( Predicate2 predicate, P parameter, R targetCollection) { throw new UnsupportedOperationException(); } @Override public MutableBag reject(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

MutableBag rejectWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public > R reject(Predicate predicate, R target) { throw new UnsupportedOperationException(); } @Override public > R rejectWith( Predicate2 predicate, P parameter, R targetCollection) { throw new UnsupportedOperationException(); } @Override public PartitionMutableBag partition(Predicate predicate) { throw new UnsupportedOperationException(); } @Override public

PartitionMutableBag partitionWith(Predicate2 predicate, P parameter) { throw new UnsupportedOperationException(); } @Override public MutableBag> zip(Iterable that) { throw new UnsupportedOperationException(); } @Override public >> R zip(Iterable that, R target) { throw new UnsupportedOperationException(); } @Override public MutableSet> zipWithIndex() { throw new UnsupportedOperationException(); } @Override public >> R zipWithIndex(R target) { throw new UnsupportedOperationException(); } @Override public RichIterable> chunk(int size) { throw new UnsupportedOperationException(); } @Override public MutableObjectLongMap sumByInt( Function groupBy, IntFunction function) { throw new UnsupportedOperationException(); } @Override public MutableObjectDoubleMap sumByFloat( Function groupBy, FloatFunction function) { throw new UnsupportedOperationException(); } @Override public MutableObjectLongMap sumByLong( Function groupBy, LongFunction function) { throw new UnsupportedOperationException(); } @Override public MutableObjectDoubleMap sumByDouble( Function groupBy, DoubleFunction function) { throw new UnsupportedOperationException(); } @Override public void appendString(Appendable appendable, String start, String separator, String end) { try { appendable.append(format("ValuesMap[size: %d]", refs.size())); } catch (IOException e) { throw new UncheckedIOException(e); } } @Override public void forEachKey(LongProcedure procedure) { refs.forEachKey(procedure); } @Override public void forEachKeyValue(LongObjectProcedure procedure) { refs.forEachKeyValue((key, ref) -> { final Value value = valuesContainer.get(ref); procedure.value(key, value); }); } @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } @Override public void forEachValue(Procedure procedure) { forEachKeyValue((k, v) -> procedure.value(v)); } @Override public Collection values() { throw new UnsupportedOperationException(); } @Override public void forEach(Procedure procedure) { forEachValue(procedure); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { throw new UnsupportedOperationException(); } @Override public

void forEachWith(Procedure2 procedure, P parameter) { throw new UnsupportedOperationException(); } @Override public Iterator iterator() { throw new UnsupportedOperationException(); } private class KeyValuesView extends AbstractLazyIterable> { @Override public void each(Procedure> procedure) { for (LongObjectPair valueLongObjectPair : this) { procedure.value(valueLongObjectPair); } } @Override public Iterator> iterator() { Iterator refsIterator = refs.keyValuesView().iterator(); return new Iterator<>() { @Override public boolean hasNext() { return refsIterator.hasNext(); } @Override public LongObjectPair next() { final LongLongPair key2ref = refsIterator.next(); final long key = key2ref.getOne(); final long ref = key2ref.getTwo(); final Value value = valuesContainer.get(ref); return PrimitiveTuples.pair(key, value); } }; } } }