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

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

Introduction

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

Prototype

public abstract M getMiddle();

Source Link

Document

Gets the middle element from this triple.

Usage

From source file:com.hurence.logisland.processor.elasticsearch.EnrichRecordsElasticsearch.java

/**
 * process events/*from  w  w  w .j  a va  2  s. co  m*/
 *
 * @param context
 * @param records
 * @return
 */
@Override
public Collection<Record> process(final ProcessContext context, final Collection<Record> records) {
    if (records.size() == 0) {
        return Collections.emptyList();
    }

    List<Triple<Record, String, IncludeFields>> recordsToEnrich = new ArrayList<>();
    MultiGetQueryRecordBuilder mgqrBuilder = new MultiGetQueryRecordBuilder();

    mgqrBuilder.excludeFields(excludesArray);

    for (Record record : records) {

        String recordKeyName = evaluatePropAsString(record, context, RECORD_KEY_FIELD);
        String indexName = evaluatePropAsString(record, context, ES_INDEX_FIELD);
        String typeName = evaluatePropAsString(record, context, ES_TYPE_FIELD);
        String includesFieldName = evaluatePropAsString(record, context, ES_INCLUDES_FIELD);

        if (recordKeyName != null && indexName != null && typeName != null) {
            try {
                // Includes :
                String[] includesArray = null;
                if ((includesFieldName != null) && (!includesFieldName.isEmpty())) {
                    includesArray = includesFieldName.split("\\s*,\\s*");
                }
                IncludeFields includeFields = new IncludeFields(includesArray);
                mgqrBuilder.add(indexName, typeName, includeFields.getAttrsToIncludeArray(), recordKeyName);
                recordsToEnrich.add(new ImmutableTriple(record, asUniqueKey(indexName, typeName, recordKeyName),
                        includeFields));
            } catch (Throwable t) {
                record.setStringField(FieldDictionary.RECORD_ERRORS, "Can not request ElasticSearch with "
                        + indexName + " " + typeName + " " + recordKeyName);
                getLogger().error(
                        "Can not request ElasticSearch with index: {}, type: {}, recordKey: {}, record id is :\n{}",
                        new Object[] { indexName, typeName, recordKeyName, record.getId() }, t);
            }
        } else {
            getLogger().warn(
                    "Can not request ElasticSearch with "
                            + "index: {}, type: {}, recordKey: {}, record id is :\n{}",
                    new Object[] { indexName, typeName, recordKeyName, record.getId() });
        }
    }

    List<MultiGetResponseRecord> multiGetResponseRecords = null;
    try {
        List<MultiGetQueryRecord> mgqrs = mgqrBuilder.build();
        if (mgqrs.isEmpty())
            return records;
        multiGetResponseRecords = elasticsearchClientService.multiGet(mgqrs);
    } catch (InvalidMultiGetQueryRecordException e) {
        getLogger().error("error while multiGet elasticsearch", e);
    }

    if (multiGetResponseRecords == null || multiGetResponseRecords.isEmpty()) {
        return records;
    }

    // Transform the returned documents from ES in a Map
    Map<String, MultiGetResponseRecord> responses = multiGetResponseRecords.stream()
            .collect(Collectors.toMap(EnrichRecordsElasticsearch::asUniqueKey, Function.identity()));

    recordsToEnrich.forEach(recordToEnrich -> {

        Triple<Record, String, IncludeFields> triple = recordToEnrich;
        Record outputRecord = triple.getLeft();
        String key = triple.getMiddle();
        IncludeFields includeFields = triple.getRight();

        MultiGetResponseRecord responseRecord = responses.get(key);
        if ((responseRecord != null) && (responseRecord.getRetrievedFields() != null)) {
            // Retrieve the fields from responseRecord that matches the ones in the recordToEnrich.
            responseRecord.getRetrievedFields().forEach((fieldName, v) -> {
                if (includeFields.includes(fieldName)) {
                    // Now check if there is an attribute mapping rule to apply
                    if (includeFields.hasMappingFor(fieldName)) {
                        String mappedAttributeName = includeFields.getAttributeToMap(fieldName);
                        // Replace the attribute name
                        outputRecord.setStringField(mappedAttributeName, v);
                    } else {
                        outputRecord.setStringField(fieldName, v);
                    }
                }
            });
        }
    });

    return records;
}

From source file:at.gridtec.lambda4j.function.tri.to.ToByteTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *//* w  ww .j  a v  a 2s . c  o  m*/
default byte applyAsByte(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsByte(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:at.gridtec.lambda4j.function.tri.to.ToCharTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *///from   w w w  .  j  a va  2 s. com
default char applyAsChar(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsChar(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:at.gridtec.lambda4j.function.tri.to.ToIntTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *///w  w  w . j  a  v  a  2 s.c  o  m
default int applyAsInt(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsInt(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:at.gridtec.lambda4j.function.tri.to.ToFloatTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *//* www  .j  a  v a2s .co  m*/
default float applyAsFloat(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsFloat(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:at.gridtec.lambda4j.function.tri.to.ToLongTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 */// www. java2  s.  c  o m
default long applyAsLong(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsLong(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:at.gridtec.lambda4j.function.tri.to.ToShortTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *//*from  w  ww .j  a  v  a  2s.c om*/
default short applyAsShort(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsShort(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:at.gridtec.lambda4j.function.tri.to.ToDoubleTriFunction.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Triple
 *///  www.  j ava 2s .  c  o m
default double applyAsDouble(@Nonnull Triple<T, U, V> tuple) {
    Objects.requireNonNull(tuple);
    return applyAsDouble(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:io.lavagna.service.EventEmitter.java

private void sendEventForLabel(List<CardFull> affectedCards, LavagnaEvent ev) {
    Triple<Set<Integer>, Set<Integer>, Set<String>> a = extractFrom(affectedCards);
    for (int cardId : a.getLeft()) {
        messagingTemplate.convertAndSend(cardData(cardId), event(ev));
    }/*  w  w w  .j  a  v a2s . c o  m*/
    for (int columnId : a.getMiddle()) {
        messagingTemplate.convertAndSend(column(columnId), event(ev));
    }
    for (String projectShortName : a.getRight()) {
        messagingTemplate.convertAndSend("/event/project/" + projectShortName + "/label-value", event(ev));
    }
}

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

@Override
protected Observable<ContainerGroupInner> createInner() {
    final ContainerGroupImpl self = this;

    if (!isInCreateMode()) {
        throw new UnsupportedOperationException(
                "Update on an existing container group resource is not supported");
    } else if (newFileShares == null || creatableStorageAccountKey == null) {
        return this.manager().inner().containerGroups().createOrUpdateAsync(this.resourceGroupName(),
                this.name(), this.inner());
    } else {/*from  ww  w.  j ava  2  s.  com*/
        final StorageAccount storageAccount = (StorageAccount) this
                .createdResource(this.creatableStorageAccountKey);
        return createFileShareAsync(storageAccount).collect(new Func0<List<Triple<String, String, String>>>() {
            @Override
            public List<Triple<String, String, String>> call() {
                return new ArrayList<>();
            }
        }, new Action2<List<Triple<String, String, String>>, Triple<String, String, String>>() {
            @Override
            public void call(List<Triple<String, String, String>> cloudFileShares,
                    Triple<String, String, String> fileShare) {
                cloudFileShares.add(fileShare);
            }
        }).flatMap(
                new Func1<List<Triple<String, String, String>>, Observable<? extends ContainerGroupInner>>() {
                    @Override
                    public Observable<? extends ContainerGroupInner> call(
                            List<Triple<String, String, String>> fileShares) {
                        for (Triple<String, String, String> fileShareEntry : fileShares) {
                            self.defineVolume(fileShareEntry.getLeft())
                                    .withExistingReadWriteAzureFileShare(fileShareEntry.getMiddle())
                                    .withStorageAccountName(storageAccount.name())
                                    .withStorageAccountKey(fileShareEntry.getRight()).attach();
                        }
                        return self.manager().inner().containerGroups()
                                .createOrUpdateAsync(self.resourceGroupName(), self.name(), self.inner());
                    }
                });
    }
}