Example usage for org.apache.commons.lang3.tuple Pair getLeft

List of usage examples for org.apache.commons.lang3.tuple Pair getLeft

Introduction

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

Prototype

public abstract L getLeft();

Source Link

Document

Gets the left element from this pair.

When treated as a key-value pair, this is the key.

Usage

From source file:com.github.rvesse.airline.utils.predicates.parser.ParsedOptionFinder.java

@Override
public boolean evaluate(Pair<OptionMetadata, Object> parsedOption) {
    if (parsedOption == null)
        return false;
    if (this.opt == null)
        return false;

    return this.opt.equals(parsedOption.getLeft());
}

From source file:com.intuit.karate.Script.java

public static ScriptValue eval(String text, ScriptContext context) {
    text = StringUtils.trimToEmpty(text);
    if (text.isEmpty()) {
        logger.trace("script is empty");
        return ScriptValue.NULL;
    }/*from w  w w . j  a  v a  2s.  c o m*/
    if (isCallSyntax(text)) { // special case in form "call foo arg"
        text = text.substring(5);
        int pos = text.indexOf(' '); // TODO handle read('file with spaces in the name')
        String arg;
        if (pos != -1) {
            arg = text.substring(pos);
            text = text.substring(0, pos);
        } else {
            arg = null;
        }
        return call(text, arg, context);
    } else if (isGetSyntax(text)) { // special case in form
        // get json[*].path
        // get /xml/path
        // get xpath-function(expression)
        text = text.substring(4);
        String left;
        String right;
        if (isVariableAndSpaceAndPath(text)) {
            int pos = text.indexOf(' ');
            right = text.substring(pos + 1);
            left = text.substring(0, pos);
        } else {
            Pair<String, String> pair = parseVariableAndPath(text);
            left = pair.getLeft();
            right = pair.getRight();
        }
        if (isXmlPath(right) || isXmlPathFunction(right)) {
            return evalXmlPathOnVarByName(left, right, context);
        } else {
            return evalJsonPathOnVarByName(left, right, context);
        }
    } else if (isJsonPath(text)) {
        return evalJsonPathOnVarByName(ScriptValueMap.VAR_RESPONSE, text, context);
    } else if (isJson(text)) {
        DocumentContext doc = JsonUtils.toJsonDoc(text);
        evalJsonEmbeddedExpressions(doc, context);
        return new ScriptValue(doc);
    } else if (isBson(text)) {
        text = text.substring(1);
        DocumentContext doc = JsonUtils.toJsonDoc(text);
        evalJsonEmbeddedExpressions(doc, context);
        JSONObject json = JSONValue.parse(doc.jsonString(), JSONObject.class);
        BsonDocument bson = BsonUtils.jsonToBson(json);
        return new ScriptValue(bson);
    } else if (isXml(text)) {
        Document doc = XmlUtils.toXmlDoc(text);
        evalXmlEmbeddedExpressions(doc, context);
        return new ScriptValue(doc);
    } else if (isXmlPath(text)) {
        return evalXmlPathOnVarByName(ScriptValueMap.VAR_RESPONSE, text, context);
    } else if (isStringExpression(text)) { // has to be above variableAndXml/JsonPath because of / in URL-s etc
        return evalInNashorn(text, context);
    } else if (isVariableAndJsonPath(text)) {
        Pair<String, String> pair = parseVariableAndPath(text);
        return evalJsonPathOnVarByName(pair.getLeft(), pair.getRight(), context);
    } else if (isVariableAndXmlPath(text)) {
        Pair<String, String> pair = parseVariableAndPath(text);
        return evalXmlPathOnVarByName(pair.getLeft(), pair.getRight(), context);
    } else {
        // js expressions e.g. foo, foo(bar), foo.bar, foo + bar, 5, true
        // including function declarations e.g. function() { }
        return evalInNashorn(text, context);
    }
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.fineGrainedLogicForOptimization.ReactorConsumer.java

private Pair<Boolean, Long> runSolver(SolutionPerJob solPerJob) {
    Pair<Optional<Double>, Long> solverResult = solverCache.evaluate(solPerJob);
    Optional<Double> solverMetric = solverResult.getLeft();
    long runtime = solverResult.getRight();

    if (solverMetric.isPresent()) {
        PerformanceSolver solver = solverCache.getPerformanceSolver();
        Technology technology = dataService.getScenario().getTechnology();
        Double mainMetric = solver.transformationFromSolverResult(solPerJob, technology)
                .apply(solverMetric.get());
        solver.metricUpdater(solPerJob, technology).accept(mainMetric);
        boolean feasible = solver.feasibilityCheck(solPerJob, technology).test(mainMetric);
        solPerJob.setFeasible(feasible);
        return new ImmutablePair<>(true, runtime);
    }//from www  .  jav  a  2s .  co  m

    solverCache.invalidate(solPerJob);
    return new ImmutablePair<>(false, runtime);
}

From source file:de.johni0702.minecraft.gui.layout.HorizontalLayout.java

@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container,
        ReadableDimension size) {//from   w  w  w  .jav a 2  s  . c  o  m
    int x = 0;
    int spacing = 0;
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        x += spacing;
        spacing = this.spacing;

        GuiElement element = entry.getKey();
        Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
        Dimension elementSize = new Dimension(element.getMinSize());
        ReadableDimension elementMaxSize = element.getMaxSize();
        elementSize.setWidth(
                Math.min(size.getWidth() - x, Math.min(elementSize.getWidth(), elementMaxSize.getWidth())));
        elementSize.setHeight(Math.min(size.getHeight(), elementMaxSize.getHeight()));
        int remainingHeight = size.getHeight() - elementSize.getHeight();
        int y = (int) (data.alignment * remainingHeight);
        map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        x += elementSize.getWidth();
    }
    if (alignment != Alignment.LEFT) {
        int remaining = size.getWidth() - x;
        if (alignment == Alignment.CENTER) {
            remaining /= 2;
        }
        for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
            ((Point) pair.getLeft()).translate(remaining, 0);
        }
    }
    return map;
}

