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

java.lang.Object
  extended by com.atlassian.greenhopper.service.ServiceOutcomeImpl<T>
All Implemented Interfaces:
com.atlassian.fugue.Effect.Applicant<T>, 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

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.
<A> ServiceOutcome<A>
flatMap(com.google.common.base.Function<? super T,ServiceOutcome<A>> func)
           
 void foreach(com.atlassian.fugue.Effect<T> visitor)
           
static
<T> ServiceOutcomeImpl<T>
from(ErrorCollection errors)
          Convenience method that returns a new ServiceOutcomeImpl containing the given errors.
static
<T> ServiceOutcomeImpl<T>
from(com.atlassian.jira.util.ErrorCollection jiraErrors)
          Convenience method that returns a new ServiceOutcomeImpl containing the given errors.
static
<T> ServiceOutcomeImpl<T>
from(com.atlassian.jira.util.ErrorCollection jiraErrors, ErrorCollection.Reason reason)
          Convenience method that returns a new ServiceOutcomeImpl containing the given errors.
static
<T> ServiceOutcomeImpl<T>
from(ErrorCollection errors, 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 isInvalid()
           
 boolean isValid()
           
<A> ServiceOutcome<A>
map(com.google.common.base.Function<? super T,A> func)
           
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.
 com.atlassian.fugue.Either<ErrorCollection,com.atlassian.fugue.Option<T>> toEither()
           
 com.atlassian.fugue.Option<T> toOption()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:
Void - 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 errors)
Convenience method that returns a new ServiceOutcomeImpl containing the given errors.

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

from

public static <T> ServiceOutcomeImpl<T> from(com.atlassian.jira.util.ErrorCollection jiraErrors)
Convenience method that returns a new ServiceOutcomeImpl containing the given errors.

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

from

public static <T> ServiceOutcomeImpl<T> from(com.atlassian.jira.util.ErrorCollection jiraErrors,
                                             ErrorCollection.Reason reason)
Convenience method that returns a new ServiceOutcomeImpl containing the given errors.

Type Parameters:
T - the type of the returned value
Parameters:
jiraErrors - a JIRA ErrorCollection
reason - the reason for the errors
Returns:
a new ServiceOutcomeImpl instance

from

public static <T> ServiceOutcomeImpl<T> from(ErrorCollection errors,
                                             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:
errors - 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.

isInvalid

public boolean isInvalid()
Specified by:
isInvalid in interface ServiceOutcome<T>

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

toOption

public com.atlassian.fugue.Option<T> toOption()
Specified by:
toOption in interface ServiceOutcome<T>

toEither

public com.atlassian.fugue.Either<ErrorCollection,com.atlassian.fugue.Option<T>> toEither()
Specified by:
toEither in interface ServiceOutcome<T>

foreach

public void foreach(com.atlassian.fugue.Effect<T> visitor)
Specified by:
foreach in interface com.atlassian.fugue.Effect.Applicant<T>

map

public <A> ServiceOutcome<A> map(com.google.common.base.Function<? super T,A> func)
Specified by:
map in interface ServiceOutcome<T>
Type Parameters:
A - the type of the ServiceOutcome
Parameters:
func - a function which takes a instance of type T and returns an instance of type A
Returns:
a new service outcome based on the output of func

flatMap

public <A> ServiceOutcome<A> flatMap(com.google.common.base.Function<? super T,ServiceOutcome<A>> func)
Specified by:
flatMap in interface ServiceOutcome<T>
Type Parameters:
A - the type of the ServiceOutcome
Parameters:
func - a function which takes a instance of type T and returns a ServiceOutcome of type A
Returns:
a new service outcome based on the output of func


Copyright © 2007-2013 Atlassian. All Rights Reserved.