Example usage for org.apache.commons.lang3.tuple Triple getMiddle

List of usage examples for org.apache.commons.lang3.tuple Triple getMiddle

Introduction

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

Prototype

public abstract M getMiddle();

Source Link

Document

Gets the middle element from this triple.

Usage

From source file:org.verdictdb.core.querying.ola.AsyncAggExecutionNode.java

/**
 * A factory method for AsyncAggExecutionNode.
 *
 * <p>This static method performs the following operations: 1. Link individual aggregate nodes and
 * combiners appropriately. 2. Create a base table which includes several placeholders - scale
 * factor placeholder - temp table placeholder
 *
 * @param idCreator//w w w.  ja  v  a  2 s  .co  m
 * @param aggblocks
 * @param combiners
 * @param meta
 * @param aggNodeBlock
 * @return
 */
public static AsyncAggExecutionNode create(IdCreator idCreator, List<AggExecutionNodeBlock> aggblocks,
        List<ExecutableNodeBase> combiners, ScrambleMetaSet meta, AggExecutionNodeBlock aggNodeBlock) {

    AsyncAggExecutionNode node = new AsyncAggExecutionNode(idCreator);

    // this placeholder base table is used for query construction later
    String alias = INNER_RAW_AGG_TABLE_ALIAS;
    Pair<BaseTable, SubscriptionTicket> tableAndTicket = node.createPlaceHolderTable(alias);
    BaseTable placeholderTable = tableAndTicket.getLeft();
    SubscriptionTicket ticket = tableAndTicket.getRight();

    // first agg -> root
    AggExecutionNode firstSource = (AggExecutionNode) aggblocks.get(0).getBlockRootNode();
    firstSource.registerSubscriber(ticket);
    //    node.subscribeTo(individualAggs.get(0), 0);

    // combiners -> root
    for (ExecutableNodeBase c : combiners) {
        c.registerSubscriber(ticket);
        //      node.subscribeTo(c, 0);
    }

    // FOR PARALLEL PROCESSING; we disable this.
    // make the leaf nodes dependent on the aggroot of the previous iteration
    // this will make all the operations on the (i+1)-th block performed after the operations
    // on the i-th block.
    //    for (int i = 0; i < aggblocks.size(); i++) {
    //      if (i > 0) {
    //        AggExecutionNodeBlock aggblock = aggblocks.get(i);
    //        List<ExecutableNodeBase> leafNodes = aggblock.getLeafNodes();
    //        ExecutableNodeBase prevAggRoot = aggblocks.get(i - 1).getBlockRootNode();
    //        for (ExecutableNodeBase leaf : leafNodes) {
    //          leaf.subscribeTo(prevAggRoot, prevAggRoot.getId());
    //        }
    //      }
    //    }

    //    // agg -> next agg (to enfore the execution order)
    //    for (int i = 0; i < individualAggs.size()-1; i++) {
    //      AggExecutionNode thisNode = (AggExecutionNode) individualAggs.get(i);
    //      AggExecutionNode nextNode = (AggExecutionNode) individualAggs.get(i+1);
    //      int channel = thisNode.getId();
    //      nextNode.subscribeTo(thisNode, channel);
    //    }

    node.setScrambleMetaSet(meta); // the scramble meta must be not be shared; thus, thread-safe
    node.setNamer(idCreator); // the name can be shared

    // creates a base query that contain placeholders
    AggMeta sourceAggMeta = firstSource.getAggMeta();
    List<SelectItem> sourceSelectList = firstSource.getSelectQuery().getSelectList();
    Triple<List<ColumnOp>, SqlConvertible, Map<Integer, String>> aggColumnsAndQuery = createBaseQueryForReplacement(
            sourceAggMeta, sourceSelectList, placeholderTable, meta);
    node.aggColumns = aggColumnsAndQuery.getLeft();
    SelectQuery subquery = (SelectQuery) aggColumnsAndQuery.getMiddle();
    Pair<SelectQuery, HashMap<String, UnnamedColumn>> pair = sumUpTierGroup(subquery, sourceAggMeta);
    node.selectQuery = pair.getLeft();
    node.aggContents = pair.getRight();
    node.scrambledTableTierInfo = new ImmutableMap.Builder<Integer, String>()
            .putAll(aggColumnsAndQuery.getRight()).build();

    // add (1) order-by, (2) limit, (3) having clauses to the select query
    QueryNodeBase aggRoot = (QueryNodeBase) aggNodeBlock.getBlockRootNode();
    SelectQuery originalAggQuery = aggRoot.getSelectQuery();

    //    int orderByCount = 0;
    //    for (OrderbyAttribute orderBy : originalAggQuery.getOrderby()) {
    //      String aliasName = ORDER_BY_ALIAS + (orderByCount++);
    //      //      if (orderBy.getAttribute() instanceof AliasedColumn) {
    //      //        aliasName = ((AliasedColumn) orderBy.getAttribute()).getAliasName();
    //      //      } else if (orderBy.getAttribute() instanceof AliasReference) {
    //      //        aliasName = ((AliasReference) orderBy.getAttribute()).getAliasName();
    //      //      } else {
    //      //        // TODO
    //      //        return null;
    //      //      }
    //      BaseColumn col = new BaseColumn(TIER_CONSOLIDATED_TABLE_ALIAS, aliasName);
    //      node.selectQuery.addOrderby(
    //          new OrderbyAttribute(col, orderBy.getOrder(), orderBy.getNullsOrder()));
    //    }

    node.selectQuery.addOrderby(originalAggQuery.getOrderby());

    //    int orderByCount = 0;
    //    for (SelectItem item : node.selectQuery.getSelectList()) {
    //      if (item instanceof AliasedColumn) {
    //        AliasedColumn ac = (AliasedColumn) item;
    //        if (ac.getAliasName().startsWith(AsyncAggExecutionNode.getOrderByAlias())) {
    //          OrderbyAttribute attr = originalAggQuery.getOrderby().get(orderByCount);
    //          BaseColumn col = new BaseColumn(TIER_CONSOLIDATED_TABLE_ALIAS, ac.getAliasName());
    //          node.selectQuery.addOrderby(
    //              new OrderbyAttribute(col, attr.getOrder(), attr.getNullsOrder()));
    //          ++orderByCount;
    //        }
    //      }
    //    }

    if (originalAggQuery.getLimit().isPresent()) {
        node.selectQuery.addLimit(originalAggQuery.getLimit().get());
    }
    if (originalAggQuery.getHaving().isPresent()) {
        node.selectQuery.addHavingByAnd(originalAggQuery.getHaving().get());
    }

    return node;
}

