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

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

Introduction

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

Prototype

@Override
public final L getKey() 

Source Link

Document

Gets the key from this pair.

This method implements the Map.Entry interface returning the left element as the key.

Usage

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 . jav  a2s  . c  o m*/
}

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();
        String v = kv.getValue();
        parameters.put(k, v);//from  ww  w  . j av a2 s. c  om
    }
    return parameters;
}

From source file:com.trenako.web.infrastructure.SearchCriteriaUrlBuilder.java

private static void append(SearchCriteria sc, StringBuilder sb, Criteria criterion) {
    String criteriaName = criterion.criterionName();
    Pair<String, String> criteria = sc.get(criterion);
    if (criteria == null)
        return;/*from  w  w  w  .ja  v a  2 s .  c  o  m*/

    sb.append("/").append(criteriaName).append("/").append(criteria.getKey());
}

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   ww w . java  2s .c  o m*/
    }
    return Optional.empty();
}

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
 *//* w  ww  . j  a v  a2 s.  co  m*/
@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.galenframework.speclang2.pagespec.ForLoop.java

public static ForLoop read(boolean isSimpleLoop, PageSpecHandler pageSpecHandler, StringCharReader reader,
        StructNode originNode) {/*from ww  w .j a va  2s.  co 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) {//from ww  w  .  j  a  v  a2s .  co  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);
        } 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;
    }
}

From source file:com.galenframework.parser.GalenPageActionReader.java

private static GalenPageAction checkActionFrom(String[] args, String originalText) {
    CommandLineReader reader = new CommandLineReader(args);

    String specPath = null;/*  w  w w  .j  a v  a 2s  .  c o m*/
    List<String> includedTags = new LinkedList<>();
    List<String> excludedTags = new LinkedList<>();
    Map<String, Object> jsVariables = new HashMap<>();

    //Skipping the check action name
    reader.skipArgument();

    while (reader.hasNext()) {
        if (!reader.isNextArgument()) {
            specPath = reader.readNext();
        } else {
            Pair<String, String> argument = reader.readArgument();

            if (argument.getKey().equals("include")) {
                includedTags.addAll(readTags(argument.getValue()));
            } else if (argument.getKey().equals("exclude")) {
                excludedTags.addAll(readTags(argument.getValue()));
            } else if (argument.getKey().startsWith("V")) {
                String varName = argument.getKey().substring(1);
                String varValue = argument.getValue();
                jsVariables.put(varName, varValue);
            } else {
                throw new SyntaxException("Unknown argument: " + argument.getKey());
            }
        }
    }

    if (specPath == null || specPath.isEmpty()) {
        throw new SyntaxException("Missing spec path");
    }

    return new GalenPageActionCheck().withSpec(specPath).withIncludedTags(includedTags)
            .withExcludedTags(excludedTags).withJsVariables(jsVariables);
}

From source file:com.yahoo.bullet.parsing.RuleUtils.java

@SafeVarargs
public static String makeMap(Pair<String, String>... pairs) {
    StringBuilder builder = new StringBuilder();
    builder.append("{");

    String delimiter = "";
    for (Pair<String, String> pair : pairs) {
        builder.append(delimiter).append("'").append(pair.getKey()).append("'").append(" : '")
                .append(pair.getValue()).append("'");
        delimiter = ", ";
    }// ww  w  .  j  av  a  2  s . c o  m
    builder.append("}");
    return builder.toString();
}