Example usage for java.util TreeMap size

List of usage examples for java.util TreeMap size

Introduction

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

Prototype

int size

To view the source code for java.util TreeMap size.

Click Source Link

Document

The number of entries in the tree

Usage

From source file:laboGrid.graphs.replication.ReplicationGraphHeuristicGenerator.java

public ReplicationGraph computeReplicationGraph(DAId[] das, GraphMapping cGraph, int backupDegree) {

    // Creating Peers dynamic structure
    TreeMap<String, Set<Integer>> dynPeers = new TreeMap<String, Set<Integer>>();
    Set<Integer>[] da2Sub = cGraph.getDa2Sub();
    for (int i = 0; i < das.length; ++i) {
        DAId c = das[i];//  w  ww  .jav  a  2 s.  c  o m
        if (da2Sub[i] != null && !da2Sub[i].isEmpty()) { // Da can be taken into account in backup graph
            //            String resourcePeer = c.getPeerId();
            String resourcePeer = "peerId";
            Set<Integer> resources = dynPeers.get(resourcePeer);
            if (resources == null) {
                System.out.println("Detected Peer: " + resourcePeer + ".");
                resources = new TreeSet<Integer>();
                dynPeers.put(resourcePeer, resources);
            }
            resources.add(i);
        }
    }

    if (dynPeers.size() == 1) {

        ReplicationGraphNaiveGenerator naiveGen = new ReplicationGraphNaiveGenerator();
        return naiveGen.computeReplicationGraph(das, cGraph, backupDegree);

    } else {

        // Convert dynamic structure into a static one
        Set<Integer>[] peers = new TreeSet[dynPeers.size()];
        Iterator<Entry<String, Set<Integer>>> it = dynPeers.entrySet().iterator();
        for (int i = 0; i < peers.length; ++i) {
            Entry<String, Set<Integer>> e = it.next();
            peers[i] = e.getValue();
        }

        return new ReplicationGraph(replicationGraph(das.length, backupDegree, peers));
    }

}

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());/*w ww  .  j  a va  2  s.co m*/
}

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

public void addSchematron(String pattern) {
    TreeMap<String, String> infos = getSchematrons();
    infos.put(ICoreConstants.X_Schematron + "_" + (infos.size() + 1), pattern);//$NON-NLS-1$
    setSchematrons(infos.values());/*w w  w  .  ja  va 2  s .  co m*/
}

From source file:ANNFileDetect.EncogTestClass.java

private void createReport(TreeMap<Double, Integer> ht, String file) throws IOException {
    TreeMap<Integer, ArrayList<Double>> tm = new TreeMap<Integer, ArrayList<Double>>();
    for (Map.Entry<Double, Integer> entry : ht.entrySet()) {
        if (tm.containsKey(entry.getValue())) {
            ArrayList<Double> al = (ArrayList<Double>) tm.get(entry.getValue());
            al.add(entry.getKey());//from   ww  w.ja v  a 2  s .c  o  m
            tm.put(entry.getValue(), al);
        } else {
            ArrayList<Double> al = new ArrayList<Double>();
            al.add(entry.getKey());
            tm.put(entry.getValue(), al);
        }
    }

    String[] tmpfl = file.split("/");
    if (tmpfl.length < 2)
        tmpfl = file.split("\\\\");

    String crp = tmpfl[tmpfl.length - 1];
    String[] actfl = crp.split("\\.");
    FileWriter fstream = new FileWriter("tempTrainingFiles/" + actfl[1].toUpperCase() + actfl[0] + ".txt");
    BufferedWriter fileto = new BufferedWriter(fstream);
    int size = tm.size();
    int cnt = 0;
    for (Map.Entry<Integer, ArrayList<Double>> entry : tm.entrySet()) {
        if (cnt > (size - 10) && entry.getKey() > 2 && entry.getValue().size() < 20) {
            double tmpval = ((double) entry.getKey()) / filebytes;
            fileto.write("Times: " + tmpval + " Values: ");
            for (Double dbl : entry.getValue()) {
                fileto.write(dbl + " ");
            }
            fileto.write("\n");
        }

        cnt++;
    }
    fileto.close();
}

