1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors
3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License");
5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License.
6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at
7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0
9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software
11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and
14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License.
15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.collect;
18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.annotations.GwtCompatible;
20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Collection;
22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Set;
23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport javax.annotation.Nullable;
25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/**
27090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * An empty immutable set.
287dd252788645e940eada959bdde927426e2531c9Paul Duffin *
29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Kevin Bourrillion
30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert@GwtCompatible(serializable = true, emulated = true)
32090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonfinal class EmptyImmutableSet extends ImmutableSet<Object> {
33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  static final EmptyImmutableSet INSTANCE = new EmptyImmutableSet();
34090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
35090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  private EmptyImmutableSet() {}
36090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
370888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override
38090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  public int size() {
39090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return 0;
40090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
41090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
420888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public boolean isEmpty() {
43090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return true;
44090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
45090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
460888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public boolean contains(@Nullable Object target) {
47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return false;
48090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
49090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
500888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public boolean containsAll(Collection<?> targets) {
517dd252788645e940eada959bdde927426e2531c9Paul Duffin    return targets.isEmpty();
527dd252788645e940eada959bdde927426e2531c9Paul Duffin  }
537dd252788645e940eada959bdde927426e2531c9Paul Duffin
540888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public UnmodifiableIterator<Object> iterator() {
55090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return Iterators.emptyIterator();
56090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
57090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
580888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override boolean isPartialView() {
591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert    return false;
601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  }
611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
627dd252788645e940eada959bdde927426e2531c9Paul Duffin  @Override
630888a09821a98ac0680fad765217302858e70fa4Paul Duffin  int copyIntoArray(Object[] dst, int offset) {
640888a09821a98ac0680fad765217302858e70fa4Paul Duffin    return offset;
65090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
66090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
677dd252788645e940eada959bdde927426e2531c9Paul Duffin  @Override
687dd252788645e940eada959bdde927426e2531c9Paul Duffin  public ImmutableList<Object> asList() {
697dd252788645e940eada959bdde927426e2531c9Paul Duffin    return ImmutableList.of();
70090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
71090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
720888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public boolean equals(@Nullable Object object) {
73090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (object instanceof Set) {
74090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson      Set<?> that = (Set<?>) object;
75090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson      return that.isEmpty();
76090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
77090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return false;
78090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
79090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
800888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public final int hashCode() {
81090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return 0;
82090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
83090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
840888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override boolean isHashCodeFast() {
85090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return true;
86090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
87090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
880888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override public String toString() {
89090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return "[]";
90090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
91090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
92090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  Object readResolve() {
93090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return INSTANCE; // preserve singleton property
94090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
95090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
96090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  private static final long serialVersionUID = 0;
97090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
98