Example usage for java.util TreeSet contains

List of usage examples for java.util TreeSet contains

Introduction

In this page you can find the example usage for java.util TreeSet contains.

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:org.apache.hadoop.hdfs.server.namenode.NamenodeFsck.java

private DatanodeInfo bestNode(DFSClient dfs, DatanodeInfo[] nodes, TreeSet<DatanodeInfo> deadNodes)
        throws IOException {
    if ((nodes == null) || (nodes.length - deadNodes.size() < 1)) {
        throw new IOException("No live nodes contain current block");
    }//from  ww w  . ja  va  2  s . c o  m
    DatanodeInfo chosenNode;
    do {
        chosenNode = nodes[DFSUtil.getRandom().nextInt(nodes.length)];
    } while (deadNodes.contains(chosenNode));
    return chosenNode;
}

From source file:cooperativegametheory.Partition.java

public Partition(int[][] partition, PlayerSet onPlayerSet) {
    //TODO cleanup
    this.players = onPlayerSet;
    TreeSet<Integer> seen = new TreeSet<Integer>();
    for (int i = 0; i < partition.length; i++) {
        Coalition component = new Coalition(players);
        for (int j = 0; j < partition[i].length; j++) {
            if (!players.contains(partition[i][j])) {
                throw new IllegalArgumentException(
                        "agument 1 is not a proper partition (component members must be from the PlayerSet)");
            } else {
                if (!component.add(partition[i][j])) {
                    throw new IllegalArgumentException(
                            "agument 1 is not a proper partition (components must be a set)");
                }//  w  ww.j  a v a 2s .c  o  m
            }
            if (!seen.add(partition[i][j])) {
                throw new IllegalArgumentException(
                        "agument 1 is not a proper partition (components must be disjoint)");
            }
        }
        if (!this.add(component)) {
            throw new IllegalArgumentException(
                    "agument 1 is not a proper partition (this error should never appear ?!)");
        }
    }
    for (int i = 0; i < players.size(); i++) {
        if (!seen.contains(i)) {
            throw new IllegalArgumentException("agument 1 is not a proper partition (not complete)");
        }
    }
}

From source file:org.apache.accumulo.monitor.rest.tables.TablesResource.java

/**
 * Generates a list of participating tservers for a table
 *
 * @param tableIdStr//  ww w. jav a 2 s  .  c  o m
 *          Table ID to find participating tservers
 * @return List of participating tservers
 */
