com.rubecula.darwin.foundation
Class Best_<T extends ComparableValue>

java.lang.Object
  extended by net.sf.tostring0.AToString
      extended by com.rubecula.darwin.foundation.Best_<T>
Type Parameters:
T - the base type for the best fit
All Implemented Interfaces:
Best<T>, Valuable, net.sf.tostring0.Identifiable, net.sf.tostring0.IToString
Direct Known Subclasses:
Best_Organism

public abstract class Best_<T extends ComparableValue>
extends net.sf.tostring0.AToString
implements Best<T>, Valuable

Class to manage the best fit of something.


Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Fields inherited from interface net.sf.tostring0.IToString
ANGBR_OPEN, ANGBRA_CLSE, BRA_CLSE, BRA_OPEN, BRCE_OPEN, BRCS_CLSE, COLON, LIST_SEPARATOR, MAX_ELEMENTS_DEFAULT, S_MT, S_PERCENT, SEPARATOR, SPACE
 
Constructor Summary
protected Best_(java.lang.String id, java.util.Collection<T> candidates, ProcessBest<T> processor)
          Construct the Best_ object based on the identifier id, and get the best value for the given candidates, using the processor if not-null.
protected Best_(java.lang.String id, int convergence)
           
protected Best_(java.lang.String id, ProcessBest<T> processor)
           
protected Best_(java.lang.String id, ProcessBest<T> processor, int convergence)
           
protected Best_(java.lang.String id, T best, ProcessBest<T> processor, int convergence)
           
 
Method Summary
protected  int getConvergence()
           
 java.lang.String getIdentifier()
           
 T getObject()
           
 ProcessBest<T> getProcessor()
           
 java.lang.Number getValue()
          Get the value which we can use to compare this object with other Valuable objects, for example in conjunction with Best interface.
protected abstract  boolean isUnique(T candidate)
           
 void reset()
          Reset this Best object as if it had been newly constructed.
protected  void setConvergence(int convergence)
           
protected  void setObject(T object)
          Sets the object AND resets the count value.
 boolean update(java.util.Collection<T> candidates)
          This method loops through each element of candidates and calls updateInternal(ComparableValue, boolean) for each candidate.
 boolean update(T candidate, boolean override)
          Method to conditionally update the best value.
 
Methods inherited from class net.sf.tostring0.AToString
toString, toString, toStringBrief, toStringId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Constructor Detail

Best_

protected Best_(java.lang.String id,
                java.util.Collection<T> candidates,
                ProcessBest<T> processor)
         throws ValueException
Construct the Best_ object based on the identifier id, and get the best value for the given candidates, using the processor if not-null.

Parameters:
id -
candidates -
processor -
Throws:
ValueException

Best_

protected Best_(java.lang.String id,
                int convergence)
Parameters:
id - the description of this "best" object
convergence - XXX

Best_

protected Best_(java.lang.String id,
                ProcessBest<T> processor)
Parameters:
id - the description of this "best" object
processor -

Best_

protected Best_(java.lang.String id,
                ProcessBest<T> processor,
                int convergence)
Parameters:
id - the description of this "best" object
processor -
convergence - XXX

Best_

protected Best_(java.lang.String id,
                T best,
                ProcessBest<T> processor,
                int convergence)
Parameters:
id - the description of this "best" object
best -
processor - the object which will process each new best object when an update occurs.
convergence - XXX
Method Detail

getIdentifier

public java.lang.String getIdentifier()
Specified by:
getIdentifier in interface net.sf.tostring0.Identifiable
See Also:
Identifiable.getIdentifier()

getObject

public T getObject()
Specified by:
getObject in interface Best<T extends ComparableValue>
Returns:
the object which has the best value.
See Also:
XXX note that we must include this method explicitly because its generic return type means it doesn't match as a bean method.

getProcessor

public ProcessBest<T> getProcessor()
Specified by:
getProcessor in interface Best<T extends ComparableValue>
Returns:
the processor

getValue

public java.lang.Number getValue()
                          throws ValueException
Description copied from interface: Valuable
Get the value which we can use to compare this object with other Valuable objects, for example in conjunction with Best interface. NOTE: that this method gets called a lot. Therefore, if invoking it requires a significant amount of work, the Valuable implementation should consider caching the value.

Specified by:
getValue in interface Valuable
Returns:
the value for this object which will be used to determine which is the "best".
Throws:
ValueException - which will in practice never be thrown by this method (since we do not crown invalid candidates as best).
See Also:
Valuable.getValue()

reset

public void reset()
Description copied from interface: Best
Reset this Best object as if it had been newly constructed.

Specified by:
reset in interface Best<T extends ComparableValue>
See Also:
Best.reset()

update

public boolean update(java.util.Collection<T> candidates)
               throws ValueException
This method loops through each element of candidates and calls updateInternal(ComparableValue, boolean) for each candidate. On an update, and provided that value of _processor is not null, we invoke _processor with the new best object and best value. Note that we do not really need to deal with convergence here, because we are processing an entire collection. It doesn't therefore matter much when the processor is actually triggered because it will be done internally while this method is in play. However, in fact, convergence is dealt with appropriately (assuming that convergence is greater than zero. If it's zero, then the whole notion of convergence is moot.

Specified by:
update in interface Best<T extends ComparableValue>
Parameters:
candidates -
Returns:
true if we actually did update the best value (i.e. candidates was not empty).
Throws:
ValueException

update

public boolean update(T candidate,
                      boolean override)
               throws ValueException
Description copied from interface: Best
Method to conditionally update the best value.

Specified by:
update in interface Best<T extends ComparableValue>
Parameters:
candidate - XXX
override - if true, then we consider convergence to be true even if the count has not been reached.
Returns:
true if we have accepted and processed the new candidate
Throws:
ValueException

getConvergence

protected int getConvergence()
Returns:
the convergence

isUnique

protected abstract boolean isUnique(T candidate)

setConvergence

protected void setConvergence(int convergence)
Parameters:
convergence - the convergence to set

setObject

protected void setObject(T object)
Sets the object AND resets the count value.

Parameters:
object - the object to set


Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.