java.util.Hashtable#elements ( )源码实例Demo

下面列出了java.util.Hashtable#elements ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public static void main(String[] args) {

    //create Hashtable object
    Hashtable ht = new Hashtable();

    //add key value pairs to Hashtable
    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    /*
      To remove a key value pair from Hashtable use
      Object remove(Object key) method of Hashtable class.
      It returns either the value mapped with the key or null if no value
      was mapped.
    */

    Object obj = ht.remove("2");
    System.out.println(obj + " Removed from Hashtable");

    //print remaining Hashtable values
    Enumeration e = ht.elements();

    //iterate through Hashtable values Enumeration
    while (e.hasMoreElements()) System.out.println(e.nextElement());
  }
 
源代码2 项目: openjdk-8   文件: IDLGenerator.java
/**
 * Write forward references for referenced interfaces and valuetypes
 * ...but not if the reference is to a boxed IDLEntity,
 * @param refHash Hashtable loaded with referenced types
 * @param p The output stream.
 */
protected void writeForwardReferences(
                                      Hashtable refHash,
                                      IndentingWriter p )
    throws IOException {
    Enumeration refEnum = refHash.elements();
    nextReference:
    while ( refEnum.hasMoreElements() ) {
        Type t = (Type)refEnum.nextElement();
        if ( t.isCompound() ) {
            CompoundType ct = (CompoundType)t;
            if ( ct.isIDLEntity() )
                continue nextReference;                  //ignore IDLEntity reference
        }
        writeForwardReference( t,p );
    }
}
 
源代码3 项目: mts   文件: RTPSessionMgr.java
public Vector getActiveParticipants()
{
    Vector vector1 = new Vector();
    RTPSourceInfoCache rtpsourceinfocache = cache.getRTPSICache();
    Hashtable hashtable = rtpsourceinfocache.getCacheTable();
    for(Enumeration enumeration = hashtable.elements(); enumeration.hasMoreElements();)
    {
        Participant participant = (Participant)enumeration.nextElement();
        if(participant == null || !(participant instanceof LocalParticipant) || !nonparticipating)
        {
            Vector vector = participant.getStreams();
            if(vector.size() > 0)
            {
                vector1.addElement(participant);
            }
        }
    }
    
    return vector1;
}
 
public static void main(String[] args) {

    //create Hashtable object
    Hashtable ht = new Hashtable();

    //add key value pairs to Hashtable
    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    /*
      get Enumeration of values contained in Hashtable using
      Enumeration elements() method of Hashtable class
    */
    Enumeration e = ht.elements();

    //iterate through Hashtable values Enumeration
    while (e.hasMoreElements()) System.out.println(e.nextElement());
  }
 
源代码5 项目: pinpoint   文件: HeaderTest.java
@Test
public void filteredHeaderNames() throws Exception {
    Hashtable<String, String> hashtable = new Hashtable<String, String>();
    hashtable.put("a", "aa");
    hashtable.put("b", Header.HTTP_FLAGS.toString());
    hashtable.put("c", "cc");
    Enumeration<String> elements = hashtable.elements();

    Enumeration enumeration = new DelegateEnumeration(elements, Header.FILTER);
    int count = 0;
    while (enumeration.hasMoreElements()) {
        count++;
        Assert.assertFalse(Header.startWithPinpointHeader((String) enumeration.nextElement()));
    }
    Assert.assertEquals(count, 2);
}
 
源代码6 项目: jdk8u60   文件: IDLGenerator.java
/**
 * Write includes for boxedRMI valuetypes for IDL sequences.
 * Write only the maximum dimension found for an ArrayType.
 * @param arrHash Hashtable loaded with array types
 * @param p The output stream.
 */
