# Class AbstractObservableValue<T>

java.lang.Object
org.eclipse.core.databinding.observable.AbstractObservable
org.eclipse.core.databinding.observable.value.AbstractObservableValue<T>

Type Parameters:
  `T` - the type of value being observed

All Implemented Interfaces:
  `IObservable, IObservableValue<T>`

Direct Known Subclasses:
  `AbstractVetoableValue, ComputedValue, DateAndTimeObservableValue, DuplexingObservableValue, LocalDateTimeObservableValue, SelectObservableValue, WritableValue`

public abstract class AbstractObservableValue<T> extends AbstractObservable implements IObservableValue<T>

This class is thread safe. All state accessing methods must be invoked from the `current realm`. Methods for adding and removing listeners may be invoked from any thread.

Since:
  1.0
Implementation Note:
  If methods are added to the interface which this class implements then implementations of those methods must be added to this class.

## Constructor Summary

Constructors
Constructor
Description
`AbstractObservableValue()`
Constructs a new instance with the default realm.
`AbstractObservableValue(Realm realm)`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`addListener(Object listenerType, IObservablesListener listener)`
`void`
`addValueChangeListener(IValueChangeListener<? super T> listener)`
`protected Object`
`clone()`
`protected abstract T`
`doGetValue()`
`protected void`
`doSetValue(T value)`
Template method for setting the value of the observable.
`protected void`
`fireChange()`
`protected void`
`fireEvent(ObservableEvent event)`
`protected void`
`fireValueChange(ValueDiff<T> diff)`
`protected void`
`firstListenerAdded()`
`Realm`
`getRealm()`
`final T`
`getValue()`
Returns the value.
`protected boolean`
`hasListeners()`
`boolean`
`isStale()`
Returns whether the state of this observable is stale and is expected to change soon.
`protected void`
`lastListenerRemoved()`
`protected void`
`removeListener(Object listenerType, IObservablesListener listener)`
`void`
`removeValueChangeListener(IValueChangeListener<? super T> listener)`
`final void`
`setValue(T value)`
Sets the value.

### Methods inherited from class AbstractObservable

`addChangeListener, addDisposeListener, addStaleListener, checkRealm, dispose, fireStale, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener`

### Methods inherited from class Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface IObservable

`addChangeListener, addDisposeListener, addStaleListener, dispose, getRealm, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener`

### Methods inherited from interface IObservableValue

`getValueType`

## Constructor Details

### AbstractObservableValue

public AbstractObservableValue()
Constructs a new instance with the default realm.

### AbstractObservableValue

public AbstractObservableValue(Realm realm)

Parameters:
  `realm` - the realm to use; not `null`

## Method Details

### addValueChangeListener

public void addValueChangeListener(IValueChangeListener<? super T> listener)

Specified by:
  `addValueChangeListener` in interface `IObservableValue<T>`
Parameters:
  `listener` - the change listener to add; not `null`

### removeValueChangeListener

public void removeValueChangeListener(IValueChangeListener<? super T> listener)

Specified by:
  `removeValueChangeListener` in interface `IObservableValue<T>`
Parameters:
  `listener` - the change listener to remove; not `null`

### setValue

public final void setValue(T value)
Description copied from interface: `IObservableValue`
Sets the value. Must be invoked in the `Realm` of the observable.

Specified by:
  `setValue` in interface `IObservableValue<T>`
Parameters:
  `value` - the value to set

### doSetValue

protected void doSetValue(T value)
Template method for setting the value of the observable. By default the method throws an `UnsupportedOperationException`.

Parameters:
  `value` - the value to set

### fireValueChange

protected void fireValueChange(ValueDiff<T> diff)

### getValue

public final T getValue()
Description copied from interface: `IObservableValue`
Returns the value. Must be invoked in the `Realm` of the observable.

Specified by:
  `getValue` in interface `IObservableValue<T>`
Returns:
  the current value

### doGetValue

protected abstract T doGetValue()

### isStale

public boolean isStale()
Description copied from interface: `IObservable`
Returns whether the state of this observable is stale and is expected to change soon. A non-stale observable that becomes stale will notify its stale listeners. A stale object that becomes non-stale does so by changing its state and notifying its change listeners, it does not notify its stale listeners about becoming non-stale. Clients that do not expect asynchronous changes may ignore staleness of observable objects.

Specified by:
  `isStale` in interface `IObservable`
Returns:
  true if this observable's state is stale and will change soon.

### fireChange

protected void fireChange()

Overrides:
  `fireChange` in class `AbstractObservable`

### addListener

protected void addListener(Object listenerType, IObservablesListener listener)

Parameters:
  `listenerType` - arbitrary object to identify a type of the listener
  `listener` - the listener to add; not `null`

### removeListener

protected void removeListener(Object listenerType, IObservablesListener listener)

Parameters:
  `listenerType` - arbitrary object to identify a type of the listener
  `listener` - the listener to remove; not `null`

### hasListeners

protected boolean hasListeners()

### fireEvent

protected void fireEvent(ObservableEvent event)

### firstListenerAdded

protected void firstListenerAdded()

### lastListenerRemoved

protected void lastListenerRemoved()

### getRealm

public Realm getRealm()

Returns:
  Returns the realm.

### clone

protected Object clone() throws CloneNotSupportedException

Overrides:
  `clone` in class `Object`
Throws:
  `CloneNotSupportedException`