Search in sources :

Example 1 with HashBag

use of org.apache.commons.collections.bag.HashBag in project ANNIS by korpling.

the class TableAccessStrategy method computeSourceTables.

protected static Bag computeSourceTables(QueryNode node, Map<String, String> tableAliases) {
    Bag tables = new HashBag();
    // hack to support table selections for ANNOTATE query
    if (node == null) {
        String[] tableNames = { NODE_TABLE, RANK_TABLE, COMPONENT_TABLE, NODE_ANNOTATION_TABLE, EDGE_ANNOTATION_TABLE };
        for (String table : tableNames) tables.add(table);
        return tables;
    }
    tables.add(tableName(tableAliases, NODE_ANNOTATION_TABLE), node.getNodeAnnotations().size());
    if (node.getNodeAnnotations().isEmpty() && node.getNodeAnnotations().size() > 0)
        tables.add(tableName(tableAliases, NODE_ANNOTATION_TABLE));
    tables.add(tableName(tableAliases, EDGE_ANNOTATION_TABLE), node.getEdgeAnnotations().size());
    if (tables.getCount(tableName(tableAliases, RANK_TABLE)) == 0 && usesRankTable(node))
        tables.add(tableName(tableAliases, RANK_TABLE));
    if (tables.getCount(tableName(tableAliases, COMPONENT_TABLE)) == 0 && usesRankTable(node))
        tables.add(tableName(tableAliases, COMPONENT_TABLE));
    if (tables.getCount(tableName(tableAliases, NODE_TABLE)) == 0)
        tables.add(tableName(tableAliases, NODE_TABLE));
    return tables;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag)

Example 2 with HashBag

use of org.apache.commons.collections.bag.HashBag in project Gargoyle by callakrsos.

the class HashBagTest method test.

@Test
public void test() {
    HashBag hashBag = new HashBag();
    hashBag.add("zzz");
    hashBag.add("zzz");
    hashBag.add("zzz");
    hashBag.add("zzz1");
    System.out.println(hashBag.getCount("zzz"));
    hashBag.forEach(System.out::println);
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) Test(org.junit.Test)

Example 3 with HashBag

use of org.apache.commons.collections.bag.HashBag in project ANNIS by korpling.

the class TestAbstractFromClauseGenerator method setupTableAliases.

// set up table access strategy to return the requested table alias
// simulate that count copies of the table (alias) are required
private Map<String, String> setupTableAliases(QueryNode node, String table, String tableAlias, int count) {
    HashMap<String, String> tableAliases = new HashMap<>();
    tableAliases.put(table, tableAlias);
    if (count > 0) {
        tableAliases.put(TableAccessStrategy.NODE_ANNOTATION_TABLE, tableAlias);
    }
    for (int i = 0; i < count; i++) {
        // this will add new entries for the source tables
        node.addNodeAnnotation(new QueryAnnotation("dummy", "dummy" + i));
    }
    tableAccessStrategy.setTableAliases(tableAliases);
    tableAccessStrategy.setNode(node);
    Bag tables = new HashBag();
    tables.add(tableAlias, count);
    given(tableAccessStrategy.computeSourceTables()).willReturn(tables);
    return tableAliases;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) HashMap(java.util.HashMap) QueryAnnotation(annis.model.QueryAnnotation) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag) TestUtils.uniqueString(annis.test.TestUtils.uniqueString)

Example 4 with HashBag

use of org.apache.commons.collections.bag.HashBag in project new-cloud by xie-summer.

the class JVMHelper method exportThread.

public static Map<String, String> exportThread(Writer writer) throws IOException {
    Map<Thread, StackTraceElement[]> traceList = Thread.getAllStackTraces();
    Bag bag = new HashBag();
    for (Map.Entry<Thread, StackTraceElement[]> trace : traceList.entrySet()) {
        Thread t = trace.getKey();
        writer.write("\"" + t.getName() + "\" - " + t.getState() + "\n");
        for (StackTraceElement stack : trace.getValue()) {
            writer.write("\tat " + stack.toString() + "\n");
        }
        writer.write("\n");
        bag.add(t.getState().name());
    }
    Map<String, String> result = Maps.newHashMap();
    result.put("threadCount", "" + traceList.size());
    for (Object key : bag.uniqueSet()) {
        result.put((String) key, "" + bag.getCount(key));
    }
    return result;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with HashBag

use of org.apache.commons.collections.bag.HashBag in project new-cloud by xie-summer.

the class JVMHelper method exportMBeanThread.

public static Map<String, String> exportMBeanThread(Writer writer) throws IOException {
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] tiList = bean.getThreadInfo(bean.getAllThreadIds(), true, true);
    Bag bag = new HashBag();
    for (ThreadInfo ti : tiList) {
        appendThreadInfo(writer, ti);
        bag.add(ti.getThreadState().name());
    }
    Map<String, String> result = Maps.newHashMap();
    result.put("threadCount", "" + tiList.length);
    for (Object key : bag.uniqueSet()) {
        result.put((String) key, "" + bag.getCount(key));
    }
    return result;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag)

Aggregations

HashBag (org.apache.commons.collections.bag.HashBag)5 Bag (org.apache.commons.collections.Bag)4 HashMap (java.util.HashMap)2 QueryAnnotation (annis.model.QueryAnnotation)1 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)1 Map (java.util.Map)1 Test (org.junit.Test)1