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:org.verdictdb.sqlreader.RelationStandardizer.java

private Pair<List<String>, AbstractRelation> setupTableSource(AbstractRelation table)
        throws VerdictDBDbmsException {
    // in order to prevent informal table alias, we replace all table alias
    if (!(table instanceof JoinTable)) {
        if (table.getAliasName().isPresent()) {
            String alias = table.getAliasName().get();
            alias = alias.replace("`", "");
            alias = alias.replace("\"", "");
            oldTableAliasMap.put(alias, verdictTableAliasPrefix + itemID);
        }/*from  w  w w  .  j  a v  a2s .  co  m*/
        table.setAliasName(verdictTableAliasPrefix + itemID++);
    }
    // if (!table.getAliasName().isPresent() && !(table instanceof JoinTable)) {
    //  table.setAliasName(verdictTableAliasPrefix + itemID++);
    // }
    if (table instanceof BaseTable) {
        BaseTable bt = (BaseTable) table;
        List<String> colName = new ArrayList<>();
        if (bt.getSchemaName() == null) {
            bt.setSchemaName(meta.getDefaultSchema());
        }
        List<Pair<String, String>> cols = meta.getColumns(bt.getSchemaName(), bt.getTableName());
        for (Pair<String, String> c : cols) {
            colNameAndTableAlias.put(c.getKey(), bt.getAliasName().get());
            colName.add(c.getKey());
        }
        tableInfoAndAlias.put(ImmutablePair.of(bt.getSchemaName(), bt.getTableName()),
                table.getAliasName().get());
        return new ImmutablePair<>(colName, table);

    } else if (table instanceof JoinTable) {
        List<String> joinColName = new ArrayList<>();
        for (int i = 0; i < ((JoinTable) table).getJoinList().size(); i++) {
            Pair<List<String>, AbstractRelation> result = setupTableSource(
                    ((JoinTable) table).getJoinList().get(i));
            ((JoinTable) table).getJoinList().set(i, result.getValue());
            joinColName.addAll(result.getKey());
            if (i != 0) {
                ((JoinTable) table).getCondition().set(i - 1,
                        replaceFilter(((JoinTable) table).getCondition().get(i - 1)));
            }
        }
        return new ImmutablePair<>(joinColName, table);

    } else if (table instanceof SelectQuery) {
        List<String> colName = new ArrayList<>();
        RelationStandardizer g = new RelationStandardizer(meta, syntax);
        g.oldTableAliasMap.putAll(oldTableAliasMap);
        g.setTableInfoAndAlias(tableInfoAndAlias);
        g.setColNameAndTableAlias(colNameAndTableAlias);
        g.setColNameAndColAlias(colNameAndColAlias);
        String aliasName = table.getAliasName().get();
        table = g.standardize((SelectQuery) table);
        table.setAliasName(aliasName);

        // Invariant: Only Aliased Column or Asterisk Column should appear in the subquery
        for (SelectItem sel : ((SelectQuery) table).getSelectList()) {
            if (sel instanceof AliasedColumn) {
                // If the aliased name of the column is replaced by ourselves, we should remember the
                // column name
                if (((AliasedColumn) sel).getColumn() instanceof BaseColumn
                        && ((AliasedColumn) sel).getAliasName().matches("^vc[0-9]+$")) {
                    colNameAndTableAlias.put(((BaseColumn) ((AliasedColumn) sel).getColumn()).getColumnName(),
                            table.getAliasName().get());
                    colNameAndTempColAlias.put(((BaseColumn) ((AliasedColumn) sel).getColumn()).getColumnName(),
                            ((AliasedColumn) sel).getAliasName());
                } else
                    colNameAndTableAlias.put(((AliasedColumn) sel).getAliasName(), table.getAliasName().get());
                colName.add(((AliasedColumn) sel).getAliasName());

            } else if (sel instanceof AsteriskColumn) {
                // put all the columns in the fromlist of subquery to the colNameAndTableAlias
                HashMap<String, String> subqueryColumnList = g.getColNameAndTableAlias();
                for (String col : subqueryColumnList.keySet()) {
                    colNameAndTableAlias.put(col, table.getAliasName().get());
                    colName.add(col);
                }
            }
        }
        return new ImmutablePair<>(colName, table);
    }
    return null;
}

From source file:org.wso2.carbon.uuf.internal.core.create.DependencyTreeParser.java

