1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  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 org.apache.commons.collections.list;
  17. import java.util.Collection;
  18. import java.util.List;
  19. import java.util.ListIterator;
  20. import org.apache.commons.collections.collection.AbstractCollectionDecorator;
  21. /**
  22. * Decorates another <code>List</code> to provide additional behaviour.
  23. * <p>
  24. * Methods are forwarded directly to the decorated list.
  25. *
  26. * @since Commons Collections 3.0
  27. * @version $Revision: 1.4 $ $Date: 2004/06/02 21:53:02 $
  28. *
  29. * @author Stephen Colebourne
  30. */
  31. public abstract class AbstractListDecorator extends AbstractCollectionDecorator implements List {
  32. /**
  33. * Constructor only used in deserialization, do not use otherwise.
  34. * @since Commons Collections 3.1
  35. */
  36. protected AbstractListDecorator() {
  37. super();
  38. }
  39. /**
  40. * Constructor that wraps (not copies).
  41. *
  42. * @param list the list to decorate, must not be null
  43. * @throws IllegalArgumentException if list is null
  44. */
  45. protected AbstractListDecorator(List list) {
  46. super(list);
  47. }
  48. /**
  49. * Gets the list being decorated.
  50. *
  51. * @return the decorated list
  52. */
  53. protected List getList() {
  54. return (List) getCollection();
  55. }
  56. //-----------------------------------------------------------------------
  57. public void add(int index, Object object) {
  58. getList().add(index, object);
  59. }
  60. public boolean addAll(int index, Collection coll) {
  61. return getList().addAll(index, coll);
  62. }
  63. public Object get(int index) {
  64. return getList().get(index);
  65. }
  66. public int indexOf(Object object) {
  67. return getList().indexOf(object);
  68. }
  69. public int lastIndexOf(Object object) {
  70. return getList().lastIndexOf(object);
  71. }
  72. public ListIterator listIterator() {
  73. return getList().listIterator();
  74. }
  75. public ListIterator listIterator(int index) {
  76. return getList().listIterator(index);
  77. }
  78. public Object remove(int index) {
  79. return getList().remove(index);
  80. }
  81. public Object set(int index, Object object) {
  82. return getList().set(index, object);
  83. }
  84. public List subList(int fromIndex, int toIndex) {
  85. return getList().subList(fromIndex, toIndex);
  86. }
  87. }