ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/RWMap.java
(Generate patch)

Comparing jsr166/src/test/loops/RWMap.java (file contents):
Revision 1.9 by dl, Thu May 3 10:11:55 2012 UTC vs.
Revision 1.12 by jsr166, Thu Jan 15 18:34:19 2015 UTC

# Line 7 | Line 7 | import java.util.*;
7   import java.util.concurrent.*;
8   import java.util.concurrent.locks.*;
9  
10
10   /**
11   * This is an incomplete implementation of a wrapper class
12   * that places read-write locks around unsynchronized Maps.
# Line 106 | Line 105 | public class RWMap implements Concurrent
105      public Object putIfAbsent(Object key, Object value) {
106          ReentrantReadWriteLock.WriteLock l = rwl.writeLock();
107          l.lock();
108 <        try {
108 >        try {
109              Object v = m.get(key);
110 <            return v == null?  m.put(key, value) : v;
110 >            return (v == null) ? m.put(key, value) : v;
111          }
112          finally { l.unlock(); }
113      }
# Line 116 | Line 115 | public class RWMap implements Concurrent
115      public boolean replace(Object key, Object oldValue, Object newValue) {
116          ReentrantReadWriteLock.WriteLock l = rwl.writeLock();
117          l.lock();
118 <        try {
118 >        try {
119              if (m.get(key).equals(oldValue)) {
120                  m.put(key, newValue);
121                  return true;
# Line 129 | Line 128 | public class RWMap implements Concurrent
128      public Object replace(Object key, Object newValue) {
129          ReentrantReadWriteLock.WriteLock l = rwl.writeLock();
130          l.lock();
131 <        try {
131 >        try {
132              if (m.containsKey(key))
133                  return m.put(key, newValue);
134              return null;
# Line 147 | Line 146 | public class RWMap implements Concurrent
146      public boolean remove(Object key, Object value) {
147          ReentrantReadWriteLock.WriteLock l = rwl.writeLock();
148          l.lock();
149 <        try {
149 >        try {
150              if (m.get(key).equals(value)) {
151                  m.remove(key);
152                  return true;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines