Documentation of 'edu.rit.pj.reduction.SharedCharacter' Java class
SharedCharacter
edu.rit.pj.reduction

Class SharedCharacter

  • All Implemented Interfaces:
    java.io.Serializable


    public class SharedCharacter
    extends java.lang.Number
    Class SharedCharacter provides a reduction variable for a value of type char.

    Class SharedCharacter is multiple thread safe. The methods use lock-free atomic compare-and-set.

    Note: Class SharedCharacter is implemented using class java.util.concurrent.atomic.AtomicInteger. The character value is stored as an int whose values are restricted to the range of type char.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      SharedCharacter()
      Construct a new character reduction variable with the initial value 0.
      SharedCharacter(char initialValue)
      Construct a new character reduction variable with the given initial value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      char addAndGet(char value)
      Add the given value to this reduction variable and return the new value.
      boolean compareAndSet(char expect, char update)
      Atomically set this reduction variable to the given updated value if the current value equals the expected value.
      char decrementAndGet()
      Subtract one from this reduction variable and return the new value.
      double doubleValue()
      Returns this reduction variable's current value converted to type double.
      float floatValue()
      Returns this reduction variable's current value converted to type float.
      char get()
      Returns this reduction variable's current value.
      char getAndAdd(char value)
      Add the given value to this reduction variable and return the previous value.
      char getAndDecrement()
      Subtract one from this reduction variable and return the previous value.
      char getAndIncrement()
      Add one to this reduction variable and return the previous value.
      char getAndSet(char value)
      Set this reduction variable to the given value and return the previous value.
      char incrementAndGet()
      Add one to this reduction variable and return the new value.
      int intValue()
      Returns this reduction variable's current value converted to type int.
      long longValue()
      Returns this reduction variable's current value converted to type long.
      char reduce(char value, CharacterOp op)
      Combine this reduction variable with the given value using the given operation.
      void set(char value)
      Set this reduction variable to the given value.
      java.lang.String toString()
      Returns a string version of this reduction variable.
      boolean weakCompareAndSet(char expect, char update)
      Atomically set this reduction variable to the given updated value if the current value equals the expected value.
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SharedCharacter

        public SharedCharacter()
        Construct a new character reduction variable with the initial value 0.
      • SharedCharacter

        public SharedCharacter(char initialValue)
        Construct a new character reduction variable with the given initial value.
        Parameters:
        initialValue - Initial value.
    • Method Detail

      • get

        public char get()
        Returns this reduction variable's current value.
        Returns:
        Current value.
      • set

        public void set(char value)
        Set this reduction variable to the given value.
        Parameters:
        value - New value.
      • getAndSet

        public char getAndSet(char value)
        Set this reduction variable to the given value and return the previous value.
        Parameters:
        value - New value.
        Returns:
        Previous value.
      • compareAndSet

        public boolean compareAndSet(char expect,
                                     char update)
        Atomically set this reduction variable to the given updated value if the current value equals the expected value.
        Parameters:
        expect - Expected value.
        update - Updated value.
        Returns:
        True if the update happened, false otherwise.
      • weakCompareAndSet

        public boolean weakCompareAndSet(char expect,
                                         char update)
        Atomically set this reduction variable to the given updated value if the current value equals the expected value. May fail spuriously.
        Parameters:
        expect - Expected value.
        update - Updated value.
        Returns:
        True if the update happened, false otherwise.
      • getAndIncrement

        public char getAndIncrement()
        Add one to this reduction variable and return the previous value.
        Returns:
        Previous value.
      • getAndDecrement

        public char getAndDecrement()
        Subtract one from this reduction variable and return the previous value.
        Returns:
        Previous value.
      • getAndAdd

        public char getAndAdd(char value)
        Add the given value to this reduction variable and return the previous value.
        Parameters:
        value - Value to add.
        Returns:
        Previous value.
      • incrementAndGet

        public char incrementAndGet()
        Add one to this reduction variable and return the new value.
        Returns:
        New value.
      • decrementAndGet

        public char decrementAndGet()
        Subtract one from this reduction variable and return the new value.
        Returns:
        New value.
      • addAndGet

        public char addAndGet(char value)
        Add the given value to this reduction variable and return the new value.
        Parameters:
        value - Value to add.
        Returns:
        New value.
      • reduce

        public char reduce(char value,
                           CharacterOp op)
        Combine this reduction variable with the given value using the given operation. The result is stored back into this reduction variable and is returned.
        Parameters:
        value - Value.
        op - Binary operation.
        Returns:
        (This variable) op (value).
      • toString

        public java.lang.String toString()
        Returns a string version of this reduction variable.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String version.
      • intValue

        public int intValue()
        Returns this reduction variable's current value converted to type int.
        Specified by:
        intValue in class java.lang.Number
        Returns:
        Current value.
      • longValue

        public long longValue()
        Returns this reduction variable's current value converted to type long.
        Specified by:
        longValue in class java.lang.Number
        Returns:
        Current value.
      • floatValue

        public float floatValue()
        Returns this reduction variable's current value converted to type float.
        Specified by:
        floatValue in class java.lang.Number
        Returns:
        Current value.
      • doubleValue

        public double doubleValue()
        Returns this reduction variable's current value converted to type double.
        Specified by:
        doubleValue in class java.lang.Number
        Returns:
        Current value.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.