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

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

Introduction

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

Prototype

public static <L, R> ImmutablePair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:com.wrmsr.wava.basic.BasicLoopInfo.java

public static BasicLoopInfo build(Iterable<Basic> basics, Multimap<Name, Name> inputs, BasicDominatorInfo di) {
    Set<Name> loops = findBasicLoops(basics, di);
    SetMultimap<Name, Name> backEdges = findBasicBackEdges(basics, loops, di);
    SetMultimap<Name, Name> loopContents = loops.stream()
            .flatMap(loop -> getLoopContents(loop, inputs, backEdges).stream()
                    .map(child -> ImmutablePair.of(loop, child)))
            .collect(toHashMultimap());//ww w. j ava  2  s .c o  m
    Map<Name, Name> loopParents = getLoopParents(loopContents);
    return new BasicLoopInfo(loops, backEdges, loopContents, loopParents);
}

From source file:io.lavagna.service.LavagnaExporter.java

private ImmutablePair<Board, Card> findByCardId(int id) {
    Card c = cardRepository.findBy(id);/*from w w w .j  a v a 2 s.co m*/
    Board b = boardRepository.findBoardById(boardColumnRepository.findById(c.getColumnId()).getBoardId());
    return ImmutablePair.of(b, c);
}

From source file:io.lavagna.service.CardDataService.java

@Transactional(readOnly = false)
public ImmutablePair<Boolean, CardData> createFile(String name, String digest, long fileSize, int cardId,
        InputStream content, String contentType, User user, Date time) {
    if (!cardDataRepository.fileExists(digest)) {
        cardDataRepository.addUploadContent(digest, fileSize, content, contentType);
    }//  w ww .j  a v  a  2  s .co  m
    if (!cardDataRepository.isFileAvailableByCard(digest, cardId)) {
        CardData file = cardDataRepository.createData(cardId, CardType.FILE, digest);
        cardDataRepository.createUploadInfo(digest, name, name, file.getId());
        eventRepository.insertFileEvent(file.getId(), cardId, EventType.FILE_UPLOAD, user.getId(), file.getId(),
                name, time);
        return ImmutablePair.of(true, file);
    }
    return ImmutablePair.of(false, null);
}

From source file:com.linkedin.pinot.tools.StarTreeIndexViewer.java

private int build(StarTreeIndexNodeInterf indexNode, StarTreeJsonNode json) {
    Iterator<? extends StarTreeIndexNodeInterf> childrenIterator = indexNode.getChildrenIterator();
    if (!childrenIterator.hasNext()) {
        return 0;
    }//from  w w  w. j  a va2  s  .c o  m
    int childDimensionId = indexNode.getChildDimensionName();
    String childDimensionName = dimensionNameToIndexMap.inverse().get(childDimensionId);
    Dictionary dictionary = dictionaries.get(childDimensionName);
    int totalChildNodes = indexNode.getNumChildren();

    Comparator<Pair<String, Integer>> comparator = new Comparator<Pair<String, Integer>>() {

        @Override
        public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
            return -1 * Integer.compare(o1.getRight(), o2.getRight());
        }
    };
    MinMaxPriorityQueue<Pair<String, Integer>> queue = MinMaxPriorityQueue.orderedBy(comparator)
            .maximumSize(MAX_CHILDREN).create();
    StarTreeJsonNode allNode = null;

    while (childrenIterator.hasNext()) {
        StarTreeIndexNodeInterf childIndexNode = childrenIterator.next();
        int childDimensionValueId = childIndexNode.getDimensionValue();
        String childDimensionValue = "ALL";
        if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) {
            childDimensionValue = dictionary.get(childDimensionValueId).toString();
        }
        StarTreeJsonNode childJson = new StarTreeJsonNode(childDimensionValue);
        totalChildNodes += build(childIndexNode, childJson);
        if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) {
            json.addChild(childJson);
            queue.add(ImmutablePair.of(childDimensionValue, totalChildNodes));
        } else {
            allNode = childJson;
        }
    }
    //put ALL node at the end
    if (allNode != null) {
        json.addChild(allNode);
    }
    if (totalChildNodes > MAX_CHILDREN) {
        Iterator<Pair<String, Integer>> qIterator = queue.iterator();
        Set<String> topKDimensions = new HashSet<>();
        topKDimensions.add("ALL");
        while (qIterator.hasNext()) {
            topKDimensions.add(qIterator.next().getKey());
        }
        Iterator<StarTreeJsonNode> iterator = json.getChildren().iterator();
        while (iterator.hasNext()) {
            StarTreeJsonNode next = iterator.next();
            if (!topKDimensions.contains(next.getName())) {
                iterator.remove();
            }
        }
    }
    return totalChildNodes;
}

From source file:io.github.carlomicieli.footballdb.starter.pages.TableTests.java

@Test
public void shouldBuildNewTablesWithHeaderRow() {
    Table table2x2WithHeaders = Table.builder().headers("FIRST", "SECOND").row("one", "two")
            .row("three", "four").toTable();

    assertThat(table2x2WithHeaders.size()).isEqualTo(ImmutablePair.of(2, 2));
    assertThat(table2x2WithHeaders.header()).contains("FIRST", "SECOND");
}

From source file:com.netflix.imfutility.conversion.executor.strategy.ExecutePipeStrategy.java

private void startPiper(ExternalProcess p1, ExternalProcess p2) {
    if (!startedPipes.contains(ImmutablePair.of(p1, p2))) {
        new Thread(new Piper(p1, p2)).start();
        startedPipes.add(ImmutablePair.of(p1, p2));
    }//from   www.  j  av a2 s  .c o m
}

