/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Returns a synchronized (thread-safe) list backed by the specified * list. In order to guarantee serial access, it is critical that * <strong>all</strong> access to the backing list is accomplished * through the returned list.<p> * * It is imperative that the user manually synchronize on the returned * list when iterating over it: * <pre> * List list = Collections.synchronizedList(new ArrayList()); * ... * synchronized (list) { * Iterator i = list.iterator(); // Must be in synchronized block * while (i.hasNext()) * foo(i.next()); * } * </pre> * Failure to follow this advice may result in non-deterministic behavior. * * <p>The returned list will be serializable if the specified list is * serializable. * * @param list the list to be "wrapped" in a synchronized list. * @return a synchronized view of the specified list. */ public static <T> List<T> synchronizedList(List<T> list) { return (list instanceof RandomAccess ? new SynchronizedRandomAccessList<>(list) : new SynchronizedList<>(list)); }
/** * Returns a synchronized (thread-safe) list backed by the specified * list. In order to guarantee serial access, it is critical that * <strong>all</strong> access to the backing list is accomplished * through the returned list.<p> * * It is imperative that the user manually synchronize on the returned * list when iterating over it: * <pre> * List list = Collections.synchronizedList(new ArrayList()); * ... * synchronized (list) { * Iterator i = list.iterator(); // Must be in synchronized block * while (i.hasNext()) * foo(i.next()); * } * </pre> * Failure to follow this advice may result in non-deterministic behavior. * * <p>The returned list will be serializable if the specified list is * serializable. * * @param list the list to be "wrapped" in a synchronized list. * @return a synchronized view of the specified list. */ public static <T> List<T> synchronizedList(List<T> list) { return (list instanceof RandomAccess ? new SynchronizedRandomAccessList<>(list) : new SynchronizedList<>(list)); }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
/** * Returns a wrapper on the specified List which synchronizes all access to * the List. * * @param list * the List to wrap in a synchronized list. * @return a synchronized List. */ public static <T> List<T> synchronizedList(List<T> list) { if (list == null) { throw new NullPointerException("list == null"); } if (list instanceof RandomAccess) { return new SynchronizedRandomAccessList<T>(list); } return new SynchronizedList<T>(list); }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
/** * Allows instances to be deserialized in pre-1.4 JREs (which do * not have SynchronizedRandomAccessList). SynchronizedList has * a readResolve method that inverts this transformation upon * deserialization. */ private Object writeReplace() { return new SynchronizedList<>(list); } }
static <T> List<T> synchronizedList(List<T> list, Object mutex) { return (list instanceof RandomAccess ? new SynchronizedRandomAccessList<>(list, mutex) : new SynchronizedList<>(list, mutex)); }
/** * Replaces this SynchronizedRandomAccessList with a SynchronizedList so * that JREs before 1.4 can deserialize this object without any * problems. This is necessary since RandomAccess API was introduced * only in 1.4. * <p> * * @return SynchronizedList * * @see SynchronizedList#readResolve() */ private Object writeReplace() { return new SynchronizedList<E>(list); } }
@Override public List<E> subList(int start, int end) { synchronized (mutex) { return new SynchronizedList<E>(list.subList(start, end), mutex); } }