protected void writeBoxedRMIIncludes(
                                     Hashtable arrHash,
                                     IndentingWriter p)
    throws IOException {
    Enumeration e1 = arrHash.elements();
    nextSequence:
    while ( e1.hasMoreElements() ) {
        ArrayType at = (ArrayType)e1.nextElement();
        int dim = at.getArrayDimension();
        Type et = at.getElementType();

        Enumeration e2 = arrHash.elements();
        while ( e2.hasMoreElements() ) {                   //eliminate duplicates
            ArrayType at2 = (ArrayType)e2.nextElement();
            if ( et == at2.getElementType() &&                //same element type &
                 dim < at2.getArrayDimension() )               //smaller dimension?
                continue nextSequence;                              //ignore this one
    }
        writeInclude( at,dim,!isThrown,p );
}
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: IDLGenerator.java
/**
 * Write #includes
 * @param incHash Hashtable loaded with Types to include
 * @param p The output stream.
 */
protected void writeInheritedIncludes(
                                      Hashtable inhHash,
                             IndentingWriter p )
    throws IOException {
    Enumeration inhEnum = inhHash.elements();
    while ( inhEnum.hasMoreElements() ) {
        CompoundType t = (CompoundType)inhEnum.nextElement();
        writeInclude( t,0,!isThrown,p );
    }
}
 
源代码8 项目: gemfirexd-oss   文件: MapCheckJUnitTest.java
static void entest2(Hashtable ht, int size) {
    int sum = 0;
    timer.start("Iter Enumeration Value ", size);
    for (Enumeration en = ht.elements(); en.hasMoreElements(); ) {
        if (en.nextElement() != MISSING)
            ++sum;
    }
    timer.finish();
    reallyAssert (sum == size);
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: IDLGenerator.java
/**
 * Write #includes
 * @param incHash Hashtable loaded with Types to include
 * @param isThrown true if Types are thrown exceptions
 * @param p The output stream.
 */
protected void writeIncludes(
                             Hashtable incHash,
                             boolean isThrown,
                             IndentingWriter p )
    throws IOException {
    Enumeration incEnum = incHash.elements();
    while ( incEnum.hasMoreElements() ) {
        CompoundType t = (CompoundType)incEnum.nextElement();
        writeInclude( t,0,isThrown,p );
        }
}
 
源代码10 项目: Bytecoder   文件: BasicPermission.java
/**
 * readObject is called to restore the state of the
 * BasicPermissionCollection from a stream.
 */
@java.io.Serial
private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    // writeObject writes a Hashtable<String, Permission> for the
    // permissions key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<String, Permission> permissions =
            (Hashtable<String, Permission>)gfields.get("permissions", null);
    perms = new ConcurrentHashMap<>(permissions.size()*2);
    perms.putAll(permissions);

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permClass
    permClass = (Class<?>) gfields.get("permClass", null);

    if (permClass == null) {
        // set permClass
        Enumeration<Permission> e = permissions.elements();
        if (e.hasMoreElements()) {
            Permission p = e.nextElement();
            permClass = p.getClass();
        }
    }
}
 
源代码11 项目: RipplePower   文件: DTLSReliableHandshake.java
private static boolean checkAll(Hashtable inboundFlight)
{
    Enumeration e = inboundFlight.elements();
    while (e.hasMoreElements())
    {
        if (((DTLSReassembler)e.nextElement()).getBodyIfComplete() == null)
        {
            return false;
        }
    }
    return true;
}
 
源代码12 项目: openjdk-8   文件: BasicPermission.java
/**
 * readObject is called to restore the state of the
 * BasicPermissionCollection from a stream.
 */
private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    // writeObject writes a Hashtable<String, Permission> for the
    // permissions key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<String, Permission> permissions =
            (Hashtable<String, Permission>)gfields.get("permissions", null);
    perms = new HashMap<String, Permission>(permissions.size()*2);
    perms.putAll(permissions);

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permClass
    permClass = (Class<?>) gfields.get("permClass", null);

    if (permClass == null) {
        // set permClass
        Enumeration<Permission> e = permissions.elements();
        if (e.hasMoreElements()) {
            Permission p = e.nextElement();
            permClass = p.getClass();
        }
    }
}
 
源代码13 项目: openjdk-8-source   文件: IDLGenerator.java
/**
 * Write #includes
 * @param incHash Hashtable loaded with Types to include
 * @param p The output stream.
 */
protected void writeInheritedIncludes(
                                      Hashtable inhHash,
                             IndentingWriter p )
    throws IOException {
    Enumeration inhEnum = inhHash.elements();
    while ( inhEnum.hasMoreElements() ) {
        CompoundType t = (CompoundType)inhEnum.nextElement();
        writeInclude( t,0,!isThrown,p );
    }
}
 
源代码14 项目: jdk8u_jdk   文件: BasicPermission.java
/**
 * readObject is called to restore the state of the
 * BasicPermissionCollection from a stream.
 */
