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:hu.mta.sztaki.lpds.cloud.simulator.iaas.statenotifications.VMStateChangeNotificationHandler.java

/**
 * The event handling mechanism for VM state change notifications
 * //from  ww w .java  2  s  . c  o m
 * @param onObject
 *            The listener to send the event to
 * @param stateData
 *            a data triplet containing the VM and its the past and future
 *            states.
 */
@Override
public void sendNotification(final StateChange onObject, Triple<VirtualMachine, State, State> stateData) {
    onObject.stateChanged(stateData.getLeft(), stateData.getMiddle(), stateData.getRight());
}

From source file:io.github.autsia.crowly.services.geolocation.impl.GeoLocationServiceImpl.java

@Override
public GeoCode convertCoordinatesToGeoCode(Triple<Double, Double, Double> location) {
    return new GeoCode(location.getLeft(), location.getMiddle(), location.getRight().intValue());
}

From source file:fr.landel.utils.assertor.helper.HelperAssertor.java

/**
 * The combine function (the main method). This method is called by each end
 * steps./*from   w w  w.  j av a 2s  . c  o  m*/
 * 
 * <p>
 * What is matcher mode: it's an Assertor starting with
 * "{@code Assertor.matcher}...". In this mode, only one variable can be
 * checked through "{@code on(object)}" method. The aim of this is to create
 * the validation steps before in another method or in a static way to
 * improve performance.
 * </p>
 * 
 * @param step
 *            the last step
 * @param object
 *            the object to test (only in matcher mode)
 * @param marcherMode
 *            if it's in matcher mode (set with "on" method)
 * @param loadMessage
 *            if the message has to beloaded and formated
 * @param <T>
 *            the type of checked object
 * @return the result
 * @throws IllegalArgumentException
 *             if in matcher mode and object is not set
 */
