Example usage for org.apache.commons.collections MapIterator next

List of usage examples for org.apache.commons.collections MapIterator next

Introduction

In this page you can find the example usage for org.apache.commons.collections MapIterator next.

Prototype

Object next();

Source Link

Document

Gets the next key from the Map.

Usage

From source file:com.projity.configuration.FieldDictionary.java

public static HashMap getAliasMap() {
    HashMap aliasMap = new HashMap();
    MapIterator i = getInstance().map.mapIterator();
    while (i.hasNext()) {
        Object key = i.next();
        Field field = (Field) i.getValue();
        if (field.getAlias() != null)
            aliasMap.put(field.getId(), field.getAlias());
    }/* w w w. ja v a  2  s.  c  o  m*/
    return aliasMap;
}

From source file:com.projity.field.StaticSelect.java

public String toString() {
    MapIterator i = stringMap.mapIterator();
    StringBuffer result = new StringBuffer();
    while (i.hasNext()) {
        i.next();
        result.append("[key]" + i.getKey() + " [value]" + i.getValue() + "\n");
    }//from  ww w  . j ava  2  s. c  o m
    return result.toString();
}

From source file:com.quinsoft.zeidon.utils.TimedLruCache.java

@SuppressWarnings("unchecked")
public void cleanup() {

    // Determine a time when objects haven't been accessed in a while and
    // need//from  w w  w. ja va  2  s  .com
    // to be removed.
    long tooOld = System.currentTimeMillis() - timeToLiveInMillis;
    ArrayList<K> keysToDelete = null;

    synchronized (cacheMap) {
        MapIterator itr = cacheMap.mapIterator();

        keysToDelete = new ArrayList<K>((cacheMap.size() / 2) + 1);

        while (itr.hasNext()) {
            K key = (K) itr.next();
            CachedObject c = (CachedObject) itr.getValue();

            if (c != null) {
                if (c.lastAccessed < tooOld)
                    keysToDelete.add(key);
                else
                    break; // All the rest of the objects are younger than
                           // time-to-live.
            }
        }

        for (K k : keysToDelete)
            cacheMap.remove(k);
    }
}

From source file:net.chat.utils.Cache.java

public void showAllCache() {

    synchronized (cacheMap) {
        MapIterator itr = cacheMap.mapIterator();
        K key = null;/*from  www . ja v a 2 s . c om*/
        CachedObject c = null;
        log.info(":");
        while (itr.hasNext()) {
            key = (K) itr.next();
            c = (CachedObject) itr.getValue();
            log.info("key:" + key + ";value:" + c.getValue());
        }
    }
}

From source file:com.projity.configuration.FieldDictionary.java

/** Fill a collection with all fields that are applicable to one or more types
 * specified by clazz.  The collection is sorted alpha-numerically by field name.
 * Lists by type should probably just be cached in static variables.
 * @param collection - collection to fill
 * @param clazz - array of class types//from w  ww.ja va 2s  . com
 */
public void populateListWithFieldsOfType(List list, Class[] clazz) {
    MapIterator i = map.mapIterator();
    while (i.hasNext()) {
        Object key = i.next();
        Field field = (Field) i.getValue();
        if (field.isApplicable(clazz))
            list.add(field);
    }
    Collections.sort(list);
}

From source file:net.chat.utils.Cache.java

@SuppressWarnings("unchecked")
public void cleanup() {

    long now = System.currentTimeMillis();
    ArrayList<K> keysToDelete = null;

    synchronized (cacheMap) {
        MapIterator itr = cacheMap.mapIterator();

        keysToDelete = new ArrayList<K>((cacheMap.size() / 2) + 1);
        K key = null;//from  w ww.ja va 2 s. c o  m
        CachedObject c = null;

        while (itr.hasNext()) {
            key = (K) itr.next();
            c = (CachedObject) itr.getValue();

            if (c != null && (now > (timeToLiveInMillis + c.lastAccessed))) {
                keysToDelete.add(key);
            }
        }
    }

    for (K key : keysToDelete) {
        synchronized (cacheMap) {
            cacheMap.remove(key);
        }

        Thread.yield();
    }
}

From source file:com.vinay.simpleadserver.cache.AdServerInMemoryCache.java

/**
 *
 * @return getAll() returns all the key/value pairs that have not expired
 * and are available in the cache.//from   www .j  a v a  2 s  .  c  o  m
 */
public Map<K, T> getAll() {
    MapIterator itr = adServerCacheMap.mapIterator();
    Map<K, T> resultMap = new LinkedHashMap<>();
    K key = null;
    AdServerCacheObject c = null;
    while (itr.hasNext()) {
        key = (K) itr.next();
        c = (AdServerCacheObject) itr.getValue();

        if (c != null && (System.currentTimeMillis() < (c.timeToLive + c.creationTime))) {
            resultMap.put(key, c.value);
        }
    }
    return resultMap;
}

From source file:de.tum.in.python.bluetooth.milling.machine.BluetoothMillingMachine.java

/** {@inheritDoc} */
@Override//from   ww w.j  a v a  2  s . c om
protected void doGet(final CloudletTopic reqTopic, final KuraRequestPayload reqPayload,
        final KuraResponsePayload respPayload) throws KuraException {
    LOGGER.info("Bluetooth Python Milling Machine Component GET handler");

    // Retrieve the configurations
    if ("configurations".equals(reqTopic.getResources()[0])) {
        LOGGER.info("Bluetooth Python Milling Machine Configuration Retrieval Started...");

        final ComponentConfiguration configuration = this.m_configurationService
                .getComponentConfiguration(APP_CONF_ID);

        final IterableMap map = (IterableMap) configuration.getConfigurationProperties();
        final MapIterator it = map.mapIterator();

        while (it.hasNext()) {
            final Object key = it.next();
            final Object value = it.getValue();

            respPayload.addMetric((String) key, value);
        }
        this.m_activityLogService.saveLog("Bluetooth Python Milling Machine Configuration Retrieved");

        respPayload.setResponseCode(KuraResponsePayload.RESPONSE_CODE_OK);

        LOGGER.info("Bluetooth Python Milling Machine Configuration Retrieval Finished");
    }
}

From source file:metrics.sink.MetricsTable.java

private void printHeaders() {
    MapIterator columnMapIterator = columnMapping.mapIterator();
    Row headerRow = currentSheet.createRow(0);
    rowCount++;//from   ww w .  j a  va2s.  c o m

    while (columnMapIterator.hasNext()) {
        Cell headerCell = headerRow.createCell((Integer) columnMapIterator.next());
        headerCell.setCellValue((String) columnMapIterator.getValue());
    }
}

From source file:com.vinay.simpleadserver.cache.AdServerInMemoryCache.java

/**
 * cleanup() method is periodically called to remove key/value pairs that
 * have expired from the cache./*from  w  ww.  j av  a  2s . com*/
 */
@SuppressWarnings("unchecked")
public void cleanup() {

    long now = System.currentTimeMillis();
    ArrayList<K> deleteKey = null;

    synchronized (adServerCacheMap) {
        MapIterator itr = adServerCacheMap.mapIterator();

        deleteKey = new ArrayList<>((adServerCacheMap.size() / 2) + 1);
        K key = null;
        AdServerCacheObject c = null;

        while (itr.hasNext()) {
            key = (K) itr.next();
            c = (AdServerCacheObject) itr.getValue();

            if (c != null && (now > (c.timeToLive + c.creationTime))) {
                deleteKey.add(key);
            }
        }
    }

    for (K key : deleteKey) {
        synchronized (adServerCacheMap) {
            adServerCacheMap.remove(key);
        }

        Thread.yield();
    }
}