@Path("{tableId}")
@GET
public TabletServers getParticipatingTabletServers(
        @PathParam("tableId") @NotNull @Pattern(regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) {
    String rootTabletLocation = monitor.getContext().getRootTabletLocation();
    TableId tableId = TableId.of(tableIdStr);

    TabletServers tabletServers = new TabletServers(monitor.getMmi().tServerInfo.size());

    if (StringUtils.isBlank(tableIdStr)) {
        return tabletServers;
    }

    TreeSet<String> locs = new TreeSet<>();
    if (RootTable.ID.equals(tableId)) {
        locs.add(rootTabletLocation);
    } else {
        String systemTableName = MetadataTable.ID.equals(tableId) ? RootTable.NAME : MetadataTable.NAME;
        MetaDataTableScanner scanner = new MetaDataTableScanner(monitor.getContext(),
                new Range(TabletsSection.getRow(tableId, new Text()), TabletsSection.getRow(tableId, null)),
                systemTableName);

        while (scanner.hasNext()) {
            TabletLocationState state = scanner.next();
            if (state.current != null) {
                try {
                    locs.add(state.current.hostPort());
                } catch (Exception ex) {
                    scanner.close();
                    return tabletServers;
                }
            }
        }
        scanner.close();
    }

    List<TabletServerStatus> tservers = new ArrayList<>();
    if (monitor.getMmi() != null) {
        for (TabletServerStatus tss : monitor.getMmi().tServerInfo) {
            try {
                if (tss.name != null && locs.contains(tss.name)) {
                    tservers.add(tss);
                }
            } catch (Exception ex) {
                return tabletServers;
            }
        }
    }

    // Adds tservers to the list
    for (TabletServerStatus status : tservers) {
        if (status == null) {
            status = NO_STATUS;
        }
        TableInfo summary = TableInfoUtil.summarizeTableStats(status);
        if (tableId != null) {
            summary = status.tableMap.get(tableId.canonical());
        }
        if (summary == null) {
            continue;
        }

        TabletServer tabletServerInfo = new TabletServer();
        tabletServerInfo.server.updateTabletServerInfo(monitor, status, summary);

        tabletServers.addTablet(tabletServerInfo);
    }

    return tabletServers;

}

From source file:ch.admin.suis.msghandler.checker.StatusCheckerSessionImpl.java

/**
 * Looks into the internal DB and selects the IDs of the messages that
 * have the status SENT or FORWARDED. Then this method checks the receipts directory
 * of the Sedex adapter to see, for which message there is already a receipt.
 * The list of the found receipt is then returned. If there are no receipts, this
 * method returns an empty collection./*from w  ww .  j a v  a 2  s  . c  o  m*/
 *
 * @see ch.admin.suis.msghandler.checker.StatusCheckerSession#getMessagesIds()
 */
@Override
public Collection<Receipt> getMessagesIds() throws LogServiceException {
    ArrayList<Receipt> receipts = new ArrayList<>();

    // the internal DB
    final LogService logService = context.getLogService();

    // the Sedex adapter's receipt directory
    File receiptsDir = new File(
            context.getClientConfiguration().getSedexAdapterConfiguration().getReceiptDir());

    // get the messages that have either FORWARDED or SENT as their status
    TreeSet<String> sentIds = new TreeSet<>(logService.getSentMessages());

    // loop over the files in the receipts directory
    // check for the files over there
    DirectoryStream<Path> files = FileUtils.listFiles(receiptsDir, FileFilters.XML_FILTER_PATH);

    if (files == null) {
        LOG.error("an I/O error occured while reading the receipts from the Sedex adapter; "
                + "check the message handler configuration to see whether the specified 'receipts' directory "
                + "for the Sedex Adapter actually exists");
        return Collections.emptyList();
    }

    //
    ArrayList<String> toBeRemoved = new ArrayList<>();
    // for each receipt found
    for (Path path : files) {
        try (InputStream reader = Files.newInputStream(path)) {
            Receipt receipt = Receipt.createFrom(reader);
            if (!sentIds.contains(receipt.getMessageId())) {
                continue;
            }
            // get the sent date for this receipt (it is not unfortunately in the receipt XML)
            receipt.setSentDate(ISO8601Utils.format(logService.getSentDate(receipt.getMessageId())));
            receipt.setReceiptFile(path.toFile());
            receipts.add(receipt);// add it now
            LOG.info(MessageFormat.format("message ID {0}: receipt found", receipt.getMessageId()));
            // set to remove the id from the tree
            toBeRemoved.add(receipt.getMessageId());
        } catch (FileNotFoundException e) {
            LOG.error("cannot find the file " + path.toString() + "; is it already removed?", e);
        } catch (IOException e) {
            LOG.error("cannot read the file " + path.toString(), e);
        } catch (JAXBException e) {
            LOG.error("cannot parse the file " + path.toString(), e);
        } catch (LogServiceException e) {
            closeStream(files);
            throw e; // In order to keep the current exception flow
        }

    }
    closeStream(files);

    // remove from the list
    sentIds.removeAll(toBeRemoved);

    // now, lets look at what has remained to find out, whether the Sedex adapter has just sent the files
    // but not received the receipt (look only at forwarded messages that are not "transparent")
    final File outputDir = new File(
            context.getClientConfiguration().getSedexAdapterConfiguration().getOutputDir());

    for (final String messageId : logService.getMessages(LogStatus.FORWARDED)) {

        // Skips execution if not all of the conditions below match
        if (sentIds.contains(messageId) && !logService.isTransparent(messageId)
                && !new File(outputDir, FileUtils.getDataFilename(messageId)).exists()) {

            // the envelope that we have created
            final Message message = getSentMessage(messageId);
            if (message == null) {
                // the file is send by the adapter but there is no receipt yet
                LOG.warn(MessageFormat.format(
                        "message ID {0}: message sent by the Sedex adapter, but there is no envelope in the Sedex sent directory",
                        messageId));
                continue;
            }
            // For each recipient, we generate a receipt
            for (String recipientId : message.getRecipientIds()) {
                receipts.add(generateReceipt(message, recipientId, messageId));
            }
            LOG.info("message has been sent by the Sedex adapter: " + messageId);

            // remove the id from the tree
            sentIds.remove(messageId);

        }

    }
    /* TODO sort out the receipts so that we can reliably process the situation where
         there is more than one receipt pro message*/
    return receipts;
}

From source file:gdsc.smlm.results.TraceManager.java

/**
 * @return The traces that have been found using {@link #traceMolecules(double, int)}
 *//* www  .  j  ava 2  s .  co m*/
public Trace[] getTraces() {
    // No tracing yet performed or no thresholds
    if (totalTraces == localisations.length) {
        if (filterActivationFrames) {
            ArrayList<Trace> traces = new ArrayList<Trace>();
            for (int index = 0; index < totalTraces; index++) {
                PeakResult peakResult = results.getResults().get(localisations[index].id);
                if (!outsideActivationWindow(peakResult.peak))
                    traces.add(new Trace(peakResult));
            }
            return traces.toArray(new Trace[traces.size()]);
        } else {
            Trace[] traces = new Trace[localisations.length];
            for (int index = 0; index < traces.length; index++)
                traces[index] = new Trace(results.getResults().get(localisations[index].id));
            return traces;
        }
    }

    if (tracker != null)
        tracker.progress(0);

    // Build the list of traces
    Trace[] traces = new Trace[getTotalTraces()];
    int n = 0;

    //for (int index = 0; index < localisations.length; index++)
    //   if (localisations[index].trace == 0)
    //      System.out.printf("error @ %d\n", index);

    // Since the trace numbers are allocated by processing the spots in frames, each frame can have 
    // trace number out-of-order. This occurs if re-allocation has been performed,
    // e.g.  [1,2,2,1,3] => [1,2,5,4,3] when spots in group 1 are reallocated before spots in group 2.

    TreeSet<Integer> processedTraces = new TreeSet<Integer>();
    for (int index = 0; index < localisations.length; index++) {
        if (tracker != null && index % 256 == 0)
            tracker.progress(index, localisations.length);

        final int traceId = localisations[index].trace;

        if (processedTraces.contains(traceId))
            continue;
        processedTraces.add(traceId);

        if (filterActivationFrames && outsideActivationWindow(localisations[index].t))
            continue;

        PeakResult peakResult = results.getResults().get(localisations[index].id);

        Trace nextTrace = new Trace(peakResult);
        final int tLimit = maxT[traceId];

        // Check if the trace has later frames
        if (tLimit > localisations[index].t) {
            for (int j = index + 1; j < localisations.length; j++) {
                if (localisations[j].t > tLimit) {
                    //for (; j < localisations.length; j++)
                    //   if (localisations[j].trace == traceId)
                    //      System.out.printf("missed %d\n", j);
                    break;
                }
                if (localisations[j].trace == traceId)
                    nextTrace.add(results.getResults().get(localisations[j].id));
            }
        }

        //// DEBUG: Check the trace does not contain two localisations from the same time frame.
        //// This should be handled by the findAlternativeForerunner code.
        //int[] time = new int[nextTrace.size()];
        //int count = 0;
        //for (PeakResult p : nextTrace.getPoints())
        //{
        //   for (int i = 0; i < count; i++)
        //      if (time[i] == p.peak)
        //         System.out.println("Trace contains multiple localisations from the same frame");
        //   time[count++] = p.peak;
        //}

        traces[n++] = nextTrace;
    }

    if (tracker != null)
        tracker.progress(1.0);

    return traces;
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java

/**
 * For each data element, we need the package for both the element and its type.
 *
 * @param cls       Class representing element, type or both
 * @param namespace of the element//ww  w  . j a  va2s  .com
 * @param localPart of the element
 * @param set       with both type and element packages set
 */
private static void setTypeAndElementPackages(Class cls, String namespace, String localPart,
        TreeSet<String> set, MarshalServiceRuntimeDescription msrd) {

    // Get the element and type classes
    Class eClass = getElement(cls, msrd);
    Class tClass = getType(cls);

    // Set the package for the type
    if (tClass != null) {
        Package typePkg = tClass.getPackage();
        //For primitive types there is no package
        String pkg = (typePkg != null) ? typePkg.getName() : null;

        if (pkg != null) {
            set.add(pkg);
            set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace)
            set.add("[" + tClass.getCanonicalName() + "]"); // Indicates a actual class reference
        }
        // If there is an xmlType, and it maps to a package then add
        // an override if the package is different.
        if (pkg != null) {
            AnnotationDesc ad = msrd.getAnnotationDesc(tClass);
            if (ad != null && ad.hasXmlType()) {
                String ns = ad.getXmlTypeNamespace();
                if (ns != null && ns.length() > 0) {
                    List pkgs = makePackages(ns);
                    if (pkgs != null) {
                        for (int i = 0; i < pkgs.size(); i++) {
                            String pkg2 = (String) pkgs.get(i);
                            if (!pkg.equals(pkg2)) {
                                String override = pkg + " > " + pkg2;
                                if (!set.contains(override)) {
                                    set.add(override);
                                    if (log.isDebugEnabled()) {
                                        log.debug("Adding override=" + override);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        addXmlSeeAlsoPackages(tClass, msrd, set);
    }

    // Set the package for the element
    if (tClass != eClass) {
        if (eClass == null) {
            // A null or empty namespace indicates that the element is
            // unqualified.  This can occur if the parameter is represented as a child element 
            // in doc/lit wrapped.  The package is determined from the wrapper element in such casses.
            if (namespace != null && namespace.length() > 0) {
                // Use default namespace to package algorithm
                List pkgs = makePackages(namespace);
                if (pkgs != null) {
                    set.addAll(pkgs);
                }
            }
        } else {
            Package elementPkg = eClass.getPackage();
            String pkg = (elementPkg != null) ? elementPkg.getName() : null;
            if (pkg != null) {
                set.add(pkg);
                set.add("@" + pkg); // Indicates a package from an actual class reference (versus namespace)
                set.add("[" + eClass.getCanonicalName() + "]"); // Indicates a actual class reference
            }

            if (pkg != null) {
                AnnotationDesc ad = msrd.getAnnotationDesc(tClass);
                if (ad != null && ad.hasXmlRootElement()) {
                    String ns = ad.getXmlRootElementNamespace();
                    if (ns != null && ns.length() > 0) {
                        List pkgs = makePackages(ns);
                        if (pkgs != null) {
                            for (int i = 0; i < pkgs.size(); i++) {
                                String pkg2 = (String) pkgs.get(i);
                                if (!pkg.equals(pkg2)) {
                                    String override = pkg + " > " + pkg2;
                                    if (!set.contains(override)) {
                                        set.add(override);
                                        if (log.isDebugEnabled()) {
                                            log.debug("Adding override=" + override);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            addXmlSeeAlsoPackages(tClass, msrd, set);
        }
    }
}

From source file:com.doitnext.http.router.DefaultEndpointResolver.java

private void addMethodToRoutes(String path, Object implInstance, RequestResponseContext rrCtx,
        Method implMethod, Class<?> implClass, HttpMethod httpMethod, TreeSet<Route> routes) {
    try {// w  ww .ja  v  a2  s.  c o  m
        PathTemplate pathTemplate = pathTemplateParser.parse(path);
        MethodReturnKey acceptKey = new MethodReturnKey(rrCtx.responseType.resolve(),
                rrCtx.responseFormat.resolve());

        if (!successHandlers.containsKey(acceptKey)) {
            logger.error(String.format("No response handler for method with %s in success handlers %s",
                    acceptKey, successHandlers));
            if (logger.isDebugEnabled())
                logger.debug(String.format("successHandlers = %s", successHandlers));
            return;
        }
        // If no error handler in errorHandlers use a 
        // default handler so we can handle errors.
        ResponseHandler errorHandler = defaultErrorHandler;
        if (errorHandlers.containsKey(acceptKey)) {
            errorHandler = errorHandlers.get(acceptKey);
        }
        ResponseHandler successHandler = successHandlers.get(acceptKey);
        Route route = new Route(httpMethod, rrCtx.requestType.resolve(), rrCtx.responseType.resolve(),
                rrCtx.requestFormat.resolve(), rrCtx.responseFormat.resolve(), pathTemplate, implClass,
                implMethod, invoker, implInstance, successHandler, errorHandler, false);
        if (routes.contains(route)) {
            Route existingRoute = null;
            for (Route r : routes) {
                if (r.compareTo(route) == 0) {
                    existingRoute = r;
                    break;
                }
            }
            logger.debug(String.format("An equivalent route to %s is already in routes. Conflicting route: %s",
                    route, existingRoute));
        } else {
            logger.debug(String.format("Adding route %s to routes.", route));
            routes.add(route);
        }
    } catch (Exception e) {
        logger.error(String.format("Error addding route for %s.%s", implClass.getName(), implMethod.getName()),
                e);
    }
}

From source file:org.pentaho.metadata.query.impl.ietl.InlineEtlQueryExecutor.java

public IPentahoResultSet executeQuery(Query query, Map<String, Object> parameters) throws Exception {
    if (query.getLimit() >= 0) {
        throw new UnsupportedOperationException(
                Messages.getErrorString("InlineEtlQueryExecutor.ERROR_0003_LIMIT_NOT_SUPPORTED"));
    }/*from  w  w w. java2s .com*/

    // resolve any missing parameters with default values
    if (parameters == null && query.getParameters().size() > 0) {
        parameters = new HashMap<String, Object>();
    }
    for (Parameter param : query.getParameters()) {
        if (!parameters.containsKey(param.getName())) {
            parameters.put(param.getName(), param.getDefaultValue());
        }
    }

    // group by?
    int groupBys = 0;
    List<QueryConstraint> queryConstraints = parseConstraints(query, parameters);

    TreeSet<String> repeatedSelections = new TreeSet<String>();
    List<Selection> allSelections = getAllSelections(query, queryConstraints);
    Map<Selection, String> selectionFieldNames = new HashMap<>();

    // calculate number of group bys, also build up a list
    // of unique field names.
    for (Selection selection : allSelections) {
        String fieldName = ((InlineEtlPhysicalColumn) selection.getLogicalColumn().getPhysicalColumn())
                .getFieldName();
        String useFieldName = fieldName;
        int count = 1;
        while (repeatedSelections.contains(useFieldName)) {
            useFieldName = fieldName + "_" + count++; //$NON-NLS-1$
        }
        repeatedSelections.add(useFieldName);
        selectionFieldNames.put(selection, useFieldName);
        if (selection.getActiveAggregationType() != null
                && selection.getActiveAggregationType() != AggregationType.NONE) {
            groupBys++;
        }
    }

    String fileAddress = getTransformLocation() + "inlinecsv.ktr"; //$NON-NLS-1$
    if (groupBys > 0 && query.getConstraints().size() == 0) {
        fileAddress = getTransformLocation() + "inlinecsv_groupby.ktr"; //$NON-NLS-1$
    }
    if (groupBys > 0 && query.getConstraints().size() > 0) {
        fileAddress = getTransformLocation() + "inlinecsv_groupby_and_constraints.ktr"; //$NON-NLS-1$
    }
    TransMeta transMeta = new TransMeta(fileAddress, null, true);
    transMeta.setFilename(fileAddress);

    doInputWiring(query, transMeta);

    //
    // SELECT
    //

    StepMeta selections = getStepMeta(transMeta, "Select values"); //$NON-NLS-1$
    SelectValuesMeta selectVals = (SelectValuesMeta) selections.getStepMetaInterface();
    selectVals.allocate(allSelections.size(), 0, 0);
    final String[] selectNames = new String[allSelections.size()];
    final String[] selectRenames = new String[allSelections.size()];
    for (int i = 0; i < allSelections.size(); i++) {
        Selection selection = allSelections.get(i);
        String fieldName = ((InlineEtlPhysicalColumn) selection.getLogicalColumn().getPhysicalColumn())
                .getFieldName();
        String renameFieldName = selectionFieldNames.get(selection);

        selectNames[i] = fieldName;
        // add a rename property if this field is used for multiple
        // selections
        if (!fieldName.equals(renameFieldName)) {
            selectRenames[i] = renameFieldName;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("SELECT " + fieldName + " RENAME TO " + renameFieldName); //$NON-NLS-1$//$NON-NLS-2$
        }
    }
    selectVals.setSelectName(selectNames);
    selectVals.setSelectRename(selectRenames);

    StepMeta finalSelections = getStepMeta(transMeta, "Select values 2"); //$NON-NLS-1$
    Map<String, String> fieldNameMap = new HashMap<>();

    SelectValuesMeta finalSelectVals = (SelectValuesMeta) finalSelections.getStepMetaInterface();
    finalSelectVals.allocate(query.getSelections().size(), 0, 0);
    final String[] finalSelectValsNames = new String[query.getSelections().size()];
    for (int i = 0; i < query.getSelections().size(); i++) {
        Selection selection = query.getSelections().get(i);
        String fieldName = selectionFieldNames.get(selection);
        fieldNameMap.put(fieldName.toUpperCase(), selection.getLogicalColumn().getId());
        finalSelectValsNames[i] = fieldName;
    }
    finalSelectVals.setSelectName(finalSelectValsNames);

    //
    // CONSTRAINTS
    //

    if (query.getConstraints().size() > 0) {

        StepMeta formula = getStepMeta(transMeta, "Formula"); //$NON-NLS-1$
        FormulaMeta formulaMeta = (FormulaMeta) formula.getStepMetaInterface();

        int alloc = 0;
        for (QueryConstraint constraint : queryConstraints) {
            if (constraint.groupby) {
                continue;
            }
            alloc++;
        }
        if (alloc > 0) {
            formulaMeta.allocate(alloc);
        }

        StepMeta filter = getStepMeta(transMeta, "Filter rows"); //$NON-NLS-1$
        FilterRowsMeta filterRows = (FilterRowsMeta) filter.getStepMetaInterface();
        Condition rootCondition = new Condition();
        int c = 0;
        for (QueryConstraint constraint : queryConstraints) {
            if (constraint.groupby) {
                continue;
            }
            String formulaVal = constraint.formula;
            formulaMeta.getFormula()[c] = new FormulaMetaFunction(__FORMULA_ + c, formulaVal,
                    ValueMetaInterface.TYPE_BOOLEAN, -1, -1, null);

            Condition condition = new Condition();
            condition.setLeftValuename(__FORMULA_ + c);
            condition.setOperator(convertOperator(constraint.orig.getCombinationType()));
            condition.setFunction(Condition.FUNC_EQUAL);
            condition.setRightExact(new ValueMetaAndData("dummy", true)); //$NON-NLS-1$
            rootCondition.addCondition(condition);
            c++;
        }

        if (c > 0) {
            filterRows.setCondition(rootCondition);

            // link the dummy step to FALSE hop
            StepMeta dummy = getStepMeta(transMeta, "Dummy 1"); //$NON-NLS-1$
            filterRows.getStepIOMeta().getTargetStreams().get(1).setStepMeta(dummy);
            transMeta.addTransHop(new TransHopMeta(filter, dummy));
        }

        if (groupBys > 0) {

            StepMeta formula2 = getStepMeta(transMeta, "Formula 2"); //$NON-NLS-1$
            FormulaMeta formulaMeta2 = (FormulaMeta) formula2.getStepMetaInterface();

            alloc = 0;
            for (QueryConstraint constraint : queryConstraints) {
                if (!constraint.groupby) {
                    continue;
                }
                alloc++;
            }
            if (alloc > 0) {
                formulaMeta2.allocate(alloc);
            }

            StepMeta filter2 = getStepMeta(transMeta, "Filter rows 2"); //$NON-NLS-1$
            FilterRowsMeta filterRows2 = (FilterRowsMeta) filter2.getStepMetaInterface();
            Condition rootCondition2 = new Condition();

            c = 0;
            for (QueryConstraint constraint : queryConstraints) {
                if (!constraint.groupby) {
                    continue;
                }
                String formulaVal = constraint.formula;
                formulaMeta2.getFormula()[c] = new FormulaMetaFunction("__FORMULA2_" + c, formulaVal, //$NON-NLS-1$
                        ValueMetaInterface.TYPE_BOOLEAN, -1, -1, null);

                Condition condition = new Condition();
                condition.setLeftValuename("__FORMULA2_" + c); //$NON-NLS-1$
                condition.setOperator(convertOperator(constraint.orig.getCombinationType()));
                condition.setFunction(Condition.FUNC_EQUAL);
                condition.setRightExact(new ValueMetaAndData("dummy", true)); //$NON-NLS-1$
                rootCondition2.addCondition(condition);
                c++;
            }
            if (c > 0) {
                filterRows2.setCondition(rootCondition2);
                // link the dummy step to FALSE hop
                StepMeta dummy2 = getStepMeta(transMeta, "Dummy 2"); //$NON-NLS-1$
                filterRows2.getStepIOMeta().getTargetStreams().get(1).setStepMeta(dummy2);
                transMeta.addTransHop(new TransHopMeta(filter2, dummy2));
            }
        }

    }
    // we could remove the formula and filter steps for performance.

    //
    // SORT
    //

    StepMeta sort = getStepMeta(transMeta, "Sort rows"); //$NON-NLS-1$

    SortRowsMeta sortRows = (SortRowsMeta) sort.getStepMetaInterface();

    sortRows.allocate(query.getOrders().size()); // allSelections.size());

    int c = 0;
    for (Order order : query.getOrders()) {
        String fieldName = selectionFieldNames.get(order.getSelection());
        sortRows.getFieldName()[c] = fieldName;
        if (logger.isDebugEnabled()) {
            logger.debug("ORDER: " + fieldName); //$NON-NLS-1$
        }
        sortRows.getAscending()[c] = (order.getType() == Order.Type.ASC);
        sortRows.getCaseSensitive()[c] = false;
        c++;
    }

    //
    // GROUP BY
    //

    if (groupBys > 0) {

        // GROUP SORT

        StepMeta groupsort = getStepMeta(transMeta, "Group Sort rows"); //$NON-NLS-1$

        SortRowsMeta groupSortRows = (SortRowsMeta) groupsort.getStepMetaInterface();

        int groups = 0;
        for (Selection selection : query.getSelections()) {
            // sort the group by fields

            if (selection.getActiveAggregationType() == null
                    || selection.getActiveAggregationType() == AggregationType.NONE) {
                groups++;
            }
        }

        groupSortRows.allocate(groups);

        c = 0;
        for (Selection selection : query.getSelections()) {
            // sort the group by fields

            if (selection.getActiveAggregationType() == null
                    || selection.getActiveAggregationType() == AggregationType.NONE) {

                String fieldName = selectionFieldNames.get(selection);
                groupSortRows.getFieldName()[c] = fieldName;
                if (logger.isDebugEnabled()) {
                    logger.debug("GROUP ORDER: " + fieldName); //$NON-NLS-1$
                }
                groupSortRows.getAscending()[c] = true;
                groupSortRows.getCaseSensitive()[c] = false;
                c++;
            }
        }

        //
        // GROUP BY
        //

        StepMeta group = getStepMeta(transMeta, "Group by"); //$NON-NLS-1$
        GroupByMeta groupStep = (GroupByMeta) group.getStepMetaInterface();
        // c is the number
        groupStep.allocate(groups, groupBys);

        // group only on selections

        c = 0;
        for (Selection selection : query.getSelections()) {
            if (selection.getActiveAggregationType() == null
                    || selection.getActiveAggregationType() == AggregationType.NONE) {
                String fieldName = selectionFieldNames.get(selection);
                groupStep.getGroupField()[c] = fieldName;
                if (logger.isDebugEnabled()) {
                    logger.debug("GROUP BY: " + fieldName); //$NON-NLS-1$
                }
                c++;
            }
        }

        // add group by fields for all the grouped selections

        c = 0;
        for (Selection selection : allSelections) {
            if (selection.getActiveAggregationType() != null
                    && selection.getActiveAggregationType() != AggregationType.NONE) {
                String fieldName = selectionFieldNames.get(selection);
                groupStep.getAggregateField()[c] = fieldName;
                groupStep.getSubjectField()[c] = fieldName;
                groupStep.getAggregateType()[c] = convertAggType(selection.getActiveAggregationType());
                groupStep.getValueField()[c] = null;
                c++;
            }
        }
    }

    InlineEtlRowListener listener = new InlineEtlRowListener();
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(transMeta.getArguments());

    // allows for subclasses to swap the csv step with an injector step
    doInjector(query, trans);

    listener.registerAsStepListener(trans, query, fieldNameMap);

    trans.startThreads();
    trans.waitUntilFinished();
    trans.cleanup();

    return listener.results;
}

From source file:gemlite.shell.admin.dao.AdminDao.java

public String prB(String regionName) {
    Map param = new HashMap();

    param.put("beanName", "PrService");
    Map args = new HashMap();
    args.put("REGIONPATH", regionName);
    param.put("userArgs", args);
    Execution execution = FunctionService.onServers(clientPool).withArgs(param);
    ResultCollector rc = execution.execute("REMOTE_ADMIN_FUNCTION");
    ArrayList rs = (ArrayList) rc.getResult();
    StringBuilder sb = new StringBuilder();
    int pNum = 0, rNum = 0, tNum = 0;
    // ???ip+node?TreeSet
    TreeSet<String> ipNodeSet = new TreeSet<String>();
    TreeSet<String> ipSet = new TreeSet<String>(); // ip
    HashMap<String, Set<String>> nodeMap = new HashMap<String, Set<String>>(); // ?ipnode
    // ?HashMap,k:ip+node+? v:bucket?,bucketId?
    HashMap<String, HashMap<Integer, String>> data = new HashMap<String, HashMap<Integer, String>>();
    if (rs != null) {
        for (Object obj : rs) {
            ArrayList list = (ArrayList) obj;
            for (Object o : list) {
                if (!(o instanceof Map)) {
                    System.out.println(o.toString());
                    continue;
                }//from  w  w  w  .  j  ava2  s.  com
                HashMap map = (HashMap) o;
                // ??,?bucket?
                String host = (String) map.get("host");
                String node = (String) map.get("node");
                Integer BucketId = (Integer) map.get("BucketId");
                if (!ipSet.contains(host))
                    ipSet.add(host);
                Set<String> nodeSet = nodeMap.get(host);
                if (nodeSet == null) {
                    nodeSet = new TreeSet<String>();
                    nodeSet.add(node);
                    nodeMap.put(host, nodeSet);
                } else {
                    if (!nodeSet.contains(node))
                        nodeSet.add(node);
                }
                String hostAndNode = host + node;
                String singleHostNode = hostAndNode;
                tNum = (Integer) map.get("TotalNumBuckets");
                ipNodeSet.add(hostAndNode);
                // 
                if ("primary".equals(map.get("type"))) {
                    singleHostNode = primary + singleHostNode;
                    pNum++;
                } else {
                    singleHostNode = redundant + singleHostNode;
                    rNum++;
                }
                if (data.containsKey(singleHostNode)) {
                    HashMap<Integer, String> buckets = data.get(singleHostNode);
                    buckets.put(BucketId, BucketId + "\t" + map.get("Bytes") + "\t" + map.get("Size"));
                } else {
                    HashMap<Integer, String> buckets = new HashMap<Integer, String>();
                    buckets.put(BucketId, BucketId + "\t" + map.get("Bytes") + "\t" + map.get("Size"));
                    data.put(singleHostNode, buckets);
                }
            }
        }
    }

    // ?,ip,ipset??
    Iterator<String> it = ipNodeSet.iterator();
    int i = 0;
    while (it.hasNext()) {
        i++;
        String host = it.next();
        // ?bucket?
        // ,??
        String p = primary + host;
        sb.append(i + ". " + p).append("\n");
        sb.append(paraseSingleNode(data, p));
        // ?bucket?
        // ,??
        String r = redundant + host;
        sb.append(i + ". " + r).append("\n");
        sb.append(paraseSingleNode(data, r));
    }
    // ??
    sb.append("Primary Bucket Count:" + pNum).append("\n");
    sb.append("Redundant Bucket Count:" + rNum).append("\n");
    sb.append("total-num-buckets (max):" + tNum).append("\n");

    // bucket?
    checkPr(ipSet, nodeMap, data, sb);
    return sb.toString();
    //System.out.println(sb.toString());
}

From source file:org.mda.bcb.tcgagsdata.create.Metadata.java

public void writeBarcodeDataFile(String theIdColumn, String theDataColumn, String theOutputFile,
        File[] theDiseaseSamplesFiles) throws IOException {
    // TODO: theDiseaseSampleFile - disease in first column, rest of row is SAMPLE barcode
    TcgaGSData.printWithFlag("Metadata::writeBarcodeDataFile - start " + theOutputFile);
    TreeSet<String> processedBarcode = new TreeSet<>();
    try (BufferedReader br = Files.newBufferedReader(Paths.get(mMetadataFile),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(theOutputFile),
                Charset.availableCharsets().get("ISO-8859-1"))) {
            // read header/write header
            int indexId = -1;
            int indexData = -1;
            {/*from www . j  a v a2  s.c  o m*/
                String line = br.readLine();
                ArrayList<String> headerArray = new ArrayList<>();
                headerArray.addAll(Arrays.asList(line.split("\t", -1)));
                indexId = headerArray.indexOf(theIdColumn);
                indexData = headerArray.indexOf(theDataColumn);
            }
            bw.write("ID\tDATA");
            bw.newLine();
            //
            for (String line = br.readLine(); null != line; line = br.readLine()) {
                String[] splitted = line.split("\t", -1);
                bw.write(splitted[indexId] + "\t" + splitted[indexData]);
                processedBarcode.add(splitted[indexId]);
                bw.newLine();
            }
            TcgaGSData.printWithFlag("Metadata::writeBarcodeDataFile - processed file " + theOutputFile);
            for (File file : theDiseaseSamplesFiles) {
                TreeSet<String> barcodes = getDiseaseSampleData(file, true);
                for (String barcode : barcodes) {
                    if (false == processedBarcode.contains(barcode)) {
                        bw.write(barcode + "\t" + MetadataTcgaNames.M_UNKNOWN);
                        processedBarcode.add(barcode);
                        bw.newLine();
                    }
                }
            }
        }
    }
    TcgaGSData.printWithFlag("Metadata::writeBarcodeDataFile - finished");
}