do not read stored objects on every get method call

This commit is contained in:
Sebastian Sdorra
2012-05-19 11:02:50 +02:00
parent caa0206202
commit a8d5e677de
3 changed files with 75 additions and 23 deletions

View File

@@ -52,6 +52,22 @@ import java.util.Set;
public abstract class AbstractListenableStore<T> implements ListenableStore<T>
{
/**
* Method description
*
*
* @return
*/
protected abstract T readObject();
/**
* Method description
*
*
* @param object
*/
protected abstract void writeObject(T object);
/**
* Method description
*
@@ -88,6 +104,43 @@ public abstract class AbstractListenableStore<T> implements ListenableStore<T>
listeners.remove(listener);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public T get()
{
if (storeObject == null)
{
storeObject = readObject();
}
return storeObject;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param obejct
*/
@Override
public void set(T obejct)
{
writeObject(obejct);
this.storeObject = obejct;
fireEvent(obejct);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -105,5 +158,8 @@ public abstract class AbstractListenableStore<T> implements ListenableStore<T>
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<ConfigChangedListener<T>> listeners = Sets.newHashSet();
protected Set<ConfigChangedListener<T>> listeners = Sets.newHashSet();
/** Field description */
protected T storeObject;
}