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:alfio.controller.api.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, @RequestParam("file") MultipartFile file) throws IOException {

    try (InputStreamReader isr = new InputStreamReader(file.getInputStream())) {
        CSVReader reader = new CSVReader(isr);
        String username = principal.getName();
        return reader.readAll().stream().map(line -> {
            String reservationID = null;
            try {
                Validate.isTrue(line.length >= 2);
                reservationID = line[0];
                eventManager.confirmPayment(eventName, reservationID, new BigDecimal(line[1]), username);
                return Triple.of(Boolean.TRUE, reservationID, "");
            } catch (Exception e) {
                return Triple.of(Boolean.FALSE, Optional.ofNullable(reservationID).orElse(""), e.getMessage());
            }//from   ww  w.  j av a 2s . c om
        }).collect(Collectors.toList());
    }
}

From source file:com.microsoft.azure.management.containerinstance.implementation.ContainerGroupImpl.java

private Observable<Triple<String, String, String>> createSingleFileShareAsync(final CloudFileClient client,
        final String volumeName, final String fileShareName, final String storageAccountKey) {
    return Observable.fromCallable(new Callable<Triple<String, String, String>>() {
        @Override/*  w  w w  .ja  v a 2 s  .  c o m*/
        public Triple<String, String, String> call() throws Exception {
            CloudFileShare cloudFileShare = client.getShareReference(fileShareName);
            cloudFileShare.createIfNotExists();

            return Triple.of(volumeName, fileShareName, storageAccountKey);
        }
    });
}

From source file:alfio.controller.api.support.TicketHelper.java

private Triple<ValidationResult, Event, Ticket> assignTicket(UpdateTicketOwnerForm updateTicketOwner,
        Optional<Errors> bindingResult, HttpServletRequest request, Optional<UserDetails> userDetails,
        Triple<Event, TicketReservation, Ticket> result) {
    Ticket t = result.getRight();//from  w ww . j  a  va 2  s  . c o m
    final Event event = result.getLeft();
    if (t.getLockedAssignment()) {
        //in case of locked assignment, fullName and Email will be overwritten
        updateTicketOwner.setFirstName(t.getFirstName());
        updateTicketOwner.setLastName(t.getLastName());
        updateTicketOwner.setFullName(t.getFullName());
        updateTicketOwner.setEmail(t.getEmail());
    }

    final TicketReservation ticketReservation = result.getMiddle();
    List<TicketFieldConfiguration> fieldConf = ticketFieldRepository
            .findAdditionalFieldsForEvent(event.getId());
    ValidationResult validationResult = Validator
            .validateTicketAssignment(updateTicketOwner, fieldConf, bindingResult, event)
            .ifSuccess(() -> updateTicketOwner(updateTicketOwner, request, t, event, ticketReservation,
                    userDetails));
    return Triple.of(validationResult, event, ticketRepository.findByUUID(t.getUuid()));
}

From source file:com.yahoo.elide.security.executors.ActivePermissionExecutor.java

/**
 * Check strictly user permissions on a specific field and entity.
 *
 * @param <A> type parameter/*from w  w  w.ja v  a  2  s  .  c  om*/
 * @param resource Resource
 * @param annotationClass Annotation class
 * @param field Field
 */
@Override
public <A extends Annotation> ExpressionResult checkUserPermissions(PersistentResource<?> resource,
        Class<A> annotationClass, String field) {
    if (requestScope.getSecurityMode() == SecurityMode.SECURITY_INACTIVE) {
        return ExpressionResult.PASS; // Bypass
    }

    // If the user check has already been evaluated before, return the result directly and save the building cost
    ExpressionResult expressionResult = userPermissionCheckCache
            .get(Triple.of(annotationClass, resource.getResourceClass(), field));
    if (expressionResult != null) {
        return expressionResult;
    }

    Expressions expressions = expressionBuilder.buildUserCheckFieldExpressions(resource, annotationClass,
            field);
    expressionResult = executeExpressions(expressions, annotationClass);

    userPermissionCheckCache.put(Triple.of(annotationClass, resource.getResourceClass(), field),
            expressionResult);

    if (expressionResult == PASS) {
        expressionResultShortCircuit.add(Triple.of(annotationClass, resource.getResourceClass(), field));
    }

    return expressionResult;
}

From source file:com.microsoft.azure.keyvault.extensions.SymmetricKey.java

