@Override public Function<A, B> apply(Function<A, ? extends B> f) { return co(f); } };
/** * Identity function. The type is based on the type of the example object to save some nasty typing, e.g. * <code>Function.<Integer>identity()</code> vs. <code>identity(0)</code> * * Please note that this constructor is only due to Java's insufficient type inference. */ public static <A> Function<A, A> identity(A example) { return identity(); }
/** * Throw a checked exception like a RuntimeException removing any needs to declare a throws clause. * * This technique has been described by James Iry at * http://james-iry.blogspot.de/2010/08/on-removing-java-checked-exceptions-by.html */ public static <A> A chuck(Throwable t) { return Functions.<RuntimeException, A> castGeneric(t); }
@Override protected final void run(A a, B b) { try { xrun(a, b); } catch (Exception e) { chuck(e); } }
/** Currying. */ public Function0<B> curry(final A a) { return Functions.curry(this, a); }
/** Function composition. <code>g.o(f).apply(x) == g(f(x))</code> */ public <C> Function<C, B> o(final Function<? super C, ? extends A> f) { return Functions.o(this, f); }
/** @see Functions#handle(Function, Function) */ public Function<A, B> handle(final Function<? super Exception, B> handler) { return Functions.handle(this, handler); }
/** Argument flipping. */ public Function2<B, A, C> flip() { return Functions.flip(this); }
/** @see Functions#rethrow(Function, Function) */ public Function<A, B> rethrow(final Function<? super Exception, ? extends Exception> transformer) { return Functions.rethrow(this, transformer); }
/** @see Functions#either(Function, Function) */ public <X> Function<A, Either<X, B>> either(final Function<Exception, X> handler) { return Functions.either(this, handler); }
@Override protected void run(A a) { try { xrun(a); } catch (Exception e) { chuck(e); } }
/** Currying. */ public Function<B, C> curry(final A a) { return Functions.curry(this, a); }
/** Function composition. <code>g.o(f).apply() == g(f())</code> */ public Function0<B> o(final Function0<? extends A> f) { return Functions.o(this, f); }
/** * Identity function. * * @param clazz * to describe the functions's type */ public static <A> Function<A, A> identity(Class<A> clazz) { return identity(); }
@GET // path prefix "bundles" is contained here and not in the path annotation of the class // See https://opencast.jira.com/browse/MH-9768 @Path("bundles/list") @Produces(APPLICATION_JSON) @RestQuery( name = "list", description = "Return a list of all running bundles on the whole cluster.", reponses = { @RestResponse(description = "A list of bundles.", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The search results, expressed as xml or json.") public Response getVersions() { final Monadics.ListMonadic<Jsons.Val> bundleInfos = mlist(getDb().getBundles()).map( Functions.<BundleInfo, Jsons.Val> co(bundleInfo)); return ok(obj(p("bundleInfos", arr(bundleInfos)), p("count", bundleInfos.value().size()))); }
@Override protected final void run() { try { xrun(); } catch (Exception e) { chuck(e); } }
/** Currying. (a, b) -> c => a -> b -> c */ public Function<A, Function<B, C>> curry() { return Functions.curry(this); }
/** m (m a) -> m a */ public static <A> Option<A> join(Option<Option<A>> a) { return a.bind(Functions.<Option<A>> identity()); }
@Override public Response apply(List<BundleInfo> infos) { final Set<BundleVersion> versions = set(); for (BundleInfo bundle : infos) { versions.add(bundle.getVersion()); } final BundleInfo example = infos.get(0); switch (versions.size()) { case 0: // no versions... throw new Error("bug"); case 1: // all versions align return ok(obj(p("consistent", true)).append(fullVersionJson.apply(example.getVersion()))); default: // multiple versions found return ok(obj(p("consistent", false), p("versions", arr(mlist(versions.iterator()) .map(Functions.<BundleVersion, Jsons.Val> co(fullVersionJson)))))); } } });
@Override public B apply(A a) { try { return f.apply(a); } catch (Exception e) { return chuck(transformer.apply(e)); } } };