private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    // writeObject writes a Hashtable<String, Permission> for the
    // permissions key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<String, Permission> permissions =
            (Hashtable<String, Permission>)gfields.get("permissions", null);
    perms = new HashMap<String, Permission>(permissions.size()*2);
    perms.putAll(permissions);

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permClass
    permClass = (Class<?>) gfields.get("permClass", null);

    if (permClass == null) {
        // set permClass
        Enumeration<Permission> e = permissions.elements();
        if (e.hasMoreElements()) {
            Permission p = e.nextElement();
            permClass = p.getClass();
        }
    }
}
 
源代码15 项目: openjdk-8-source   文件: BasicPermission.java
/**
 * readObject is called to restore the state of the
 * BasicPermissionCollection from a stream.
 */
private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    // writeObject writes a Hashtable<String, Permission> for the
    // permissions key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<String, Permission> permissions =
            (Hashtable<String, Permission>)gfields.get("permissions", null);
    perms = new HashMap<String, Permission>(permissions.size()*2);
    perms.putAll(permissions);

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permClass
    permClass = (Class<?>) gfields.get("permClass", null);

    if (permClass == null) {
        // set permClass
        Enumeration<Permission> e = permissions.elements();
        if (e.hasMoreElements()) {
            Permission p = e.nextElement();
            permClass = p.getClass();
        }
    }
}
 
源代码16 项目: gemfirexd-oss   文件: IntMapCheckJUnitTest.java
static void entest2(Hashtable ht, int size) {
    int sum = 0;
    timer.start("Iter Enumeration Value ", size);
    for (Enumeration en = ht.elements(); en.hasMoreElements(); ) {
        if (en.nextElement() != MISSING)
            ++sum;
    }
    timer.finish();
    reallyAssert (sum == size);
}
 
源代码17 项目: openjdk-jdk8u   文件: ReachableObjects.java
public ReachableObjects(JavaHeapObject root,
                        final ReachableExcludes excludes) {
    this.root = root;

    final Hashtable<JavaHeapObject, JavaHeapObject> bag = new Hashtable<JavaHeapObject, JavaHeapObject>();
    final Hashtable<String, String> fieldsExcluded = new Hashtable<String, String>();  //Bag<String>
    final Hashtable<String, String> fieldsUsed = new Hashtable<String, String>();   // Bag<String>
    JavaHeapObjectVisitor visitor = new AbstractJavaHeapObjectVisitor() {
        public void visit(JavaHeapObject t) {
            // Size is zero for things like integer fields
            if (t != null && t.getSize() > 0 && bag.get(t) == null) {
                bag.put(t, t);
                t.visitReferencedObjects(this);
            }
        }

        public boolean mightExclude() {
            return excludes != null;
        }

        public boolean exclude(JavaClass clazz, JavaField f) {
            if (excludes == null) {
                return false;
            }
            String nm = clazz.getName() + "." + f.getName();
            if (excludes.isExcluded(nm)) {
                fieldsExcluded.put(nm, nm);
                return true;
            } else {
                fieldsUsed.put(nm, nm);
                return false;
            }
        }
    };
    // Put the closure of root and all objects reachable from root into
    // bag (depth first), but don't include root:
    visitor.visit(root);
    bag.remove(root);

    // Now grab the elements into a vector, and sort it in decreasing size
    JavaThing[] things = new JavaThing[bag.size()];
    int i = 0;
    for (Enumeration e = bag.elements(); e.hasMoreElements(); ) {
        things[i++] = (JavaThing) e.nextElement();
    }
    ArraySorter.sort(things, new Comparer() {
        public int compare(Object lhs, Object rhs) {
            JavaThing left = (JavaThing) lhs;
            JavaThing right = (JavaThing) rhs;
            int diff = right.getSize() - left.getSize();
            if (diff != 0) {
                return diff;
            }
            return left.compareTo(right);
        }
    });
    this.reachables = things;

    this.totalSize = root.getSize();
    for (i = 0; i < things.length; i++) {
        this.totalSize += things[i].getSize();
    }

    excludedFields = getElements(fieldsExcluded);
    usedFields = getElements(fieldsUsed);
}
 