public static Result parse(List<String> dependencyTreeLines) {
    // Flattened dependencies map.
    // key   = component name
    // value = all dependencies of the 'key'
    SetMultimap<String, String> flattenedDependencies = HashMultimap.create();
    // Leveled dependencies list.
    // index       = dependency level, index 0 == root component's dependencies
    // List.get(i) = set of dependencies in level i
    List<Set<ComponentData>> leveledDependencies = new ArrayList<>(6);

    int previousLevel = 0;
    String previousComponentName = null;
    Deque<Pair<String, List<String>>> parentNodesStack = new LinkedList<>();

    for (int i = 0; i < dependencyTreeLines.size(); i++) {
        String line = dependencyTreeLines.get(i);
        int level = countLevel(line);
        int jump = (level - previousLevel);
        ComponentData currentComponent = getComponentData(line);

        if (level < leveledDependencies.size()) {
            leveledDependencies.get(level).add(currentComponent);
        } else {/*from   w w  w . j  ava2s  . c  o m*/
            Set<ComponentData> set = new HashSet<>();
            set.add(currentComponent);
            leveledDependencies.add(level, set);
        }

        if (i == 0) {
            // Very first leaf dependency.
            previousComponentName = currentComponent.name;
            continue;
        }
        if (jump < 0) {
            // Dependency level decreased, so remove entries from the stack.
            for (int j = Math.abs(jump); j > 0; j--) {
                Pair<String, List<String>> entry = parentNodesStack.removeLast();
                flattenedDependencies.putAll(entry.getKey(), entry.getValue());
            }
        } else if (jump > 0) { // jump == 1
            // Dependency level increased, so add an entry to the stack.
            parentNodesStack.add(new ImmutablePair<>(previousComponentName, new ArrayList<>(3)));
        }
        // (jump == 0): Same dependency level, no need to change the stack.

        // Add current component name to all parent nodes as a dependency.
        for (Pair<String, List<String>> entry : parentNodesStack) {
            entry.getValue().add(currentComponent.name);
        }

        previousLevel = level;
        previousComponentName = currentComponent.name;
    }
    // If there is any remaining stack elements, add them to the flattenedDependencies.
    for (Pair<String, List<String>> entry : parentNodesStack) {
        flattenedDependencies.putAll(entry.getKey(), entry.getValue());
    }

    return new Result(flattenedDependencies, leveledDependencies);
}

From source file:org.xwiki.search.solr.internal.job.IndexerJob.java

private void updateSolrIndex(int progressSize, DiffDocumentIterator<String> iterator) {
    this.progressManager.pushLevelProgress(progressSize, this);

    try {/*from w  w w . j  a  v a 2  s .c o  m*/
        long[] counter = new long[Action.values().length];

        while (iterator.hasNext()) {
            this.progressManager.startStep(this);

            Pair<DocumentReference, Action> entry = iterator.next();
            if (entry.getValue() == Action.ADD || entry.getValue() == Action.UPDATE) {
                // The database entry has not been indexed or the indexed version doesn't match the latest
                // version
                // from the database.
                this.indexer.index(entry.getKey(), true);
            } else if (entry.getValue() == Action.DELETE && getRequest().isRemoveMissing()) {
                // The index entry doesn't exist anymore in the database.
                this.indexer.delete(entry.getKey(), true);
            }

            counter[entry.getValue().ordinal()]++;

            this.progressManager.endStep(this);
        }

        this.logger.info(
                "{} documents added, {} deleted and {} updated during the synchronization of the Solr index.",
                counter[Action.ADD.ordinal()], counter[Action.DELETE.ordinal()],
                counter[Action.UPDATE.ordinal()]);
    } finally {
        this.progressManager.popLevelProgress(this);
    }
}

From source file:petascope.util.ras.TypeRegistry.java

/**
 * Returns the mdd type for a given collection type.
 *
 * @param collectionType the collection type.
 * @return the mdd type, empty if nothing is found.
 *//*from   w  w w  . ja va  2s  .  co  m*/
public String getMddTypeForCollectionType(String collectionType) {
    String mddType = "";
    for (Pair<String, String> i : setTypeDefinitions) {
        if (collectionType.equals(i.getKey())) {
            mddType = i.getValue();
            break;
        }
    }
    return mddType;
}

From source file:petascope.util.ras.TypeRegistry.java

/**
 * Builds the registry from the collected types gathered by parsing the rasdl output
 *//*from  w w w .j  av  a  2s. com*/
