Example usage for java.util TreeMap values

List of usage examples for java.util TreeMap values

Introduction

In this page you can find the example usage for java.util TreeMap values.

Prototype

public Collection<V> values() 

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:org.apache.hadoop.mapred.PriorityScheduler.java

private Collection<KillQueue> getKillQueues(Map<String, QueueQuota> queueQuota) {
    TreeMap killQueues = new TreeMap(QUEUE_COMPARATOR);
    for (QueueJobs queueJob : queueJobs.values()) {
        QueueQuota quota = queueQuota.get(queueJob.name);
        if (quota.quota >= 0) {
            continue;
        }//w  ww. jav a  2 s .  c  om
        for (JobInProgress job : queueJob.jobs) {
            if (job.getStatus().getRunState() == JobStatus.RUNNING) {
                KillQueue killQueue = new KillQueue();
                killQueue.name = queueJob.name;
                killQueue.startTime = job.getStartTime();
                killQueue.quota = quota;
                killQueues.put(killQueue, killQueue);
            }
        }
    }
    return killQueues.values();
}

From source file:uk.gov.gchq.gaffer.function.MultiFilterFunction.java

@Override
public Class<?>[] getInputClasses() {
    final TreeMap<Integer, Class<?>> inputClassMap = new TreeMap<>();
    for (final ConsumerFunctionContext<Integer, FilterFunction> context : getFunctions()) {
        final Class<?>[] inputClasses = context.getFunction().getInputClasses();
        for (int i = 0; i < inputClasses.length; i++) {
            final Integer index = context.getSelection().get(i);
            if (inputClassMap.containsKey(index)) {
                final Class<?> otherClazz = inputClassMap.get(index);
                if (otherClazz.isAssignableFrom(inputClasses[i])) {
                    inputClassMap.put(index, inputClasses[i]);
                } else if (!inputClasses[i].isAssignableFrom(otherClazz)) {
                    throw new InputMismatchException(
                            "Input types for function " + getClass().getSimpleName() + " are not compatible");
                }//  www .j a  v a  2 s  .  com
            } else {
                inputClassMap.put(index, inputClasses[i]);
            }
        }
    }

    return inputClassMap.values().toArray(new Class<?>[inputClassMap.size()]);
}

From source file:com.almende.dht.rpc.DHT.java

/**
 * Iterative_node_lookup./*from   ww  w.j  av a  2s  .  c om*/
 *
 * @param near
 *            the near
 * @return the list
 */
public List<Node> iterative_node_lookup(final Key near) {
    final TreeMap<Key, Node> shortList = new TreeMap<Key, Node>();
    final Set<Node> tried = new HashSet<Node>();

    insert(shortList, near, rt.getClosestNodes(near, Constants.A));

    final int[] noInFlight = new int[1];
    noInFlight[0] = 0;
    boolean keepGoing = true;
    while (keepGoing) {
        while (noInFlight[0] > 0) {
            synchronized (shortList) {
                try {
                    shortList.wait(100);
                } catch (InterruptedException e) {
                }
            }
        }

        List<Node> copy = Arrays.asList(shortList.values().toArray(new Node[0]));
        Collections.sort(copy);
        final Iterator<Node> iter = copy.iterator();
        int count = 0;
        while (iter.hasNext() && count < Constants.A) {
            final Node next = iter.next();
            if (tried.contains(next)) {
                continue;
            }
            count++;
            tried.add(next);
            try {
                ObjectNode params = JOM.createObjectNode();
                params.set("me", JOM.getInstance().valueToTree(rt.getMyKey()));
                params.set("near", JOM.getInstance().valueToTree(near));

                AsyncCallback<ObjectNode> callback = new AsyncCallback<ObjectNode>() {

                    @Override
                    public void onSuccess(ObjectNode res) {
                        List<Node> result = NODELIST.inject(res.get("nodes"));
                        rt.seenNode(next);
                        synchronized (shortList) {
                            insert(shortList, near, result);
                            noInFlight[0]--;
                            shortList.notifyAll();
                        }
                    }

                    @Override
                    public void onFailure(Exception exception) {
                        synchronized (shortList) {
                            shortList.remove(near.dist(next.getKey()));
                            noInFlight[0]--;
                            shortList.notifyAll();
                            LOG.log(Level.WARNING, noInFlight[0] + ":OnFailure called:" + next.getUri(),
                                    exception);
                        }
                    }

                };
                caller.call(next.getUri(), "dht.find_close_nodes", params, callback);
                synchronized (shortList) {
                    noInFlight[0]++;
                }
            } catch (IOException e) {
                synchronized (shortList) {
                    shortList.remove(near.dist(next.getKey()));
                }
                continue;
            }
        }
        if (count == 0) {
            keepGoing = false;
        }
    }
    synchronized (shortList) {
        return new ArrayList<Node>(shortList.values());
    }
}

