Example usage for org.apache.commons.collections.map MultiKeyMap MultiKeyMap

List of usage examples for org.apache.commons.collections.map MultiKeyMap MultiKeyMap

Introduction

In this page you can find the example usage for org.apache.commons.collections.map MultiKeyMap MultiKeyMap.

Prototype

public MultiKeyMap() 

Source Link

Document

Constructs a new MultiKeyMap that decorates a HashedMap.

Usage

From source file:edu.cmu.tetrad.search.LocalScoreCache.java

public LocalScoreCache() {
    map = new MultiKeyMap();
}

From source file:com.navercorp.pinpoint.collector.dao.hbase.stat.HbaseDataSourceListDao.java

private List<DataSourceListBo> reorderDataSourceListBos(List<DataSourceListBo> dataSourceListBos) {
    // reorder dataSourceBo using id and timeSlot
    MultiKeyMap dataSourceListBoMap = new MultiKeyMap();

    for (DataSourceListBo dataSourceListBo : dataSourceListBos) {
        for (DataSourceBo dataSourceBo : dataSourceListBo.getList()) {
            int id = dataSourceBo.getId();
            long timestamp = dataSourceBo.getTimestamp();
            long timeSlot = AgentStatUtils.getBaseTimestamp(timestamp);

            DataSourceListBo mappedDataSourceListBo = (DataSourceListBo) dataSourceListBoMap.get(id, timeSlot);
            if (mappedDataSourceListBo == null) {
                mappedDataSourceListBo = new DataSourceListBo();
                mappedDataSourceListBo.setAgentId(dataSourceBo.getAgentId());
                mappedDataSourceListBo.setStartTimestamp(dataSourceBo.getStartTimestamp());
                mappedDataSourceListBo.setTimestamp(dataSourceBo.getTimestamp());

                dataSourceListBoMap.put(id, timeSlot, mappedDataSourceListBo);
            }// ww w  .  j av  a  2 s .  co m

            // set fastest timestamp
            if (mappedDataSourceListBo.getTimestamp() > dataSourceBo.getTimestamp()) {
                mappedDataSourceListBo.setTimestamp(dataSourceBo.getTimestamp());
            }

            mappedDataSourceListBo.add(dataSourceBo);
        }
    }

    Collection values = dataSourceListBoMap.values();
    return new ArrayList<DataSourceListBo>(values);
}

From source file:de.unidue.langtech.teaching.rp.detector.LanguageDetectorWeb1T.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    providerMap = new HashMap<String, FrequencyCountProvider>();
    multiKeyMap = new MultiKeyMap();

    for (FrequencyCountProvider provider : frequencyProviders) {
        try {//w  w w.j  a va  2 s.  co m
            providerMap.put(provider.getLanguage(), provider);
        } catch (Exception e) {
            throw new ResourceInitializationException(e);
        }
    }

}

From source file:com.gs.obevo.db.apps.reveng.DbFileMerger.java