From source file:de.openknowledge.jaxrs.versioning.conversion.InterversionConverter.java

private boolean match(VersionType<?> versionType, VersionType<?> previousVersionType,
        Set<Pair<VersionType<?>, VersionType<?>>> visited) {
    ImmutablePair<?, ?> pair = ImmutablePair.of(versionType, previousVersionType);
    if (visited.contains(pair)) {
        return true;
    }/* ww  w .  j ava2 s .  co m*/
    visited.add((Pair<VersionType<?>, VersionType<?>>) pair);
    for (VersionProperty property : versionType.getProperties()) {
        if (match(property, previousVersionType.getProperty(property.getName()), visited)) {
            return true;
        }
    }
    return false;
}

From source file:edu.ucdenver.ccp.nlp.ae.dict_util.GeneInfoToDictionary.java

private ImmutablePair<String, String> parseLine(String line) {
    try {/*from ww  w .  jav  a 2  s . co  m*/
        String[] parts = line.split("\t");

        String id = parts[1];
        String name = parts[2];
        return ImmutablePair.of(id, name);
    } catch (Exception x) {
        System.out.println("error: " + x);
        System.out.println("LINE:" + line);
        x.printStackTrace();
        throw new RuntimeException(x);
    }
}

From source file:io.github.carlomicieli.footballdb.starter.pages.TableTests.java

@Test
public void shouldBuildNewTablesWithHeaderRowWhenHeadAreSpanOverMultipleColumns() {
    Table table1x4WithHeaders = Table.builder().headers(cells(cell("FIRST"), multiple("SECOND", 3)))
            .row("one", "two", "three", "four").toTable();

    assertThat(table1x4WithHeaders.size()).isEqualTo(ImmutablePair.of(1, 4));
    assertThat(table1x4WithHeaders.header()).contains("FIRST", "SECOND", "SECOND", "SECOND");
}

From source file:io.dockstore.webservice.helpers.EntryVersionHelper.java

private Map<String, ImmutablePair<SourceFile, FileDescription>> getSourceFiles(long workflowId, String tag,
        SourceFile.FileType fileType) {//from w w  w .  j ava2  s  .  c  om
    T entry = (T) dao.findById(workflowId);
    Helper.checkEntry(entry);
    this.filterContainersForHiddenTags(entry);
    Version tagInstance = null;

    Map<String, ImmutablePair<SourceFile, FileDescription>> resultMap = new HashMap<>();

    if (tag == null) {
        // This is an assumption made for quay tools. Workflows will not have a latest unless it is created by the user,
        // and would thus make more sense to use master for workflows.
        tag = "latest";
    }

    // todo: why the cast here?
    for (Object o : entry.getVersions()) {
        Version t = (Version) o;
        if (t.getName().equals(tag)) {
            tagInstance = t;
        }
    }

    if (tagInstance == null) {
        throw new CustomWebApplicationException("Invalid version.", HttpStatus.SC_BAD_REQUEST);
    } else {
        if (tagInstance instanceof WorkflowVersion) {
            final WorkflowVersion workflowVersion = (WorkflowVersion) tagInstance;
            for (SourceFile file : workflowVersion.getSourceFiles()) {
                final String workflowPath = workflowVersion.getWorkflowPath();
                final String workflowVersionPath = workflowVersion.getWorkflowPath();
                final String actualPath = workflowVersionPath == null || workflowVersionPath.isEmpty()
                        ? workflowPath
                        : workflowVersionPath;
                boolean isPrimary = file.getType() == fileType && file.getPath().equalsIgnoreCase(actualPath);
                resultMap.put(file.getPath(), ImmutablePair.of(file, new FileDescription(isPrimary)));
            }
        } else {
            final Tool tool = (Tool) entry;
            final Tag workflowVersion = (Tag) tagInstance;
            for (SourceFile file : workflowVersion.getSourceFiles()) {
                // dockerfile is a special case since there always is only a max of one
                if (fileType == SourceFile.FileType.DOCKERFILE) {
                    if (file.getType() == SourceFile.FileType.DOCKERFILE) {
                        resultMap.put(file.getPath(), ImmutablePair.of(file, new FileDescription(true)));
                    }
                    continue;
                }

                final String workflowPath;
                if (fileType == SourceFile.FileType.DOCKSTORE_CWL) {
                    workflowPath = tool.getDefaultCwlPath();
                } else if (fileType == SourceFile.FileType.DOCKSTORE_WDL) {
                    workflowPath = tool.getDefaultWdlPath();
                } else {
                    throw new CustomWebApplicationException("Format " + fileType + " not valid",
                            HttpStatus.SC_BAD_REQUEST);
                }

                String workflowVersionPath;
                if (fileType == SourceFile.FileType.DOCKSTORE_CWL) {
                    workflowVersionPath = workflowVersion.getCwlPath();
                } else if (fileType == SourceFile.FileType.DOCKSTORE_WDL) {
                    workflowVersionPath = workflowVersion.getWdlPath();
                } else {
                    throw new CustomWebApplicationException("Format " + fileType + " not valid",
                            HttpStatus.SC_BAD_REQUEST);
                }

                final String actualPath = (workflowVersionPath == null || workflowVersionPath.isEmpty())
                        ? workflowPath
                        : workflowVersionPath;
                boolean isPrimary = file.getType() == fileType && actualPath.equalsIgnoreCase(file.getPath());
                if (fileType == file.getType()) {
                    resultMap.put(file.getPath(), ImmutablePair.of(file, new FileDescription(isPrimary)));
                }
            }
        }
        return resultMap;
    }
}