1 16 package org.apache.commons.collections.list; 17 18 import java.util.Collection ; 19 import java.util.List ; 20 import java.util.ListIterator ; 21 22 import org.apache.commons.collections.collection.SynchronizedCollection; 23 24 37 public class SynchronizedList extends SynchronizedCollection implements List { 38 39 40 private static final long serialVersionUID = -1403835447328619437L; 41 42 48 public static List decorate(List list) { 49 return new SynchronizedList(list); 50 } 51 52 59 protected SynchronizedList(List list) { 60 super(list); 61 } 62 63 70 protected SynchronizedList(List list, Object lock) { 71 super(list, lock); 72 } 73 74 79 protected List getList() { 80 return (List ) collection; 81 } 82 83 public void add(int index, Object object) { 85 synchronized (lock) { 86 getList().add(index, object); 87 } 88 } 89 90 public boolean addAll(int index, Collection coll) { 91 synchronized (lock) { 92 return getList().addAll(index, coll); 93 } 94 } 95 96 public Object get(int index) { 97 synchronized (lock) { 98 return getList().get(index); 99 } 100 } 101 102 public int indexOf(Object object) { 103 synchronized (lock) { 104 return getList().indexOf(object); 105 } 106 } 107 108 public int lastIndexOf(Object object) { 109 synchronized (lock) { 110 return getList().lastIndexOf(object); 111 } 112 } 113 114 124 public ListIterator listIterator() { 125 return getList().listIterator(); 126 } 127 128 138 public ListIterator listIterator(int index) { 139 return getList().listIterator(index); 140 } 141 142 public Object remove(int index) { 143 synchronized (lock) { 144 return getList().remove(index); 145 } 146 } 147 148 public Object set(int index, Object object) { 149 synchronized (lock) { 150 return getList().set(index, object); 151 } 152 } 153 154 public List subList(int fromIndex, int toIndex) { 155 synchronized (lock) { 156 List list = getList().subList(fromIndex, toIndex); 157 return new SynchronizedList(list, lock); 160 } 161 } 162 163 } 164 | Popular Tags |