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

org.javersion.util.PersistentMap Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2013 Samppa Saarela
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.javersion.util;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Spliterator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import javax.annotation.concurrent.Immutable;

import com.google.common.collect.Iterables;

@Immutable
public interface PersistentMap extends Iterable> {

    PersistentMap assoc(K key, V value);

    PersistentMap assocAll(Map map);

    PersistentMap assocAll(Iterable> entries);

    PersistentMap merge(K key, V value, Merger> merger);

    PersistentMap mergeAll(Map map, Merger> merger);

    PersistentMap mergeAll(Iterable> entries, Merger> merger);

    PersistentMap dissoc(Object key);

    PersistentMap dissoc(Object key, Merger> merger);

    V get(Object key);

    boolean containsKey(Object key);

    Spliterator> spliterator();

    Spliterator keySpliterator();

    Spliterator valueSpliterator();

    int size();

    boolean isEmpty();

    MutableMap toMutableMap();

    Map asMap();

    default Iterable keys() {
        return Iterables.transform(this, MapUtils.mapKeyFunction());
    }

    default Iterable values() {
        return Iterables.transform(this, MapUtils.mapValueFunction());
    }

    default Stream> stream() {
        return StreamSupport.stream(spliterator(), false);
    }

    default Stream> parallelStream() {
        return StreamSupport.stream(spliterator(), true);
    }

    default Stream keyStream() {
        return StreamSupport.stream(keySpliterator(), false);
    }

    default Stream parallelKeyStream() {
        return StreamSupport.stream(keySpliterator(), true);
    }

    default Stream valueStream() {
        return StreamSupport.stream(valueSpliterator(), false);
    }

    default Stream parallelValueStream() {
        return StreamSupport.stream(valueSpliterator(), true);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy