Example usage for org.apache.commons.lang3.tuple Triple of

List of usage examples for org.apache.commons.lang3.tuple Triple of

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Triple of.

Prototype

public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right) 

Source Link

Document

Obtains an immutable triple of from three objects inferring the generic types.

This factory allows the triple to be created using inference to obtain the generic types.

Usage

From source file:at.gridtec.lambda4j.function.tri.TriBooleanFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriBooleanFunction}. Whenever it is called, the mapping
 * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the
 * memoized value instead of computing the return value again.
 * <p>//from  ww w .  ja  v  a2  s  .  co  m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriBooleanFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriBooleanFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Boolean, Boolean, Boolean>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriBooleanFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriIntFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriIntFunction}. Whenever it is called, the mapping between
 * the input parameters and the return value is preserved in a cache, making subsequent calls returning the memoized
 * value instead of computing the return value again.
 * <p>//from   w w  w.jav  a  2 s  .co  m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriIntFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriIntFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Integer, Integer, Integer>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriIntFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriLongFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriLongFunction}. Whenever it is called, the mapping between
 * the input parameters and the return value is preserved in a cache, making subsequent calls returning the memoized
 * value instead of computing the return value again.
 * <p>// www  . j a v a 2  s.c o m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriLongFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriLongFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Long, Long, Long>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriLongFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriByteFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriByteFunction}. Whenever it is called, the mapping between
 * the input parameters and the return value is preserved in a cache, making subsequent calls returning the memoized
 * value instead of computing the return value again.
 * <p>// w w  w.j  a v  a 2s  . c o m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriByteFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriByteFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Byte, Byte, Byte>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriByteFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriCharFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriCharFunction}. Whenever it is called, the mapping between
 * the input parameters and the return value is preserved in a cache, making subsequent calls returning the memoized
 * value instead of computing the return value again.
 * <p>// w  w w. j ava 2  s .com
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriCharFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriCharFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Character, Character, Character>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriCharFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriFloatFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriFloatFunction}. Whenever it is called, the mapping between
 * the input parameters and the return value is preserved in a cache, making subsequent calls returning the memoized
 * value instead of computing the return value again.
 * <p>// w w  w .  j  a v  a2s .  c  o m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriFloatFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriFloatFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Float, Float, Float>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriFloatFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriShortFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriShortFunction}. Whenever it is called, the mapping between
 * the input parameters and the return value is preserved in a cache, making subsequent calls returning the memoized
 * value instead of computing the return value again.
 * <p>/*from  w  w  w .j a va2  s .c  o  m*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriShortFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriShortFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Short, Short, Short>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriShortFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.TriDoubleFunction.java

/**
 * Returns a memoized (caching) version of this {@link TriDoubleFunction}. Whenever it is called, the mapping
 * between the input parameters and the return value is preserved in a cache, making subsequent calls returning the
 * memoized value instead of computing the return value again.
 * <p>/* ww  w  .jav  a 2s .co m*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code TriDoubleFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default TriDoubleFunction<R> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<Double, Double, Double>, R> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (TriDoubleFunction<R> & Memoized) (value1, value2, value3) -> {
            final R returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3),
                        key -> apply(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:com.formkiq.core.service.workflow.WorkflowServiceImplTest.java

/**
 * testStartSigning01()./*from w w w .j ava 2s.c  o  m*/
 * @throws IOException IOException
 */
@Test
public void testStartSigning01() throws IOException {
    // given
    final int sigId = 8;
    FormJSON allfields = TestDataBuilder.createAllFields();
    FormJSONField field = findField(allfields, sigId).get();
    assertEquals(FormJSONFieldType.SIGNATURE, field.getType());

    Map<String, FormJSON> formsMap = ImmutableMap.of("k1", allfields);
    String document = UUID.randomUUID().toString();
    String stoken = UUID.randomUUID().toString();

    // when
    expect(this.signingService.findAssets(document, stoken))
            .andReturn(Triple.of(this.docmsg, this.archive, this.queueMessage));
    expect(this.archive.getForms()).andReturn(formsMap);
    expect(this.docmsg.getFolderid()).andReturn(this.folder);

    replayAll();
    Pair<ModelAndView, WebFlow> result = this.ws.startSigning(this.req, document, stoken);

    // then
    verifyAll();

    final int numberOfStates = 3;
    assertEquals("redirect:/flow/workflow?execution=s1e1", result.getLeft().getViewName());

    WebFlow flow = result.getRight();
    assertEquals(numberOfStates, flow.getStates().size());
    assertEquals("flow/summary", flow.getCurrentState().getViewName());
    assertEquals(Boolean.TRUE, flow.getCurrentState().getParameter("geoLocation"));
    assertEquals(this.docmsg, flow.getParameter("docsignmsg"));
    assertEquals(FormJSONRequiredType.IMMEDIATE, field.getRequired());
}

From source file:alfio.controller.api.admin.EventApiController.java

@RequestMapping(value = "/events/{eventName}/pending-payments/bulk-confirmation", method = POST)
public List<Triple<Boolean, String, String>> bulkConfirmation(@PathVariable("eventName") String eventName,
        Principal principal, @RequestBody UploadBase64FileModification file) throws IOException {

    try (InputStreamReader isr = new InputStreamReader(file.getInputStream());
            CSVReader reader = new CSVReader(isr)) {
        Event event = loadEvent(eventName, principal);
        return reader.readAll().stream().map(line -> {
            String reservationID = null;
            try {
                Validate.isTrue(line.length >= 2);
                reservationID = line[0];
                ticketReservationManager.validateAndConfirmOfflinePayment(reservationID, event,
                        new BigDecimal(line[1]), principal.getName());
                return Triple.of(Boolean.TRUE, reservationID, "");
            } catch (Exception e) {
                return Triple.of(Boolean.FALSE, Optional.ofNullable(reservationID).orElse(""), e.getMessage());
            }/*from   w w  w . j  a v a  2  s  .com*/
        }).collect(toList());
    }
}