From source file:de.johni0702.minecraft.gui.layout.VerticalLayout.java

@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container,
        ReadableDimension size) {//  w  w  w. ja  va2 s.  com
    int y = 0;
    int spacing = 0;
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        y += spacing;
        spacing = this.spacing;

        GuiElement element = entry.getKey();
        Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
        Dimension elementSize = new Dimension(element.getMinSize());
        ReadableDimension elementMaxSize = element.getMaxSize();
        elementSize.setHeight(
                Math.min(size.getHeight() - y, Math.min(elementSize.getHeight(), elementMaxSize.getHeight())));
        elementSize.setWidth(Math.min(size.getWidth(), element.getMaxSize().getWidth()));
        int remainingWidth = size.getWidth() - elementSize.getWidth();
        int x = (int) (data.alignment * remainingWidth);
        map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        y += elementSize.getHeight();
    }
    if (alignment != Alignment.TOP) {
        int remaining = size.getHeight() - y;
        if (alignment == Alignment.CENTER) {
            remaining /= 2;
        }
        for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
            ((Point) pair.getLeft()).translate(0, remaining);
        }
    }
    return map;
}

From source file:com.blacklocus.jres.handler.JresJsonResponseHandler.java

@Override
public REPLY handleResponse(HttpResponse http) throws IOException, JresErrorReplyException {

    int statusCode = http.getStatusLine().getStatusCode();

    if (statusCode / 100 == 2) {
        Pair<JsonNode, REPLY> replyPair = read(http, getReplyClass());
        REPLY reply = replyPair.getRight();
        reply.node(replyPair.getLeft());
        return reply;

    } else if (statusCode / 100 >= 4) {
        Pair<JsonNode, JresJsonReply> replyPair = read(http, null); // only want the node
        JsonNode node = replyPair.getLeft();
        String error = node != null && node.has("error") ? node.get("error").asText() : null;
        throw new JresErrorReplyException(error, statusCode, node);

    } else {/*from w ww . j  ava 2  s .  c  om*/
        // Does ElasticSearch ever return 1xx or 3xx (or other)?
        throw new RuntimeException("Erm... dernt nerr wert erm derern?"); // Um, don't know what I'm doing?
    }

}