From source file:com.almende.dht.rpc.DHT.java

/**
 * Iterative_find_value./*from w  ww  . ja v  a 2  s .  c  o  m*/
 *
 * @param key
 *            the key
 * @param multiple
 *            the multiple
 * @return the object node
 */
public JsonNode iterative_find_value(final Key key, final boolean multiple) {
    final JsonNode[] result = new JsonNode[1];

    final TreeMap<Key, Node> shortList = new TreeMap<Key, Node>();
    final Set<Node> tried = new HashSet<Node>();

    insert(shortList, key, rt.getClosestNodes(key, Constants.A));
    final int[] noInFlight = new int[1];
    noInFlight[0] = 0;
    boolean keepGoing = true;
    while (keepGoing) {
        while (noInFlight[0] > 0 && result[0] == null) {
            synchronized (shortList) {
                try {
                    shortList.wait(100);
                } catch (InterruptedException e) {
                }
            }
        }

        List<Node> copy = Arrays.asList(shortList.values().toArray(new Node[0]));
        Collections.sort(copy);
        final Iterator<Node> iter = copy.iterator();
        int count = 0;
        while (iter.hasNext() && count < Constants.A) {
            final Node next = iter.next();
            if (tried.contains(next)) {
                continue;
            }
            count++;
            tried.add(next);
            try {
                ObjectNode params = JOM.createObjectNode();
                params.set("me", JOM.getInstance().valueToTree(rt.getMyKey()));
                params.set("key", JOM.getInstance().valueToTree(key));
                params.put("multiple", multiple);

                AsyncCallback<ObjectNode> callback = new AsyncCallback<ObjectNode>() {

                    @Override
                    public void onSuccess(ObjectNode res) {
                        if (res.has("value")) {
                            result[0] = (ObjectNode) res.get("value");
                        } else if (res.has("values")) {
                            result[0] = (ArrayNode) res.get("values");
                        } else {
                            List<Node> nodes = NODELIST.inject(res.get("nodes"));
                            synchronized (shortList) {
                                insert(shortList, key, nodes);
                            }
                        }
                        rt.seenNode(next);
                        synchronized (shortList) {
                            noInFlight[0]--;
                            shortList.notifyAll();
                        }
                    }

                    @Override
                    public void onFailure(Exception exception) {
                        synchronized (shortList) {
                            shortList.remove(key.dist(next.getKey()));
                            noInFlight[0]--;
                            shortList.notifyAll();
                            LOG.log(Level.WARNING, noInFlight[0] + ":OnFailure called:" + next.getUri(),
                                    exception);
                        }
                    }

                };
                caller.call(next.getUri(), "dht.find_value", params, callback);
                synchronized (shortList) {
                    noInFlight[0]++;
                }
            } catch (IOException e) {
                synchronized (shortList) {
                    shortList.remove(key.dist(next.getKey()));
                }
                continue;
            }
        }
        if (count == 0) {
            keepGoing = false;
        }
    }
    if (result[0] == null) {
        return JOM.createNullNode();
    } else {
        return result[0];
    }
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

public boolean setWorkflow(int num, String system) {
    TreeMap<String, String> infos = getSchematrons();
    infos.put(ICoreConstants.X_Workflow + "_" + num, system);//$NON-NLS-1$
    setSchematrons(infos.values());
    // return setForeignKeyInfos(new ArrayList(infos.values()));
    return true;// w w  w. java 2s.c o m
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

public boolean setSchematron(int num, String system) {
    TreeMap<String, String> infos = getSchematrons();
    infos.put(ICoreConstants.X_Schematron + "_" + num, system);//$NON-NLS-1$
    setSchematrons(infos.values());
    // return setForeignKeyInfos(new ArrayList(infos.values()));
    return true;/* w  ww  .ja  v a 2  s .  c o m*/
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

/****************************************************************************
 * HIDDEN ACCESSES/*from  w w w  .j ava  2  s.  co m*/
 ****************************************************************************/

public boolean setHiddenAccess(int num, String role) {
    TreeMap<String, String> infos = getHiddenAccesses();
    infos.put("X_Hide_" + num, role);//$NON-NLS-1$
    return setForeignKeyInfos(new ArrayList<String>(infos.values()));
}

From source file:org.commoncrawl.service.listcrawler.CrawlHistoryManager.java

private static void testWriteMapFileToHDFS(EventLoop eventLoop) {
    try {/*from ww  w.j a  va2  s . co m*/
        // initialize log manager
        CrawlHistoryManager logManager = initializeTestLogManager(eventLoop, true);

        // initialize item list
        TreeMap<URLFP, ProxyCrawlHistoryItem> items = buildTestList(urlList1);
        final TreeMap<String, URLFP> urlToURLFPMap = new TreeMap<String, URLFP>();

        for (Map.Entry<URLFP, ProxyCrawlHistoryItem> item : items.entrySet()) {
            urlToURLFPMap.put(item.getValue().getOriginalURL(), item.getKey());
        }

        // add to local item map in log manager
        for (ProxyCrawlHistoryItem item : items.values()) {
            logManager.appendItemToLog(item);
        }
        // ok shutdown log manager ...
        logManager.shutdown();

        // restart - reload log file ...
        logManager = initializeTestLogManager(eventLoop, false);

        // write to 'hdfs'
        logManager.doCheckpoint();

        syncAndValidateItems(items, logManager);

        logManager.shutdown();

        // restart
        logManager = initializeTestLogManager(eventLoop, false);

        // tweak original items
        updateTestItemStates(items);

        // ok append items
        for (ProxyCrawlHistoryItem item : items.values()) {
            logManager.appendItemToLog(item);
        }

        syncAndValidateItems(items, logManager);

        // ok now checkpoint the items
        logManager.doCheckpoint();

        // ok now validate one last time
        syncAndValidateItems(items, logManager);

        // shutown
        logManager.shutdown();

        logManager = null;

        {
            // start from scratch ...
            final CrawlHistoryManager logManagerTest = initializeTestLogManager(eventLoop, true);

            // create a final version of the tree map reference
            final TreeMap<URLFP, ProxyCrawlHistoryItem> itemList = items;
            // create filename
            File urlInputFile = new File(logManagerTest.getLocalDataDir(),
                    "testURLS-" + System.currentTimeMillis());
            // ok create a crawl list from urls
            CrawlList.generateTestURLFile(urlInputFile, urlList1);
            long listId = logManagerTest.loadList(urlInputFile, 0);

            CrawlList listObject = logManagerTest.getList(listId);

            final Semaphore listCompletionSemaphore = new Semaphore(-(itemList.size() - 1));

            listObject.setEventListener(new CrawlList.CrawlListEvents() {

                @Override
                public void itemUpdated(URLFP itemFingerprint) {
                    // TODO Auto-generated method stub
                    listCompletionSemaphore.release();
                }
            });

            // ok start the appropriate threads
            logManagerTest.startLogWriterThread(0);
            logManagerTest.startListLoaderThread();
            logManagerTest.startQueueLoaderThread(new CrawlQueueLoader() {

                @Override
                public void queueURL(URLFP urlfp, String url) {
                    logManagerTest.crawlComplete(
                            proxyCrawlHitoryItemToCrawlURL(itemList.get(urlToURLFPMap.get(url))));
                }

                @Override
                public void flush() {
                    // TODO Auto-generated method stub

                }
            });

            LOG.info("Waiting for Release");

            // and wait for the finish
            listCompletionSemaphore.acquireUninterruptibly();

            LOG.info("Got Here");

        }

    } catch (IOException e) {
        LOG.error(CCStringUtils.stringifyException(e));
    }
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

public void addWorkflow(String pattern) {
    TreeMap<String, String> infos = getSchematrons();
    infos.put(ICoreConstants.X_Workflow + "_" + (infos.size() + 1), pattern);//$NON-NLS-1$
    setSchematrons(infos.values());
}