Package: SynchronizedList

SynchronizedList

nameinstructionbranchcomplexitylinemethod
SynchronizedList(List, 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(int, Object)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addAll(int, Collection)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
equals(Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
get(int)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
hashCode()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
indexOf(Object)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lastIndexOf(Object)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
listIterator()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
listIterator(int)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
remove(int)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
set(int, Object)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
subList(int, int)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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.Collection;
15: import java.util.List;
16: import java.util.ListIterator;
17:
18: /**
19: * {@link SynchronizedList} wraps a given {@link List} and protects access to the collection and any
20: * iterators created from the collection by synchronizing on a given monitor.
21: * <p />
22: *
23: * <strong>Concurrent Semantics</strong><br />
24: *
25: * This class is thread safe, but ConcurrentModificationException may still be thrown.
26: *
27: * @param <T> the type of the list elements
28: */
29: public class SynchronizedList<T> extends SynchronizedCollection<T> implements List<T> {
30:
31: final Object monitor;
32:
33: private final List<T> list;
34:
35: @SuppressWarnings("unchecked")
36: public SynchronizedList(List<? extends T> list, Object monitor) {
37: super(list, monitor);
38: this.monitor = monitor;
39: this.list = (List<T>) list;
40: }
41:
42: /**
43: * {@inheritDoc}
44: */
45: public void add(int index, T element) {
46: synchronized (this.monitor) {
47: this.list.add(index, element);
48: }
49: }
50:
51: /**
52: * {@inheritDoc}
53: */
54: public boolean addAll(int index, Collection<? extends T> c) {
55: synchronized (this.monitor) {
56: return this.list.addAll(index, c);
57: }
58: }
59:
60: /**
61: * {@inheritDoc}
62: */
63: public T get(int index) {
64: synchronized (this.monitor) {
65: return this.list.get(index);
66: }
67: }
68:
69: /**
70: * {@inheritDoc}
71: */
72: public int indexOf(Object o) {
73: synchronized (this.monitor) {
74: return this.list.indexOf(o);
75: }
76: }
77:
78: /**
79: * {@inheritDoc}
80: */
81: public int lastIndexOf(Object o) {
82: synchronized (this.monitor) {
83: return this.list.lastIndexOf(o);
84: }
85: }
86:
87: /**
88: * {@inheritDoc}
89: */
90: public ListIterator<T> listIterator() {
91: synchronized (this.monitor) {
92: return new SynchronizedListIterator<T>(this.list.listIterator(), this.monitor);
93: }
94: }
95:
96: /**
97: * {@inheritDoc}
98: */
99: public ListIterator<T> listIterator(int index) {
100: synchronized (this.monitor) {
101: return new SynchronizedListIterator<T>(this.list.listIterator(index), this.monitor);
102: }
103: }
104:
105: /**
106: * {@inheritDoc}
107: */
108: public T remove(int index) {
109: synchronized (this.monitor) {
110: return this.list.remove(index);
111: }
112: }
113:
114: /**
115: * {@inheritDoc}
116: */
117: public T set(int index, T element) {
118: synchronized (this.monitor) {
119: return this.list.set(index, element);
120: }
121: }
122:
123: /**
124: * {@inheritDoc}
125: */
126: public List<T> subList(int fromIndex, int toIndex) {
127: synchronized (this.monitor) {
128: return new SynchronizedList<T>(this.list.subList(fromIndex, toIndex), this.monitor);
129: }
130: }
131:
132: /**
133: * {@inheritDoc}
134: */
135: @Override
136: public int hashCode() {
137: return super.hashCode();
138: }
139:
140: /**
141: * {@inheritDoc}
142: */
143: @Override
144: public boolean equals(Object obj) {
145: return super.equals(obj);
146: }
147:
148:
149: }