/core/src/main/java/com/googlecode/ehcache/annotations/key/ReadOnlyList.java

http://ehcache-spring-annotations.googlecode.com/ · Java · 153 lines · 101 code · 30 blank · 22 comment · 2 complexity · e7422b45c862ac18687b063a65ee8a70 MD5 · raw file

  1. /**
  2. * Copyright 2010-2011 Nicholas Blair, Eric Dalquist
  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. package com.googlecode.ehcache.annotations.key;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.Iterator;
  21. import java.util.List;
  22. import java.util.ListIterator;
  23. /**
  24. * Composite interface that denotes a {@link Serializable} {@link List} that is read only. None of the modification
  25. * methods will work on this list.
  26. *
  27. * @author Eric Dalquist
  28. * @version $Revision: 656 $
  29. */
  30. public class ReadOnlyList<E> implements List<E>, Serializable {
  31. private static final long serialVersionUID = 1L;
  32. private final List<E> readOnlyDelegate;
  33. private int hashCodeCache;
  34. public ReadOnlyList(List<E> readOnlyDelegate) {
  35. this.readOnlyDelegate = Collections.unmodifiableList(readOnlyDelegate);
  36. }
  37. public boolean add(E e) {
  38. return readOnlyDelegate.add(e);
  39. }
  40. public void add(int index, E element) {
  41. readOnlyDelegate.add(index, element);
  42. }
  43. public boolean addAll(Collection<? extends E> c) {
  44. return readOnlyDelegate.addAll(c);
  45. }
  46. public boolean addAll(int index, Collection<? extends E> c) {
  47. return readOnlyDelegate.addAll(index, c);
  48. }
  49. public void clear() {
  50. readOnlyDelegate.clear();
  51. }
  52. public boolean contains(Object o) {
  53. return readOnlyDelegate.contains(o);
  54. }
  55. public boolean containsAll(Collection<?> c) {
  56. return readOnlyDelegate.containsAll(c);
  57. }
  58. @Override
  59. public boolean equals(Object o) {
  60. return readOnlyDelegate.equals(o);
  61. }
  62. public E get(int index) {
  63. return readOnlyDelegate.get(index);
  64. }
  65. @Override
  66. public int hashCode() {
  67. int h = this.hashCodeCache;
  68. if (h == 0) {
  69. h = readOnlyDelegate.hashCode();
  70. this.hashCodeCache = h;
  71. }
  72. return h;
  73. }
  74. public int indexOf(Object o) {
  75. return readOnlyDelegate.indexOf(o);
  76. }
  77. public boolean isEmpty() {
  78. return readOnlyDelegate.isEmpty();
  79. }
  80. public Iterator<E> iterator() {
  81. return readOnlyDelegate.iterator();
  82. }
  83. public int lastIndexOf(Object o) {
  84. return readOnlyDelegate.lastIndexOf(o);
  85. }
  86. public ListIterator<E> listIterator() {
  87. return readOnlyDelegate.listIterator();
  88. }
  89. public ListIterator<E> listIterator(int index) {
  90. return readOnlyDelegate.listIterator(index);
  91. }
  92. public E remove(int index) {
  93. return readOnlyDelegate.remove(index);
  94. }
  95. public boolean remove(Object o) {
  96. return readOnlyDelegate.remove(o);
  97. }
  98. public boolean removeAll(Collection<?> c) {
  99. return readOnlyDelegate.removeAll(c);
  100. }
  101. public boolean retainAll(Collection<?> c) {
  102. return readOnlyDelegate.retainAll(c);
  103. }
  104. public E set(int index, E element) {
  105. return readOnlyDelegate.set(index, element);
  106. }
  107. public int size() {
  108. return readOnlyDelegate.size();
  109. }
  110. public List<E> subList(int fromIndex, int toIndex) {
  111. return readOnlyDelegate.subList(fromIndex, toIndex);
  112. }
  113. public Object[] toArray() {
  114. return readOnlyDelegate.toArray();
  115. }
  116. public <T> T[] toArray(T[] a) {
  117. return readOnlyDelegate.toArray(a);
  118. }
  119. @Override
  120. public String toString() {
  121. return readOnlyDelegate.toString();
  122. }
  123. }