private void buildRegistry() {
    for (Pair<String, String> entry : setTypeDefinitions) {
        String domainType = marrayTypeDefinitions.get(entry.getValue());
        if (domainType != null) {
            String[] domainTypeParts = domainType.split(",");
            if (domainTypeParts.length >= 2) {
                String[] baseTypeParts = ArrayUtils.remove(domainTypeParts, domainTypeParts.length - 1);
                String baseType = StringUtils.join(baseTypeParts, "");
                String[] nullParts = setTypeNullValues.get(entry.getKey()).split(",");
                ArrayList<String> nullValues = new ArrayList<String>();
                for (String i : nullParts) {
                    if (!i.isEmpty()) {
                        //if the value that is parsed is an interval with the same limits (e.g. 5:5), add only 1
                        //value. This is needed because currently there is a bug when creating types via rasql,
                        //which doesn't allow single values to be specified. However, petascope needs to display single
                        //values when presenting the output to the user.
                        if (i.contains(":")) {
                            String[] parts = i.split(":");
                            if (parts.length == 2 & parts[0].equals(parts[1])) {
                                i = parts[0];
                            }
                        }
                        nullValues.add(i);
                    }
                }
                typeRegistry.put(entry.getKey(), new TypeRegistryEntry(baseType, domainType, nullValues));
            }
        }
    }
}

From source file:petascope.util.ras.TypeResolverUtil.java

/**
 * Guesses the rasdaman collection type from a file.
 *
 * @param filePath path to the file//from   ww w  .java 2 s  .  c  o m
 * @return the rasdaman collection type
 * @throws IOException
 */
public static String guessCollectionTypeFromFile(String filePath, int dimension, ArrayList<String> nullValues)
        throws IOException, PetascopeException {
    Pair<Integer, ArrayList<String>> dimTypes = Gdalinfo.getDimensionAndTypes(filePath);
    return guessCollectionType(dimension, dimTypes.getValue(), nullValues);
}

From source file:petascope.wcs2.handlers.wcst.UpdateCoverageHandler.java

/**
 * Gets the array in the values clause to be used in a rasdaman update query, when values are given as tuple list.
 *
 * @param coverage the coverage providing the values.
 * @param rangeSet the rangeSet element.
 * @return string representations of the values clause, as rasdaman array constant.
 * @throws PetascopeException/*from  www.  ja  v a  2 s .co m*/
 */
private String getReplacementValuesFromTupleList(CoverageMetadata coverage, Element rangeSet,
        String pixelDataType) throws PetascopeException {
    Element dataBlock = GMLParserUtil.parseDataBlock(rangeSet);
    Pair<String, String> collectionType = TypeResolverUtil.guessCollectionType(coverage.getNumberOfBands(),
            coverage.getDimension(), coverage.getAllUniqueNullValues(), pixelDataType);
    String values = GMLParserUtil.parseGMLTupleList(dataBlock, coverage.getCellDomainList(),
            collectionType.getValue());
    return values;
}

From source file:py.una.pol.karaku.replication.client.ReplicationHandler.java

/**
 * @param ri/*  w w w.  j a  v  a2s.c  o m*/
 * @param response
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private String handleResponse(ReplicationInfo ri, Object response) {

    Pair<String, Collection<?>> pair = responseHandlers.getChanges(response);
    Collection items = pair.getValue();
    String newLastId = pair.getKey();

    Converter converter = converterProvider.getConverter(ri.getEntityClazz(), ri.getDaoClazz());

    handleCacheAll(converter);

    int i = 0;
    for (Object obj : items) {
        DTO dto = (DTO) obj;
        i++;
        try {
            log.info("Process {}: {}/{} ({}%)",
                    new Object[] { ri.getEntityClassName(), i, items.size(), i * 100 / items.size() });
            Shareable entity = converter.toEntity(dto);
            merge(ri, entity);
        } catch (EntityNotFoundException enf) {
            log.warn("Can't get entity from uri, entity with uri {}", dto.getUri());
            throw new KarakuRuntimeException(
                    "Can't replicate entity " + obj.getClass().getSimpleName() + " uri = " + dto.getUri(), enf);
        } catch (Exception e) {
            log.warn("Can't replicate entity with name {} and uri {}", obj.getClass().getSimpleName(),
                    dto.getUri());
            throw new KarakuRuntimeException(
                    "Can't replicate entity " + obj.getClass().getSimpleName() + " uri = " + dto.getUri(), e);
        }
    }

    return newLastId;
}

