1 13 14 package EDU.oswego.cs.dl.util.concurrent; 15 16 22 23 public class WaitableFloat extends SynchronizedFloat { 24 28 public WaitableFloat(float initialValue) { 29 super(initialValue); 30 } 31 32 36 public WaitableFloat(float initialValue, Object lock) { 37 super(initialValue, lock); 38 } 39 40 41 public float set(float newValue) { 42 synchronized (lock_) { 43 lock_.notifyAll(); 44 return super.set(newValue); 45 } 46 } 47 48 public boolean commit(float assumedValue, float newValue) { 49 synchronized (lock_) { 50 boolean success = super.commit(assumedValue, newValue); 51 if (success) lock_.notifyAll(); 52 return success; 53 } 54 } 55 56 57 public float add(float amount) { 58 synchronized (lock_) { 59 lock_.notifyAll(); 60 return super.add(amount); 61 } 62 } 63 64 public float subtract(float amount) { 65 synchronized (lock_) { 66 lock_.notifyAll(); 67 return super.subtract(amount); 68 } 69 } 70 71 public float multiply(float factor) { 72 synchronized (lock_) { 73 lock_.notifyAll(); 74 return super.multiply(factor); 75 } 76 } 77 78 public float divide(float factor) { 79 synchronized (lock_) { 80 lock_.notifyAll(); 81 return super.divide(factor); 82 } 83 } 84 85 86 90 91 public void whenEqual(float c, Runnable action) throws InterruptedException { 92 synchronized(lock_) { 93 while (!(value_ == c)) lock_.wait(); 94 if (action != null) action.run(); 95 } 96 } 97 98 102 public void whenNotEqual(float c, Runnable action) throws InterruptedException { 103 synchronized (lock_) { 104 while (!(value_ != c)) lock_.wait(); 105 if (action != null) action.run(); 106 } 107 } 108 109 113 public void whenLessEqual(float c, Runnable action) throws InterruptedException { 114 synchronized (lock_) { 115 while (!(value_ <= c)) lock_.wait(); 116 if (action != null) action.run(); 117 } 118 } 119 120 124 public void whenLess(float c, Runnable action) throws InterruptedException { 125 synchronized (lock_) { 126 while (!(value_ < c)) lock_.wait(); 127 if (action != null) action.run(); 128 } 129 } 130 131 135 public void whenGreaterEqual(float c, Runnable action) throws InterruptedException { 136 synchronized (lock_) { 137 while (!(value_ >= c)) lock_.wait(); 138 if (action != null) action.run(); 139 } 140 } 141 142 146 public void whenGreater(float c, Runnable action) throws InterruptedException { 147 synchronized (lock_) { 148 while (!(value_ > c)) lock_.wait(); 149 if (action != null) action.run(); 150 } 151 } 152 153 } 154 155 | Popular Tags |