From source file:org.lockss.servlet.DisplayContentTab.java

/**
 * Creates the relevant content for each of the tabs
 *
 * @param divTable The table object to add to
 * @param sortName Name of the publisher or plugin
 * @param auSet    TreeSet of archival units
 * @throws java.io.UnsupportedEncodingException
 *
 *///from   ww  w.  j a va2  s  .c  o  m
private void createTabContent(Table divTable, String sortName, TreeMap<String, TreeSet<ArchivalUnit>> auSet)
        throws UnsupportedEncodingException {
    if (auSet != null) {
        String cleanNameString = cleanName(sortName);
        createTitleRow(divTable, sortName, auSet.size());
        for (Map.Entry<String, TreeSet<ArchivalUnit>> filteredAu : auSet.entrySet()) {
            createAuRow(divTable, filteredAu, cleanNameString);
        }
        addClearRow(divTable, cleanNameString, false);
    }
}

From source file:util.ExpiringObjectPool.java

/**
 * Use this method to get objects from the pool. You must pass the
 * name of the bean, like "directory", "userpage" etc. It will look
 * for an expired bean in the queue, and return a reference to this
 * bean if it is found. If it does not find an expired bean, it will
 * create a new bean on the heap and add it to the queue if the 
 * max size of the queue has not been exceeded. If the max size of the
 * queue has been exceeded, it will not add it to the queue, and this
 * means the bean on the heap will be garbage collected. Over time
 * the max size of the pool can be calibrated. The method will log
 * a warning whenever, the max size of the queue is exceeded for a 
 * specific bean name.//from  w w  w .j a va  2 s . co  m
 *
 * @param beanName the name of the bean which corresponds to a queue
 * @return Object return the bean as an Object
 * @exception ObjException if anything goes wrong
 */
public synchronized Object newObject(String beanName) throws ObjException {
    if (disablePool) {
        Stringifier bean = null;
        try {
            Class myclass = (Class) queueMap.get(beanName);
            bean = (Stringifier) myclass.newInstance();
        } catch (Exception e) {
            throw new ObjException("Could not instantiate object of type " + beanName, e);
        }
        return bean;
    }

    sweepIfRequired(beanName);

    TreeMap beanMap = (TreeMap) objectMap.get((Object) beanName);
    if (beanMap == null) {
        throw new ObjException("No queue exists for " + beanName
                + ", update the spring config to add a new mapping for " + beanName);
    }
    Iterator iter = beanMap.values().iterator();
    Long age = new Long(System.currentTimeMillis());
    long counter = 1;

    while (iter.hasNext()) {
        counter++;
        Stringifier bean = (Stringifier) iter.next();
        if (!((Boolean) bean.getObject(POOL)).booleanValue()) {
            bean.reset();
            bean.setObject(AGE, age);
            bean.setObject(POOL, new Boolean(true));
            updateStats(beanName, counter, beanMap.size());
            return (Object) bean;
        }
    }

    updateStats(beanName, counter, beanMap.size());

    // didn't find an expired object in pool, allocating on heap now
    Stringifier bean = null;
    try {
        Class myclass = (Class) queueMap.get(beanName);
        bean = (Stringifier) myclass.newInstance();
    } catch (Exception e) {
        throw new ObjException("Could not instantiate object of type " + beanName, e);
    }

    // check if exceeded max objects on the pool
    if (beanMap.size() > maxObjects) {
        logger.warn("Object pool size " + maxObjects + ", exceeded for beanName " + beanName);
    } else {
        bean.setObject(POOL, new Boolean(true));
        bean.setObject(AGE, age);
        beanMap.put(new Long(System.currentTimeMillis()), bean);
    }
    return (Object) bean;
}

