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

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

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Checks to see if there are more entries still to be iterated.

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();/*from  ww w.j  a v a2s. com*/
            Cookie cookie = iter.getValue();

            // remove expired cookies
            if (cookie.expiresAt() <= System.currentTimeMillis()) {
                iter.remove();
                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();/*from ww  w .  j  av a2 s .  c om*/
        Record<Object> value = (Record<Object>) it.getValue();
        store.update(key, value.value, value.serializer);
    }
}

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//  w w w.j av  a2  s . c  om
 * @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 a v  a2s.c  o m*/
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;//from w w  w .  j av  a2 s . c o  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

/**
 *
 *//* w  w w. j av a 2 s  .com*/
@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 va  2s. 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 w  w. j av  a 2 s.  c  o  m*/
    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();/*from   w  w w .  j a va  2 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();//from   ww  w  .  j ava 2 s  .  co m
            Cookie cookie = iter.getValue();

            // remove expired cookies
            if (cookie.expiresAt() <= System.currentTimeMillis()) {
                iter.remove();
                continue;
            }

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

    return cookies;
}