Package: SynchronizedObject

SynchronizedObject

nameinstructionbranchcomplexitylinemethod
SynchronizedObject(Object, Object)
M: 10 C: 13
57%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 6
75%
M: 0 C: 1
100%
toString()
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%

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: /**
15: * {@link SynchronizedObject} wraps a given {@link Object} and protects access to the object by synchronizing on a given
16: * monitor.
17: * <p />
18: * Note that <code>hashCode</code> and <code>equals</code> are not delegated as this object is distinct from the wrapped object.
19: *
20: * <strong>Concurrent Semantics</strong><br />
21: *
22: * This class is thread safe.
23: *
24: */
25: public class SynchronizedObject extends Object {
26:
27: private final Object monitor;
28:
29: private final Object object;
30:
31: public SynchronizedObject(Object object, Object monitor) {
32:• if (object == null) {
33: throw new IllegalArgumentException("null object");
34: }
35:• if (monitor == null) {
36: throw new IllegalArgumentException("null monitor");
37: }
38: this.object = object;
39: this.monitor = monitor;
40: }
41:
42: /**
43: * {@inheritDoc}
44: */
45: @Override
46: public String toString() {
47: synchronized (this.monitor) {
48: return this.object.toString();
49: }
50: }
51:
52: }