Example usage for java.util Collections synchronizedSortedMap

List of usage examples for java.util Collections synchronizedSortedMap

Introduction

In this page you can find the example usage for java.util Collections synchronizedSortedMap.

Prototype

public static <K, V> SortedMap<K, V> synchronizedSortedMap(SortedMap<K, V> m) 

Source Link

Document

Returns a synchronized (thread-safe) sorted map backed by the specified sorted map.

Usage

From source file:Main.java

public static void main(String[] args) {
    // create map
    SortedMap<String, String> map = new TreeMap<String, String>();

    // populate the map
    map.put("1", "A");
    map.put("2", "B");
    map.put("3", "from java2s.com");

    // create a sorted map
    SortedMap<String, String> sortedmap = (SortedMap<String, String>) Collections.synchronizedSortedMap(map);

    System.out.println("Synchronized sorted map is :" + sortedmap);
}

From source file:Main.java

public static void main(String[] args) {
    NavigableMap<Integer, String> nmap = new TreeMap<Integer, String>();
    nmap.put(1, "this");
    nmap.put(2, "is");
    nmap.put(3, "a");
    nmap.put(4, "test");
    nmap.put(5, ".");

    System.out.println(nmap);/*from w w w  .ja  v a 2  s .  com*/
    System.out.println(nmap.subMap(4, true, 5, true).values());
    nmap.subMap(1, true, 3, true).clear();
    System.out.println(nmap);
    // wrap into synchronized SortedMap
    SortedMap<Integer, String> ssmap = Collections.synchronizedSortedMap(nmap);

    System.out.println(ssmap.subMap(4, 5));
    System.out.println(ssmap.subMap(4, 5 + 1));
}

From source file:kmi.taa.core.PredicateObjectRetriever.java

public SortedMap<Integer, String> retrieveAll(Map<Integer, String> originalLines, String proxy) {
    SortedMap<Integer, String> results = Collections.synchronizedSortedMap(new TreeMap<Integer, String>());
    ExecutorService pool = Executors.newFixedThreadPool(50);

    int howManyslinks = originalLines.size();

    for (Integer id : originalLines.keySet()) {
        String line = originalLines.get(id);
        String[] str = line.split("\t");
        String candidateUrl = str[2];
        pool.execute(new Retriever(id, candidateUrl, proxy, results));
    }/*  ww  w .  j a  v a2 s .co  m*/
    pool.shutdown();

    int count = 0;
    int previousResultSize = 0;
    while (results.size() < howManyslinks && count < 100) {
        try {
            Thread.sleep(1000);
            count += 1;
            if (results.size() != previousResultSize) {
                previousResultSize = results.size();
                count = 0;
            }
            System.out.println("Already retrieved " + results.size() + " triples ...");
        } catch (InterruptedException e) {

        }
    }

    System.out.println("All slinks are queried");
    return results;
}

From source file:com.ning.maven.plugins.dependencyversionscheck.AbstractDependencyVersionsMojo.java

/**
 * Creates a map of all version resolutions used in this project in a given scope. The result is a map from artifactName to a list of version numbers used in the project, based on the element
 * requesting//from  w ww  .java2  s.  c  o  m
 * the version.
 *
 * If the special scope "null" is used, a superset of all scopes is used (this is used by the check mojo).
 */
protected Map buildResolutionMap(final String scope)
        throws MojoExecutionException, InvalidDependencyVersionException, ProjectBuildingException,
        ArtifactResolutionException, ArtifactNotFoundException {
    final String[] visibleScopes = (String[]) VISIBLE_SCOPES.get(scope);
    final String[] transitiveScopes = (String[]) TRANSITIVE_SCOPES.get(scope);

    if (visibleScopes == null) {
        throw new MojoExecutionException("No valid scopes found for '" + scope + "'");
    }

    // Map from artifactName --> list of resolutions found on the tree
    final SortedMap resolutionMap = Collections.synchronizedSortedMap(new TreeMap());
    final List futures = new ArrayList();
    LOG.debug("Using parallel dependency resolution: " + useParallelDependencyResolution);

    for (final Iterator iter = project.getDependencies().iterator(); iter.hasNext();) {
        final Dependency dependency = (Dependency) iter.next();

        if (useParallelDependencyResolution) {
            futures.add(executorService.submit(new Runnable() {
                public void run() {
                    try {
                        updateResolutionMapForDep(visibleScopes, transitiveScopes, resolutionMap, dependency);
                    } catch (Exception e) {
                        Throwables.propagate(e);
                    }
                }
            }));
        } else {
            updateResolutionMapForDep(visibleScopes, transitiveScopes, resolutionMap, dependency);
        }
    }
    if (useParallelDependencyResolution) {
        try {
            Futures.allAsList(futures).get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            Throwables.propagate(e);
        } catch (ExecutionException e) {
            Throwables.propagate(e);
        }
    }
    return resolutionMap;
}

