Search in sources :

Example 6 with Bag

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

the class TableAccessStrategy method aliasedTable.

public static String aliasedTable(QueryNode node, Map<String, String> tableAliases, String table, int count) {
    if (node != null) {
        // throw new IllegalArgumentException("access to node annotation table out of range: " + count);
        if (table.equals(EDGE_ANNOTATION_TABLE) && count > node.getEdgeAnnotations().size()) {
            throw new IllegalArgumentException("access to edge annotation table out of range: " + count);
        }
        if (table.equals(NODE_TABLE) && count > 1) {
            throw new IllegalArgumentException("access to struct table out of range: " + count);
        }
        if (table.equals(RANK_TABLE) && count > 1) {
            throw new IllegalArgumentException("access to rank table out of range: " + count);
        }
        // offset table count for edge annotations if node and edge annotations are the same table
        if (table.equals(EDGE_ANNOTATION_TABLE) && isMaterialized(tableAliases, EDGE_ANNOTATION_TABLE, NODE_ANNOTATION_TABLE)) {
            count = count + node.getNodeAnnotations().size() - 1;
        }
    }
    if (count == 0) {
        count = 1;
    }
    // compute table counts
    Bag tables = computeSourceTables(node, tableAliases);
    String aliasedName = tableName(tableAliases, table);
    String aliasCount = node != null ? String.valueOf(node.getId()) : "";
    String countSuffix = tables.getCount(aliasedName) > 1 ? "_" + count : "";
    return aliasedName + aliasCount + countSuffix;
}
Also used : Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag)

Example 7 with Bag

use of org.apache.commons.collections.Bag 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 8 with Bag

use of org.apache.commons.collections.Bag 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

Bag (org.apache.commons.collections.Bag)8 HashBag (org.apache.commons.collections.bag.HashBag)6 HashMap (java.util.HashMap)2 HashBag (org.apache.commons.collections.HashBag)2 QueryAnnotation (annis.model.QueryAnnotation)1 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)1 Map (java.util.Map)1