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

com.gs.collections.impl.map.fixed.EmptyMap Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2014 Goldman Sachs.
 *
 * 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 com.gs.collections.impl.map.fixed;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
import com.gs.collections.api.map.FixedSizeMap;
import com.gs.collections.api.map.ImmutableMap;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.multimap.set.MutableSetMultimap;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.factory.Lists;
import com.gs.collections.impl.factory.Maps;
import com.gs.collections.impl.factory.Multimaps;
import com.gs.collections.impl.factory.Sets;
import net.jcip.annotations.Immutable;

@Immutable
final class EmptyMap
        extends AbstractMemoryEfficientMutableMap
        implements Serializable
{
    private static final long serialVersionUID = 1L;

    private Object readResolve()
    {
        return Maps.fixedSize.of();
    }

    public int size()
    {
        return 0;
    }

    @Override
    public MutableMap withKeyValue(K addKey, V addValue)
    {
        return new SingletonMap(addKey, addValue);
    }

    @Override
    public MutableMap withoutKey(K key)
    {
        return this;
    }

    // Weird implementation of clone() is ok on final classes
    @Override
    public EmptyMap clone()
    {
        return this;
    }

    @Override
    public ImmutableMap toImmutable()
    {
        return Maps.immutable.of();
    }

    @Override
    public MutableSetMultimap flip()
    {
        return Multimaps.mutable.set.with();
    }

    public boolean containsKey(Object key)
    {
        return false;
    }

    public boolean containsValue(Object value)
    {
        return false;
    }

    public V get(Object key)
    {
        return null;
    }

    public Set keySet()
    {
        return Sets.fixedSize.of();
    }

    public Collection values()
    {
        return Lists.fixedSize.of();
    }

    public MutableSet> entrySet()
    {
        return Sets.fixedSize.of();
    }

    @Override
    public String toString()
    {
        return "{}";
    }

    @Override
    public int hashCode()
    {
        return 0;
    }

    @Override
    public boolean equals(Object other)
    {
        if (!(other instanceof Map))
        {
            return false;
        }
        Map that = (Map) other;
        return that.size() == this.size();
    }

    @Override
    public MutableMap flipUniqueValues()
    {
        return Maps.fixedSize.with();
    }

    public void forEachKeyValue(Procedure2 procedure)
    {
    }

    @Override
    public void forEachKey(Procedure procedure)
    {
    }

    @Override
    public void forEachValue(Procedure procedure)
    {
    }

    @Override
    public void forEachWithIndex(ObjectIntProcedure objectIntProcedure)
    {
    }

    @Override
    public 

void forEachWith(Procedure2 procedure, P parameter) { } @Override public FixedSizeMap select(Predicate2 predicate) { return Maps.fixedSize.of(); } @Override public FixedSizeMap collectValues(Function2 function) { return Maps.fixedSize.of(); } @Override public FixedSizeMap collect(Function2> function) { return Maps.fixedSize.of(); } @Override public FixedSizeMap reject(Predicate2 predicate) { return Maps.fixedSize.of(); } @Override public Pair detect(Predicate2 predicate) { return null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy