edu.washington.cs.sounddetector.server.api
Class MethodResult<T extends Method>

java.lang.Object
  extended by edu.washington.cs.sounddetector.server.api.MethodResult<T>
Direct Known Subclasses:
ClassifyResult, GetOldNotificationsResult, GetPendingNotificationsResult, GetSoundResult, GetSoundsResult, RegisterReceiverPhoneResult, RenameDetectorResult, SetSoundClassPropertiesResult, TrainResult, UnregisterReceiverPhoneResult, UntrainResult

public abstract class MethodResult<T extends Method>
extends Object

A MethodResult represents the response from executing a Method. A MethodResult will provide a method call to obtain the results of the Method. This method will either return the results of the Method or throw a subclass of SoundDetectorAPIException to indicate failure.

More details:

There are two general states a MethodResult can be in: one for if the Method was successful and one for if it was not successful.

If the execution of a Method was successful, then the MethodResult will contain the expected data from running the Method.

On the other hand, if the execution of a Method was unsuccessful, then the MethodResult will contain the reason it was unsuccessful in the form of an SoundDetectorAPIException. This exception will be triggered upon attempted retrieval of the results.

Requirements for subclasses of MethodResult:

  • A getter method which returns the data of the result, or throws an exception(s) to indicate the failure. These exceptions should be subclasses of SoundDetectorAPIException.
  • A static 'successful' method which creates and returns an instance of your class.
  • One or more static 'failure' methods which create and resturn an instance of your class.
  • Author:
    the.dylan.price@gmail.com

    Nested Class Summary
    static class MethodResult.FailureReason
              FailureReason enumerates all the possible reasons the execution of a method could fail.
     
    Constructor Summary
    protected MethodResult(boolean successful, MethodResult.FailureReason reason)
              Constructs a new MethodResult.
     
    Method Summary
     MethodResult.FailureReason getReason()
               
     boolean isSuccessful()
               
     void setReason(MethodResult.FailureReason reason)
               
     void setSuccessful(boolean successful)
               
     String toString()
               
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Constructor Detail

    MethodResult

    protected MethodResult(boolean successful,
                           MethodResult.FailureReason reason)
    Constructs a new MethodResult. All subclasses should call this constructor.

    Parameters:
    successful - whether the method was successful or not
    reason - If successful == true, then this should be null. If successful == false, then this must not be null.
    Method Detail

    isSuccessful

    public boolean isSuccessful()
    Returns:
    the successful

    setSuccessful

    public void setSuccessful(boolean successful)
    Parameters:
    successful - the successful to set

    setReason

    public void setReason(MethodResult.FailureReason reason)
    Parameters:
    reason - the reason to set

    getReason

    public MethodResult.FailureReason getReason()
    Returns:
    if the method failed, then returns the reason it failed. Otherwise returns null.

    toString

    public String toString()
    Overrides:
    toString in class Object


    Copyright © 2012. All Rights Reserved.