Package: SynchronizedListIterator

SynchronizedListIterator

nameinstructionbranchcomplexitylinemethod
SynchronizedListIterator(ListIterator, Object)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
add(Object)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
hasPrevious()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
nextIndex()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
previous()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
previousIndex()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
set(Object)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.util.common;
13:
14: import java.util.ListIterator;
15:
16: /**
17: * {@link SynchronizedListIterator} wraps a given {@link ListIterator} and protects access to the iterator by
18: * synchronizing on the monitor of the containing {@link SynchronizedList}.
19: * <p />
20: *
21: * <strong>Concurrent Semantics</strong><br />
22: *
23: * This class is thread safe, but ConcurrentModificationException may still be thrown.
24: *
25: * @param <T> the type of the list elements
26: */
27: public class SynchronizedListIterator<T> extends SynchronizedIterator<T> implements ListIterator<T> {
28:
29: private final Object monitor;
30:
31: private final ListIterator<T> listIterator;
32:
33: public SynchronizedListIterator(ListIterator<T> listIterator, Object monitor) {
34: super(listIterator, monitor);
35: this.monitor = monitor;
36: this.listIterator = listIterator;
37: }
38:
39: /**
40: * {@inheritDoc}
41: */
42: public void add(T e) {
43: synchronized (this.monitor) {
44: this.listIterator.add(e);
45: }
46: }
47:
48: /**
49: * {@inheritDoc}
50: */
51: public boolean hasPrevious() {
52: synchronized (this.monitor) {
53: return this.listIterator.hasPrevious();
54: }
55: }
56:
57: /**
58: * {@inheritDoc}
59: */
60: public int nextIndex() {
61: synchronized (this.monitor) {
62: return this.listIterator.nextIndex();
63: }
64: }
65:
66: /**
67: * {@inheritDoc}
68: */
69: public T previous() {
70: synchronized (this.monitor) {
71: return this.listIterator.previous();
72: }
73: }
74:
75: /**
76: * {@inheritDoc}
77: */
78: public int previousIndex() {
79: synchronized (this.monitor) {
80: return this.listIterator.previousIndex();
81: }
82: }
83:
84: /**
85: * {@inheritDoc}
86: */
87: public void set(T e) {
88: synchronized (this.monitor) {
89: this.listIterator.set(e);
90: }
91: }
92:
93: }