Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.espertech.esper.epl.join.base.JoinSetComposerFactoryImpl.java

/**
 * Builds join tuple composer./*from ww w .  j  a  v  a  2  s  . c o  m*/
 * @param outerJoinDescList - list of descriptors for outer join criteria
 * @param optionalFilterNode - filter tree for analysis to build indexes for fast access
 * @param streamTypes - types of streams
 * @param streamNames - names of streams
 * @param streamViews - leaf view per stream
 * @param selectStreamSelectorEnum - indicator for rstream or istream-only, for optimization
 * @return composer implementation
 * @throws ExprValidationException is thrown to indicate that
 * validation of view use in joins failed.
 */
public JoinSetComposerDesc makeComposer(List<OuterJoinDesc> outerJoinDescList, ExprNode optionalFilterNode,
        EventType[] streamTypes, String[] streamNames, Viewable[] streamViews,
        SelectClauseStreamSelectorEnum selectStreamSelectorEnum,
        StreamJoinAnalysisResult streamJoinAnalysisResult, ExprEvaluatorContext exprEvaluatorContext,
        boolean queryPlanLogging, Annotation[] annotations) throws ExprValidationException {
    // Determine if there is a historical stream, and what dependencies exist
    DependencyGraph historicalDependencyGraph = new DependencyGraph(streamTypes.length);
    boolean[] isHistorical = new boolean[streamViews.length];
    boolean hasHistorical = false;
    for (int i = 0; i < streamViews.length; i++) {
        if (streamViews[i] instanceof HistoricalEventViewable) {
            HistoricalEventViewable historicalViewable = (HistoricalEventViewable) streamViews[i];
            isHistorical[i] = true;
            hasHistorical = true;
            SortedSet<Integer> streamsThisStreamDependsOn = historicalViewable.getRequiredStreams();
            historicalDependencyGraph.addDependency(i, streamsThisStreamDependsOn);
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("Dependency graph: " + historicalDependencyGraph);
    }

    QueryStrategy[] queryStrategies;

    // Handle a join with a database or other historical data source for 2 streams
    if ((hasHistorical) && (streamViews.length == 2)) {
        return makeComposerHistorical2Stream(outerJoinDescList, optionalFilterNode, streamTypes, streamViews,
                exprEvaluatorContext, queryPlanLogging);
    }

    boolean isOuterJoins = !OuterJoinDesc.consistsOfAllInnerJoins(outerJoinDescList);

    // Query graph for graph relationships between streams/historicals
    // For outer joins the query graph will just contain outer join relationships
    QueryGraph queryGraph = new QueryGraph(streamTypes.length);
    if (!outerJoinDescList.isEmpty()) {
        OuterJoinAnalyzer.analyze(outerJoinDescList, queryGraph);
        if (log.isDebugEnabled()) {
            log.debug(".makeComposer After outer join queryGraph=\n" + queryGraph);
        }
    }

    // Let the query graph reflect the where-clause
    if (optionalFilterNode != null) {
        // Analyze relationships between streams using the optional filter expression.
        // Relationships are properties in AND and EQUALS nodes of joins.
        FilterExprAnalyzer.analyze(optionalFilterNode, queryGraph, isOuterJoins);
        if (log.isDebugEnabled()) {
            log.debug(".makeComposer After filter expression queryGraph=\n" + queryGraph);
        }

        // Add navigation entries based on key and index property equivalency (a=b, b=c follows a=c)
        QueryGraph.fillEquivalentNav(streamTypes, queryGraph);
        if (log.isDebugEnabled()) {
            log.debug(".makeComposer After fill equiv. nav. queryGraph=\n" + queryGraph);
        }
    }

    // Historical index lists
    HistoricalStreamIndexList[] historicalStreamIndexLists = new HistoricalStreamIndexList[streamTypes.length];

    QueryPlan queryPlan = QueryPlanBuilder.getPlan(streamTypes, outerJoinDescList, queryGraph, streamNames,
            hasHistorical, isHistorical, historicalDependencyGraph, historicalStreamIndexLists,
            exprEvaluatorContext, streamJoinAnalysisResult, queryPlanLogging, annotations);

    // remove unused indexes - consider all streams or all unidirectional
    HashSet<String> usedIndexes = new HashSet<String>();
    QueryPlanIndex[] indexSpecs = queryPlan.getIndexSpecs();
    for (int streamNum = 0; streamNum < queryPlan.getExecNodeSpecs().length; streamNum++) {
        QueryPlanNode planNode = queryPlan.getExecNodeSpecs()[streamNum];
        if (planNode != null) {
            planNode.addIndexes(usedIndexes);
        }
    }
    for (QueryPlanIndex indexSpec : indexSpecs) {
        if (indexSpec == null) {
            continue;
        }
        Map<String, QueryPlanIndexItem> items = indexSpec.getItems();
        String[] indexNames = items.keySet().toArray(new String[items.size()]);
        for (String indexName : indexNames) {
            if (!usedIndexes.contains(indexName)) {
                items.remove(indexName);
            }
        }
    }

    if (queryPlanLogging && queryPlanLog.isInfoEnabled()) {
        queryPlanLog.info("Query plan: " + queryPlan.toQueryPlan());
    }

    // Build indexes
    Map<String, EventTable>[] indexesPerStream = new HashMap[indexSpecs.length];
    for (int streamNo = 0; streamNo < indexSpecs.length; streamNo++) {
        if (indexSpecs[streamNo] == null) {
            continue;
        }

        Map<String, QueryPlanIndexItem> items = indexSpecs[streamNo].getItems();
        indexesPerStream[streamNo] = new LinkedHashMap<String, EventTable>();

        for (Map.Entry<String, QueryPlanIndexItem> entry : items.entrySet()) {
            EventTable index;
            if (streamJoinAnalysisResult.getViewExternal()[streamNo] != null) {
                index = streamJoinAnalysisResult.getViewExternal()[streamNo]
                        .getJoinIndexTable(items.get(entry.getKey()));
            } else {
                index = EventTableFactory.buildIndex(streamNo, items.get(entry.getKey()), streamTypes[streamNo],
                        false);
            }
            indexesPerStream[streamNo].put(entry.getKey(), index);
        }
    }

    // Build strategies
    QueryPlanNode[] queryExecSpecs = queryPlan.getExecNodeSpecs();
    queryStrategies = new QueryStrategy[queryExecSpecs.length];
    for (int i = 0; i < queryExecSpecs.length; i++) {
        QueryPlanNode planNode = queryExecSpecs[i];
        if (planNode == null) {
            log.debug(".makeComposer No execution node for stream " + i + " '" + streamNames[i] + "'");
            continue;
        }

        ExecNode executionNode = planNode.makeExec(indexesPerStream, streamTypes, streamViews,
                historicalStreamIndexLists, streamJoinAnalysisResult.getViewExternal());

        if (log.isDebugEnabled()) {
            log.debug(".makeComposer Execution nodes for stream " + i + " '" + streamNames[i] + "' : \n"
                    + ExecNode.print(executionNode));
        }

        queryStrategies[i] = new ExecNodeQueryStrategy(i, streamTypes.length, executionNode);
    }

    // If this is not unidirectional and not a self-join (excluding self-outer-join)
    if ((!streamJoinAnalysisResult.isUnidirectional())
            && (!streamJoinAnalysisResult.isPureSelfJoin() || !outerJoinDescList.isEmpty())) {
        JoinSetComposer composer;
        if (hasHistorical) {
            composer = new JoinSetComposerHistoricalImpl(indexesPerStream, queryStrategies, streamViews,
                    exprEvaluatorContext);
        } else {
            composer = new JoinSetComposerImpl(indexesPerStream, queryStrategies,
                    streamJoinAnalysisResult.isPureSelfJoin(), exprEvaluatorContext);
        }

        // rewrite the filter expression for all-inner joins in case "on"-clause outer join syntax was used to include those expressions
        ExprNode filterExpression = getFilterExpressionInclOnClause(optionalFilterNode, outerJoinDescList);

        ExprEvaluator postJoinEval = filterExpression == null ? null : filterExpression.getExprEvaluator();
        return new JoinSetComposerDesc(composer, postJoinEval);
    } else {
        QueryStrategy driver;
        int unidirectionalStream;
        if (streamJoinAnalysisResult.getUnidirectionalStreamNumber() != -1) {
            unidirectionalStream = streamJoinAnalysisResult.getUnidirectionalStreamNumber();
            driver = queryStrategies[unidirectionalStream];
        } else {
            unidirectionalStream = 0;
            driver = queryStrategies[0];
        }
        JoinSetComposer composer = new JoinSetComposerStreamToWinImpl(indexesPerStream,
                streamJoinAnalysisResult.isPureSelfJoin(), unidirectionalStream, driver,
                streamJoinAnalysisResult.getUnidirectionalNonDriving());
        ExprEvaluator postJoinEval = optionalFilterNode == null ? null : optionalFilterNode.getExprEvaluator();
        return new JoinSetComposerDesc(composer, postJoinEval);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassDaoJena.java

public void getAllSuperClassURIs(String classURI, HashSet<String> subtree) {
    List<String> directSuperclasses = getSuperClassURIs(classURI, true);
    Iterator<String> it = directSuperclasses.iterator();
    while (it.hasNext()) {
        String uri = it.next();//from   w ww . j av a 2 s.  c  om
        if (!subtree.contains(uri)) {
            subtree.add(uri);
            getAllSuperClassURIs(uri, subtree);
        }
    }
}

From source file:com.rapidminer.operator.preprocessing.transformation.aggregation.AggregationOperator.java

@Override
protected MetaData modifyMetaData(ExampleSetMetaData metaData) throws UndefinedParameterError {
    ExampleSetMetaData resultMD = metaData.clone();
    resultMD.clear();//w w  w. j av a2  s  .co  m

    // add group by attributes
    if (isParameterSet(PARAMETER_GROUP_BY_ATTRIBUTES)
            && !getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTES).isEmpty()) {
        String attributeRegex = getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTES);
        Pattern pattern = Pattern.compile(attributeRegex);

        for (AttributeMetaData amd : metaData.getAllAttributes()) {
            if (pattern.matcher(amd.getName()).matches()) {
                if (amd.isNumerical() && getCompatibilityLevel().isAtMost(VERSION_5_1_6)) {
                    // converting type to mimic NumericalToPolynomial used below
                    amd.setType(Ontology.NOMINAL);
                    amd.setValueSet(Collections.<String>emptySet(), SetRelation.SUPERSET);
                }
                resultMD.addAttribute(amd);
            }
        }
        resultMD.getNumberOfExamples().reduceByUnknownAmount();
    }
    if (resultMD.getAllAttributes().isEmpty() && getCompatibilityLevel().isAtMost(VERSION_5_1_6)) {
        AttributeMetaData allGroup = new AttributeMetaData(GENERIC_GROUP_NAME, Ontology.NOMINAL);
        Set<String> values = new TreeSet<>();
        values.add(GENERIC_ALL_NAME);
        allGroup.setValueSet(values, SetRelation.EQUAL);
        resultMD.addAttribute(allGroup);
        resultMD.setNumberOfExamples(new MDInteger(1));
    }

    // add aggregated attributes of default aggregation: They will apply only to those attribute
    // not mentioned explicitly
    List<String[]> parameterList = this.getParameterList(PARAMETER_AGGREGATION_ATTRIBUTES);
    HashSet<String> explicitDefinedAttributes = new HashSet<>();
    for (String[] function : parameterList) {
        explicitDefinedAttributes.add(function[0]);
    }
    if (getParameterAsBoolean(PARAMETER_USE_DEFAULT_AGGREGATION)) {
        String defaultFunction = getParameterAsString(PARAMETER_DEFAULT_AGGREGATION_FUNCTION);
        ExampleSetMetaData metaDataSubset = attributeSelector.getMetaDataSubset(metaData, false);
        for (AttributeMetaData amd : metaDataSubset.getAllAttributes()) {
            if (!explicitDefinedAttributes.contains(amd.getName())) {
                AttributeMetaData newAMD = AggregationFunction.getAttributeMetaData(defaultFunction, amd,
                        getExampleSetInputPort());
                if (newAMD != null) {
                    resultMD.addAttribute(newAMD);
                }
            }
        }
    }

    // add explicitly defined attributes of list
    for (String[] function : parameterList) {
        AttributeMetaData amd = metaData.getAttributeByName(function[0]);
        if (amd != null) {
            AttributeMetaData newMD = AggregationFunction.getAttributeMetaData(function[1], amd,
                    getExampleSetInputPort());
            if (newMD != null) {
                resultMD.addAttribute(newMD);
            }
        } else {
            // in this case we should register a warning, but continue anyway in cases we don't
            // have the correct set available
            getExampleSetInputPort().addError(new SimpleMetaDataError(Severity.WARNING,
                    getExampleSetInputPort(), "aggregation.attribute_unknown", function[0]));
            AttributeMetaData newAMD = AggregationFunction.getAttributeMetaData(function[1],
                    new AttributeMetaData(function[0], Ontology.ATTRIBUTE_VALUE), getExampleSetInputPort());
            if (newAMD != null) {
                resultMD.addAttribute(newAMD);
            }
        }
    }

    if (getCompatibilityLevel().isAbove(VERSION_6_0_6)) {
        String[] groupByAttributes = getParameterAsString(PARAMETER_GROUP_BY_ATTRIBUTES)
                .split(ParameterTypeAttributes.ATTRIBUTE_SEPARATOR_REGEX);
        for (String attribute : groupByAttributes) {
            // if the list is empty, there is already a warning:
            if (!attribute.isEmpty() && metaData.getAttributeByName(attribute) == null) {
                getExampleSetInputPort().addError(new SimpleMetaDataError(Severity.WARNING,
                        getExampleSetInputPort(), "aggregation.group_by_attribute_unknown", attribute));
            }
        }
    }

    return resultMD;
}

From source file:de.tarent.maven.plugins.pkg.AbstractPackagingMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {

    // We will merge all targetConfigurations with their parents,
    // so tat all configurations are ready to be used from this point on

    Utils.mergeAllConfigurations(targetConfigurations);

    // For some tasks it is practical to have the TargetConfiguration
    // instances as a
    // map. This transformation step also serves as check for double
    // entries./*  w  w w  .ja  v a  2  s  .  co  m*/
    Map<String, TargetConfiguration> targetConfigurationMap = Utils.toMap(targetConfigurations);

    // Container for collecting target configurations that have been built.
    // This
    // is used to make sure that TCs are not build repeatedly when the given
    // target
    // configuration have a dependency to a common target configuration.
    HashSet<String> finishedTargets = new HashSet<String>();

    checkIfPackagesWillOverwrite();

    for (String t : getTargets()) {
        // A single target (and all its dependent target configurations are
        // supposed to use the same
        // distro value).
        String d = (distro != null) ? distro : Utils.getDefaultDistro(t, targetConfigurations, getLog());

        // Retrieve all target configurations that need to be build for /t/
        List<TargetConfiguration> buildChain = Utils.createBuildChain(t, d, targetConfigurations);

        for (TargetConfiguration tc : buildChain) {
            if (!finishedTargets.contains(tc.getTarget()) && tc.isReady()) {
                WorkspaceSession ws = new WorkspaceSession();
                ws.setMojo(this); // its us
                ws.setTargetConfigurationMap(targetConfigurationMap);
                ws.setTargetConfiguration(tc);

                // Populates session with PackageMap, Helper and resolved
                // relations
                prepareWorkspaceSession(ws, d);

                executeTargetConfiguration(ws);

                // Mark as done.
                finishedTargets.add(tc.getTarget());
            }

        }
    }
    getLog().info("pkg-maven-plugin goal succesfully executed for " + finishedTargets.size() + " target(s).");
    cleanUp();
}

From source file:de.tsystems.mms.apm.performancesignature.ui.PerfSigProjectAction.java

@JavaScriptMethod
public void setDashboardConfiguration(final String dashboard, final String data) throws InterruptedException {
    Map<String, JSONDashlet> defaultConfiguration = createJSONConfiguration(false);
    HashSet<String> idsFromJson = new HashSet<>();

    String json = StringEscapeUtils.unescapeJava(data);
    if (!json.startsWith("[")) {
        json = json.substring(1, json.length() - 1);
    }/*from w w  w .  j  a v  a2  s . c  o  m*/

    List<JSONDashlet> jsonDashletList = new Gson().fromJson(json, new TypeToken<List<JSONDashlet>>() {
    }.getType());
    for (JSONDashlet jsonDashlet : jsonDashletList) {
        idsFromJson.add(jsonDashlet.getId());
    }

    try {
        for (JSONDashlet jsonDashlet : getJsonDashletMap().values()) {
            if (!jsonDashlet.getDashboard().equals(dashboard)) { //filter out dashlets from other dashboards
                continue;
            }
            if (!idsFromJson.contains(jsonDashlet.getId())) { //remove dashlet, if it's not present in gridConfiguration
                getJsonDashletMap().remove(jsonDashlet.getId());
            }
        }

        for (JSONDashlet modifiedDashlet : jsonDashletList) {
            JSONDashlet unmodifiedDashlet = defaultConfiguration.get(modifiedDashlet.getId());
            JSONDashlet originalDashlet = getJsonDashletMap().get(modifiedDashlet.getId());
            if (modifiedDashlet.getId().equals(UNITTEST_DASHLETNAME)) {
                if (originalDashlet != null) {
                    modifiedDashlet.setCustomBuildCount(originalDashlet.getCustomBuildCount());
                    modifiedDashlet.setCustomName(originalDashlet.getCustomName());
                }
                getJsonDashletMap().put(modifiedDashlet.getId(), modifiedDashlet);
            } else if (unmodifiedDashlet != null) { //newly added dashlets
                modifiedDashlet.setDashboard(unmodifiedDashlet.getDashboard());
                modifiedDashlet.setChartDashlet(unmodifiedDashlet.getChartDashlet());
                modifiedDashlet.setMeasure(unmodifiedDashlet.getMeasure());
                modifiedDashlet.setDescription(unmodifiedDashlet.getDescription());
                modifiedDashlet.setId(modifiedDashlet.generateID());

                getJsonDashletMap().put(modifiedDashlet.getId(), modifiedDashlet);
            } else if (originalDashlet != null) { //old dashlets
                modifiedDashlet.setDashboard(originalDashlet.getDashboard());
                modifiedDashlet.setChartDashlet(originalDashlet.getChartDashlet());
                modifiedDashlet.setMeasure(originalDashlet.getMeasure());
                modifiedDashlet.setDescription(originalDashlet.getDescription());
                modifiedDashlet.setAggregation(originalDashlet.getAggregation());
                modifiedDashlet.setCustomBuildCount(originalDashlet.getCustomBuildCount());
                modifiedDashlet.setCustomName(originalDashlet.getCustomName());

                modifiedDashlet.setId(modifiedDashlet.generateID());
                getJsonDashletMap().remove(originalDashlet.getId());
                getJsonDashletMap().put(modifiedDashlet.getId(), modifiedDashlet);
            }
        }
        writeConfiguration(getJsonDashletMap());
    } catch (InterruptedException e) {
        logger.log(Level.SEVERE, Messages.PerfSigProjectAction_FailedToSaveGrid(), e);
        throw e;
    } catch (IOException e) {
        logger.log(Level.SEVERE, Messages.PerfSigProjectAction_FailedToSaveGrid(), e);
    }
}

From source file:com.linkedin.databus.core.TestDbusEventBufferMult.java

@Test
public void testSinglePPartionStreamFromLatest() throws Exception {
    createBufMult();// w  w  w . ja  v  a 2  s .c  o m

    PhysicalPartition[] p = { _pConfigs[0].getPhysicalPartition() };

    //generate a bunch of windows for 3 partitions
    int windowsNum = 10;
    for (int i = 1; i <= windowsNum; ++i) {
        DbusEventBufferAppendable buf = _eventBufferMult.getDbusEventBufferAppendable(p[0]);

        buf.startEvents();
        byte[] schema = "abcdefghijklmnop".getBytes(Charset.defaultCharset());
        assertTrue(buf.appendEvent(new DbusEventKey(1), (short) 100, (short) 0,
                System.currentTimeMillis() * 1000000, (short) 2, schema, new byte[10], false, null));
        buf.endEvents(100 * i, null);
    }
    String[] pnames = new String[p.length];
    int count = 0;
    for (PhysicalPartition ip : p) {
        pnames[count++] = ip.toSimpleString();
    }

    StatsCollectors<DbusEventsStatisticsCollector> statsColl = createStats(pnames);

    PhysicalPartitionKey[] pkeys = { new PhysicalPartitionKey(p[0]) };

    CheckpointMult cpMult = new CheckpointMult();
    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
    cpMult.addCheckpoint(p[0], cp);

    DbusEventBufferBatchReadable reader = _eventBufferMult.getDbusEventBufferBatchReadable(cpMult,
            Arrays.asList(pkeys), statsColl);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    WritableByteChannel writeChannel = Channels.newChannel(baos);
    // Set streamFromLatestScn == true
    reader.streamEvents(true, 1000000, writeChannel, Encoding.BINARY, new AllowAllDbusFilter());
    writeChannel.close();
    baos.close();

    //make sure we got the physical partition names right
    List<String> ppartNames = statsColl.getStatsCollectorKeys();
    assertEquals(ppartNames.size(), 1);

    HashSet<String> expectedPPartNames = new HashSet<String>(Arrays.asList(p[0].toSimpleString()));
    for (String ppartName : ppartNames) {
        assertTrue(expectedPPartNames.contains(ppartName));
    }

    //verify event counts per partition
    DbusEventsTotalStats[] ppartStats = { statsColl.getStatsCollector(p[0].toSimpleString()).getTotalStats() };

    // Only the last window is returned in each of the partitions
    assertEquals(ppartStats[0].getNumDataEvents(), 1);
    assertEquals(ppartStats[0].getNumSysEvents(), 1);

    assertEquals(statsColl.getStatsCollector().getTotalStats().getNumDataEvents(), (1));
    assertEquals(statsColl.getStatsCollector().getTotalStats().getNumSysEvents(), (1));

    assertEquals(statsColl.getStatsCollector().getTotalStats().getMaxTimeLag(), ppartStats[0].getTimeLag());
    assertEquals(statsColl.getStatsCollector().getTotalStats().getMinTimeLag(), ppartStats[0].getTimeLag());
}

From source file:ch.unil.genescore.pathway.GeneSetLibrary.java

License:asdf

/** Load gene set library, only genes that have scores are included */
private void load(File geneSetFile, HashMap<String, Gene> genes) {

    geneSets_ = new ArrayList<GeneSet>();

    genes_ = new HashSet<Gene>();
    notFoundInGenomeAnnot_ = new HashSet<String>();
    if (!Pascal.set.onlyPathwayGenesAsBackground_) {
        for (Map.Entry<String, Gene> entry : genes.entrySet()) {
            if (entry.getValue().getChi2Stat() != -1)
                genes_.add(entry.getValue());
        }/*from  w  w  w  .  j  a  v a  2s .c o  m*/
    }
    // The column where the gene list starts
    int firstGeneCol = 1; // standard format: id gene1 gene2 ...
    if (geneSetFile.getName().endsWith(".gmt"))
        firstGeneCol = 2; // gmt format (msigdb): id url gene1 gene2 ...

    // Open the file
    FileParser parser = new FileParser(Pascal.log, geneSetFile);

    // Check that gene set ids are unique
    HashSet<String> geneSetIds = new HashSet<String>();

    while (true) {
        // Read next line
        String[] nextLine = parser.readLine();
        if (nextLine == null)
            break;

        // The next gene set
        String geneSetId = nextLine[0];
        // Check that ids are unique
        if (geneSetIds.contains(geneSetId))
            throw new RuntimeException("Gene set " + geneSetId + " is listed twice");

        // Create the gene set
        GeneSet geneSet = new GeneSet(geneSetId);
        geneSets_.add(geneSet);
        geneSetIds.add(geneSetId);

        // Add the genes in pathways to gene sets
        for (int i = firstGeneCol; i < nextLine.length; i++) {
            String id = nextLine[i];
            Gene gene = genes.get(id);

            if (gene != null && gene.getChi2Stat() != -1) {
                geneSet.add(gene);
                if (Pascal.set.onlyPathwayGenesAsBackground_) {
                    genes_.add(gene);
                }

            } else {
                // The gene has no score, skip
                notFoundInGenomeAnnot_.add(id);
            }
        }

    }

    parser.close();
}

From source file:com.milaboratory.core.tree.SequenceTreeMapTest.java

@Test
public void testNIterator() throws Exception {
    SequenceTreeMap<NucleotideSequence, Integer> map = new SequenceTreeMap<>(NucleotideSequence.ALPHABET);

    assertNull(map.put(new NucleotideSequence("attagaca"), 1)); // 1 mm
    assertNull(map.put(new NucleotideSequence("attacaca"), 2)); // match
    assertNull(map.put(new NucleotideSequence("ataacaca"), 3)); // 1 mm
    assertNull(map.put(new NucleotideSequence("attcgtca"), 4)); // many mm
    assertNull(map.put(new NucleotideSequence("atttacaca"), 5)); // 1 insertion in stretch
    assertNull(map.put(new NucleotideSequence("atacaca"), 6)); // 1 deletion in the "t" stretch
    assertNull(map.put(new NucleotideSequence("attacacta"), 7)); // 1 insertion
    assertNull(map.put(new NucleotideSequence("attcaca"), 8)); // 1 deletion
    assertNull(map.put(new NucleotideSequence("attacac"), 9)); // 1 deletion in the end
    assertNull(map.put(new NucleotideSequence("ttacaca"), 10)); // 1 deletion in the beginning
    assertNull(map.put(new NucleotideSequence("tattacaca"), 11)); // 1 insertion in the beginning
    assertNull(map.put(new NucleotideSequence("attacacat"), 12)); // 1 insertion in the ent
    assertNull(map.put(new NucleotideSequence("attacact"), 13)); // 1 mm end
    assertNull(map.put(new NucleotideSequence("tttacaca"), 14)); // 1 mm begin

    NucleotideSequence reference = new NucleotideSequence("attacaca");

    SequenceTreeMap.Node<Integer> node;

    HashSet<Integer>[] allAsserts = new HashSet[3];
    allAsserts[0] = new HashSet<>(Arrays.asList(1, 3, 13, 14));
    allAsserts[1] = new HashSet<>(Arrays.asList(6, 8, 9, 10));
    allAsserts[2] = new HashSet<>(Arrays.asList(5, 7, 11, 12));

    for (int i = 0; i < 8; ++i) {

        double lastPenalty = -1.0;
        HashSet<Integer> asserts = new HashSet<>();
        asserts.add(2);//www .jav a 2 s. c  om
        int[] maxMut = new int[3];
        for (int j = 0; j < 3; ++j) {
            if (((0x1 << j) & i) != 0) {
                maxMut[j] = 1;
                asserts.addAll(allAsserts[j]);
            }
        }

        HashSet<Integer> asserts1 = new HashSet<>(asserts);

        NeighborhoodIterator ni = map.getNeighborhoodIterator(reference, 0.5,
                new double[] { 0.31, 0.301, 0.3001 }, maxMut, null);

        while ((node = ni.nextNode()) != null) {
            assertTrue(lastPenalty <= ni.getPenalty());
            lastPenalty = ni.getPenalty();
            asserts.remove(node.object);
            assertTrue(asserts1.contains(node.object));
        }
        assertTrue(asserts.isEmpty());
    }
}

From source file:com.trsst.client.Client.java

/**
 * Posts a new entry to the feed associated with the specified public
 * signing key to the home server, creating a new feed if needed.
 * /*from   ww w  .  j av a 2  s . c o m*/
 * @param signingKeys
 *            Required: the signing keys associated with public feed id of
 *            this feed.
 * @param encryptionKey
 *            Required: the public encryption key associated with this
 *            account; this public key will be used by others to encrypt
 *            private message for this account.
 * @param options
 *            The data to be posted.
 * @return The feed as posted to the home server.
 * @throws IOException
 * @throws SecurityException
 * @throws GeneralSecurityException
 * @throws contentKey
 */
public Feed post(KeyPair signingKeys, KeyPair encryptionKeys, EntryOptions options, FeedOptions feedOptions)
        throws IOException, SecurityException, GeneralSecurityException, Exception {
    // inlining all the steps to help implementors and porters (and
    // debuggers)

    // configure for signing
    Element signedNode, signatureElement, keyInfo;
    AbderaSecurity security = new AbderaSecurity(Abdera.getInstance());
    Signature signer = security.getSignature();

    String feedId = Common.toFeedId(signingKeys.getPublic());
    Feed feed = pull(feedId);
    if (feed == null) {
        feed = Abdera.getInstance().newFeed();
        feed.declareNS(Common.NS_URI, Common.NS_ABBR);
    }

    // remove each entry and retain the most recent one (if any)
    List<Entry> entries = feed.getEntries();
    Entry mostRecentEntry = null;
    for (Entry entry : entries) {
        if (mostRecentEntry == null || mostRecentEntry.getUpdated() == null
                || mostRecentEntry.getUpdated().before(entry.getUpdated())) {
            mostRecentEntry = entry;
        }
        entry.discard();
    }

    // update and sign feed (without any entries)
    feed.setUpdated(new Date());

    // ensure the correct keys are in place
    signatureElement = feed.getFirstChild(new QName(Common.NS_URI, Common.SIGN));
    if (signatureElement != null) {
        signatureElement.discard();
    }
    feed.addExtension(new QName(Common.NS_URI, Common.SIGN))
            .setText(Common.toX509FromPublicKey(signingKeys.getPublic()));
    signatureElement = feed.getFirstChild(new QName(Common.NS_URI, Common.ENCRYPT));
    if (signatureElement != null) {
        signatureElement.discard();
    }
    feed.addExtension(new QName(Common.NS_URI, Common.ENCRYPT))
            .setText(Common.toX509FromPublicKey(encryptionKeys.getPublic()));
    feed.setId(Common.toFeedUrn(feedId));
    feed.setMustPreserveWhitespace(false);

    // update feed properties
    if (feedOptions.title != null) {
        feed.setTitle(feedOptions.title);
    }
    if (feedOptions.subtitle != null) {
        feed.setSubtitle(feedOptions.subtitle);
    }
    if (feedOptions.icon != null) {
        while (feed.getIconElement() != null) {
            feed.getIconElement().discard();
        }
        feed.setIcon(feedOptions.icon);
    }
    if (feedOptions.logo != null) {
        while (feed.getLogoElement() != null) {
            feed.getLogoElement().discard();
        }
        feed.setLogo(feedOptions.logo);
    }

    Person author = feed.getAuthor();
    if (author == null) {
        // author is a required element
        author = Abdera.getInstance().getFactory().newAuthor();
        String defaultName = feed.getTitle();
        if (defaultName == null) {
            defaultName = Common.toFeedIdString(feed.getId());
        }
        author.setName(defaultName);
        feed.addAuthor(author);
    }

    // update author
    if (feedOptions.name != null || feedOptions.email != null || feedOptions.uri != null) {
        if (feedOptions.name != null) {
            author.setName(feedOptions.name);
        }
        if (feedOptions.email != null) {
            author.setEmail(feedOptions.email);
        }
        if (feedOptions.uri != null) {
            if (feedOptions.uri.indexOf(':') == -1) {
                // default to "acct:" urn
                author.setUri("acct:" + feedOptions.uri + ".trsst.com");
                // FIXME: domain should be specified by user
            } else {
                author.setUri(feedOptions.uri);
            }
        }
    }

    // set base
    if (feedOptions.base != null) {
        String uri = feedOptions.base;
        if (!uri.endsWith("/")) {
            uri = uri + '/';
        }
        uri = uri + feedId;
        feed.setBaseUri(uri);
    }

    // set link self
    IRI base = feed.getBaseUri();
    if (base != null) {
        while (feed.getLink(Link.REL_SELF) != null) {
            feed.getLink(Link.REL_SELF).discard();
        }
        feed.addLink(base.toString(), Link.REL_SELF);
    }

    // holds any attachments (can be used for logo and icons)
    String[] contentIds = new String[options.getContentCount()];

    // subject or verb or attachment is required to create an entry
    Entry entry = null;
    if (options.status != null || options.verb != null || contentIds.length > 0) {

        // create the new entry
        entry = Abdera.getInstance().newEntry();
        entry.setUpdated(feed.getUpdated());
        entry.setId(Common.toEntryUrn(feedId, feed.getUpdated().getTime()));
        entry.addLink(feedId + '/' + Common.toEntryIdString(entry.getId()));
        if (options.publish != null) {
            entry.setPublished(options.publish);
        } else {
            entry.setPublished(entry.getUpdated());
        }

        if (options.status != null) {
            entry.setTitle(options.status);
        } else {
            // title is a required element:
            // default to verb
            if (options.verb != null) {
                entry.setTitle(options.verb);
            } else {
                // "post" is the default verb
                entry.setSummary("post");
            }
        }

        if (options.verb != null) {
            feed.declareNS("http://activitystrea.ms/spec/1.0/", "activity");
            entry.addSimpleExtension(new QName("http://activitystrea.ms/spec/1.0/", "verb", "activity"),
                    options.verb);
        }

        if (options.body != null) {
            // was: entry.setSummary(options.body);
            entry.setSummary(options.body, org.apache.abdera.model.Text.Type.HTML);
            // FIXME: some readers only show type=html
        } else {
            // summary is a required element in some cases
            entry.setSummary("", org.apache.abdera.model.Text.Type.TEXT);
            // FIXME: use tika to generate a summary
        }

        // generate proof-of-work stamp for this feed id and entry id
        Element stampElement = entry.addExtension(new QName(Common.NS_URI, Common.STAMP));
        stampElement.setText(Crypto.computeStamp(Common.STAMP_BITS, entry.getUpdated().getTime(), feedId));

        if (options.mentions != null) {
            HashSet<String> set = new HashSet<String>();
            for (String s : options.mentions) {
                if (!set.contains(s)) {
                    set.add(s); // prevent duplicates
                    entry.addCategory(Common.MENTION_URN, s, "Mention");
                    stampElement = entry.addExtension(new QName(Common.NS_URI, Common.STAMP));
                    stampElement
                            .setText(Crypto.computeStamp(Common.STAMP_BITS, entry.getUpdated().getTime(), s));
                    // stamp is required for each mention
                }
            }
        }
        if (options.tags != null) {
            HashSet<String> set = new HashSet<String>();
            for (String s : options.tags) {
                if (!set.contains(s)) {
                    set.add(s); // prevent duplicates
                    entry.addCategory(Common.TAG_URN, s, "Tag");
                    stampElement = entry.addExtension(new QName(Common.NS_URI, Common.STAMP));
                    stampElement
                            .setText(Crypto.computeStamp(Common.STAMP_BITS, entry.getUpdated().getTime(), s));
                    // stamp is required for each tag
                }
            }
        }

        // generate an AES256 key for encrypting
        byte[] contentKey = null;
        if (options.recipientIds != null) {
            contentKey = Crypto.generateAESKey();
        }

        // for each content part
        for (int part = 0; part < contentIds.length; part++) {
            byte[] currentContent = options.getContentData()[part];
            String currentType = options.getMimetypes()[part];

            // encrypt before hashing if necessary
            if (contentKey != null) {
                currentContent = Crypto.encryptAES(currentContent, contentKey);
            }

            // calculate digest to determine content id
            byte[] digest = Common.ripemd160(currentContent);
            contentIds[part] = new Base64(0, null, true).encodeToString(digest);

            // add mime-type hint to content id (if not encrypted):
            // (some readers like to see a file extension on enclosures)
            if (currentType != null && contentKey == null) {
                String extension = "";
                int i = currentType.lastIndexOf('/');
                if (i != -1) {
                    extension = '.' + currentType.substring(i + 1);
                }
                contentIds[part] = contentIds[part] + extension;
            }

            // set the content element
            if (entry.getContentSrc() == null) {
                // only point to the first attachment if multiple
                entry.setContent(new IRI(contentIds[part]), currentType);
            }

            // use a base uri so src attribute is simpler to process
            entry.getContentElement().setBaseUri(Common.toEntryIdString(entry.getId()) + '/');
            entry.getContentElement().setAttributeValue(new QName(Common.NS_URI, "hash", "trsst"), "ripemd160");

            // if not encrypted
            if (contentKey == null) {
                // add an enclosure link
                entry.addLink(Common.toEntryIdString(entry.getId()) + '/' + contentIds[part],
                        Link.REL_ENCLOSURE, currentType, null, null, currentContent.length);
            }

        }

        if (contentIds.length == 0 && options.url != null) {
            Content content = Abdera.getInstance().getFactory().newContent();
            if (options.url.startsWith("urn:feed:") || options.url.startsWith("urn:entry:")) {
                content.setMimeType("application/atom+xml");
            } else {
                content.setMimeType("text/html");
            }
            content.setSrc(options.url);
            entry.setContentElement(content);
        }

        // add the previous entry's signature value
        String predecessor = null;
        if (mostRecentEntry != null) {
            signatureElement = mostRecentEntry
                    .getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"));
            if (signatureElement != null) {
                signatureElement = signatureElement
                        .getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureValue"));
                if (signatureElement != null) {
                    predecessor = signatureElement.getText();
                    signatureElement = entry.addExtension(new QName(Common.NS_URI, Common.PREDECESSOR));
                    signatureElement.setText(predecessor);
                    signatureElement.setAttributeValue(Common.PREDECESSOR_ID,
                            mostRecentEntry.getId().toString());
                } else {
                    log.error("No signature value found for entry: " + entry.getId());
                }
            } else {
                log.error("No signature found for entry: " + entry.getId());
            }
        }

        if (options.recipientIds == null) {
            // public post
            entry.setRights(Common.RIGHTS_NDBY_REVOCABLE);
        } else {
            // private post
            entry.setRights(Common.RIGHTS_RESERVED);
            try {
                StringWriter stringWriter = new StringWriter();
                StreamWriter writer = Abdera.getInstance().getWriterFactory().newStreamWriter();
                writer.setWriter(stringWriter);
                writer.startEntry();
                writer.writeId(entry.getId());
                writer.writeUpdated(entry.getUpdated());
                writer.writePublished(entry.getPublished());
                if (predecessor != null) {
                    writer.startElement(Common.PREDECESSOR, Common.NS_URI);
                    writer.writeElementText(predecessor);
                    writer.endElement();
                }
                if (options.publicOptions != null) {
                    // these are options that will be publicly visible
                    if (options.publicOptions.status != null) {
                        writer.writeTitle(options.publicOptions.status);
                    } else {
                        writer.writeTitle(""); // empty title
                    }
                    if (options.publicOptions.body != null) {
                        writer.writeSummary(options.publicOptions.body);
                    }
                    if (options.publicOptions.verb != null) {
                        writer.startElement("verb", "http://activitystrea.ms/spec/1.0/");
                        writer.writeElementText(options.publicOptions.verb);
                        writer.endElement();
                    }
                    if (options.publicOptions.tags != null) {
                        for (String s : options.publicOptions.tags) {
                            writer.writeCategory(s);
                        }
                    }
                    if (options.publicOptions.mentions != null) {
                        for (String s : options.publicOptions.mentions) {
                            writer.startElement("mention", Common.NS_URI, "trsst");
                            writer.writeElementText(s);
                            writer.endElement();
                        }
                    }
                } else {
                    writer.writeTitle(""); // empty title
                }

                writer.startContent("application/xenc+xml");

                List<PublicKey> keys = new LinkedList<PublicKey>();
                for (String id : options.recipientIds) {
                    // for each recipient
                    Feed recipientFeed = pull(id);
                    if (recipientFeed != null) {
                        // fetch encryption key
                        Element e = recipientFeed.getExtension(new QName(Common.NS_URI, Common.ENCRYPT));
                        if (e == null) {
                            // fall back to signing key
                            e = recipientFeed.getExtension(new QName(Common.NS_URI, Common.SIGN));
                        }
                        keys.add(Common.toPublicKeyFromX509(e.getText()));
                    }
                }

                // enforce the convention:
                keys.remove(encryptionKeys.getPublic());
                // move to end if exists;
                // last encrypted key is for ourself
                keys.add(encryptionKeys.getPublic());

                // encrypt content key separately for each recipient
                for (PublicKey recipient : keys) {
                    byte[] bytes = Crypto.encryptKeyWithIES(contentKey, feed.getUpdated().getTime(), recipient,
                            encryptionKeys.getPrivate());
                    String encoded = new Base64(0, null, true).encodeToString(bytes);
                    writer.startElement("EncryptedData", "http://www.w3.org/2001/04/xmlenc#");
                    writer.startElement("CipherData", "http://www.w3.org/2001/04/xmlenc#");
                    writer.startElement("CipherValue", "http://www.w3.org/2001/04/xmlenc#");
                    writer.writeElementText(encoded);
                    writer.endElement();
                    writer.endElement();
                    writer.endElement();
                }

                // now: encrypt the payload with content key
                byte[] bytes = encryptElementAES(entry, contentKey);
                String encoded = new Base64(0, null, true).encodeToString(bytes);
                writer.startElement("EncryptedData", "http://www.w3.org/2001/04/xmlenc#");
                writer.startElement("CipherData", "http://www.w3.org/2001/04/xmlenc#");
                writer.startElement("CipherValue", "http://www.w3.org/2001/04/xmlenc#");
                writer.writeElementText(encoded);
                writer.endElement();
                writer.endElement();
                writer.endElement();

                // done with encrypted elements
                writer.endContent();
                writer.endEntry();
                writer.flush();
                // this constructed entry now replaces the encrypted
                // entry
                entry = (Entry) Abdera.getInstance().getParserFactory().getParser()
                        .parse(new StringReader(stringWriter.toString())).getRoot();
                // System.out.println(stringWriter.toString());
            } catch (Throwable t) {
                log.error("Unexpected error while encrypting, exiting: " + options.recipientIds, t);
                t.printStackTrace();
                throw new IllegalArgumentException("Unexpected error: " + t);
            }
        }

        // sign the new entry
        signedNode = signer.sign(entry, getSignatureOptions(signer, signingKeys));
        signatureElement = signedNode
                .getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"));
        keyInfo = signatureElement.getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "KeyInfo"));
        if (keyInfo != null) {
            // remove key info (because we're not using certs)
            keyInfo.discard();
        }
        entry.addExtension(signatureElement);
    } else {
        log.info("No valid entries detected; updating feed.");
    }

    // remove existing feed signature element if any
    signatureElement = feed.getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"));
    if (signatureElement != null) {
        signatureElement.discard();
    }

    // remove all navigation links before signing
    for (Link link : feed.getLinks()) {
        if (Link.REL_FIRST.equals(link.getRel()) || Link.REL_LAST.equals(link.getRel())
                || Link.REL_CURRENT.equals(link.getRel()) || Link.REL_NEXT.equals(link.getRel())
                || Link.REL_PREVIOUS.equals(link.getRel())) {
            link.discard();
        }
    }

    // remove all opensearch elements before signing
    for (Element e : feed.getExtensions("http://a9.com/-/spec/opensearch/1.1/")) {
        e.discard();
    }

    // set logo and/or icon
    if (contentIds.length > 0) {
        String url = Common.toEntryIdString(entry.getId()) + '/' + contentIds[0];
        if (feedOptions.asIcon) {
            feed.setIcon(url);
        }
        if (feedOptions.asLogo) {
            feed.setLogo(url);
        }
    }

    // sign the feed
    signedNode = signer.sign(feed, getSignatureOptions(signer, signingKeys));
    signatureElement = signedNode.getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"));
    keyInfo = signatureElement.getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "KeyInfo"));
    if (keyInfo != null) {
        // remove key info (because we're not using certs)
        keyInfo.discard();
    }
    feed.addExtension(signatureElement);

    // add the new entry to the feed, if there is one,
    // only after we have signed the feed
    if (entry != null) {
        feed.addEntry(entry);
    }

    // post to server
    if (contentIds.length > 0) {
        return push(feed, contentIds, options.getMimetypes(), options.getContentData(), serving);
    }
    return push(feed, serving);
}

From source file:com.quinsoft.zeidon.standardoe.ViewImpl.java

/**
 * This is used to look for memory leaks of EntityInstanceImpl.
 *
 * @return/*www . ja va2  s. co m*/
 */
int countAllEntities() {
    int count = 0;
    HashSet<EntityInstanceImpl> allEntities = new HashSet<EntityInstanceImpl>();
    HashMap<String, Integer> entities = new HashMap<String, Integer>();
    for (EntityInstanceImpl ei = getObjectInstance().getRootEntityInstance(); ei != null; ei = ei
            .getNextHier()) {
        ei.countAllVersions(allEntities);
        for (EntityInstanceImpl linked : ei.getAllLinkedInstances(true)) {
            if (!allEntities.contains(linked))
                linked.countAllVersions(allEntities);
        }
    }

    for (EntityInstanceImpl ei : allEntities) {
        String name = (ei == null) ? "null" : ei.getEntityDef().getName();
        Integer ec = entities.get(name);
        if (ec == null)
            ec = 1;
        else
            ec = ec + 1;
        entities.put(name, ec);
    }

    count = allEntities.size();
    log().info("Entities = " + entities.toString());
    log().info("Total entities = " + count);
    return count;
}