From source file:com.alibaba.wasp.master.handler.TableEventHandler.java

public boolean reOpenAllEntityGroups(List<EntityGroupInfo> entityGroups) throws IOException {
    boolean done = false;
    LOG.info("Bucketing entityGroups by entityGroup server...");
    TreeMap<ServerName, List<EntityGroupInfo>> serverToEntityGroups = Maps.newTreeMap();
    NavigableMap<EntityGroupInfo, ServerName> egiHserverMapping = FMetaScanner
            .allTableEntityGroups(server.getConfiguration(), tableName, false);

    List<EntityGroupInfo> reEntityGroups = new ArrayList<EntityGroupInfo>();
    for (EntityGroupInfo egi : entityGroups) {
        ServerName egLocation = egiHserverMapping.get(egi);

        // Skip the offlined split parent EntityGroup
        if (null == egLocation) {
            LOG.info("Skip " + egi);
            continue;
        }//from   ww w.j a  v  a 2  s. co m
        if (!serverToEntityGroups.containsKey(egLocation)) {
            LinkedList<EntityGroupInfo> egiList = Lists.newLinkedList();
            serverToEntityGroups.put(egLocation, egiList);
        }
        reEntityGroups.add(egi);
        serverToEntityGroups.get(egLocation).add(egi);
    }

    LOG.info("Reopening " + reEntityGroups.size() + " entityGroups on " + serverToEntityGroups.size()
            + " fservers.");
    this.fMasterServices.getAssignmentManager().setEntityGroupsToReopen(reEntityGroups);
    BulkReOpen bulkReopen = new BulkReOpen(this.server, serverToEntityGroups,
            this.fMasterServices.getAssignmentManager());
    while (true) {
        try {
            if (bulkReopen.bulkReOpen()) {
                done = true;
                break;
            } else {
                LOG.warn("Timeout before reopening all entityGroups");
            }
        } catch (InterruptedException e) {
            LOG.warn("Reopen was interrupted");
            // Preserve the interrupt.
            Thread.currentThread().interrupt();
            break;
        }
    }
    return done;
}

From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java

private TreeMap<String, List<String>> initiateMpusForMultipleKeys(AmazonS3 s3, String accountName, int numKeys,
        int numUploads, String prefix) {
    TreeMap<String, List<String>> keyUploadIdMap = new TreeMap<String, List<String>>();

    // Cycle through a bunch of different keys
    for (int i = 0; i < numKeys; i++) {
        String key = prefix + UUID.randomUUID().toString().replaceAll("-", "");

        // Add the key and upload ID list to the treemap
        keyUploadIdMap.put(key, initiateMpusForKey(s3, accountA, key, bucketName, numUploads));
    }/*  w  w  w .j a  v a 2  s. c o m*/
    assertTrue("Expected " + numKeys + " keys, but got " + keyUploadIdMap.size(),
            numKeys == keyUploadIdMap.size());

    return keyUploadIdMap;
}

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");
                }/*from  w w  w. jav  a2s.com*/
            } else {
                inputClassMap.put(index, inputClasses[i]);
            }
        }
    }

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

From source file:com.sfs.whichdoctor.beans.SearchBean.java

/**
 * Removes the search vector./*from   w  ww  .  jav a2  s.com*/
 *
 * @param vectorindex the vectorindex
 */
public final void removeSearchVector(final int vectorindex) {
    TreeMap<Integer, Object[]> newVectors = new TreeMap<Integer, Object[]>();

    if (this.searchVectors != null) {
        for (Integer index : this.searchVectors.keySet()) {
            Object[] vector = this.searchVectors.get(index);
            if (vectorindex != index) {
                /* Vector is not getting removed add to new vector map */
                Integer newIndex = new Integer(newVectors.size());
                newVectors.put(newIndex, vector);
            }
        }
    }
    setSearchVectors(newVectors);
}