All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.client.SphereResultRaw Maven / Gradle / Ivy

package io.sphere.sdk.client;

import com.google.common.base.Function;
import io.sphere.sdk.utils.Validation;

import javax.annotation.Nonnull;

final class SphereResultRaw extends Validation {

    //TODO make private?
    public SphereResultRaw(T value, SphereBackendException exception) {
        super(value, exception);
    }

    /**
     * Creates a new erroneous result.
     */
    public static  SphereResultRaw error(SphereBackendException exception) {
        return new SphereResultRaw<>(null, exception);
    }

    @Override
    public T getValue() {
        if (!isSuccess()) throw getError();
        return super.getValue();
    }

    /**
     * If successful, transforms the success value. Otherwise does nothing.
     */
    public  SphereResultRaw transform(@Nonnull Function successFunc) {
        return isSuccess() ?
                new SphereResultRaw<>(successFunc.apply(getValue()), null) :
                SphereResultRaw.error(getError());
    }

    @Override
    public String toString() {
        return this.getClass().getCanonicalName() + "{" + super.toString() + "}";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy