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

org.eclipse.collections.impl.factory.Multimaps Maven / Gradle / Ivy

There is a newer version: 12.0.0.M3
Show newest version
/*
 * Copyright (c) 2015 Goldman Sachs.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

package org.eclipse.collections.impl.factory;

import java.util.Comparator;

import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap;
import org.eclipse.collections.api.multimap.list.MutableListMultimap;
import org.eclipse.collections.api.multimap.set.ImmutableSetMultimap;
import org.eclipse.collections.api.multimap.set.MutableSetMultimap;
import org.eclipse.collections.api.multimap.sortedset.ImmutableSortedSetMultimap;
import org.eclipse.collections.api.multimap.sortedset.MutableSortedSetMultimap;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.sorted.ImmutableSortedSet;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.multimap.bag.ImmutableBagMultimapImpl;
import org.eclipse.collections.impl.multimap.list.FastListMultimap;
import org.eclipse.collections.impl.multimap.list.ImmutableListMultimapImpl;
import org.eclipse.collections.impl.multimap.set.ImmutableSetMultimapImpl;
import org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap;
import org.eclipse.collections.impl.multimap.set.sorted.ImmutableSortedSetMultimapImpl;
import org.eclipse.collections.impl.multimap.set.sorted.TreeSortedSetMultimap;

@SuppressWarnings("ConstantNamingConvention")
public final class Multimaps
{
    public static final ImmutableMultimaps immutable = new ImmutableMultimaps();
    public static final MutableMultimaps mutable = new MutableMultimaps();

    private Multimaps()
    {
        throw new AssertionError("Suppress default constructor for noninstantiability");
    }

    @SuppressWarnings("PublicField")
    public static final class ImmutableMultimaps
    {
        public final ImmutableListMultimapFactory list = new ImmutableListMultimapFactory();
        public final ImmutableSetMultimapFactory set = new ImmutableSetMultimapFactory();
        public final ImmutableSortedSetMultimapFactory sortedSet = new ImmutableSortedSetMultimapFactory();
        public final ImmutableBagMultimapFactory bag = new ImmutableBagMultimapFactory();

        private ImmutableMultimaps()
        {
        }

        public static final class ImmutableListMultimapFactory
        {
            public static final ImmutableListMultimap EMPTY = new ImmutableListMultimapImpl(Maps.immutable.>with());

            private ImmutableListMultimapFactory()
            {
            }

            public  ImmutableListMultimap empty()
            {
                return (ImmutableListMultimap) EMPTY;
            }

            public  ImmutableListMultimap with()
            {
                return this.empty();
            }

            public  ImmutableListMultimap with(K key, V value)
            {
                return new ImmutableListMultimapImpl(Maps.immutable.with(key, Lists.immutable.with(value)));
            }

            public  ImmutableListMultimap with(K key1, V value1, K key2, V value2)
            {
                FastListMultimap fastListMultimap = FastListMultimap.newMultimap();
                fastListMultimap.put(key1, value1);
                fastListMultimap.put(key2, value2);
                return fastListMultimap.toImmutable();
            }

            public  ImmutableListMultimap with(K key1, V value1, K key2, V value2, K key3, V value3)
            {
                FastListMultimap fastListMultimap = FastListMultimap.newMultimap();
                fastListMultimap.put(key1, value1);
                fastListMultimap.put(key2, value2);
                fastListMultimap.put(key3, value3);
                return fastListMultimap.toImmutable();
            }
        }

        public static final class ImmutableSetMultimapFactory
        {
            public static final ImmutableSetMultimap EMPTY = new ImmutableSetMultimapImpl(Maps.immutable.>with());

            private ImmutableSetMultimapFactory()
            {
            }

            public  ImmutableSetMultimap empty()
            {
                return (ImmutableSetMultimap) EMPTY;
            }

            public  ImmutableSetMultimap with()
            {
                return this.empty();
            }

            public  ImmutableSetMultimap with(K key, V value)
            {
                return new ImmutableSetMultimapImpl(Maps.immutable.with(key, Sets.immutable.with(value)));
            }

            public  ImmutableSetMultimap with(K key1, V value1, K key2, V value2)
            {
                UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap();
                unifiedSetMultimap.put(key1, value1);
                unifiedSetMultimap.put(key2, value2);
                return unifiedSetMultimap.toImmutable();
            }

            public  ImmutableSetMultimap with(K key1, V value1, K key2, V value2, K key3, V value3)
            {
                UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap();
                unifiedSetMultimap.put(key1, value1);
                unifiedSetMultimap.put(key2, value2);
                unifiedSetMultimap.put(key3, value3);
                return unifiedSetMultimap.toImmutable();
            }
        }

        public static final class ImmutableSortedSetMultimapFactory
        {
            private ImmutableSortedSetMultimapFactory()
            {
            }

            public  ImmutableSortedSetMultimap with(Comparator comparator)
            {
                return new ImmutableSortedSetMultimapImpl(Maps.immutable.>with(), comparator);
            }

            public  ImmutableSortedSetMultimap with(Comparator comparator, K key, V value)
            {
                return new ImmutableSortedSetMultimapImpl(Maps.immutable.with(key, SortedSets.immutable.with(comparator, value)), comparator);
            }

            public  ImmutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2)
            {
                TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator);
                treeSortedSetMultimap.put(key1, value1);
                treeSortedSetMultimap.put(key2, value2);
                return treeSortedSetMultimap.toImmutable();
            }

            public  ImmutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3)
            {
                TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator);
                treeSortedSetMultimap.put(key1, value1);
                treeSortedSetMultimap.put(key2, value2);
                treeSortedSetMultimap.put(key3, value3);
                return treeSortedSetMultimap.toImmutable();
            }
        }

        public static final class ImmutableBagMultimapFactory
        {
            public static final ImmutableBagMultimap EMPTY = new ImmutableBagMultimapImpl(Maps.immutable.>with());

            private ImmutableBagMultimapFactory()
            {
            }

            public  ImmutableBagMultimap empty()
            {
                return (ImmutableBagMultimap) EMPTY;
            }

            public  ImmutableBagMultimap with()
            {
                return this.empty();
            }

            public  ImmutableBagMultimap with(K key, V value)
            {
                return new ImmutableBagMultimapImpl(Maps.immutable.with(key, Bags.immutable.with(value)));
            }

            public  ImmutableBagMultimap with(K key1, V value1, K key2, V value2)
            {
                HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap();
                hashBagMultimap.put(key1, value1);
                hashBagMultimap.put(key2, value2);
                return hashBagMultimap.toImmutable();
            }

            public  ImmutableBagMultimap with(K key1, V value1, K key2, V value2, K key3, V value3)
            {
                HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap();
                hashBagMultimap.put(key1, value1);
                hashBagMultimap.put(key2, value2);
                hashBagMultimap.put(key3, value3);
                return hashBagMultimap.toImmutable();
            }
        }
    }

    @SuppressWarnings("PublicField")
    public static final class MutableMultimaps
    {
        public final MutableListMultimapFactory list = new MutableListMultimapFactory();
        public final MutableSetMultimapFactory set = new MutableSetMultimapFactory();
        public final MutableSortedSetMultimapFactory sortedSet = new MutableSortedSetMultimapFactory();
        public final MutableBagMultimapFactory bag = new MutableBagMultimapFactory();

        private MutableMultimaps()
        {
        }

        public static final class MutableListMultimapFactory
        {
            private MutableListMultimapFactory()
            {
            }

            public  MutableListMultimap empty()
            {
                return FastListMultimap.newMultimap();
            }

            public  MutableListMultimap with()
            {
                return this.empty();
            }

            public  MutableListMultimap with(K key, V value)
            {
                FastListMultimap fastListMultimap = FastListMultimap.newMultimap();
                fastListMultimap.put(key, value);
                return fastListMultimap;
            }

            public  MutableListMultimap with(K key1, V value1, K key2, V value2)
            {
                FastListMultimap fastListMultimap = FastListMultimap.newMultimap();
                fastListMultimap.put(key1, value1);
                fastListMultimap.put(key2, value2);
                return fastListMultimap;
            }

            public  MutableListMultimap with(K key1, V value1, K key2, V value2, K key3, V value3)
            {
                FastListMultimap fastListMultimap = FastListMultimap.newMultimap();
                fastListMultimap.put(key1, value1);
                fastListMultimap.put(key2, value2);
                fastListMultimap.put(key3, value3);
                return fastListMultimap;
            }
        }

        public static final class MutableSetMultimapFactory
        {
            private MutableSetMultimapFactory()
            {
            }

            public  MutableSetMultimap empty()
            {
                return UnifiedSetMultimap.newMultimap();
            }

            public  MutableSetMultimap with()
            {
                return this.empty();
            }

            public  MutableSetMultimap with(K key, V value)
            {
                UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap();
                unifiedSetMultimap.put(key, value);
                return unifiedSetMultimap;
            }

            public  MutableSetMultimap with(K key1, V value1, K key2, V value2)
            {
                UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap();
                unifiedSetMultimap.put(key1, value1);
                unifiedSetMultimap.put(key2, value2);
                return unifiedSetMultimap;
            }

            public  MutableSetMultimap with(K key1, V value1, K key2, V value2, K key3, V value3)
            {
                UnifiedSetMultimap unifiedSetMultimap = UnifiedSetMultimap.newMultimap();
                unifiedSetMultimap.put(key1, value1);
                unifiedSetMultimap.put(key2, value2);
                unifiedSetMultimap.put(key3, value3);
                return unifiedSetMultimap;
            }
        }

        public static final class MutableSortedSetMultimapFactory
        {
            private MutableSortedSetMultimapFactory()
            {
            }

            public  MutableSortedSetMultimap with(Comparator comparator)
            {
                return TreeSortedSetMultimap.newMultimap(comparator);
            }

            public  MutableSortedSetMultimap with(Comparator comparator, K key, V value)
            {
                TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator);
                treeSortedSetMultimap.put(key, value);
                return treeSortedSetMultimap;
            }

            public  MutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2)
            {
                TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator);
                treeSortedSetMultimap.put(key1, value1);
                treeSortedSetMultimap.put(key2, value2);
                return treeSortedSetMultimap;
            }

            public  MutableSortedSetMultimap with(Comparator comparator, K key1, V value1, K key2, V value2, K key3, V value3)
            {
                TreeSortedSetMultimap treeSortedSetMultimap = TreeSortedSetMultimap.newMultimap(comparator);
                treeSortedSetMultimap.put(key1, value1);
                treeSortedSetMultimap.put(key2, value2);
                treeSortedSetMultimap.put(key3, value3);
                return treeSortedSetMultimap;
            }
        }

        public static final class MutableBagMultimapFactory
        {
            private MutableBagMultimapFactory()
            {
            }

            public  MutableBagMultimap empty()
            {
                return HashBagMultimap.newMultimap();
            }

            public  MutableBagMultimap with()
            {
                return this.empty();
            }

            public  MutableBagMultimap with(K key, V value)
            {
                HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap();
                hashBagMultimap.put(key, value);
                return hashBagMultimap;
            }

            public  MutableBagMultimap with(K key1, V value1, K key2, V value2)
            {
                HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap();
                hashBagMultimap.put(key1, value1);
                hashBagMultimap.put(key2, value2);
                return hashBagMultimap;
            }

            public  MutableBagMultimap with(K key1, V value1, K key2, V value2, K key3, V value3)
            {
                HashBagMultimap hashBagMultimap = HashBagMultimap.newMultimap();
                hashBagMultimap.put(key1, value1);
                hashBagMultimap.put(key2, value2);
                hashBagMultimap.put(key3, value3);
                return hashBagMultimap;
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy