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:at.gridtec.lambda4j.function.tri.ThrowableTriFunction.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}
 * @throws X Any throwable from this functions action
 * @see org.apache.commons.lang3.tuple.Triple
 *///from  w w w.j  a  v  a 2 s . c  o  m
default R applyThrows(@Nonnull Triple<T, U, V> tuple) throws X {
    Objects.requireNonNull(tuple);
    return applyThrows(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:com.nttec.everychan.ui.gallery.GalleryInitResult.java

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(initPosition);/*  w  w  w.java 2s.  c  o m*/
    dest.writeInt(shouldWaitForPageLoaded ? 1 : 0);
    dest.writeInt(attachments.size());
    for (Triple<AttachmentModel, String, String> tuple : attachments) {
        AttachmentModel attachment = tuple.getLeft();
        dest.writeInt(attachment.type);
        dest.writeInt(attachment.size);
        dest.writeString(attachment.thumbnail);
        dest.writeString(attachment.path);
        dest.writeInt(attachment.width);
        dest.writeInt(attachment.height);
        dest.writeString(attachment.originalName);
        dest.writeInt(attachment.isSpoiler ? 1 : 0);
        dest.writeString(tuple.getMiddle());
        dest.writeString(tuple.getRight());
    }
}

From source file:at.gridtec.lambda4j.predicate.tri.TriPredicate.java

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

From source file:alfio.controller.TicketController.java

@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/download-ticket", method = RequestMethod.GET)
public void generateTicketPdf(@PathVariable("eventName") String eventName,
        @PathVariable("ticketIdentifier") String ticketIdentifier, HttpServletRequest request,
        HttpServletResponse response) throws IOException, WriterException {

    Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager
            .fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (!oData.isPresent()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;/* w w  w .j av  a  2 s.c  o  m*/
    }
    Triple<Event, TicketReservation, Ticket> data = oData.get();

    Ticket ticket = data.getRight();

    response.setContentType("application/pdf");
    response.addHeader("Content-Disposition", "attachment; filename=ticket-" + ticketIdentifier + ".pdf");
    try (OutputStream os = response.getOutputStream()) {
        PdfBoxRenderer renderer = preparePdfTicket(request, data.getLeft(), data.getMiddle(), ticket)
                .generate(ticket);
        if (renderer != null) {
            renderer.createPDF(os);
        }
    }
}

From source file:com.uber.hoodie.common.util.collection.converter.HoodieRecordConverter.java

@Override
public HoodieRecord getData(byte[] bytes) {
    try {/*from  w ww.jav a 2  s. c o  m*/
        Triple<Pair<String, String>, Pair<byte[], byte[]>, byte[]> data = SerializationUtils.deserialize(bytes);
        Optional<GenericRecord> payload = Optional.empty();
        HoodieRecordLocation currentLocation = null;
        HoodieRecordLocation newLocation = null;
        if (data.getRight().length > 0) {
            // This can happen if the record is deleted, the payload is optional with 0 bytes
            payload = Optional.of(HoodieAvroUtils.bytesToAvro(data.getRight(), schema));
        }
        // Get the currentLocation for the HoodieRecord
        if (data.getMiddle().getLeft().length > 0) {
            currentLocation = SerializationUtils.deserialize(data.getMiddle().getLeft());
        }
        // Get the newLocation for the HoodieRecord
        if (data.getMiddle().getRight().length > 0) {
            newLocation = SerializationUtils.deserialize(data.getMiddle().getRight());
        }
        HoodieRecord<? extends HoodieRecordPayload> hoodieRecord = new HoodieRecord<>(
                new HoodieKey(data.getLeft().getKey(), data.getLeft().getValue()),
                ReflectionUtils.loadPayload(payloadClazz, new Object[] { payload }, Optional.class));
        hoodieRecord.setCurrentLocation(currentLocation);
        hoodieRecord.setNewLocation(newLocation);
        return hoodieRecord;
    } catch (IOException io) {
        throw new HoodieNotSerializableException("Cannot de-serialize value from bytes", io);
    }
}

From source file:alfio.controller.TicketController.java

private String internalShowTicket(String eventName, String ticketIdentifier, boolean ticketEmailSent,
        Model model, String backSuffix, Locale locale) {
    Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager
            .fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (!oData.isPresent()) {
        return "redirect:/event/" + eventName;
    }//from   www. j  a  v a2 s .co  m
    Triple<Event, TicketReservation, Ticket> data = oData.get();

    TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(data.getRight().getCategoryId(),
            data.getLeft().getId());
    Organization organization = organizationRepository.getById(data.getLeft().getOrganizationId());
    Event event = data.getLeft();

    TicketReservation reservation = data.getMiddle();
    model.addAttribute("ticket", data.getRight())//
            .addAttribute("reservation", reservation)//
            .addAttribute("event", event)//
            .addAttribute("ticketCategory", ticketCategory)//
            .addAttribute("organization", organization)//
            .addAttribute("ticketEmailSent", ticketEmailSent)
            .addAttribute("reservationId",
                    ticketReservationManager.getShortReservationID(event, reservation.getId()))
            .addAttribute("deskPaymentRequired",
                    Optional.ofNullable(reservation.getPaymentMethod()).orElse(PaymentProxy.STRIPE)
                            .isDeskPaymentRequired())
            .addAttribute("backSuffix", backSuffix).addAttribute("userLanguage", locale.getLanguage())
            .addAttribute("pageTitle", "show-ticket.header.title")
            .addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName())
            .addAttribute("validityStart",
                    Optional.ofNullable(ticketCategory.getTicketValidityStart(event.getZoneId()))
                            .orElse(event.getBegin()))
            .addAttribute("validityEnd",
                    Optional.ofNullable(ticketCategory.getTicketValidityEnd(event.getZoneId()))
                            .orElse(event.getEnd()))
            .addAttribute("ticketIdParam", "ticketId=" + ticketIdentifier);

    return "/event/show-ticket";
}

From source file:com.hurence.logisland.processor.datastore.EnrichRecords.java

/**
 * process events/*from w w w.j a v  a2 s  . com*/
 *
 * @param context
 * @param records
 * @return
 */
@Override
public Collection<Record> process(final ProcessContext context, final Collection<Record> records) {

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

    if (records.size() != 0) {
        String excludesFieldName = context.getPropertyValue(EXCLUDES_FIELD).asString();

        // Excludes :
        String[] excludesArray = null;
        if ((excludesFieldName != null) && (!excludesFieldName.isEmpty())) {
            excludesArray = excludesFieldName.split("\\s*,\\s*");
        }

        //List<MultiGetQueryRecord> multiGetQueryRecords = new ArrayList<>();
        MultiGetQueryRecordBuilder mgqrBuilder = new MultiGetQueryRecordBuilder();

        mgqrBuilder.excludeFields(excludesArray);

        List<MultiGetResponseRecord> multiGetResponseRecords = null;
        // HashSet<String> ids = new HashSet<>(); // Use a Set to avoid duplicates

        for (Record record : records) {

            String recordKeyName = null;
            String indexName = null;
            String typeName = FieldDictionary.RECORD_TYPE;
            String includesFieldName = null;

            try {
                recordKeyName = context.getPropertyValue(RECORD_KEY_FIELD).evaluate(record).asString();
                indexName = context.getPropertyValue(COLLECTION_NAME).evaluate(record).asString();
                if (context.getPropertyValue(TYPE_NAME).isSet())
                    typeName = context.getPropertyValue(TYPE_NAME).evaluate(record).asString();
                includesFieldName = context.getPropertyValue(INCLUDES_FIELD).evaluate(record).asString();
            } catch (Throwable t) {
                record.setStringField(FieldDictionary.RECORD_ERRORS,
                        "Failure in executing EL. Error: " + t.getMessage());
                getLogger().error("Cannot interpret EL : " + record, t);
            }

            if (recordKeyName != null) {
                try {
                    String key = record.getField(recordKeyName).asString();
                    // 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(), key);

                    recordsToEnrich.add(
                            new ImmutableTriple(record, asUniqueKey(indexName, typeName, key), includeFields));
                } catch (Throwable t) {
                    record.setStringField(FieldDictionary.RECORD_ERRORS, "Can not request datastore with "
                            + indexName + " " + typeName + " " + recordKeyName);
                    outputRecords.add(record);
                }
            } else {
                //record.setStringField(FieldDictionary.RECORD_ERRORS, "Interpreted EL returned null for recordKeyName");
                outputRecords.add(record);
                //logger.error("Interpreted EL returned null for recordKeyName");
            }
        }

        try {
            List<MultiGetQueryRecord> mgqrs = mgqrBuilder.build();

            multiGetResponseRecords = datastoreClientService.multiGet(mgqrs);
        } catch (InvalidMultiGetQueryRecordException e) {
            getLogger().error("error while multiger", 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(EnrichRecords::asUniqueKey, Function.identity()));

        recordsToEnrich.forEach(recordToEnrich -> {

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

            // TODO: should probably store the resulting recordKeyName during previous invocation above
            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((k, v) -> {
                    String fieldName = k.toString();
                    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.toString());
                        } else {
                            outputRecord.setStringField(fieldName, v.toString());
                        }
                    }
                });
            }
            outputRecords.add(outputRecord);

        });
    }
    return outputRecords;
}

From source file:at.gridtec.lambda4j.function.tri.to.ThrowableToIntTriFunction.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}
 * @throws X Any throwable from this functions action
 * @see org.apache.commons.lang3.tuple.Triple
 *//*from w w w  .  jav a 2 s  . c  om*/
default int applyAsIntThrows(@Nonnull Triple<T, U, V> tuple) throws X {
    Objects.requireNonNull(tuple);
    return applyAsIntThrows(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}

From source file:blusunrize.immersiveengineering.common.items.ItemDrill.java

@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos,
        EntityLivingBase living) {/*  w  w  w  . j a  va  2 s  .  c  o  m*/
    if ((double) state.getBlockHardness(world, pos) != 0.0D) {
        int dmg = ForgeHooks.isToolEffective(world, pos, stack) ? 1 : 3;
        ItemStack head = getHead(stack);
        if (!head.isEmpty()) {
            if (living instanceof EntityPlayer) {
                if (((EntityPlayer) living).capabilities.isCreativeMode)
                    return true;
                ((IDrillHead) head.getItem()).afterBlockbreak(stack, head, (EntityPlayer) living);
            }
            if (!getUpgrades(stack).getBoolean("oiled") || Utils.RAND.nextInt(4) == 0)
                ((IDrillHead) head.getItem()).damageHead(head, dmg);
            this.setHead(stack, head);
            IFluidHandler handler = FluidUtil.getFluidHandler(stack);
            handler.drain(1, true);

            Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry
                    .getStoredShaderAndCase(stack);
            if (shader != null)
                shader.getMiddle().getEffectFunction().execute(world, shader.getLeft(), stack,
                        shader.getRight().getShaderType(),
                        new Vec3d(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5), null, .375f);
        }
    }

    return true;
}

From source file:at.gridtec.lambda4j.function.tri.to.ThrowableToByteTriFunction.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}
 * @throws X Any throwable from this functions action
 * @see org.apache.commons.lang3.tuple.Triple
 *///from   w  ww .j a v a 2s.  c  o m
default byte applyAsByteThrows(@Nonnull Triple<T, U, V> tuple) throws X {
    Objects.requireNonNull(tuple);
    return applyAsByteThrows(tuple.getLeft(), tuple.getMiddle(), tuple.getRight());
}