public static <T> ResultAssertor combine(final StepAssertor<T> step, final Object object,
        final boolean marcherMode, final boolean loadMessage) {

    final List<StepAssertor<?>> steps = validatesAndReverse(step, marcherMode);

    boolean not = false;
    boolean valid = true;
    PairIso<Boolean> resultValid;
    EnumOperator operator = null;
    final MessagesAssertor messages = new MessagesAssertor();
    Object obj;
    final Object matcherObject;
    boolean checked = false;
    EnumType type = null;
    ParameterAssertor<?> param = null;

    final List<ParameterAssertor<?>> parameters = new ArrayList<>();

    Optional<Pair<Boolean, MessagesAssertor>> dontNeedCheck = Optional.empty();

    // get the object to check
    // in matcher mode, two ways are available to inject the object:
    // - first: directly through the combine function
    boolean inMatcherMode = marcherMode;
    if (inMatcherMode) {
        obj = object;
        // - second:
    } else if (EnumStep.PREDICATE_OBJECT.equals(step.getStepType())) {
        obj = step.getObject();
        inMatcherMode = true;
    } else {
        obj = null;
    }

    // create a temporary variable for sub steps (in matcher mode)
    matcherObject = obj;

    for (StepAssertor<?> s : steps) {
        if (s.getStepType() == null) {
            continue;
        }

        switch (s.getStepType()) {

        // the first step of an Assertor in predicate mode (ex:
        // Assertor.ofNumber...)
        case PREDICATE:
            type = s.getType();
            if (EnumType.UNKNOWN.equals(type)) {
                type = EnumType.getType(obj);
            }
            param = new ParameterAssertor<>(obj, type, true);

            parameters.add(param);

            break;
        // the first step of an Assertor (ex: Assertor.that(object)...)
        case CREATION:
            obj = s.getObject();
            type = s.getType();
            checked = s.isChecked();
            param = new ParameterAssertor<>(obj, type, checked);

            parameters.add(param);

            break;
        // the validation step
        case ASSERTION:
            parameters.addAll(s.getParameters());

            // if precondition returns false, we end all treatments
            if (!HelperAssertor.preCheck(s, obj)) {
                return HelperAssertor.getPreconditionMessage(s, param, parameters, loadMessage);

            } else {
                resultValid = HelperAssertor.validatesAndGetMessage(s, param, obj, valid, not, operator,
                        messages, loadMessage);
                valid = resultValid.getRight();
            }

            if (operator != null && !valid) {
                dontNeedCheck = checkValidityAndOperator(resultValid.getLeft(), operator, messages,
                        loadMessage);
            }

            not = false;

            break;
        // the combining step between two validation steps
        case OPERATOR:
            operator = s.getOperator();

            dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage);

            break;
        // the not step to reverse the next validation step
        case NOT:
            not = not ^ s.isNot();

            break;
        // the object provided by the mapper
        case PROPERTY:
            if (s.getMapper().isPresent()) {
                operator = s.getOperator();
                obj = s.getMapper().get().apply(obj);
                type = s.getType();
                checked = s.isChecked();
                param = new ParameterAssertor<>(obj, type, checked);

                parameters.add(param);

                dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage);
            } else {
                throw new IllegalStateException("property cannot be null");
            }
            break;
        // the other object to validate
        case OBJECT:
            operator = s.getOperator();
            obj = s.getObject();
            type = s.getType();
            checked = s.isChecked();
            param = new ParameterAssertor<>(obj, type, checked);

            parameters.add(param);

            dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage);

            break;
        // the sub step to emulate parenthesis in a check (ex:
        // Assertor.that(2).isZero().or(Assertor.that(2).isGTE(1).and().isLTE(10)))
        case SUB:
            if (s.getSubStep().isPresent()) {
                dontNeedCheck = checkValidityAndOperator(valid, s.getOperator(), messages, loadMessage);

                if (!dontNeedCheck.isPresent()) {
                    final Triple<Boolean, EnumOperator, ResultAssertor> output = HelperAssertor.managesSub(s,
                            matcherObject, inMatcherMode, parameters, valid, operator, messages, loadMessage);

                    if (output.getRight() != null) {
                        return output.getRight();
                    } else {
                        valid = output.getLeft();
                        operator = output.getMiddle();
                    }
                }
            }
            break;
        // sub assertor step to check sub properties
        case SUB_ASSERTOR:
            if (s.getSubAssertor().isPresent()) {
                operator = s.getOperator();

                dontNeedCheck = checkValidityAndOperator(valid, operator, messages, loadMessage);

                if (!dontNeedCheck.isPresent()) {
                    final Step<?, ?> stepSubAssertor = Objects.requireNonNull(
                            s.getSubAssertor().get().apply(obj), "Sub assertor mapper cannot be null");
                    final ResultAssertor intermediateResult = combine(stepSubAssertor.getStep(), null,
                            inMatcherMode, loadMessage);

                    valid = intermediateResult.isPrecondition()
                            && isValid(valid, intermediateResult.isValid(), operator);

                    parameters.addAll(intermediateResult.getParameters());

                    if (!valid && loadMessage && intermediateResult.getMessages() != null) {
                        if (messages.isNotEmpty()) {
                            messages.append(operator);
                        }
                        messages.append(intermediateResult.getMessages());
                    }

                    if (intermediateResult.isPrecondition()) {
                        dontNeedCheck = checkValidityAndOperator(intermediateResult.isValid(), operator,
                                messages, loadMessage);
                    } else {
                        dontNeedCheck = Optional.of(Pair.of(false, intermediateResult.getMessages()));
                    }
                }
            } else {
                throw new IllegalStateException("sub assertor cannot be null");
            }
            break;
        default: // MATCHER_OBJECT (don't need treatment)
        }

        if (dontNeedCheck.isPresent()) {
            return new ResultAssertor(true, dontNeedCheck.get().getKey(), dontNeedCheck.get().getValue(),
                    parameters);
        }
    }

    return new ResultAssertor(true, valid, messages, parameters);
}

From source file:com.minlia.cloud.framework.client.util.SearchUriBuilder.java

public final SearchUriBuilder consume(final Triple<String, ClientOperation, String> constraint) {
    final ClientOperation operation = (constraint == null) ? null : constraint.getMiddle();
    final boolean negated = (constraint == null) ? false : constraint.getMiddle().isNegated();
    final String key = (constraint == null) ? null : constraint.getLeft();
    final String value = (constraint == null) ? null : constraint.getRight();

    return consume(operation, key, value, negated);
}

From source file:cherry.foundation.bizcal.WorkdayManagerImpl.java

@Override
public void afterPropertiesSet() {
    numberOfWorkdayCache = CacheBuilder.from(numberOfWorkdayCacheSpec)
            .build(new CacheLoader<Triple<String, LocalDate, LocalDate>, Integer>() {
                @Override/*from  w w w.  ja v  a2s  .com*/
                public Integer load(Triple<String, LocalDate, LocalDate> key) {
                    return workdayStore.getNumberOfWorkday(key.getLeft(), key.getMiddle(), key.getRight());
                }
            });
    nextWorkdayCache = CacheBuilder.from(nextWorkdayCacheSpec)
            .build(new CacheLoader<Triple<String, LocalDate, Integer>, LocalDate>() {
                @Override
                public LocalDate load(Triple<String, LocalDate, Integer> key) {
                    return workdayStore.getNextWorkday(key.getLeft(), key.getMiddle(), key.getRight());
                }
            });
}

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

