Example usage for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair

Introduction

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

Prototype

public ImmutablePair(final L left, final R right) 

Source Link

Document

Create a new pair instance.

Usage

From source file:com.epam.dlab.backendapi.core.commands.CommandParserMock.java

/**
 * Return pair name/value separated./*from  ww  w . ja  v  a2 s .  c  o  m*/
 *
 * @param argName   name of argument.
 * @param value     value.
 * @param separator separator.
 */
private Pair<String, String> getPair(String argName, String value, String separator) {
    String[] array = value.split(separator);
    if (array.length != 2) {
        throw new DlabException("Invalid value for \"" + argName + "\": " + value);
    }
    return new ImmutablePair<>(array[0], array[1]);
}

From source file:com.pinterest.terrapin.client.FileSetViewManager.java

public Pair<FileSetInfo, ViewInfo> getFileSetViewInfo(String fileSet) throws TerrapinGetException {
    FileSetInfo fileSetInfo = zkBackedFileSetInfoMap.get(fileSet);
    if (fileSetInfo == null) {
        throw new TerrapinGetException("File set " + fileSet + " not found.",
                TerrapinGetErrorCode.FILE_SET_NOT_FOUND);
    }/*  w ww . j av  a2  s.co  m*/
    if (!fileSetInfo.valid) {
        throw new TerrapinGetException("Invalid info for fileset " + fileSet,
                TerrapinGetErrorCode.FILE_SET_NOT_FOUND);
    }
    ViewInfo viewInfo = zkBackedViewInfoMap.get(fileSetInfo.servingInfo.helixResource);
    if (viewInfo == null) {
        LOG.warn("View not found for " + fileSet + ", trying backup resource");
        fileSetInfo = fileSetInfoBackupMap.get(fileSet);
        if (fileSetInfo == null) {
            throw new TerrapinGetException("View for file set " + fileSet + " not found.",
                    TerrapinGetErrorCode.INVALID_FILE_SET_VIEW);
        }
        viewInfo = zkBackedViewInfoMap.get(fileSetInfo.servingInfo.helixResource);
        if (viewInfo == null) {
            throw new TerrapinGetException("View not file set " + fileSet + " not found.",
                    TerrapinGetErrorCode.INVALID_FILE_SET_VIEW);
        }
    }
    return new ImmutablePair(fileSetInfo, viewInfo);
}

From source file:lineage2.loginserver.accounts.Account.java

/**
 * Method addAccountInfo./*  w  w w  . j  ava2  s. c  om*/
 * @param serverId int
 * @param size int
 * @param deleteChars int[]
 */
public void addAccountInfo(int serverId, int size, int[] deleteChars) {
    _serversInfo.put(serverId, new ImmutablePair<>(size, deleteChars));
}

From source file:io.cloudslang.lang.compiler.modeller.MetadataModellerImpl.java

private Pair<Metadata, List<RuntimeException>> transformToExecutableMetadata(Map<String, String> parsedData) {
    String description = "";
    String prerequisites = "";
    Map<String, String> inputs = new LinkedHashMap<>();
    Map<String, String> outputs = new LinkedHashMap<>();
    Map<String, String> results = new LinkedHashMap<>();
    Map<String, String> systemProperties = new LinkedHashMap<>();
    List<RuntimeException> errors = new ArrayList<>();

    for (Map.Entry<String, String> entry : parsedData.entrySet()) {
        String declaration = entry.getKey();
        String[] declarationElements = descriptionPatternMatcher.splitDeclaration(declaration);
        String tag = declarationElements[0];
        if (DescriptionTag.isDescriptionTag(tag)) {
            String content = entry.getValue();
            DescriptionTag descriptionTag = DescriptionTag.fromString(tag);
            if (descriptionTag != null) {
                switch (descriptionTag) {
                case DESCRIPTION:
                    description = content;
                    break;
                case PREREQUISITES:
                    prerequisites = content;
                    break;
                case INPUT:
                    processExecutableDeclaration(declarationElements, errors, tag, inputs, content);
                    break;
                case OUTPUT:
                    processExecutableDeclaration(declarationElements, errors, tag, outputs, content);
                    break;
                case RESULT:
                    processExecutableDeclaration(declarationElements, errors, tag, results, content);
                    break;
                case SYSTEM_PROPERTY:
                    processExecutableDeclaration(declarationElements, errors, tag, systemProperties, content);
                    break;
                default:
                    // shouldn't get here
                    errors.add(new NotImplementedException("Unrecognized tag: " + descriptionTag));
                }// w  w  w .j a  v  a 2 s  . c  o  m
            } else {
                // shouldn't get here
                errors.add(new RuntimeException("Unrecognized tag: " + tag));
            }
        } else {
            errors.add(new RuntimeException("Unrecognized tag for executable description section: " + tag));
        }
    }

    Metadata executableMetadata = new Metadata(description, prerequisites, inputs, outputs, results,
            systemProperties);
    return new ImmutablePair<>(executableMetadata, errors);
}

From source file:io.knotx.assembler.FragmentAssemblerTest.java

private Pair<List<String>, String> toPair(String filePath, String... knots) throws IOException {
    return new ImmutablePair<>(Arrays.asList(knots), FileReader.readText(filePath));
}

From source file:com.garethahealy.quotalimitsgenerator.cli.parsers.DefaultCLIParser.java

private Map<String, Pair<Integer, Integer>> parseLines(String instanceTypeCsv)
        throws IOException, URISyntaxException, ParseException {
    InputStreamReader inputStreamReader;
    if (instanceTypeCsv.equalsIgnoreCase("classpath")) {
        inputStreamReader = new InputStreamReader(
                getClass().getClassLoader().getResourceAsStream("instancetypes.csv"), Charset.forName("UTF-8"));
    } else {//  w  ww .  ja  v a  2s  .  c o m
        URI uri = new URI(instanceTypeCsv);
        inputStreamReader = new InputStreamReader(new FileInputStream(new File(uri)), Charset.forName("UTF-8"));
    }

    CSVParser parser = null;
    List<CSVRecord> lines = null;
    try {
        parser = CSVFormat.DEFAULT.parse(new BufferedReader(inputStreamReader));
        lines = parser.getRecords();
    } finally {
        inputStreamReader.close();

        if (parser != null) {
            parser.close();
        }
    }

    if (lines == null || lines.size() <= 0) {
        throw new ParseException("instance-type-csv data is empty");
    }

    Map<String, Pair<Integer, Integer>> linesMap = new HashMap<String, Pair<Integer, Integer>>();
    for (CSVRecord current : lines) {
        linesMap.put(current.get(1), new ImmutablePair<Integer, Integer>(Integer.parseInt(current.get(2)),
                Integer.parseInt(current.get(3))));
    }

    return linesMap;
}

From source file:eu.nerdz.api.impl.reverse.messages.ReverseConversationHandler.java

/**
 * Fetches messages and returns a pair containing a list of messages of given conversation and also a Boolean representing the fact that the conversation has still messages to be read.
 * Not working properly in Reverse (but working great in FastReverse)
 * @param conversation//from  w w w  . j  a  v  a2s  .  c  om
 * @param start
 * @param howMany
 * @return
 * @throws IOException
 * @throws HttpException
 * @throws ContentException
 */
protected Pair<List<Message>, Boolean> getMessagesAndCheck(Conversation conversation, int start, int howMany)
        throws IOException, HttpException, ContentException {

    if (howMany > 10) {
        howMany = 10;
    }

    List<Message> messages;
    HashMap<String, String> form = new HashMap<String, String>(4);
    form.put("from", String.valueOf(conversation.getOtherID()));
    form.put("to", String.valueOf(this.mMessenger.getUserID()));
    form.put("start", String.valueOf(start / howMany));
    form.put("num", String.valueOf(howMany));

    UserInfo userInfo = this.mMessenger.getUserInfo();

    String body = this.mMessenger.post("/pages/pm/read.html.php?action=conversation", form);

    int endOfList = body.indexOf("<form id=\"convfrm\"");
    Boolean hasMore = body.contains("class=\"more_btn\" href=\"#\">");

    switch (endOfList) {
    case 0:
        return null;
    case -1: {
        if (start == 0)
            throw new ContentException("malformed response: " + body);
    }
    default: {
        int headOfList = body.indexOf("<div style=\"margin-top: 3px\" id=\"pm");
        if (headOfList < 0) {
            throw new ContentException("malformed response: " + body);
        }

        messages = new LinkedList<Message>();
        for (String messageString : this.splitMessages(
                endOfList > 0 ? body.substring(headOfList, endOfList) : body.substring(headOfList)))
            messages.add(new ReverseMessage(conversation, userInfo, this.parseDate(messageString),
                    this.parseMessage(messageString),
                    this.parseSender(messageString).equals(conversation.getOtherName())));
    }
    }

    return new ImmutablePair<List<Message>, Boolean>(messages, hasMore);
}