public void generateDiffs(DbPlatform dialect, MutableCollection<DbMergeInfo> dbNameLocationPairs,
        File outputDir) {/*from w  w w .  j av  a 2 s. c o  m*/
    System.out.println("Generating diffs for " + dbNameLocationPairs);
    MultiKeyMap objectMap = new MultiKeyMap();
    for (DbMergeInfo dbNameLocationPair : dbNameLocationPairs) {
        FileObject mainDir = FileRetrievalMode.FILE_SYSTEM
                .resolveSingleFileObject(dbNameLocationPair.getInputDir().getAbsolutePath());
        for (FileObject schemaDir : mainDir.getChildren()) {
            if (schemaDir.getType() != FileType.FOLDER) {
                continue;
            }
            for (ChangeType changeType : dialect.getChangeTypes()) {
                FileObject changeTypeDir = schemaDir.getChild(changeType.getDirectoryName());
                if (changeTypeDir != null && changeTypeDir.isReadable()
                        && changeTypeDir.getType() == FileType.FOLDER) {
                    FileObject[] childFiles = changeTypeDir.getChildren();
                    for (FileObject objectFile : childFiles) {
                        if (objectFile.getType() == FileType.FILE) {
                            FileComparison fileComparison = (FileComparison) objectMap.get(changeType,
                                    objectFile.getName().getBaseName());
                            if (fileComparison == null) {
                                fileComparison = new FileComparison(schemaDir.getName().getBaseName(),
                                        changeType, objectFile.getName().getBaseName());
                                objectMap.put(changeType, objectFile.getName().getBaseName(), fileComparison);
                            }

                            fileComparison.addFilePair(Tuples.pair(dbNameLocationPair.getName(), objectFile));
                            String fileContent = objectFile.getStringContent();
                            String normalizedContent = DAStringUtil
                                    .normalizeWhiteSpaceFromStringOld(fileContent);
                            // modify the content here if needed
                            fileComparison.addContentValues(fileContent);
                            fileComparison.addDistinctValue(normalizedContent);
                            fileComparison.incrementCount();
                        }
                    }
                }
            }
        }
    }

    for (FileComparison fileComparison : (Collection<FileComparison>) objectMap.values()) {
        File fileComparisonFileRoot = new File(new File(outputDir, fileComparison.getSchemaName()),
                fileComparison.getChangeType().getDirectoryName());
        if (fileComparison.getDistinctValues().size() == 1) {
            File outputFile;
            if (fileComparison.getCount() == dbNameLocationPairs.size()) {
                outputFile = new File(fileComparisonFileRoot, fileComparison.getName());
            } else {
                MutableList<String> dbNames = fileComparison.getFilePairs()
                        .collect(Functions.<String>firstOfPair());
                String dbNameString = "only-" + dbNames.sortThis().makeString("-");
                File dbDir = new File(fileComparisonFileRoot, dbNameString);
                outputFile = new File(dbDir, fileComparison.getName());

                File packageInfoFile = new File(dbDir, "package-info.txt");
                FileUtilsCobra.writeStringToFile(packageInfoFile, "//// METADATA includeEnvs=\""
                        + dbNames.sortThis().collect(StringFunctions.append("*")).makeString(",") + "\"");
            }
            FileUtilsCobra.writeStringToFile(outputFile, fileComparison.getContentValues().getFirst());
        } else {
            for (Pair<String, FileObject> dbNameFileObjectPair : fileComparison.getFilePairs()) {
                String dbName = dbNameFileObjectPair.getOne();
                File outputFile = new File(new File(fileComparisonFileRoot, dbName), fileComparison.getName());
                File packageInfoFile = new File(new File(fileComparisonFileRoot, dbName), "package-info.txt");

                String fileContent = dbNameFileObjectPair.getTwo().getStringContent();
                FileUtilsCobra.writeStringToFile(outputFile, fileContent);
                FileUtilsCobra.writeStringToFile(packageInfoFile,
                        "//// METADATA includeEnvs=\"" + StringFunctions.append("*").valueOf(dbName) + "\"");
            }
        }
    }
}

From source file:com.qq.tars.service.expand.ExpandServerService.java

private MultiKeyMap getSoruceAdapterMap(String application, String serverName, String nodeName) {
    MultiKeyMap map = new MultiKeyMap();
    adapterMapper.getAdapterConf(application, serverName, nodeName).forEach(adapter -> {
        String servant = adapter.getServant();
        map.put(adapter.getApplication(), adapter.getServerName(), adapter.getNodeName(),
                servant.substring(servant.lastIndexOf('.') + 1), adapter);
    });//from   w  w w .ja v  a2s  . co m
    return map;
}

From source file:com.qq.tars.service.monitor.TARSPropertyMonitorService.java