@Override
public Future<Triple<byte[], byte[], String>> encryptAsync(final byte[] plaintext, final byte[] iv,
        final byte[] authenticationData, final String algorithm) throws NoSuchAlgorithmException {

    if (plaintext == null) {
        throw new IllegalArgumentException("plaintext");
    }/* ww  w.  j  av  a 2 s.  c  o m*/

    if (iv == null) {
        throw new IllegalArgumentException("iv");
    }

    // Interpret the algorithm
    String algorithmName = (Strings.isNullOrWhiteSpace(algorithm)) ? getDefaultEncryptionAlgorithm()
            : algorithm;
    Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName);

    if (baseAlgorithm == null || !(baseAlgorithm instanceof SymmetricEncryptionAlgorithm)) {
        throw new NoSuchAlgorithmException(algorithm);
    }

    SymmetricEncryptionAlgorithm algo = (SymmetricEncryptionAlgorithm) baseAlgorithm;

    ICryptoTransform transform = null;

    try {
        transform = algo.CreateEncryptor(_key, iv, authenticationData);
    } catch (Exception e) {
        return new FutureExecutionException<Triple<byte[], byte[], String>>(e);
    }

    byte[] cipherText = null;

    try {
        cipherText = transform.doFinal(plaintext);
    } catch (Exception e) {
        return new FutureExecutionException<Triple<byte[], byte[], String>>(e);
    }

    byte[] authenticationTag = null;

    if (transform instanceof IAuthenticatedCryptoTransform) {

        IAuthenticatedCryptoTransform authenticatedTransform = (IAuthenticatedCryptoTransform) transform;

        authenticationTag = authenticatedTransform.getTag().clone();
    }

    return new FutureImmediate<Triple<byte[], byte[], String>>(
            Triple.of(cipherText, authenticationTag, algorithm));
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static Triple<String, List<Pair<Integer, Float>>, String> split(String line) {
    String[] fields = line.split(" ");
    if (fields[0].isEmpty() || fields.length == 1) {
        return Triple.of(fields[0], asList(), "");
    }//from w w  w  .  ja  va2s. c  o m
    StringBuilder prefix = new StringBuilder();
    int i = 0;
    for (; i < fields.length; i++) {
        int index = fields[i].indexOf(":");
        if (index < 0 || !fields[i].substring(0, index).matches("[0-9]+")) {
            prefix.append(fields[i]).append(" ");
        } else {
            break;
        }
    }

    List<Pair<Integer, Float>> pairs = new ArrayList<>();

    for (; i < fields.length; i++) {
        if (fields[i].startsWith("#")) {
            break;
        }
        int index = fields[i].indexOf(":");
        pairs.add(
                Pair.of(new Integer(fields[i].substring(0, index)), new Float(fields[i].substring(index + 1))));
    }

    StringBuilder suffix = new StringBuilder();
    for (; i < fields.length; i++) {
        suffix.append(" ").append(fields[i]);
    }

    return Triple.of(prefix.toString(), pairs, suffix.toString());
}

From source file:alfio.manager.NotificationManager.java

private static Function<Map<String, String>, byte[]> receiptOrInvoiceFactory(EventRepository eventRepository,
        Function<Triple<Event, Locale, Map<String, Object>>, Optional<byte[]>> pdfGenerator) {
    return (model) -> {
        String reservationId = model.get("reservationId");
        Event event = eventRepository.findById(Integer.valueOf(model.get("eventId"), 10));
        Locale language = Json.fromJson(model.get("language"), Locale.class);

        Map<String, Object> reservationEmailModel = Json.fromJson(model.get("reservationEmailModel"),
                new TypeReference<Map<String, Object>>() {
                });/*from  w  w w .j av  a2 s.c om*/
        //FIXME hack: reservationEmailModel should be a minimal and typed container
        reservationEmailModel.put("event", event);
        Optional<byte[]> receipt = pdfGenerator.apply(Triple.of(event, language, reservationEmailModel));

        if (!receipt.isPresent()) {
            log.warn("was not able to generate the receipt for reservation id " + reservationId + " for locale "
                    + language);
        }
        return receipt.orElse(null);
    };
}

From source file:com.microsoft.azure.keyvault.cryptography.algorithms.AesCbcHmacSha2.java

