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
17package com.google.common.collect;
18
19import com.google.common.annotations.GwtCompatible;
20
21import java.util.Map;
22
23import javax.annotation.Nullable;
24
25/**
26 * An empty immutable map.
27 *
28 * @author Jesse Wilson
29 * @author Kevin Bourrillion
30 */
31@GwtCompatible(serializable = true, emulated = true)
32final class EmptyImmutableMap extends ImmutableMap<Object, Object> {
33  static final EmptyImmutableMap INSTANCE = new EmptyImmutableMap();
34
35  private EmptyImmutableMap() {}
36
37  @Override public Object get(@Nullable Object key) {
38    return null;
39  }
40
41  @Override
42  public int size() {
43    return 0;
44  }
45
46  @Override public boolean isEmpty() {
47    return true;
48  }
49
50  @Override public boolean containsKey(@Nullable Object key) {
51    return false;
52  }
53
54  @Override public boolean containsValue(@Nullable Object value) {
55    return false;
56  }
57
58  @Override public ImmutableSet<Entry<Object, Object>> entrySet() {
59    return ImmutableSet.of();
60  }
61
62  @Override public ImmutableSet<Object> keySet() {
63    return ImmutableSet.of();
64  }
65
66  @Override public ImmutableCollection<Object> values() {
67    return ImmutableCollection.EMPTY_IMMUTABLE_COLLECTION;
68  }
69
70  @Override public boolean equals(@Nullable Object object) {
71    if (object instanceof Map) {
72      Map<?, ?> that = (Map<?, ?>) object;
73      return that.isEmpty();
74    }
75    return false;
76  }
77
78  @Override boolean isPartialView() {
79    return false;
80  }
81
82  @Override public int hashCode() {
83    return 0;
84  }
85
86  @Override public String toString() {
87    return "{}";
88  }
89
90  Object readResolve() {
91    return INSTANCE; // preserve singleton property
92  }
93
94  private static final long serialVersionUID = 0;
95}
96