Java Code Examples for org.apache.commons.collections.MapIterator#hasNext()

The following examples show how to use org.apache.commons.collections.MapIterator#hasNext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerCache.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Closes all the db instances and resets the cache.
 */
public void shutdownCache() {
  lock.lock();
  try {
    // iterate the cache and close each db
    MapIterator iterator = cache.mapIterator();
    while (iterator.hasNext()) {
      iterator.next();
      ReferenceCountedDB db = (ReferenceCountedDB) iterator.getValue();
      Preconditions.checkArgument(db.cleanup(), "refCount:",
          db.getReferenceCount());
    }
    // reset the cache
    cache.clear();
  } finally {
    lock.unlock();
  }
}
 
Example 2
Source File: MultiKeyMap.java    From Penetration_Testing_POC with Apache License 2.0 6 votes vote down vote up
/**
 * Removes all mappings where the first three keys are those specified.
 * <p>
 * This method removes all the mappings where the <code>MultiKey</code>
 * has three or more keys, and the first three match those specified.
 * 
 * @param key1  the first key
 * @param key2  the second key
 * @param key3  the third key
 * @return true if any elements were removed
 */
public boolean removeAll(Object key1, Object key2, Object key3) {
    boolean modified = false;
    MapIterator it = mapIterator();
    while (it.hasNext()) {
        MultiKey multi = (MultiKey) it.next();
        if (multi.size() >= 3 &&
            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
            (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2)))) {
            it.remove();
            modified = true;
        }
    }
    return modified;
}
 
Example 3
Source File: MultiKeyMap.java    From Penetration_Testing_POC with Apache License 2.0 6 votes vote down vote up
/**
 * Removes all mappings where the first four keys are those specified.
 * <p>
 * This method removes all the mappings where the <code>MultiKey</code>
 * has four or more keys, and the first four match those specified.
 * 
 * @param key1  the first key
 * @param key2  the second key
 * @param key3  the third key
 * @param key4  the fourth key
 * @return true if any elements were removed
 */
public boolean removeAll(Object key1, Object key2, Object key3, Object key4) {
    boolean modified = false;
    MapIterator it = mapIterator();
    while (it.hasNext()) {
        MultiKey multi = (MultiKey) it.next();
        if (multi.size() >= 4 &&
            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) &&
            (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) &&
            (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3)))) {
            it.remove();
            modified = true;
        }
    }
    return modified;
}
 
Example 4
Source File: AbstractHashedMap.java    From Penetration_Testing_POC with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the map as a String.
 * 
 * @return a string version of the map
 */
public String toString() {
    if (size() == 0) {
        return "{}";
    }
    StringBuffer buf = new StringBuffer(32 * size());
    buf.append('{');

    MapIterator it = mapIterator();
    boolean hasNext = it.hasNext();
    while (hasNext) {
        Object key = it.next();
        Object value = it.getValue();
        buf.append(key == this ? "(this Map)" : key)
           .append('=')
           .append(value == this ? "(this Map)" : value);

        hasNext = it.hasNext();
        if (hasNext) {
            buf.append(',').append(' ');
        }
    }

    buf.append('}');
    return buf.toString();
}
 
Example 5
Source File: TreeBidiMap.java    From Penetration_Testing_POC with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the string form of this map as per AbstractMap.
 *
 * @param index  the KEY or VALUE int
 * @return the string form of this map
 */
private String doToString(final int type) {
    if (nodeCount == 0) {
        return "{}";
    }
    StringBuffer buf = new StringBuffer(nodeCount * 32);
    buf.append('{');
    MapIterator it = new ViewMapIterator(this, type);
    boolean hasNext = it.hasNext();
    while (hasNext) {
        Object key = it.next();
        Object value = it.getValue();
        buf.append(key == this ? "(this Map)" : key)
           .append('=')
           .append(value == this ? "(this Map)" : value);

        hasNext = it.hasNext();
        if (hasNext) {
            buf.append(", ");
        }
    }

    buf.append('}');
    return buf.toString();
}
 
Example 6
Source File: MultiKeyMap.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all mappings where the first key is that specified.
 * <p>
 * This method removes all the mappings where the <code>MultiKey</code>
 * has one or more keys, and the first matches that specified.
 * 
 * @param key1  the first key
 * @return true if any elements were removed
 */
public boolean removeAll(Object key1) {
    boolean modified = false;
    MapIterator it = mapIterator();
    while (it.hasNext()) {
        MultiKey multi = (MultiKey) it.next();
        if (multi.size() >= 1 &&
            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) {
            it.remove();
            modified = true;
        }
    }
    return modified;
}
 
Example 7
Source File: MultiKeyMap.java    From Penetration_Testing_POC with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all mappings where the first two keys are those specified.
 * <p>
 * This method removes all the mappings where the <code>MultiKey</code>
 * has two or more keys, and the first two match those specified.
 * 
 * @param key1  the first key
 * @param key2  the second key
 * @return true if any elements were removed
 */
public boolean removeAll(Object key1, Object key2) {
    boolean modified = false;
    MapIterator it = mapIterator();
    while (it.hasNext()) {
        MultiKey multi = (MultiKey) it.next();
        if (multi.size() >= 2 &&
            (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) &&
            (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)))) {
            it.remove();
            modified = true;
        }
    }
    return modified;
}