private MultiKeyMap call(List<String> groupBy, List<String> conditions) throws IOException {
    String template = "{\"groupby\":%s,\"method\":\"query\",\"dataid\":\"tars_property\","
            + "\"filter\":%s,\"indexs\":[\"value\"]}";

    ObjectMapper mapper = new ObjectMapper();
    String request = String.format(template, mapper.writeValueAsString(groupBy),
            mapper.writeValueAsString(conditions));

    List<Pair<String, Integer>> addrs = adminService.getEndpoints("tars.tarsqueryproperty.NoTarsObj");
    if (addrs.isEmpty()) {
        throw new IOException("tars.tarsqueryproperty.NoTarsObj not found");
    }//w w  w  .ja  va 2s  .  c  o  m

    Pair<String, Integer> addr = addrs.get(0);
    log.info("tars.tarsqueryproperty.NoTarsObj, use {}:{}", addr.getLeft(), addr.getRight());

    TCPClient client = new TCPClient(addr.getLeft(), addr.getRight());
    List<String> response = client.sendAndReceive(request.getBytes(), 60000);

    log.debug("request={}", request);
    log.debug("reponse={}", StringUtils.join(response, "\n"));

    String line1 = response.get(0);
    if (!line1.startsWith("Ret:")) {
        throw new IOException(String.format("line #1, doesn't start with \"Ret:\", line=%s", line1));
    }
    int ret = Integer.parseInt(line1.substring(line1.lastIndexOf(':') + 1));
    if (ret == -1) {
        throw new IOException(String.format("line #1, Ret=%s", ret));
    }

    String line6 = response.get(5);
    if (!line6.startsWith("linecount:")) {
        throw new IOException(String.format("line #6, doesn't start with \"linecount:\", line=%s", line6));
    }
    int count = Integer.parseInt(line6.substring(line6.lastIndexOf(':') + 1));
    if (count + 7 != response.size()) {
        throw new IOException(String.format("line #6, size not match, %s vs %s", count + 7, response.size()));
    }

    String lastLine = response.get(response.size() - 1);
    if (!"endline".equals(lastLine)) {
        throw new IOException(
                String.format("line #%s, doesn't equal to \"endline\", line=%s", response.size(), lastLine));
    }

    MultiKeyMap result = new MultiKeyMap();
    for (int i = 6; i < response.size() - 1; i++) {
        String line = StringUtils.removeEnd(response.get(i), ",");
        String[] tokens = line.split(",");
        if (tokens.length != groupBy.size() + 1) {
            throw new IOException(String.format("line format error, line=%s", line));
        }

        String[] key = new String[groupBy.size()];
        int j = 0;
        for (; j < key.length; j++) {
            key[j] = tokens[j];
        }

        double[] value = new double[] { Double.parseDouble(tokens[j]) };
        result.put(new MultiKey(key), value);
    }
    return result;
}

From source file:com.qq.tars.service.monitor.TARSStatMonitorService.java

private MultiKeyMap call(List<String> groupBy, List<String> conditions) throws IOException {
    String template = "{\"groupby\":%s,\"method\":\"query\",\"dataid\":\"tars_stat\","
            + "\"filter\":%s,\"indexs\":[\"succ_count\",\"timeout_count\",\"exce_count\",\"total_time\"]}";

    ObjectMapper mapper = new ObjectMapper();
    String request = String.format(template, mapper.writeValueAsString(groupBy),
            mapper.writeValueAsString(conditions));

    List<Pair<String, Integer>> addrs = adminService.getEndpoints("tars.tarsquerystat.NoTarsObj");
    if (addrs.isEmpty()) {
        throw new IOException("tars.tarsquerystat.NoTarsObj not found");
    }//from   w  w  w.  j  av  a 2s .co  m

    Pair<String, Integer> addr = addrs.get(0);
    log.info("tars.tarsquerystat.NoTarsObj, use {}:{}", addr.getLeft(), addr.getRight());

    TCPClient client = new TCPClient(addr.getLeft(), addr.getRight());
    List<String> response = client.sendAndReceive(request.getBytes(), 60000);

    log.debug("request={}", request);
    log.debug("reponse={}", StringUtils.join(response, "\n"));

    String line1 = response.get(0);
    if (!line1.startsWith("Ret:")) {
        throw new IOException(String.format("line #1, doesn't start with \"Ret:\", line=%s", line1));
    }
    int ret = Integer.parseInt(line1.substring(line1.lastIndexOf(':') + 1));
    if (ret == -1) {
        throw new IOException(String.format("line #1, Ret=%s", ret));
    }

    String line6 = response.get(5);
    if (!line6.startsWith("linecount:")) {
        throw new IOException(String.format("line #6, doesn't start with \"linecount:\", line=%s", line6));
    }
    int count = Integer.parseInt(line6.substring(line6.lastIndexOf(':') + 1));
    if (count + 7 != response.size()) {
        throw new IOException(String.format("line #6, size not match, %s vs %s", count + 7, response.size()));
    }

    String lastLine = response.get(response.size() - 1);
    if (!"endline".equals(lastLine)) {
        throw new IOException(
                String.format("line #%s, doesn't equal to \"endline\", line=%s", response.size(), lastLine));
    }

    MultiKeyMap result = new MultiKeyMap();
    for (int i = 6; i < response.size() - 1; i++) {
        String line = StringUtils.removeEnd(response.get(i), ",");
        String[] tokens = line.split(",");
        if (tokens.length != groupBy.size() + 4) {
            throw new IOException(String.format("line format error, line=%s", line));
        }

        String[] key = new String[groupBy.size()];
        int j = 0;
        for (; j < key.length; j++) {
            key[j] = tokens[j];
        }

        long[] value = new long[] { Long.parseLong(tokens[j++]), Long.parseLong(tokens[j++]),
                Long.parseLong(tokens[j++]), Long.parseLong(tokens[j]) };
        result.put(new MultiKey(key), value);
    }
    return result;
}

