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 java.util.Collection; 20 import java.util.List; 21 22 import javax.annotation.Nullable; 23 24 /** 25 * GWT emulated version of {@link ImmutableList}. 26 * TODO(cpovirk): more doc 27 * 28 * @author Hayward Chan 29 */ 30 abstract class ForwardingImmutableList<E> extends ImmutableList<E> { 31 32 ForwardingImmutableList() { 33 } 34 35 abstract List<E> delegateList(); 36 37 public int indexOf(@Nullable Object object) { 38 return delegateList().indexOf(object); 39 } 40 41 public int lastIndexOf(@Nullable Object object) { 42 return delegateList().lastIndexOf(object); 43 } 44 45 public E get(int index) { 46 return delegateList().get(index); 47 } 48 49 public ImmutableList<E> subList(int fromIndex, int toIndex) { 50 return unsafeDelegateList(delegateList().subList(fromIndex, toIndex)); 51 } 52 53 @Override public Object[] toArray() { 54 // Note that ArrayList.toArray() doesn't work here because it returns E[] 55 // instead of Object[]. 56 return delegateList().toArray(new Object[size()]); 57 } 58 59 @Override public boolean equals(Object obj) { 60 return delegateList().equals(obj); 61 } 62 63 @Override public int hashCode() { 64 return delegateList().hashCode(); 65 } 66 67 @Override public UnmodifiableIterator<E> iterator() { 68 return Iterators.unmodifiableIterator(delegateList().iterator()); 69 } 70 71 @Override public boolean contains(@Nullable Object object) { 72 return object != null && delegateList().contains(object); 73 } 74 75 @Override public boolean containsAll(Collection<?> targets) { 76 return delegateList().containsAll(targets); 77 } 78 79 public int size() { 80 return delegateList().size(); 81 } 82 83 @Override public boolean isEmpty() { 84 return delegateList().isEmpty(); 85 } 86 87 @Override public <T> T[] toArray(T[] other) { 88 return delegateList().toArray(other); 89 } 90 91 @Override public String toString() { 92 return delegateList().toString(); 93 } 94 } 95