From source file:com.minlia.cloud.framework.common.security.SpringSecurityUtil.java

public static Pair<String, String> decodeAuthorizationKey(final String basicAuthValue) {
    if (basicAuthValue == null) {
        return null;
    }//  www  .ja va2  s.c  o  m
    final byte[] decodeBytes = Base64.decodeBase64(basicAuthValue.substring(basicAuthValue.indexOf(' ') + 1));
    String decoded = null;
    try {
        decoded = new String(decodeBytes, "UTF-8");
    } catch (final UnsupportedEncodingException e) {
        return null;
    }
    final int indexOfDelimiter = decoded.indexOf(':');
    final String username = decoded.substring(0, indexOfDelimiter);
    final String password = decoded.substring(indexOfDelimiter + 1);
    return new ImmutablePair<String, String>(username, password);
}

From source file:com.nextdoor.bender.operation.conditional.ConditionalOperationTest.java

@Test
public void testTwoConditions() {
    List<Pair<FilterOperation, List<OperationProcessor>>> conditions = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>();
    /*//from w w  w.  j ava2  s .co m
     * Case 1
     */
    List<OperationProcessor> case1Ops = new ArrayList<OperationProcessor>();

    DummyAppendOperationFactory pos = new DummyAppendOperationFactory();
    DummyAppendOperationConfig posConf = new DummyAppendOperationConfig();
    posConf.setAppendStr("+");
    pos.setConf(posConf);
    case1Ops.add(new OperationProcessor(pos));
    FilterOperation case1Filter = new BasicFilterOperation(false);
    conditions.add(new ImmutablePair<FilterOperation, List<OperationProcessor>>(case1Filter, case1Ops));

    /*
     * Case 2
     */
    List<OperationProcessor> case2Ops = new ArrayList<OperationProcessor>();

    DummyAppendOperationFactory neg = new DummyAppendOperationFactory();
    DummyAppendOperationConfig negConf = new DummyAppendOperationConfig();
    negConf.setAppendStr("-");
    neg.setConf(negConf);
    case2Ops.add(new OperationProcessor(neg));
    FilterOperation case2Filter = new BasicFilterOperation(true);
    conditions.add(new ImmutablePair<FilterOperation, List<OperationProcessor>>(case2Filter, case2Ops));

    ConditionalOperation op = new ConditionalOperation(conditions, false);

    /*
     * Create thread that supplies input events
     */
    Queue<InternalEvent> inputQueue = new Queue<InternalEvent>();
    supply(2, inputQueue);

    /*
     * Process
     */
    Stream<InternalEvent> input = inputQueue.stream();
    Stream<InternalEvent> output = op.getOutputStream(input);

    List<String> actual = output.map(m -> {
        return m.getEventObj().getPayload().toString();
    }).collect(Collectors.toList());
    List<String> expected = Arrays.asList("0-", "1-");

    assertEquals(2, actual.size());
    assertTrue(expected.containsAll(actual));
}

From source file:com.linkedin.pinot.broker.broker.helix.ClusterChangeMediator.java

@Override
public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs, NotificationContext context) {
    // If the deferred update thread is alive, defer the update
    if (_deferredClusterUpdater != null && _deferredClusterUpdater.isAlive()) {
        try {/*from w ww .  ja  va  2 s .  c  om*/
            _clusterChangeQueue
                    .put(new ImmutablePair<>(UpdateType.INSTANCE_CONFIG, System.currentTimeMillis()));
        } catch (InterruptedException e) {
            LOGGER.warn("Was interrupted while trying to add external view change to queue", e);
        }
    } else {
        LOGGER.warn(
                "Deferred cluster updater thread is null or stopped, not deferring instance config change notification");
        _helixExternalViewBasedRouting.processInstanceConfigChange();
    }
}