From source file:org.apache.hadoop.hbase.master.RegionManager.java

private void startCFAction(final byte[] regionName, final byte[] columnFamily, final HRegionInfo info,
        final HServerAddress server,
        final SortedMap<byte[], SortedMap<byte[], Pair<HRegionInfo, HServerAddress>>> map) {
    synchronized (map) {
        SortedMap<byte[], Pair<HRegionInfo, HServerAddress>> cfMap = map.get(regionName);
        if (cfMap == null) {
            cfMap = Collections.synchronizedSortedMap(
                    new TreeMap<byte[], Pair<HRegionInfo, HServerAddress>>(Bytes.BYTES_COMPARATOR));
        }//from  w w  w  .  j ava2  s .  com
        cfMap.put(columnFamily, new Pair<HRegionInfo, HServerAddress>(info, server));
        map.put(regionName, cfMap);
    }
}

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

/**
 * Create a base 64 encoded SHA1 hash key for a given XML element. The key
 * is based on the element name, the attribute names and their values. Child
 * elements are ignored. Attributes named 'z' are not concluded since they
 * contain the hash key itself.// w w w  .java  2s.  c  om
 * 
 * @param element The element to create the base 64 encoded hash key for
 * @return the unique key
 */
public static String calculateUniqueKeyFor(Element element) {
    StringBuilder sb = new StringBuilder();
    sb.append(element.getTagName());
    NamedNodeMap attributes = element.getAttributes();
    SortedMap<String, String> attrKVStore = Collections.synchronizedSortedMap(new TreeMap<String, String>());
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attr = attributes.item(i);
        if (!"z".equals(attr.getNodeName()) && !attr.getNodeName().startsWith("_")) {
            attrKVStore.put(attr.getNodeName(), attr.getNodeValue());
        }
    }
    for (Entry<String, String> entry : attrKVStore.entrySet()) {
        sb.append(entry.getKey()).append(entry.getValue());
    }
    return base64(sha1(sb.toString().getBytes()));
}

From source file:org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl.java

public synchronized SortedMap<Long, PendingConfirm> addListener(Listener listener) {
    Assert.notNull(listener, "Listener cannot be null");
    if (this.listeners.size() == 0) {
        this.delegate.addConfirmListener(this);
        this.delegate.addReturnListener(this);
    }/*from   w ww. java 2s  .  co m*/
    if (!this.listeners.values().contains(listener)) {
        this.listeners.put(listener.getUUID(), listener);
        this.pendingConfirms.put(listener,
                Collections.synchronizedSortedMap(new TreeMap<Long, PendingConfirm>()));
        if (logger.isDebugEnabled()) {
            logger.debug("Added listener " + listener);
        }
    }
    return this.pendingConfirms.get(listener);
}

From source file:org.wso2.developerstudio.eclipse.distribution.project.editor.DistProjectEditorPage.java

public void initContent() throws Exception {

    pomFileRes = ((IFileEditorInput) (getEditor().getEditorInput())).getFile();
    pomFile = pomFileRes.getLocation().toFile();

    ProjectList projectListProvider = new ProjectList();
    List<ListData> projectListData = projectListProvider.getListData(null, null);
    SortedMap<String, DependencyData> projectList = Collections
            .synchronizedSortedMap(new TreeMap<String, DependencyData>());
    Map<String, Dependency> dependencyMap = new LinkedHashMap<String, Dependency>();
    for (ListData data : projectListData) {
        DependencyData dependencyData = (DependencyData) data.getData();
        projectList.put(data.getCaption(), dependencyData);
    }/*from   w  ww.ja  v  a 2 s.  co m*/

    parentPrj = MavenUtils.getMavenProject(pomFile);

    /*
     * if propeties of pom in old format(DevS 3.2 or earlier) reformat it to
     * new format.
     */
    updatePomToNewFormat();

    for (Dependency dependency : (List<Dependency>) parentPrj.getDependencies()) {
        dependencyMap.put(DistProjectUtils.getArtifactInfoAsString(dependency), dependency);
        serverRoleList.put(DistProjectUtils.getArtifactInfoAsString(dependency),
                DistProjectUtils.getServerRole(parentPrj, dependency));
    }
    setProjectName(parentPrj.getName());
    setArtifactId(parentPrj.getArtifactId());
    setGroupId(parentPrj.getGroupId());
    setVersion(parentPrj.getVersion());
    setDescription(parentPrj.getDescription());
    setProjectList(projectList);
    setDependencyList(dependencyMap);
    setMissingDependencyList((Map<String, Dependency>) ((HashMap) getDependencyList()).clone());
}