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

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

Introduction

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

Prototype

@Override
public R getValue() 

Source Link

Document

Gets the value from this pair.

This method implements the Map.Entry interface returning the right element as the value.

Usage

From source file:com.hortonworks.registries.storage.util.StorageUtils.java

public static Optional<Pair<Field, Long>> getVersionFieldValue(Storable storable)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    for (Pair<Field, Object> kv : getAnnotatedFieldValues(storable, VersionField.class)) {
        if (kv.getValue() instanceof Long) {
            return Optional.of(Pair.of(kv.getKey(), (Long) kv.getValue()));
        }//from w  ww .j  av a  2  s .  c o  m
    }
    return Optional.empty();
}

From source file:com.quartercode.eventbridge.test.ExtraAssert.java

public static void assertMapEquals(String message, Map<?, ?> map, Pair<?, ?>... entries) {

    assertTrue(message, map.size() == entries.length);

    Map<?, ?> mapClone = new HashMap<>(map);
    for (Pair<?, ?> expectedEntry : entries) {
        Object actualValue = mapClone.get(expectedEntry.getKey());
        assertTrue(message, Objects.equals(expectedEntry.getValue(), actualValue));

        mapClone.remove(expectedEntry.getKey());
    }/*from  w  w w.  j  av a  2 s .  c  o  m*/
}

From source file:io.wcm.caravan.pipeline.extensions.hal.crawler.LinkExtractors.java

/**
 * Returns all relations and links in a HAL resource having no URI template expressions.
 * @return Filtered links/*  ww w .j  av a 2 s  .c o  m*/
 */
public static LinkExtractor noUriTemplates() {
    return new LinkExtractor() {

        @Override
        public ListMultimap<String, Link> extract(HalResource hal) {
            return HalUtil.getAllLinks(hal, new Predicate<Pair<String, Link>>() {

                @Override
                public boolean apply(Pair<String, Link> input) {
                    return UriTemplate.fromTemplate(input.getValue().getHref()).expressionCount() == 0;
                }
            });
        }

        @Override
        public String getId() {
            return "NO-URI-TEMPLATES";
        }

    };
}

From source file:com.creditcloud.investmentfund.model.huaan.money.CommonMessage.java

protected static Map<String, String> parseResponseText(String responseText) {
    List<String> lines = StringUtils.parseLines(responseText);
    Map<String, String> parameters = new HashMap<>();
    final String splitterKeyValue = "=";
    for (String line : lines) {
        Pair<String, String> kv = StringUtils.parseNamedValue(line, splitterKeyValue);
        String k = kv.getKey();/*ww w .ja v  a 2 s . com*/
        String v = kv.getValue();
        parameters.put(k, v);
    }
    return parameters;
}

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

public static <K, L> Pair<K, Double> findMax2(Map<K, Pair<L, Double>> map) {
    Pair<K, Double> ret = null;
    for (Map.Entry<K, Pair<L, Double>> e : map.entrySet()) {
        if (ret == null || e.getValue().getValue() > ret.getValue()) {
            ret = Pair.of(e.getKey(), e.getValue().getValue());
        }// w w  w  .j a v  a 2 s.c  om
    }
    return ret;
}

From source file:com.spleefleague.core.utils.DatabaseConnection.java

public static void updateFields(MongoCollection<Document> dbcoll, Document index,
        Pair<String, Object>... update) {
    Map<String, Object> updates = new HashMap<>();
    for (Pair<String, Object> pair : update)
        updates.put(pair.getKey(), pair.getValue());
    updateFields(dbcoll, index, new Document(updates));
}

From source file:net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.java

/**
 * @param listData map of modId string to version string, represents the mods available on the given side
 * @param side the side that listData is coming from, either client or server
 * @return null if everything is fine, returns a string error message if there are mod rejections
 *//* www.  j  ava2 s .  c om*/
@Nullable
public static String checkModList(Map<String, String> listData, Side side) {
    List<Pair<ModContainer, String>> rejects = NetworkRegistry.INSTANCE.registry().entrySet().stream()
            .map(entry -> Pair.of(entry.getKey(), entry.getValue().checkCompatible(listData, side)))
            .filter(pair -> pair.getValue() != null).sorted(Comparator.comparing(o -> o.getKey().getName()))
            .collect(Collectors.toList());
    if (rejects.isEmpty()) {
        return null;
    } else {
        List<String> rejectStrings = new ArrayList<>();
        for (Pair<ModContainer, String> reject : rejects) {
            ModContainer modContainer = reject.getKey();
            rejectStrings.add(modContainer.getName() + ": " + reject.getValue());
        }
        String rejectString = String.join("\n", rejectStrings);
        FMLLog.log.info("Rejecting connection {}: {}", side, rejectString);
        return String.format("Server Mod rejections:\n%s", rejectString);
    }
}

From source file:com.helion3.prism.api.query.QueryBuilder.java

/**
 * Parses a parameter argument.//from   w  w  w .j  av a 2  s  .c  o  m
 *
 * @param session QuerySession current session.
 * @param query Query query being built.
 * @param parameter String argument which should be a parameter
 * @return Optional<ListenableFuture<?>>
 * @throws ParameterException
 */
