Пример #1
0
 /**
  * Invariant functor map over this enumerator.
  *
  * @param f The covariant map.
  * @param g The contra-variant map.
  * @return An enumerator after the given functions are applied.
  */
 public <B> Enumerator<B> xmap(final F<A, B> f, final F<B, A> g) {
   final F<Option<A>, Option<B>> of = o -> o.map(f);
   return enumerator(
       compose(compose(of, successor), g),
       compose(compose(of, predecessor), g),
       max.map(f),
       min.map(f),
       order.contramap(g),
       compose(compose(Function.<Long, Option<A>, Option<B>>compose().f(of), plus), g));
 }
Пример #2
0
  @Path("/events/{eventName}/icons/labels/{label}.png")
  @GET
  @Produces("image/png")
  public Response getLabelIcon(
      @PathParam("eventName") final String eventName, @PathParam("label") final String label) {
    OperationResult<Event> eventResult = incogito.getEventByName(eventName);

    if (!eventResult.isOk()) {
      return toJsr311(eventResult);
    }

    Option<File> fileOption = eventResult.value().labelMap.get(label).map(Label.iconFile_);

    if (!fileOption.isSome()) {
      return toJsr311(OperationResult.<Object>notFound("No icon for label '" + label + "'."));
    }

    // TODO: How about some caching here?

    Option<byte[]> bytes =
        join(
            fileOption
                .map(IO.<byte[]>runFileInputStream_().f(IO.ByteArrays.streamToByteArray))
                .map(compose(P1.<Option<byte[]>>__1(), Callables.<byte[]>option())));

    return toJsr311(fromOption(bytes, "Unable to read label file."), cacheForOneHourCacheControl);
  }
 public String toString() {
   return "user="******"<not set>")
       + ", "
       + "group="
       + group.orSome("<not set>")
       + ", "
       + "mode="
       + mode.map(showLong).orSome("<not set>");
 }