From source file:com.amalto.core.server.StorageAdminImpl.java

private void registerStorage(String storageName, Storage storage) {
    MultiKeyMap multiKeyMap = storages.get(storageName);
    if (multiKeyMap == null) {
        multiKeyMap = new MultiKeyMap();
        storages.put(storageName, multiKeyMap);
    }/*from   w w  w. ja v a  2 s  .c o m*/
    multiKeyMap.put(StringUtils.EMPTY, storage.getType(), storage);
}

From source file:edu.cmu.tetrad.search.SearchGraphUtils.java

/**
 * Returns the set of nodes reachable from the given set of initial nodes in the given graph according to the
 * criteria in the given legal pairs object.
 * <p/>//  w  w  w .ja va  2s  .com
 * A variable V is reachable from initialNodes iff for some variable X in initialNodes thers is a path U [X, Y1,
 * ..., V] such that legalPairs.isLegalFirstNode(X, Y1) and for each [H1, H2, H3] as subpaths of U,
 * legalPairs.isLegalPairs(H1, H2, H3).
 * <p/>
 * The algorithm used is a variant of Algorithm 1 from Geiger, Verma, & Pearl (1990).
 *
 * @param initialNodes  The nodes that reachability paths start from.
 * @param legalPairs    Specifies initial edges (given initial nodes) and legal edge pairs.
 * @param c             a set of vertices (intuitively, the set of variables to be conditioned on.
 * @param d             a set of vertices (intuitively to be used in tests of legality, for example, the set of
 *                      ancestors of c).
 * @param graph         the graph with respect to which reachability is
 * @param maxPathLength
 */
public static Set<Node> getReachableNodes(List<Node> initialNodes, LegalPairs legalPairs, List<Node> c,
        List<Node> d, Graph graph, int maxPathLength) {
    HashSet<Node> reachable = new HashSet<Node>();
    MultiKeyMap visited = new MultiKeyMap();
    List<ReachabilityEdge> nextEdges = new LinkedList<ReachabilityEdge>();

    for (Node x : initialNodes) {
        List<Node> adjX = graph.getAdjacentNodes(x);

        for (Node y : adjX) {
            if (legalPairs.isLegalFirstEdge(x, y)) {
                reachable.add(y);
                nextEdges.add(new ReachabilityEdge(x, y));
                visited.put(x, y, Boolean.TRUE);
            }
        }
    }

    int pathLength = 1;

    while (nextEdges.size() > 0) {
        //            System.out.println("Path length = " + pathLength);
        if (++pathLength > maxPathLength)
            return reachable;

        List<ReachabilityEdge> currEdges = nextEdges;
        nextEdges = new LinkedList<ReachabilityEdge>();

        for (ReachabilityEdge edge : currEdges) {
            Node x = edge.getFrom();
            Node y = edge.getTo();
            List<Node> adjY = graph.getAdjacentNodes(y);

            for (Node z : adjY) {
                if ((visited.get(y, z)) == Boolean.TRUE) {
                    continue;
                }

                if (legalPairs.isLegalPair(x, y, z, c, d)) {
                    reachable.add(z);

                    nextEdges.add(new ReachabilityEdge(y, z));
                    visited.put(y, z, Boolean.TRUE);
                }
            }
        }
    }

    return reachable;
}

From source file:org.amplafi.flow.impl.FlowStateImpl.java

@Override
public synchronized void setCached(String namespace, String key, Object value) {
    if (cachedValues == null) {
        if (value == null) {
            // nothing to cache and no cached values.
            return;
        }/*from  w ww .jav  a2  s  . co  m*/
        cachedValues = new MultiKeyMap();
        flowManagement.registerForCacheClearing();
    }
    if (value == null) {
        cachedValues.remove(namespace, key);
    } else {
        cachedValues.put(namespace, key, value);
    }
}