com.atlassian.greenhopper.service
Class ServiceOutcomeImpl<T>

java.lang.Object
  extended by com.atlassian.greenhopper.service.ServiceOutcomeImpl<T>
All Implemented Interfaces:
ServiceOutcome<T>

public class ServiceOutcomeImpl<T>
extends java.lang.Object
implements ServiceOutcome<T>

Generic service outcome that can optionally hold a value.

Since:
v5.8.5

Constructor Summary
ServiceOutcomeImpl(ErrorCollection errorCollection)
          Creates a new ServiceOutcomeImpl with the given errors.
ServiceOutcomeImpl(ErrorCollection errorCollection, T value)
          Creates a new ServiceOutcomeImpl with the given errors and returned value.
 
Method Summary
static
<T> ServiceOutcomeImpl<T>
error(ErrorCollection.Reason reason, java.lang.String messageKey, java.lang.Object... params)
          Convenience method that returns a new ServiceOutcomeImpl instance containing the provided error message, and no return value.
static
<T> ServiceOutcomeImpl<T>
error(ServiceOutcome<?> outcome)
          Convenience method that returns a new ServiceOutcomeImpl containing the given errors.
static
<T> ServiceOutcomeImpl<T>
error(java.lang.String contextId, ErrorCollection.Reason reason, java.lang.String messageKey, java.lang.Object... params)
          Convenience method that returns a new ServiceOutcomeImpl instance containing the provided contextual error message, and no return value.
static
<T> ServiceOutcomeImpl<T>
from(ErrorCollection errorCollection)
          Convenience method that returns a new ServiceOutcomeImpl containing the given errors.
static
<T> ServiceOutcomeImpl<T>
from(ErrorCollection errorCollection, T value)
          Convenience method that returns a new ServiceOutcomeImpl containing the given errors and returned value.
 ErrorCollection getErrors()
           
 T getValue()
          Returns the value that was returned by the service, or null.
 boolean isValid()
           
static
<Void> ServiceOutcomeImpl<Void>
ok()
          Convenience method that returns a new ServiceOutcomeImpl instance containing no errors, and with the provided returned value.
static
<T> ServiceOutcomeImpl<T>
ok(T returnedValue)
          Convenience method that returns a new ServiceOutcomeImpl instance containing no errors, and with the provided returned value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceOutcomeImpl

public ServiceOutcomeImpl(ErrorCollection errorCollection)
Creates a new ServiceOutcomeImpl with the given errors. The returned value will be set to null.

Parameters:
errorCollection - an ErrorCollection

ServiceOutcomeImpl

public ServiceOutcomeImpl(ErrorCollection errorCollection,
                          T value)
Creates a new ServiceOutcomeImpl with the given errors and returned value.

Parameters:
errorCollection - an ErrorCollection
value - the wrapped value
Method Detail

ok

public static <T> ServiceOutcomeImpl<T> ok(T returnedValue)
Convenience method that returns a new ServiceOutcomeImpl instance containing no errors, and with the provided returned value.

Type Parameters:
T - the type of the returned value
Parameters:
returnedValue - the returned value
Returns:
a new ServiceOutcomeImpl

ok

public static <Void> ServiceOutcomeImpl<Void> ok()
Convenience method that returns a new ServiceOutcomeImpl instance containing no errors, and with the provided returned value.

Type Parameters:
T - the type of the returned value
Returns:
a new ServiceOutcomeImpl

error

public static <T> ServiceOutcomeImpl<T> error(ErrorCollection.Reason reason,
                                              java.lang.String messageKey,
                                              java.lang.Object... params)
Convenience method that returns a new ServiceOutcomeImpl instance containing the provided error message, and no return value.

Parameters:
reason - the reason for the error
messageKey - the key of the message
params - the parameters to the key
Returns:
a new ServiceOutcomeImpl

error

public static <T> ServiceOutcomeImpl<T> error(java.lang.String contextId,
                                              ErrorCollection.Reason reason,
                                              java.lang.String messageKey,
                                              java.lang.Object... params)
Convenience method that returns a new ServiceOutcomeImpl instance containing the provided contextual error message, and no return value.

Parameters:
contextId - context of the error
reason - the reason for the error
messageKey - the key of the message
params - the parameters to the key
Returns:
a new ServiceOutcomeImpl

error

public static <T> ServiceOutcomeImpl<T> error(ServiceOutcome<?> outcome)
Convenience method that returns a new ServiceOutcomeImpl containing the given errors.


from

public static <T> ServiceOutcomeImpl<T> from(ErrorCollection errorCollection)
Convenience method that returns a new ServiceOutcomeImpl containing the given errors.

Type Parameters:
T - the type of the returned value
Parameters:
errorCollection - an ErrorCollection
Returns:
a new ServiceOutcomeImpl instance

from

public static <T> ServiceOutcomeImpl<T> from(ErrorCollection errorCollection,
                                             T value)
Convenience method that returns a new ServiceOutcomeImpl containing the given errors and returned value.

Type Parameters:
T - the type of the returned value
Parameters:
errorCollection - an ErrorCollection
value - the returned value
Returns:
a new ServiceOutcomeImpl instance

isValid

public boolean isValid()
Specified by:
isValid in interface ServiceOutcome<T>
Returns:
true if there are no errors, false otherwise.

getErrors

public ErrorCollection getErrors()
Specified by:
getErrors in interface ServiceOutcome<T>
Returns:
an ErrorCollection that contains any errors that may have happened as a result of the validations.

getValue

public T getValue()
Returns the value that was returned by the service, or null.

Specified by:
getValue in interface ServiceOutcome<T>
Returns:
the value returned by the service, or null


Copyright © 2007-2012 Atlassian. All Rights Reserved.