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

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

Introduction

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

Prototype

K next();

Source Link

Document

Gets the next key from the Map.

Usage

From source file:at.bitfire.davdroid.MemoryCookieStore.java

@Override
public List<Cookie> loadForRequest(HttpUrl url) {
    List<Cookie> cookies = new LinkedList<>();

    synchronized (storage) {
        MapIterator<MultiKey<? extends String>, Cookie> iter = storage.mapIterator();
        while (iter.hasNext()) {
            iter.next();
            Cookie cookie = iter.getValue();

            // remove expired cookies
            if (cookie.expiresAt() <= System.currentTimeMillis()) {
                iter.remove();/*www  .  j av a  2  s  . co  m*/
                continue;
            }

            // add applicable cookies
            if (cookie.matches(url))
                cookies.add(cookie);
        }
    }

    return cookies;
}

From source file:com.pungwe.db.io.store.InstanceCachingStore.java

private void flushCache() throws IOException {
    LRUMap<Long, Record<?>> current = cache;
    cache = new LRUMap<Long, Record<?>>(cacheSize);
    MapIterator<Long, Record<?>> it = current.mapIterator();
    while (it.hasNext()) {
        Long key = it.next();
        Record<Object> value = (Record<Object>) it.getValue();
        store.update(key, value.value, value.serializer);
    }/*from  w ww  . j av  a 2  s. com*/
}

From source file:femr.util.DataStructure.Mapping.TabFieldMultiMap.java

/**
 * Checks to see if the map contains an entry for a field
 *
 * @param fieldName name of the field/*from   w  w  w . ja  v  a2s  . co  m*/
 * @return true if the field has an entry, false otherwise
 */
public boolean containsTabField(String fieldName) {

    MapIterator multiMapIterator = this.getMultiMapIterator();
    while (multiMapIterator.hasNext()) {

        multiMapIterator.next();
        MultiKey mk = (MultiKey) multiMapIterator.getKey();
        if (mk.getKey(0) != null) {

            if (fieldName.equals(mk.getKey(0))) {

                return true;
            }
        }
    }
    return false;
}

From source file:femr.util.DataStructure.Mapping.TabFieldMultiMap.java

/**
 * Checks to see if the map contains any entries for a field
 *
 * @param fieldName      name of the field
 * @param chiefComplaint chiefcomplaint that it belongs to (can be null)
 * @return true if the field has an entry, false otherwise
 *///  w  w  w  .j  ava 2  s . c om
public boolean containsTabField(String fieldName, String chiefComplaint) {

    MapIterator multiMapIterator = this.getMultiMapIterator();
    while (multiMapIterator.hasNext()) {

        multiMapIterator.next();
        MultiKey mk = (MultiKey) multiMapIterator.getKey();
        if (mk.getKey(0) != null && mk.getKey(2) != null) {

            if (fieldName.equals(mk.getKey(0)) && chiefComplaint.equals(mk.getKey(2))) {

                return true;
            }
        }
    }
    return false;
}

From source file:Model.CacheInMemory.java

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

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

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

        deleteKey = new ArrayList<K>((cacheMap.size() / 2) + 1);
        K key = null;/*w w  w.j a v a  2s. co m*/
        CacheObject c = null;

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

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

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

        Thread.yield();
    }
}

From source file:imitationLearning.WordSequenceCache.java

/**
 *
 *///from  ww  w .  j a v  a  2  s . co m
@SuppressWarnings("unchecked")
public void cleanup() {

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

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

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

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

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

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

        Thread.yield();
    }
}

From source file:com.joyent.manta.http.MantaHttpHeaders.java

/**
 * Returns the headers as an array of {@link org.apache.http.Header} instances.
 *
 * @return an array of {@link org.apache.http.Header} instances
 *///from   w  ww  .j  a  v  a 2 s.c  o m
public Header[] asApacheHttpHeaders() {
    if (wrappedHeaders.isEmpty()) {
        return new Header[0];
    }

    final int length = wrappedHeaders.size();
    final Header[] headers = new Header[length];
    final MapIterator<String, Object> itr = wrappedHeaders.mapIterator();

    int i = 0;
    while (itr.hasNext()) {
        String key = itr.next();
        Object val = itr.getValue();

        final HeaderGroup extracted = parseHeaderKeyValue(key, val);
        headers[i++] = extracted.getCondensedHeader(key);
    }

    if (length == i) {
        return headers;
    }

    return Arrays.copyOfRange(headers, 0, i);
}

From source file:org.apache.openmeetings.web.app.Application.java

public static boolean isUserOnline(Long userId) {
    MapIterator<MultiKey<? extends String>, org.apache.openmeetings.web.app.Client> it = ONLINE_USERS
            .mapIterator();//from   w ww.j av  a 2s  .c  om
    boolean isUserOnline = false;
    while (it.hasNext()) {
        MultiKey<? extends String> multi = it.next();
        if (multi.size() > 0 && userId.equals(multi.getKey(0))) {
            isUserOnline = true;
            break;
        }
    }
    return isUserOnline;
}

From source file:org.apache.openmeetings.web.app.Application.java

public static List<org.apache.openmeetings.web.app.Client> getClients(Long userId) {
    List<org.apache.openmeetings.web.app.Client> result = new ArrayList<org.apache.openmeetings.web.app.Client>();
    MapIterator<MultiKey<? extends String>, org.apache.openmeetings.web.app.Client> it = ONLINE_USERS
            .mapIterator();// w w  w  . j  a  v a2  s.co  m
    while (it.hasNext()) {
        MultiKey<? extends String> multi = it.next();
        if (multi.size() > 1 && userId.equals(multi.getKey(0))) {
            result.add(getClientByKeys(userId, (String) (multi.getKey(1))));
            break;
        }
    }
    return result;
}

From source file:org.tasks.caldav.MemoryCookieStore.java

@Override
public List<Cookie> loadForRequest(HttpUrl url) {
    List<Cookie> cookies = new LinkedList<>();

    synchronized (storage) {
        MapIterator<MultiKey<? extends String>, Cookie> iter = storage.mapIterator();
        while (iter.hasNext()) {
            iter.next();
            Cookie cookie = iter.getValue();

            // remove expired cookies
            if (cookie.expiresAt() <= System.currentTimeMillis()) {
                iter.remove();/*  ww  w  .  j a  v a  2  s  .c o  m*/
                continue;
            }

            // add applicable cookies
            if (cookie.matches(url)) {
                cookies.add(cookie);
            }
        }
    }

    return cookies;
}