From source file:py.una.pol.karaku.test.test.replication.ReplicationResponseHandlerTest.java

@Test
public void testHandleResponse() throws Exception {

    ReplicationResponseTest1 t1 = new ReplicationResponseTest1();
    List<Object> td1 = new ArrayList<Object>();
    t1.data = td1;/*  w w  w.j a  v a2s. com*/
    t1.id = ZERO;

    Pair<String, Collection<?>> changes = handler.getChanges(t1);
    assertEquals(changes.getKey(), ZERO);
    assertEquals(changes.getValue(), td1);

    ReplicationResponseTest2 t2 = new ReplicationResponseTest2();
    Set<Object> td2 = new HashSet<Object>();
    t2.entitiess = td2;
    t2.lastId = ZERO;

    Pair<String, Collection<?>> changes2 = handler.getChanges(t1);
    assertEquals(changes2.getKey(), ZERO);
    assertEquals(changes2.getValue(), td1);
}

From source file:richtercloud.document.scanner.gui.MainPanel.java

/**
 * Handles both switching documents (if {@code old} and {@code aNew} are not
 * {@code null} and adding the first document (if {@code old} is
 * {@code null}./*from  w w  w . java 2 s .com*/
 * @param old
 * @param aNew
 */
/*
internal implementation notes:
- handling both switching and adding the first document maximizes code
reusage
*/
private void switchDocument(OCRSelectComponent old, final OCRSelectComponent aNew) {
    synchronized (aNew.getTreeLock()) {
        Pair<OCRPanel, EntityPanel> newPair = documentSwitchingMap.get(aNew);
        assert newPair != null;
        OCRPanel oCRPanelNew = newPair.getKey();
        EntityPanel entityPanelNew = newPair.getValue();
        assert oCRPanelNew != null;
        assert entityPanelNew != null;
        //check if dockables already exist in order to avoid failure of
        //CControl.replace if dockable is recreated
        MultipleCDockable oCRPanelNewDockable = dockableMap.get(oCRPanelNew);
        if (oCRPanelNewDockable == null) {
            oCRPanelNewDockable = new DefaultMultipleCDockable(null, "OCR result", oCRPanelNew);
            dockableMap.put(oCRPanelNew, oCRPanelNewDockable);
        }
        MultipleCDockable entityPanelNewDockable = dockableMap.get(entityPanelNew);
        if (entityPanelNewDockable == null) {
            entityPanelNewDockable = new DefaultMultipleCDockable(null, "Entities", entityPanelNew);
            dockableMap.put(entityPanelNew, entityPanelNewDockable);
        }
        if (old != null) {
            Pair<OCRPanel, EntityPanel> oldPair = documentSwitchingMap.get(old);
            assert oldPair != null;
            //order doesn't matter
            OCRPanel oCRPanelOld = oldPair.getKey();
            EntityPanel entityPanelOld = oldPair.getValue();
            assert oCRPanelOld != null;
            assert entityPanelOld != null;
            MultipleCDockable oCRPanelOldDockable = dockableMap.get(oCRPanelOld);
            MultipleCDockable entityPanelOldDockable = dockableMap.get(entityPanelOld);
            control.replace(oCRPanelOldDockable, oCRPanelNewDockable);
            //CControl.replace fails if new dockable is already
            //registered at CControl
            //CControl.replace fails if old dockable has already been
            //removed from CControl
            //CDockable.setVisible(false) unregisters dockable at
            //CControl
            oCRPanelNewDockable.setVisible(true);
            control.replace(entityPanelOldDockable, entityPanelNewDockable);
            //MultipleCDockable.setVisible(true) fails if it's not
            //registered at a CControl (which has to be done with
            //CControl.replace (see above))
            entityPanelNewDockable.setVisible(true);
        } else {
            //order matters
            control.addDockable(oCRPanelNewDockable);
            control.addDockable(entityPanelNewDockable);
            oCRPanelNewDockable.setLocation(CLocation.base().normalEast(0.4));
            oCRPanelNewDockable.setVisible(true);
            entityPanelNewDockable.setLocation(CLocation.base().normalSouth(0.4));
            entityPanelNewDockable.setVisible(true);
        }
        this.oCRSelectComponentScrollPane = aNew;
        validate();
    }
}