• 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 org.checkerframework.checker.nullness.qual.Nullable;
22 
23 @GwtCompatible(emulated = true)
24 @ElementTypesAreNonnullByDefault
25 abstract class IndexedImmutableSet<E> extends ImmutableSet<E> {
get(int index)26   abstract E get(int index);
27 
28   @Override
iterator()29   public UnmodifiableIterator<E> iterator() {
30     return asList().iterator();
31   }
32 
33   @Override
34   @GwtIncompatible
copyIntoArray(@ullable Object[] dst, int offset)35   int copyIntoArray(@Nullable Object[] dst, int offset) {
36     return asList().copyIntoArray(dst, offset);
37   }
38 
39   @Override
createAsList()40   ImmutableList<E> createAsList() {
41     return new ImmutableList<E>() {
42       @Override
43       public E get(int index) {
44         return IndexedImmutableSet.this.get(index);
45       }
46 
47       @Override
48       boolean isPartialView() {
49         return IndexedImmutableSet.this.isPartialView();
50       }
51 
52       @Override
53       public int size() {
54         return IndexedImmutableSet.this.size();
55       }
56     };
57   }
58 }
59