From source file:org.verdictdb.sqlreader.ScrambleTableReplacer.java

private int replaceQuery(SelectQuery query, boolean doReset,
        Triple<Boolean, Boolean, BaseColumn> outerInspectionInfo) throws VerdictDBValueException {
    if (doReset) {
        replaceCount = 0;//from   w w  w.j  a va2 s.c  o  m
    }

    // check select list
    Triple<Boolean, Boolean, BaseColumn> inspectionInfo = SelectQueryCoordinator
            .inspectAggregatesInSelectList(query);
    boolean containAggregatedItem = inspectionInfo.getLeft();
    boolean containCountDistinctItem = inspectionInfo.getMiddle();
    BaseColumn countDistinctColumn = inspectionInfo.getRight();

    if (containCountDistinctItem && countDistinctColumn == null) {
        throw new VerdictDBValueException(
                "A base column is not found " + "inside the count-distinct function.");
    }

    // this is to handle the case that an outer query includes aggregate functions,
    // the current query is simply a projection.
    if (outerInspectionInfo != null && !containAggregatedItem && !containCountDistinctItem) {
        containAggregatedItem = outerInspectionInfo.getLeft();
        containCountDistinctItem = outerInspectionInfo.getMiddle();
        inspectionInfo = outerInspectionInfo;
    }

    // if both count-distinct and other aggregates appear
    if (containAggregatedItem && containCountDistinctItem) {
        throw new RuntimeException("This line is not supposed to be reached.");
    }
    // if no count-distinct appears and other aggregates appear
    else if (containAggregatedItem) {
        List<AbstractRelation> fromList = query.getFromList();
        for (int i = 0; i < fromList.size(); i++) {
            fromList.set(i, replaceTableForSimpleAggregates(fromList.get(i), inspectionInfo));
        }
    }
    // if only count-distinct appears
    else if (containCountDistinctItem) {
        List<AbstractRelation> fromList = query.getFromList();
        for (int i = 0; i < fromList.size(); i++) {
            fromList.set(i, replaceTableForCountDistinct(fromList.get(i), inspectionInfo));
        }
    }
    // no aggregate appears; check any subqueries
    else {
        List<AbstractRelation> fromList = query.getFromList();
        for (int i = 0; i < fromList.size(); i++) {
            AbstractRelation rel = fromList.get(i);
            if (rel instanceof JoinTable) {
                for (AbstractRelation joined : ((JoinTable) rel).getJoinList()) {
                    if (joined instanceof SelectQuery) {
                        replaceQuery((SelectQuery) joined, false, null);
                    }
                }
            } else if (rel instanceof SelectQuery) {
                replaceQuery((SelectQuery) rel, false, null);
            }
        }
    }

    return replaceCount;
}

From source file:rapture.plugin.app.FileBasedSandboxLoader.java

@Override
public void loadSandboxFromEntries(String root, String part, PluginSandbox sandbox) throws Exception {
    String area = root + part;//from  www .  j  a  va2 s  .c  o m
    System.out.println("From " + area);

    String[] folders = getResourceFolders(area);
    String[] files = getResourceFiles(area);

    for (String f : files) {
        String path = root + part + f;
        Triple<String, String, Scheme> trip = PluginSandboxItem.extractScheme(part + f);
        RaptureURI uri = RaptureURI.createFromFullPathWithAttribute(trip.getLeft(), trip.getMiddle(),
                trip.getRight());
        String fileFullPath = SelfInstaller.class.getResource(path).getPath();
        System.out.println("File " + fileFullPath);
        sandbox.makeItemFromInternalEntry(uri, SelfInstaller.class.getResourceAsStream(path), fileFullPath,
                null);
    }

    for (String f : folders) {
        loadSandboxFromEntries(root, part + f + "/", sandbox);
    }
}

From source file:rapture.plugin.app.JarBasedSandboxLoader.java

@Override
public void loadSandboxFromEntries(String root, String variant, PluginSandbox sandbox) throws Exception {
    String[] files = getResourceFiles(root, variant);

    for (String f : files) {
        boolean isVariant = false;
        String path = "/" + f;
        System.out.println("Path is " + path);
        // remove PLUGIN/
        f = f.substring(7);/*from  ww w .  j a  v a 2 s. com*/
        if (f.startsWith(PluginSandbox.CONTENT)) {
            // remove content/ from filename
            f = f.substring(PluginSandbox.CONTENT.length());
        } else if (f.startsWith(variant + "/")) {
            // remove <variant>/ from filename
            f = f.substring(variant.length() + 1);
            isVariant = true;
        }
        System.out.println("File is " + f);
        Triple<String, String, Scheme> trip = PluginSandboxItem.extractScheme(f);
        System.out.println("Triple is " + trip.toString());

        // Triple is (/curtisweb/,null,blob)
        RaptureURI uri = RaptureURI.createFromFullPathWithAttribute(trip.getLeft(), trip.getMiddle(),
                trip.getRight());
        System.out.println("URI is " + uri.toString());
        sandbox.makeItemFromInternalEntry(uri, SelfInstaller.class.getResourceAsStream(path),
                isVariant ? variant : null);
    }
}

From source file:rapture.plugin.install.PluginSandboxItem.java

public static Pair<RaptureURI, String> calculateURI(String leafTail) {
    String variant = (leafTail.startsWith(CONTENTDIR)) ? null : extractVariant(leafTail);
    Triple<String, String, Scheme> trip = extractScheme(leafTail.substring(variantLength(variant)));
    checkArgument(trip != null, "extraneuous file");
    RaptureURI uri = null;/*from   w  w  w .java  2s .c  o  m*/
    switch (trip.getRight()) {
    case USER:
    case ENTITLEMENTGROUP:
        if (trip.getLeft().indexOf("/") == -1) {
            uri = new RaptureURI(trip.getLeft(), trip.getRight());
        }
        break;
    default:
        break;
    }
    if (uri == null) {
        uri = RaptureURI.createFromFullPathWithAttribute(trip.getLeft(), trip.getMiddle(), trip.getRight());
    }
    return new ImmutablePair<RaptureURI, String>(uri, variant);
}

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

