# Class PreferenceMemento

java.lang.Object
org.eclipse.jface.preference.PreferenceMemento

public class PreferenceMemento extends Object
A utility to change and remember preference values and later restore there original value. The first time a preference value is changed its current value is stored. Later you can reset all preference values (which are changed through this class) to the state they had when creating the memento.

This class is most useful for testing to prevent leakage of preference changes between individual tests.

Since:
  3.18

## Constructor Summary

Constructors
Constructor
Description
`PreferenceMemento()`

## Method Summary

Modifier and Type
Method
Description
`void`
`resetPreferences()`
Reset every preference changed by this utility to its state before the first change.
`<T> void`
`setValue(IPreferenceStore store, String name, T value)`
Set the value for the given preference on the given store.

### Methods inherited from class Object

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

## Constructor Details

### PreferenceMemento

public PreferenceMemento()

## Method Details

### setValue

public <T> void setValue(IPreferenceStore store, String name, T value)
Set the value for the given preference on the given store.

The first time this preference is changed its value before change is remembered and can later be restored using `resetPreferences()`.

Type Parameters:
  `T` - the preference value type. The type must have a corresponding `IPreferenceStore` setter.
Parameters:
  `store` - the preference store to manipulate (not `null`)
  `name` - the name of the preference (not `null`)
  `value` - the new current value of the preference.
Throws:
  `IllegalArgumentException` - when setting a type which is not supported by `IPreferenceStore`
See Also:
  - `IPreferenceStore.setValue(String, double)`
  - `IPreferenceStore.setValue(String, float)`
  - `IPreferenceStore.setValue(String, int)`
  - `IPreferenceStore.setValue(String, long)`
  - `IPreferenceStore.setValue(String, boolean)`
  - `IPreferenceStore.setValue(String, String)`
  - `resetPreferences()`

### resetPreferences

public void resetPreferences()
Reset every preference changed by this utility to its state before the first change. After this the instance can still be used as if it was just created.