Coverage Summary for Class: RegularImmutableList (com.google.common.collect)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| RegularImmutableList | 100% (1/1) | 90.9% (10/11) | 92.9% (13/14) |
1 /* 2 * Copyright (C) 2009 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.VisibleForTesting; 21 import java.util.Spliterator; 22 import java.util.Spliterators; 23 import org.checkerframework.checker.nullness.qual.Nullable; 24 25 /** 26 * Implementation of {@link ImmutableList} backed by a simple array. 27 * 28 * @author Kevin Bourrillion 29 */ 30 @GwtCompatible(serializable = true, emulated = true) 31 @SuppressWarnings("serial") // uses writeReplace(), not default serialization 32 @ElementTypesAreNonnullByDefault 33 class RegularImmutableList<E> extends ImmutableList<E> { 34 static final ImmutableList<Object> EMPTY = new RegularImmutableList<>(new Object[0]); 35 36 @VisibleForTesting final transient Object[] array; 37 38 RegularImmutableList(Object[] array) { 39 this.array = array; 40 } 41 42 @Override 43 public int size() { 44 return array.length; 45 } 46 47 @Override 48 boolean isPartialView() { 49 return false; 50 } 51 52 @Override 53 Object[] internalArray() { 54 return array; 55 } 56 57 @Override 58 int internalArrayStart() { 59 return 0; 60 } 61 62 @Override 63 int internalArrayEnd() { 64 return array.length; 65 } 66 67 @Override 68 int copyIntoArray(@Nullable Object[] dst, int dstOff) { 69 System.arraycopy(array, 0, dst, dstOff, array.length); 70 return dstOff + array.length; 71 } 72 73 // The fake cast to E is safe because the creation methods only allow E's 74 @Override 75 @SuppressWarnings("unchecked") 76 public E get(int index) { 77 return (E) array[index]; 78 } 79 80 @SuppressWarnings("unchecked") 81 @Override 82 public UnmodifiableListIterator<E> listIterator(int index) { 83 // for performance 84 // The fake cast to E is safe because the creation methods only allow E's 85 return (UnmodifiableListIterator<E>) Iterators.forArray(array, 0, array.length, index); 86 } 87 88 @Override 89 public Spliterator<E> spliterator() { 90 return Spliterators.spliterator(array, SPLITERATOR_CHARACTERISTICS); 91 } 92 93 // TODO(lowasser): benchmark optimizations for equals() and see if they're worthwhile 94 }