源代码18 项目: Atomic   文件: PircBot.java
private final void updateUser(String channel, int userMode, String nick) {
  channel = channel.toLowerCase();
  synchronized (_channels) {
    Hashtable<User, User> users = _channels.get(channel);
    User newUser = null;
    if( users != null ) {
      Enumeration<User> enumeration = users.elements();
      while ( enumeration.hasMoreElements() ) {
        User userObj = enumeration.nextElement();
        if( userObj.getNick().equalsIgnoreCase(nick) ) {
          if( userMode == OP_ADD ) {
            if( userObj.hasVoice() ) {
              newUser = new User("@+", nick);
            } else {
              newUser = new User("@", nick);
            }
          } else if( userMode == OP_REMOVE ) {
            if( userObj.hasVoice() ) {
              newUser = new User("+", nick);
            } else {
              newUser = new User("", nick);
            }
          } else if( userMode == VOICE_ADD ) {
            if( userObj.isOp() ) {
              newUser = new User("@+", nick);
            } else {
              newUser = new User("+", nick);
            }
          } else if( userMode == VOICE_REMOVE ) {
            if( userObj.isOp() ) {
              newUser = new User("@", nick);
            } else {
              newUser = new User("", nick);
            }
          } else if( userMode == HALFOP_ADD ) {
            if( userObj.hasVoice() ) {
              newUser = new User("%+", nick);
            } else {
              newUser = new User("%", nick);
            }
          } else if( userMode == HALFOP_REMOVE ) {
            if( userObj.hasVoice() ) {
              newUser = new User("+", nick);
            } else {
              newUser = new User("", nick);
            }
          }
        }
      }
    }
    if( newUser != null ) {
      users.put(newUser, newUser);
    } else {
      // just in case ...
      newUser = new User("", nick);
      users.put(newUser, newUser);
    }
  }
}
 
源代码19 项目: gemfirexd-oss   文件: JCache.java
public static Enumeration listCacheObjects()
{
    Hashtable h = CacheAccess.getDefault().getCombinedView();
    return h.elements();
}
 
源代码20 项目: TencentKona-8   文件: ReachableObjects.java
public ReachableObjects(JavaHeapObject root,
                        final ReachableExcludes excludes) {
    this.root = root;

    final Hashtable<JavaHeapObject, JavaHeapObject> bag = new Hashtable<JavaHeapObject, JavaHeapObject>();
    final Hashtable<String, String> fieldsExcluded = new Hashtable<String, String>();  //Bag<String>
    final Hashtable<String, String> fieldsUsed = new Hashtable<String, String>();   // Bag<String>
    JavaHeapObjectVisitor visitor = new AbstractJavaHeapObjectVisitor() {
        public void visit(JavaHeapObject t) {
            // Size is zero for things like integer fields
            if (t != null && t.getSize() > 0 && bag.get(t) == null) {
                bag.put(t, t);
                t.visitReferencedObjects(this);
            }
        }

        public boolean mightExclude() {
            return excludes != null;
        }

        public boolean exclude(JavaClass clazz, JavaField f) {
            if (excludes == null) {
                return false;
            }
            String nm = clazz.getName() + "." + f.getName();
            if (excludes.isExcluded(nm)) {
                fieldsExcluded.put(nm, nm);
                return true;
            } else {
                fieldsUsed.put(nm, nm);
                return false;
            }
        }
    };
    // Put the closure of root and all objects reachable from root into
    // bag (depth first), but don't include root:
    visitor.visit(root);
    bag.remove(root);

    // Now grab the elements into a vector, and sort it in decreasing size
    JavaThing[] things = new JavaThing[bag.size()];
    int i = 0;
    for (Enumeration<JavaHeapObject> e = bag.elements(); e.hasMoreElements(); ) {
        things[i++] = (JavaThing) e.nextElement();
    }
    ArraySorter.sort(things, new Comparer() {
        public int compare(Object lhs, Object rhs) {
            JavaThing left = (JavaThing) lhs;
            JavaThing right = (JavaThing) rhs;
            long diff = right.getSize() - left.getSize();
            if (diff != 0) {
                return Long.signum(diff);
            }
            return left.compareTo(right);
        }
    });
    this.reachables = things;

    this.totalSize = root.getSize();
    for (i = 0; i < things.length; i++) {
        this.totalSize += things[i].getSize();
    }

    excludedFields = getElements(fieldsExcluded);
    usedFields = getElements(fieldsUsed);
}