Home | History | Annotate | Download | only in collect
      1 /*
      2  * Copyright (C) 2008 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.collect;
     18 
     19 import com.google.common.annotations.GwtCompatible;
     20 
     21 import javax.annotation.Nullable;
     22 
     23 /**
     24  * Bimap with no mappings.
     25  *
     26  * @author Jared Levy
     27  */
     28 @GwtCompatible(emulated = true)
     29 @SuppressWarnings("serial") // uses writeReplace(), not default serialization
     30 final class EmptyImmutableBiMap extends ImmutableBiMap<Object, Object> {
     31   static final EmptyImmutableBiMap INSTANCE = new EmptyImmutableBiMap();
     32 
     33   private EmptyImmutableBiMap() {}
     34 
     35   @Override public ImmutableBiMap<Object, Object> inverse() {
     36     return this;
     37   }
     38 
     39   @Override
     40   public int size() {
     41     return 0;
     42   }
     43 
     44   @Override
     45   public boolean isEmpty() {
     46     return true;
     47   }
     48 
     49   @Override
     50   public Object get(@Nullable Object key) {
     51     return null;
     52   }
     53 
     54   @Override
     55   public ImmutableSet<Entry<Object, Object>> entrySet() {
     56     return ImmutableSet.of();
     57   }
     58 
     59   @Override
     60   ImmutableSet<Entry<Object, Object>> createEntrySet() {
     61     throw new AssertionError("should never be called");
     62   }
     63 
     64   @Override
     65   public ImmutableSetMultimap<Object, Object> asMultimap() {
     66     return ImmutableSetMultimap.of();
     67   }
     68 
     69   @Override
     70   public ImmutableSet<Object> keySet() {
     71     return ImmutableSet.of();
     72   }
     73 
     74   @Override
     75   boolean isPartialView() {
     76     return false;
     77   }
     78 
     79   Object readResolve() {
     80     return INSTANCE; // preserve singleton property
     81   }
     82 }
     83