Java 类org.apache.commons.collections.MapIterator 实例源码

项目:keepass2android    文件:AbstractHashedMap.java   
/**
 * 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();
}
项目:KeePass2Android    文件:AbstractHashedMap.java   
/**
 * 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();
}
项目:guidoless-python    文件:MyNode.java   
/**
 * A method which is used to remove variables and functions from the
 * symbol table when they are out of scope.
 */
protected void removeScope()
{
    MapIterator mp = symtab.mapIterator();
    ArrayList<String> variables = new ArrayList<String>();

    while(mp.hasNext())
    {
        MultiKey mult = ((MultiKey)mp.next());
        if(mult.getKey(1) == scope)
        {
            variables.add(mult.getKey(0).toString());
        }
    }

    for(int i = 0; i < variables.size(); i++)
    {
        symtab.remove(variables.get(i), scope);
    }
    scope--;
}
项目:scribe    文件:CRMSessionCache.java   
public final void initialize() {
  if (cacheManager != null) {
    cacheManager.cancel();
  }
  cacheManager = new Timer(true);
  cacheManager.schedule(new TimerTask() {
    public void run() {
      long now = System.currentTimeMillis();
      try {
        MapIterator itr = cacheMap.mapIterator();
        while (itr.hasNext()) {
          Object key = itr.next();
          final CachedObject cobj = (CachedObject) itr.getValue();
          if (cobj == null || cobj.hasExpired(now)) {

            if (logger.isDebugEnabled()) {
              logger.debug("----Inside CRMSessionCache: removing " + key + ": Idle time= " + (now - cobj.timeAccessedLast) + "; Stale time= "
                  + (now - cobj.timeCached) + "; Object count in cache= " + cacheMap.size());
            }
            itr.remove();
            Thread.yield();
          }
        }
      } catch (ConcurrentModificationException cme) {
        /*
         * This is just a timer cleaning up. It will catch up on cleaning next time it runs.
         */
        if (logger.isDebugEnabled()) {
          logger.debug("----Inside CRMSessionCache:Ignorable ConcurrentModificationException");
        }
      }
    }
  }, 0, tiv);
}
项目:incubator-taverna-server    文件:DirectoryDelegate.java   
void forgetEntry(@Nonnull RemoteDirectoryEntry entry) {
    synchronized (localCache) {
        MapIterator i = localCache.mapIterator();
        while (i.hasNext()) {
            Object key = i.next();
            if (entry == i.getValue()) {
                localCache.remove(key);
                break;
            }
        }
    }
}
项目:nci-term-browser    文件:ScoreTerm.java   
/**
 * Display results to the user.
 * @param result
 */
protected void printReport(BidiMap result) {
    final String Dash6  = "------";
    final String Dash10 = "----------";
    final String Dash60 = "------------------------------------------------------------";

    Formatter f = new Formatter();

    // Print header.
    String format = "%-5.5s|%-10.10s|%-60.60s\n";
    Object[] hSep = new Object[] { Dash6, Dash10, Dash60 };
    f.format(format, hSep);
    f.format(format, new Object[] { "Score", "Code", "Term" });
    f.format(format, hSep);

    // Iterate over the result.
    for (MapIterator items = result.inverseBidiMap().mapIterator(); items.hasNext(); ) {
        ScoredTerm st = (ScoredTerm) items.next();
        String code = (String) items.getValue();

        // Evaluate code
        if (code != null && code.length() > 10)
            code = code.substring(0, 7) + "...";

        // Evaluate term (wrap if necessary)
        String term = st.term;
        if (term != null && term.length() < 60)
            f.format(format, new Object[] {st.score, code, term });
        else {
            String sub = term.substring(0, 60);
            f.format(format, new Object[] {st.score, code, sub });
            int begin = 60; int end = term.length();
            while (begin < end) {
                sub = term.substring(begin, Math.min(begin+60, end));
                f.format(format, new Object[] {"", "", sub });
                begin+=60;
            }
        }
    }
    Util.displayMessage(f.out().toString());
}
项目:keepass2android    文件:AbstractReferenceMap.java   
/**
 * Replaces the superclass method to store the state of this class.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 * 
 * @param out  the output stream
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeInt(keyType);
    out.writeInt(valueType);
    out.writeBoolean(purgeValues);
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    for (MapIterator it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
    out.writeObject(null);  // null terminate map
    // do not call super.doWriteObject() as code there doesn't work for reference map
}
项目:keepass2android    文件:AbstractHashedMap.java   
/**
 * Gets an iterator over the map.
 * Changes made to the iterator affect this map.
 * <p>
 * A MapIterator returns the keys in the map. It also provides convenient
 * methods to get the key and value, and set the value.
 * It avoids the need to create an entrySet/keySet/values object.
 * It also avoids creating the Map.Entry object.
 * 
 * @return the map iterator
 */
public MapIterator mapIterator() {
    if (size == 0) {
        return EmptyMapIterator.INSTANCE;
    }
    return new HashMapIterator(this);
}
项目:keepass2android    文件:AbstractHashedMap.java   
/**
 * Writes the map data to the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 * 
 * @param out  the output stream
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    out.writeInt(size);
    for (MapIterator it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
}
项目:KeePass2Android    文件:AbstractReferenceMap.java   
/**
 * Replaces the superclass method to store the state of this class.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 * 
 * @param out  the output stream
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeInt(keyType);
    out.writeInt(valueType);
    out.writeBoolean(purgeValues);
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    for (MapIterator it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
    out.writeObject(null);  // null terminate map
    // do not call super.doWriteObject() as code there doesn't work for reference map
}
项目:KeePass2Android    文件:AbstractHashedMap.java   
/**
 * Gets an iterator over the map.
 * Changes made to the iterator affect this map.
 * <p>
 * A MapIterator returns the keys in the map. It also provides convenient
 * methods to get the key and value, and set the value.
 * It avoids the need to create an entrySet/keySet/values object.
 * It also avoids creating the Map.Entry object.
 * 
 * @return the map iterator
 */
public MapIterator mapIterator() {
    if (size == 0) {
        return EmptyMapIterator.INSTANCE;
    }
    return new HashMapIterator(this);
}
项目:KeePass2Android    文件:AbstractHashedMap.java   
/**
 * Writes the map data to the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 * 
 * @param out  the output stream
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    out.writeInt(size);
    for (MapIterator it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
}
项目:keepass2android    文件:AbstractReferenceMap.java   
/**
 * Gets a MapIterator over the reference map.
 * The iterator only returns valid key/value pairs.
 * 
 * @return a map iterator
 */
public MapIterator mapIterator() {
    return new ReferenceMapIterator(this);
}
项目:KeePass2Android    文件:AbstractReferenceMap.java   
/**
 * Gets a MapIterator over the reference map.
 * The iterator only returns valid key/value pairs.
 * 
 * @return a map iterator
 */
public MapIterator mapIterator() {
    return new ReferenceMapIterator(this);
}