private static Triple<byte[], byte[], Mac> GetAlgorithmParameters(String algorithm, byte[] key)
        throws InvalidKeyException, NoSuchAlgorithmException {

    byte[] aes_key;
    byte[] hmac_key;
    Mac hmac;//from www.  ja  va  2s  .  co  m

    if (algorithm.equalsIgnoreCase(Aes128CbcHmacSha256.ALGORITHM_NAME)) {
        if ((key.length << 3) < 256) {
            throw new IllegalArgumentException(
                    String.format("%s key length in bits %d < 256", algorithm, key.length << 3));
        }

        hmac_key = new byte[128 >> 3];
        aes_key = new byte[128 >> 3];

        // The HMAC key precedes the AES key
        System.arraycopy(key, 0, hmac_key, 0, 128 >> 3);
        System.arraycopy(key, 128 >> 3, aes_key, 0, 128 >> 3);

        hmac = Mac.getInstance("HmacSHA256");
        hmac.init(new SecretKeySpec(hmac_key, "HmacSHA256"));

    } else if (algorithm.equalsIgnoreCase(Aes192CbcHmacSha384.ALGORITHM_NAME)) {

        if ((key.length << 3) < 384) {
            throw new IllegalArgumentException(
                    String.format("%s key length in bits %d < 384", algorithm, key.length << 3));
        }

        hmac_key = new byte[192 >> 3];
        aes_key = new byte[192 >> 3];

        // The HMAC key precedes the AES key
        System.arraycopy(key, 0, hmac_key, 0, 192 >> 3);
        System.arraycopy(key, 192 >> 3, aes_key, 0, 192 >> 3);

        hmac = Mac.getInstance("HmacSHA384");
        hmac.init(new SecretKeySpec(hmac_key, "HmacSHA384"));
    } else if (algorithm.equalsIgnoreCase(Aes256CbcHmacSha512.ALGORITHM_NAME)) {

        if ((key.length << 3) < 512) {
            throw new IllegalArgumentException(
                    String.format("%s key length in bits %d < 512", algorithm, key.length << 3));
        }

        hmac_key = new byte[256 >> 3];
        aes_key = new byte[256 >> 3];

        // The HMAC key precedes the AES key
        System.arraycopy(key, 0, hmac_key, 0, 256 >> 3);
        System.arraycopy(key, 256 >> 3, aes_key, 0, 256 >> 3);

        hmac = Mac.getInstance("HmacSHA512");
        hmac.init(new SecretKeySpec(hmac_key, "HmacSHA512"));
    } else {
        throw new IllegalArgumentException(String.format("Unsupported algorithm: %s", algorithm));
    }

    return Triple.of(aes_key, hmac_key, hmac);
}

From source file:com.yahoo.elide.security.executors.ActivePermissionExecutor.java

/**
 * Check strictly user permissions on an entity.
 *
 * @param <A> type parameter//from w  w  w  .j  av  a 2s  . c  om
 * @param resourceClass Resource class
 * @param annotationClass Annotation class
 */
@Override
public <A extends Annotation> ExpressionResult checkUserPermissions(Class<?> resourceClass,
        Class<A> annotationClass) {
    if (requestScope.getSecurityMode() == SecurityMode.SECURITY_INACTIVE) {
        return ExpressionResult.PASS; // Bypass
    }

    // If the user check has already been evaluated before, return the result directly and save the building cost
    ExpressionResult expressionResult = userPermissionCheckCache
            .get(Triple.of(annotationClass, resourceClass, null));
    if (expressionResult != null) {
        return expressionResult;
    }

    Expressions expressions = expressionBuilder.buildUserCheckAnyExpression(resourceClass, annotationClass,
            requestScope);
    expressionResult = executeExpressions(expressions, annotationClass);

    userPermissionCheckCache.put(Triple.of(annotationClass, resourceClass, null), expressionResult);

    if (expressionResult == PASS) {
        expressionResultShortCircuit.add(Triple.of(annotationClass, resourceClass, null));
    }

    return expressionResult;
}

From source file:com.microsoft.azure.keyvault.cryptography.SymmetricKey.java

@Override
public ListenableFuture<Triple<byte[], byte[], String>> encryptAsync(final byte[] plaintext, final byte[] iv,
        final byte[] authenticationData, final String algorithm) throws NoSuchAlgorithmException {

    if (plaintext == null) {
        throw new IllegalArgumentException("plaintext");
    }//from w ww  . jav  a 2s .c  o m

    if (iv == null) {
        throw new IllegalArgumentException("iv");
    }

    // Interpret the algorithm
    String algorithmName = (Strings.isNullOrWhiteSpace(algorithm)) ? getDefaultEncryptionAlgorithm()
            : algorithm;
    Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName);

    if (baseAlgorithm == null || !(baseAlgorithm instanceof SymmetricEncryptionAlgorithm)) {
        throw new NoSuchAlgorithmException(algorithm);
    }

    SymmetricEncryptionAlgorithm algo = (SymmetricEncryptionAlgorithm) baseAlgorithm;

    ICryptoTransform transform = null;

    try {
        transform = algo.CreateEncryptor(_key, iv, authenticationData, _provider);
    } catch (Exception e) {
        return Futures.immediateFailedFuture(e);
    }

    byte[] cipherText = null;

    try {
        cipherText = transform.doFinal(plaintext);
    } catch (Exception e) {
        return Futures.immediateFailedFuture(e);
    }

    byte[] authenticationTag = null;

    if (transform instanceof IAuthenticatedCryptoTransform) {

        IAuthenticatedCryptoTransform authenticatedTransform = (IAuthenticatedCryptoTransform) transform;

        authenticationTag = authenticatedTransform.getTag().clone();
    }

    return Futures.immediateFuture(Triple.of(cipherText, authenticationTag, algorithm));
}