private void init(final SaneDevice device, Map<SaneDevice, Map<SaneOption, Object>> changedOptions)
        throws IOException, SaneException {
    initComponents();/*from  w ww  .  j a  v  a  2  s . co  m*/
    if (!device.isOpen()) {
        device.open();
    }
    Triple<String, Integer, String> defaultValuePair = configureDefaultOptionValues(device, changedOptions,
            false);
    for (String mode : device.getOption("mode").getStringConstraints()) {
        modeComboBoxModel.addElement(mode);
    }
    this.modeComboBox.setSelectedItem(defaultValuePair.getLeft());
    for (SaneWord resolution : device.getOption("resolution").getWordConstraints()) {
        resolutionComboBoxModel.addElement(String.valueOf(resolution.integerValue()));
    }
    this.resolutionComboBox.setSelectedItem(String.valueOf(defaultValuePair.getMiddle()));
    List<String> documentSourceConstraints = device.getOption("source").getStringConstraints();
    for (String documentSource : documentSourceConstraints) {
        this.documentSourceComboBoxModel.addElement(documentSource);
    }
    if (documentSourceConstraints.contains("Automatic Document Feeder")) {
        this.documentSourceComboBox.setSelectedItem("Automatic Document Feeder");
    }
    //add ItemListener after setup
    this.modeComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            try {
                String mode = (String) ScannerEditDialog.this.modeComboBox.getSelectedItem();
                ScannerEditDialog.this.device.getOption("mode").setStringValue(mode);
            } catch (IOException | SaneException ex) {
                //not supposed to happen
                throw new RuntimeException(ex);
            }
        }
    });
    this.resolutionComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            try {
                int resolution = Integer
                        .valueOf((String) ScannerEditDialog.this.resolutionComboBox.getSelectedItem());
                ScannerEditDialog.this.device.getOption("resolution").setIntegerValue(resolution);
            } catch (IOException | SaneException ex) {
                //not supposed to happen
                throw new RuntimeException(ex);
            }
        }
    });
    this.documentSourceComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            try {
                String documentSource = (String) ScannerEditDialog.this.documentSourceComboBox
                        .getSelectedItem();
                ScannerEditDialog.this.device.getOption("source").setStringValue(documentSource);
            } catch (IOException | SaneException ex) {
                throw new RuntimeException(ex);
            }
        }
    });
}

From source file:specminers.referenceparser.graphvizdot.PradelsDotFilesToJffConverter.java

private Document getJffXMLDocument() throws ParserConfigurationException, IOException {
    this.convert();
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    Document doc = docBuilder.newDocument();

    Element structure = doc.createElement("structure");
    doc.appendChild(structure);//from   www  .  jav  a2  s  . c om

    Element type = doc.createElement("type");
    type.setTextContent("fa");
    structure.appendChild(type);

    Element automaton = doc.createElement("automaton");

    for (String stateName : this.stateNames) {
        Element state = doc.createElement("state");
        state.setAttribute("id", stateName);
        state.setAttribute("name", "q" + stateName);

        if (initialStates.contains(stateName)) {
            Element initial = doc.createElement("initial");
            state.appendChild(initial);
        }

        if (finalStates.contains(stateName)) {
            Element accepting = doc.createElement("final");
            state.appendChild(accepting);
        }

        automaton.appendChild(state);
    }

    for (Triple<String, String, String> transition : this.transitions) {
        Element t = doc.createElement("transition");

        Element from = doc.createElement("from");
        from.setTextContent(transition.getLeft());
        t.appendChild(from);

        Element to = doc.createElement("to");
        to.setTextContent(transition.getMiddle());
        t.appendChild(to);

        Element read = doc.createElement("read");
        read.setTextContent(transition.getRight());
        t.appendChild(read);

        automaton.appendChild(t);
    }

    structure.appendChild(automaton);
    return doc;
}

From source file:storm.lrb.bolt.LastAverageSpeedBolt.java

private void emitLav(Triple<Integer, Integer, Integer> xsd, List<Integer> vehicleCounts,
        List<Double> speedValues, int minute) {

    double speedAverage = this.calcLav(speedValues, minute);
    int segmentCarCount = vehicleCounts.get(minute);

    this.collector.emit(new Values(xsd.getLeft(), xsd.getMiddle(), xsd.getRight(), segmentCarCount,
            speedAverage, minute + 1));/*  www  .jav  a2s.c om*/
}

From source file:urls.CurlStore.java

public Pair<String, InputStream> get() {
    final Triple<String, Process, Long> triple = QUEUE.poll();
    if (triple == null)
        return null;

    final Process process = triple.getMiddle();
    final Long startTime = triple.getRight();
    final String url = triple.getLeft();

    if (process.isAlive()) {
        if (System.currentTimeMillis() - startTime < timeout)
            QUEUE.offer(triple);//from   ww w .j  a  v  a 2 s  .co m
        else {
            process.destroy();
            EXIT_VALUES.append(". ");
        }
        return null;
    }

    if (process.exitValue() != 0) {
        EXIT_VALUES.append(process.exitValue() + " ");
        return null;
    }

    return Pair.of(url, process.getInputStream());
}