public int getParcelSize() {
    int total = 12;
    for (Triple<AttachmentModel, String, String> tuple : attachments) {
        total += 40;/*w w  w. j a v a  2 s . c  o  m*/
        AttachmentModel attachment = tuple.getLeft();
        String hash = tuple.getMiddle();
        String post = tuple.getRight();
        if (attachment.thumbnail != null)
            total += attachment.thumbnail.length() * 2;
        if (attachment.path != null)
            total += attachment.path.length() * 2;
        if (attachment.originalName != null)
            total += attachment.originalName.length() * 2;
        if (hash != null)
            total += hash.length() * 2;
        if (post != null)
            total += post.length() * 2;
    }
    return total;
}

From source file:com.act.lcms.v2.fullindex.SearcherTest.java

@Test
public void searchIndexInRange() throws Exception {
    List<TMzI> actual = searcher.searchIndexInRange(Pair.of(100.004, 100.016), Pair.of(1.5, 3.5));

    List<Triple<Float, Double, Float>> expected = Arrays.asList(Triple.of(2.0F, 100.005, 10.0F),
            Triple.of(2.0F, 100.010, 20.0F), Triple.of(2.0F, 100.015, 30.0F), Triple.of(3.0F, 100.010, 100.0F),
            Triple.of(3.0F, 100.015, 200.0F));

    assertEquals("Searcher returned expected number of TMzI tuples", expected.size(), actual.size());
    for (int i = 0; i < expected.size(); i++) {
        Triple<Float, Double, Float> e = expected.get(i);
        TMzI a = actual.get(i);// w  ww.ja va 2s  .  c  om
        assertEquals("Time matches expected", e.getLeft(), a.getTime(), FP_TOLERANCE);
        assertEquals("M/z matches expected", e.getMiddle(), a.getMz(), FP_TOLERANCE);
        assertEquals("Intensity matches expected", e.getRight(), a.getIntensity(), FP_TOLERANCE);
    }
}

From source file:com.quancheng.saluki.gateway.zuul.filter.LimitAccessFilter.java

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    String auth = request.getHeader("Authorization");
    String accessToken = auth.split(" ")[1];
    ctx.set("LimitAccess", Boolean.TRUE);
    try {/* w w w .j  a v  a  2  s. co  m*/
        Triple<Long, String, Long> clientTriple = databaseUserDetailService.loadClientByToken(accessToken);
        String user = clientTriple.getMiddle();
        Long intervalInMills = clientTriple.getLeft();
        Long limits = clientTriple.getRight();
        if (intervalInMills != null && intervalInMills != 0l && limits != null && limits != 0l) {
            if (!access(user, intervalInMills, limits)) {
                ctx.set("LimitAccess", Boolean.FALSE);
                ctx.setSendZuulResponse(false);
                ctx.setResponseStatusCode(HttpServletResponse.SC_BAD_REQUEST);
                ctx.setResponseBody("The times of usage is limited");
            }
        }
    } catch (Throwable e) {
    }
    return null;
}

From source file:com.boozallen.cognition.ingest.storm.bolt.starter.LineRegexReplaceInRegionBolt.java

String replaceAll(String record) {
    for (Triple<Pattern, String, String> entry : groupSearchReplaceList) {
        Pattern pattern = entry.getLeft();
        String regex = entry.getMiddle();
        String replacement = entry.getRight();

        record = replace(record, pattern, regex, replacement);
    }/*from w  w  w.j  a  va  2s.  c o  m*/
    return record;
}

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

private TicketReservationDescriptor toReservationDescriptor(String reservationId,
        Triple<TicketReservation, List<Ticket>, Event> triple) {
    List<SerializablePair<TicketCategory, List<Ticket>>> tickets = triple.getMiddle().stream()
            .collect(Collectors.groupingBy(Ticket::getCategoryId)).entrySet().stream()
            .map(entry -> SerializablePair.of(
                    eventManager.getTicketCategoryById(entry.getKey(), triple.getRight().getId()),
                    entry.getValue()))/*from ww  w .  j  ava2  s .c o m*/
            .collect(Collectors.toList());
    TicketReservation reservation = triple.getLeft();
    return new TicketReservationDescriptor(reservation, ticketReservationManager.orderSummaryForReservationId(
            reservationId, triple.getRight(), Locale.forLanguageTag(reservation.getUserLanguage())), tickets);
}