org.apache.mahout.cf.taste.impl.common
Class RefreshHelper

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.common.RefreshHelper
All Implemented Interfaces:
Refreshable

public final class RefreshHelper
extends Object
implements Refreshable

A helper class for implementing Refreshable. This object is typically included in an implementation Refreshable to implement Refreshable.refresh(Collection). It execute the class's own supplied update logic, after updating all the object's dependencies. This also ensures that dependencies are not updated multiple times.


Constructor Summary
RefreshHelper(Callable<?> refreshRunnable)
           
 
Method Summary
 void addDependency(Refreshable refreshable)
          Add a dependency to be refreshed first when the encapsulating object does.
static Collection<Refreshable> buildRefreshed(Collection<Refreshable> currentAlreadyRefreshed)
          Creates a new and empty Collection if the method parameter is null.
static void maybeRefresh(Collection<Refreshable> alreadyRefreshed, Refreshable refreshable)
          Adds the specified Refreshable to the given collection of Refreshables if it is not already there and immediately refreshes it.
 void refresh(Collection<Refreshable> alreadyRefreshed)
          Typically this is called in Refreshable.refresh(java.util.Collection) and is the entire body of that method.
 void removeDependency(Refreshable refreshable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RefreshHelper

public RefreshHelper(Callable<?> refreshRunnable)
Parameters:
refreshRunnable - encapsulates the containing object's own refresh logic
Method Detail

addDependency

public void addDependency(Refreshable refreshable)
Add a dependency to be refreshed first when the encapsulating object does.


removeDependency

public void removeDependency(Refreshable refreshable)

refresh

public void refresh(Collection<Refreshable> alreadyRefreshed)
Typically this is called in Refreshable.refresh(java.util.Collection) and is the entire body of that method.

Specified by:
refresh in interface Refreshable
Parameters:
alreadyRefreshed - Refreshables that are known to have already been refreshed as a result of an initial call to a Refreshable.refresh(Collection) method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.

buildRefreshed

public static Collection<Refreshable> buildRefreshed(Collection<Refreshable> currentAlreadyRefreshed)
Creates a new and empty Collection if the method parameter is null.

Parameters:
currentAlreadyRefreshed - Refreshables to refresh later on
Returns:
an empty Collection if the method param was null or the unmodified method param.

maybeRefresh

public static void maybeRefresh(Collection<Refreshable> alreadyRefreshed,
                                Refreshable refreshable)
Adds the specified Refreshable to the given collection of Refreshables if it is not already there and immediately refreshes it.

Parameters:
alreadyRefreshed - the collection of Refreshables
refreshable - the Refreshable to potentially add and refresh


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.