• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 import com.google.common.annotations.GwtIncompatible;
21 import com.google.common.annotations.J2ktIncompatible;
22 import org.checkerframework.checker.nullness.qual.Nullable;
23 
24 @GwtCompatible(emulated = true)
25 @ElementTypesAreNonnullByDefault
26 abstract class IndexedImmutableSet<E> extends ImmutableSet<E> {
get(int index)27   abstract E get(int index);
28 
29   @Override
iterator()30   public UnmodifiableIterator<E> iterator() {
31     return asList().iterator();
32   }
33 
34   @Override
35   @GwtIncompatible
copyIntoArray(@ullable Object[] dst, int offset)36   int copyIntoArray(@Nullable Object[] dst, int offset) {
37     return asList().copyIntoArray(dst, offset);
38   }
39 
40   @Override
createAsList()41   ImmutableList<E> createAsList() {
42     return new ImmutableList<E>() {
43       @Override
44       public E get(int index) {
45         return IndexedImmutableSet.this.get(index);
46       }
47 
48       @Override
49       boolean isPartialView() {
50         return IndexedImmutableSet.this.isPartialView();
51       }
52 
53       @Override
54       public int size() {
55         return IndexedImmutableSet.this.size();
56       }
57 
58       // redeclare to help optimizers with b/310253115
59       @SuppressWarnings("RedundantOverride")
60       @Override
61       @J2ktIncompatible // serialization
62       @GwtIncompatible // serialization
63       Object writeReplace() {
64         return super.writeReplace();
65       }
66     };
67   }
68 
69   // redeclare to help optimizers with b/310253115
70   @SuppressWarnings("RedundantOverride")
71   @Override
72   @J2ktIncompatible // serialization
73   @GwtIncompatible // serialization
74   Object writeReplace() {
75     return super.writeReplace();
76   }
77 }
78