private static Optional<ListenableFuture<?>> parseParameterFromArgument(QuerySession session, Query query,
        Pair<String, String> parameter) throws ParameterException {
    // Simple validation
    if (parameter.getKey().length() <= 0 || parameter.getValue().length() <= 0) {
        throw new ParameterException("Invalid empty value for parameter \"" + parameter.getKey() + "\".");
    }

    // Find a handler
    Optional<ParameterHandler> optionalHandler = Prism.getParameterHandler(parameter.getKey());
    if (!optionalHandler.isPresent()) {
        throw new ParameterException(
                "\"" + parameter.getKey() + "\" is not a valid parameter. No handler found.");
    }

    ParameterHandler handler = optionalHandler.get();

    // Allows this command source?
    if (!handler.acceptsSource(session.getCommandSource().get())) {
        throw new ParameterException(
                "This command source may not use the \"" + parameter.getKey() + "\" parameter.");
    }

    // Validate value
    if (!handler.acceptsValue(parameter.getValue())) {
        throw new ParameterException(
                "Invalid value \"" + parameter.getValue() + "\" for parameter \"" + parameter.getKey() + "\".");
    }

    return handler.process(session, parameter.getKey(), parameter.getValue(), query);
}

From source file:com.galenframework.speclang2.pagespec.ForLoop.java

public static ForLoop read(boolean isSimpleLoop, PageSpecHandler pageSpecHandler, StringCharReader reader,
        StructNode originNode) {/* w  w  w  .j  a v  a2  s.c  o m*/
    try {
        String emptyness = reader.readUntilSymbol('[').trim();
        if (!emptyness.isEmpty()) {
            throw new SyntaxException(originNode, "Unexpected token: " + emptyness);
        }

        String sequenceStatement = reader.readUntilSymbol(']');
        Object[] sequence;
        if (isSimpleLoop) {
            sequence = readSequenceForSimpleLoop(sequenceStatement, originNode.getPlace());
        } else {
            sequence = readSequenceFromPageObjects(sequenceStatement, pageSpecHandler);
        }

        String variableName = DEFAULT_VARIABLE_NAME;

        String previousMapping = null;
        String nextMapping = null;
        String indexMapping = null;

        if (reader.hasMoreNormalSymbols()) {
            String nextWord = reader.readWord();
            if (!nextWord.equals("as")) {
                throw new SyntaxException("Invalid token: " + nextWord);
            }

            variableName = reader.readWord();

            if (variableName.isEmpty()) {
                throw new SyntaxException("Missing index");
            }

            if (reader.hasMoreNormalSymbols()) {
                reader.readUntilSymbol(',');

                Pair<String, String> extraMappings = parseExtraMapping(reader);
                if ("prev".equals(extraMappings.getKey())) {
                    previousMapping = extraMappings.getValue();
                } else if ("next".equals(extraMappings.getKey())) {
                    nextMapping = extraMappings.getValue();
                } else if ("index".equals(extraMappings.getKey())) {
                    indexMapping = extraMappings.getValue();
                } else {
                    throw new SyntaxException("Unknown loop mapping: " + extraMappings.getKey());
                }
            }
        }
        return new ForLoop(sequence, variableName, previousMapping, nextMapping, indexMapping);
    } catch (SyntaxException ex) {
        ex.setPlace(originNode.getPlace());
        throw ex;
    }
}

From source file:com.galenframework.speclang2.reader.pagespec.ForLoop.java

public static ForLoop read(boolean isSimpleLoop, PageSpecHandler pageSpecHandler, StringCharReader reader,
        StructNode originNode) {// w  w  w  .j  a  va  2 s.  com
    try {
        String emptyness = reader.readUntilSymbol('[').trim();
        if (!emptyness.isEmpty()) {
            throw new SyntaxException(originNode, "Unexpected token: " + emptyness);
        }

        String sequenceStatement = reader.readUntilSymbol(']');
        Object[] sequence;
        if (isSimpleLoop) {
            sequence = readSequenceForSimpleLoop(sequenceStatement);
        } else {
            sequence = readSequenceFromPageObjects(sequenceStatement, pageSpecHandler);
        }

        String indexName = INDEX_DEFAULT_NAME;

        String previousMapping = null;
        String nextMapping = null;

        if (reader.hasMoreNormalSymbols()) {
            String as = reader.readWord();
            if (as.equals("as")) {

            } else {
                throw new SyntaxException("Invalid token: " + as);
            }

            indexName = reader.readWord();

            if (indexName.isEmpty()) {
                throw new SyntaxException("Missing index");
            }

            if (reader.hasMoreNormalSymbols()) {
                reader.readUntilSymbol(',');

                Pair<String, String> extraMappings = parseExtraMapping(reader);
                if ("prev".equals(extraMappings.getKey())) {
                    previousMapping = extraMappings.getValue();
                } else if ("next".equals(extraMappings.getKey())) {
                    nextMapping = extraMappings.getValue();
                } else {
                    throw new SyntaxException("Unknown loop mapping: " + extraMappings.getKey());
                }
            }
        }
        return new ForLoop(sequence, indexName, previousMapping, nextMapping);
    } catch (SyntaxException ex) {
        ex.setLine(new Line(originNode.getSource(), originNode.getFileLineNumber()));
        throw ex;
    }
}