## EDU.oswego.cs.dl.util.concurrent
Class WaitableInt

    java.lang.Object
      EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
          EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
              EDU.oswego.cs.dl.util.concurrent.WaitableInt

All Implemented Interfaces:
  Executor, java.lang.Cloneable, java.lang.Comparable

    public class WaitableInt

extends SynchronizedInt

A class useful for offloading waiting and signalling operations on single int variables.

[ Introduction to this package. ]

Field Summary

Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
`value_`

Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
`lock_`

Constructor Summary
`WaitableInt(int initialValue)` Make a new WaitableInt with the given initial value, and using its own internal lock.
`WaitableInt(int initialValue, java.lang.Object lock)` Make a new WaitableInt with the given initial value, and using the supplied lock.

Method Summary
`int` `add(int amount)` Add amount to value (i.e., set value += amount)
`int` `and(int b)` Set value to value & b.
`boolean` `commit(int assumedValue, int newValue)` Set value to newValue only if it is currently assumedValue.
`int` `complement()` Set the value to its complement
`int` `decrement()` Decrement the value.
`int` `divide(int factor)` Divide value by factor (i.e., set value /= factor)
`int` `increment()` Increment the value.
`int` `multiply(int factor)` Multiply value by factor (i.e., set value *= factor)
`int` `or(int b)` Set value to value | b.
`int` `set(int newValue)` Set to newValue.
`int` `subtract(int amount)` Subtract amount from value (i.e., set value -= amount)
`void` `whenEqual(int c, java.lang.Runnable action)` Wait until value equals c, then run action if nonnull.
`void` `whenGreater(int c, java.lang.Runnable action)` wait until value greater than c, then run action if nonnull.
`void` `whenGreaterEqual(int c, java.lang.Runnable action)` wait until value greater than or equal to c, then run action if nonnull.
`void` `whenLess(int c, java.lang.Runnable action)` wait until value less than c, then run action if nonnull.
`void` `whenLessEqual(int c, java.lang.Runnable action)` wait until value less than or equal to c, then run action if nonnull.
`void` `whenNotEqual(int c, java.lang.Runnable action)` wait until value not equal to c, then run action if nonnull.
`int` `xor(int b)` Set value to value ^ b.

Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
`compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toString`

Methods inherited from class EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
`execute, getLock`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### WaitableInt

    public WaitableInt(int initialValue)

  Make a new WaitableInt with the given initial value, and using its own internal lock.

### WaitableInt

    public WaitableInt(int initialValue,
                       java.lang.Object lock)

  Make a new WaitableInt with the given initial value, and using the supplied lock.

Method Detail

### set

    public int set(int newValue)

  Description copied from class: `SynchronizedInt`
  Set to newValue.

  Overrides:
    `set` in class `SynchronizedInt`
  Returns:
    the old value

### commit

    public boolean commit(int assumedValue,
                          int newValue)

  Description copied from class: `SynchronizedInt`
  Set value to newValue only if it is currently assumedValue.

  Overrides:
    `commit` in class `SynchronizedInt`
  Returns:
    true if successful

### increment

    public int increment()

  Description copied from class: `SynchronizedInt`
  Increment the value.

  Overrides:
    `increment` in class `SynchronizedInt`
  Returns:
    the new value

### decrement

    public int decrement()

  Description copied from class: `SynchronizedInt`
  Decrement the value.

  Overrides:
    `decrement` in class `SynchronizedInt`
  Returns:
    the new value

### add

    public int add(int amount)

  Description copied from class: `SynchronizedInt`
  Add amount to value (i.e., set value += amount)

  Overrides:
    `add` in class `SynchronizedInt`
  Returns:
    the new value

### subtract

    public int subtract(int amount)

  Description copied from class: `SynchronizedInt`
  Subtract amount from value (i.e., set value -= amount)

  Overrides:
    `subtract` in class `SynchronizedInt`
  Returns:
    the new value

### multiply

    public int multiply(int factor)

  Description copied from class: `SynchronizedInt`
  Multiply value by factor (i.e., set value *= factor)

  Overrides:
    `multiply` in class `SynchronizedInt`
  Returns:
    the new value

### divide

    public int divide(int factor)

  Description copied from class: `SynchronizedInt`
  Divide value by factor (i.e., set value /= factor)

  Overrides:
    `divide` in class `SynchronizedInt`
  Returns:
    the new value

### complement

    public int complement()

  Set the value to its complement

  Overrides:
    `complement` in class `SynchronizedInt`
  Returns:
    the new value

### and

    public int and(int b)

  Set value to value & b.

  Overrides:
    `and` in class `SynchronizedInt`
  Returns:
    the new value

### or

    public int or(int b)

  Set value to value | b.

  Overrides:
    `or` in class `SynchronizedInt`
  Returns:
    the new value

### xor

    public int xor(int b)

  Set value to value ^ b.

  Overrides:
    `xor` in class `SynchronizedInt`
  Returns:
    the new value

### whenEqual

    public void whenEqual(int c,
                          java.lang.Runnable action)
                   throws java.lang.InterruptedException

  Wait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.

  Throws:
    `java.lang.InterruptedException`

### whenNotEqual

    public void whenNotEqual(int c,
                             java.lang.Runnable action)
                      throws java.lang.InterruptedException

  wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.

  Throws:
    `java.lang.InterruptedException`

### whenLessEqual

    public void whenLessEqual(int c,
                              java.lang.Runnable action)
                       throws java.lang.InterruptedException

  wait until value less than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.

  Throws:
    `java.lang.InterruptedException`

### whenLess

    public void whenLess(int c,
                         java.lang.Runnable action)
                  throws java.lang.InterruptedException

  wait until value less than c, then run action if nonnull. The action is run with the synchronization lock held.

  Throws:
    `java.lang.InterruptedException`

### whenGreaterEqual

    public void whenGreaterEqual(int c,
                                 java.lang.Runnable action)
                          throws java.lang.InterruptedException

  wait until value greater than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.

  Throws:
    `java.lang.InterruptedException`

### whenGreater

    public void whenGreater(int c,
                            java.lang.Runnable action)
                     throws java.lang.InterruptedException

  wait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.

  Throws:
    `java.lang.InterruptedException`