/** Returns try if this is a failed try, false if it is a successful try. */ public boolean isFailure () { return !isSuccess(); }
public Try<R> apply (Try<T> result) { return result.map(func); } };
/** * Loads a JSON encoded library synchronously. * @param baseDir The base directory, containing library.json and texture atlases. */ public static Library loadLibrarySync (final Platform plat, String baseDir) throws Exception { final ImageLoader syncLoader = new ImageLoader() { @Override public Image load (String path) { return plat.assets().getImageSync(path); } }; String text = plat.assets().getTextSync(baseDir + "/library.json"); Try<Library> result = decodeLibrary(plat.json().parse(text), baseDir, syncLoader).result(); if (result.isSuccess()) return result.get(); Throwable error = result.getFailure(); if (error instanceof Exception) throw (Exception)error; else throw new RuntimeException(error); }
/** Causes this promise to be completed successfully with {@code value}. */ public void succeed (T value) { complete(Try.success(value)); }
/** Returns a future with a pre-existing failure value. */ public static <T> RFuture<T> failure (Throwable cause) { return result(Try.<T>failure(cause)); }
/** Maps the value of a successful result using {@code func} upon arrival. */ public <R> RFuture<R> map (final Function<? super T, R> func) { Object sigh = Try.lift(func); @SuppressWarnings("unchecked") Function<Try<? super T>,Try<R>> lifted = (Function<Try<? super T>,Try<R>>)sigh; return transform(lifted); }
/** Returns a future with a pre-existing success value. */ public static <T> RFuture<T> success (T value) { return result(Try.success(value)); }
/** Causes this promise to be completed with failure caused by {@code cause}. */ public void fail (Throwable cause) { complete(Try.<T>failure(cause)); }
/** Maps the value of a successful result using {@code func} upon arrival. */ public <R> RFuture<R> map (final Function<? super T, R> func) { Object sigh = Try.lift(func); @SuppressWarnings("unchecked") Function<Try<? super T>,Try<R>> lifted = (Function<Try<? super T>,Try<R>>)sigh; return transform(lifted); }
/** Returns try if this is a failed try, false if it is a successful try. */ public boolean isFailure () { return !isSuccess(); }
/** Returns a future with a pre-existing success value. */ public static <T> RFuture<T> success (T value) { return result(Try.success(value)); }
/** Returns a future with a pre-existing failure value. */ public static <T> RFuture<T> failure (Throwable cause) { return result(Try.<T>failure(cause)); }
public Try<R> apply (Try<T> result) { return result.map(func); } };
/** * Returns whether this image is successfully loaded. If it is still loading, or loading failed, * {@code false} will be returned. In general you'll want to react to {@link #state}, but this * method is useful when you need to assert that something is only allowed on a fully loaded * image. */ public boolean isLoaded () { Try<Image> cur = state.result(); return cur != null && cur.isSuccess(); }
/** Causes this promise to be completed successfully with {@code value}. */ public void succeed (T value) { complete(Try.success(value)); }
/** Causes this promise to be completed with failure caused by {@code cause}. */ public void fail (Throwable cause) { complete(Try.<T>failure(cause)); }
/** * Returns whether this image is successfully loaded. If it is still loading, or loading failed, * {@code false} will be returned. In general you'll want to react to {@link #state}, but this * method is useful when you need to assert that something is only allowed on a fully loaded * image. */ public boolean isLoaded () { Try<Image> cur = state.result(); return cur != null && cur.isSuccess(); }