From source file:hu.ppke.itk.nlpg.purepos.common.lemma.SuffixLemmaTransformation.java

@Override
protected Pair<String, Integer> encode(String word, Pair<String, Integer> representation) {
    int tagCode = representation.getRight() / SHIFT;
    int cutSize = representation.getRight() % SHIFT;
    String add = representation.getLeft();
    String lemma = word.substring(0, word.length() - cutSize) + add;
    return Pair.of(lemma, tagCode);
}

From source file:flens.input.GraphiteInput.java

@Override
//metric_path value timestamp\n  
//http://graphite.wikidot.com/getting-your-data-into-graphite
public void readAndProcess(Pair<String, BufferedReader> inx) throws IOException {
    BufferedReader in = inx.getRight();
    String host = inx.getLeft();
    String line = in.readLine();/*from w  ww . ja v  a 2  s  .  com*/
    if (line == null)
        throw new IOException("connection lost");

    Scanner st = new Scanner(line);

    try {

        String metricName = st.next();
        String metric = st.next();
        long time = st.nextLong();

        Map<String, Object> tags = new HashMap<String, Object>();

        tags.put(Constants.METRIC, metricName);
        tags.put(Constants.VALUE, metric);

        Record r = Record.createWithTimeHostAndValues(time * 1000, host, tags);
        dispatch(r);
    } catch (NoSuchElementException e) {
        warn("line too short", line);
    }

}

From source file:com.twitter.distributedlog.subscription.ZKSubscriptionsStore.java

private void getLastCommitPositions(final Promise<Map<String, DLSN>> result, List<String> subscribers) {
    List<Future<Pair<String, DLSN>>> futures = new ArrayList<Future<Pair<String, DLSN>>>(subscribers.size());
    for (String s : subscribers) {
        final String subscriber = s;
        Future<Pair<String, DLSN>> future =
                // Get the last commit position from zookeeper
                getSubscriber(subscriber).getLastCommitPositionFromZK()
                        .map(new AbstractFunction1<DLSN, Pair<String, DLSN>>() {
                            @Override
                            public Pair<String, DLSN> apply(DLSN dlsn) {
                                return Pair.of(subscriber, dlsn);
                            }/*from w  w w  .  j av a2 s .  c o  m*/
                        });
        futures.add(future);
    }
    Future.collect(futures).foreach(new AbstractFunction1<List<Pair<String, DLSN>>, BoxedUnit>() {
        @Override
        public BoxedUnit apply(List<Pair<String, DLSN>> subscriptions) {
            Map<String, DLSN> subscriptionMap = new HashMap<String, DLSN>();
            for (Pair<String, DLSN> pair : subscriptions) {
                subscriptionMap.put(pair.getLeft(), pair.getRight());
            }
            result.setValue(subscriptionMap);
            return BoxedUnit.UNIT;
        }
    });
}

From source file:com.cfitzarl.cfjwed.controller.StatsController.java

/**
 * This returns four different statistics back to the browser:
 *
 * <ul>//w ww  . j a  va2  s. c om
 *    <li>The number of attendants who have accepted</li>
 *    <li>The number of attendants who have declined</li>
 *    <li>The number of attendants who have not yet responded</li>
 *    <li>A breakdown of each meal and how many people have chosen them</li>
 * </ul>
 *
 * @return the stats
 */
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "", method = RequestMethod.GET)
public StatsDTO displayStats() {

    StatsDTO dto = new StatsDTO();
    dto.setAcceptedAttendants(attendantService.countByStatus(ResponseStatus.ACCEPTED));
    dto.setDeclinedAttendants(attendantService.countByStatus(ResponseStatus.DECLINED));
    dto.setPendingAttendants(attendantService.countByStatus(ResponseStatus.PENDING));

    for (Pair<MealOption, Long> mealGroupings : mealOptionService.getChosenMealCount()) {
        dto.addMealStat(mealGroupings.getLeft().getName(), mealGroupings.getRight());
    }

    return dto;
}