Java Code Examples for java.util.Hashtable.elements()

The following are Jave code examples for showing how to use elements() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * 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 );
    }
}
 
Example 2
Project: javaide   File: IterateValuesOfHashtableExample.java   View Source Code Vote up 6 votes
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());
  }
 
Example 3
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * 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 );
    }
}
 
Example 4
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * Write #includes for boxed IDLEntity references.
 * @param refHash Hashtable loaded with referenced types
 * @param p The output stream.
 */
protected void writeIDLEntityIncludes(
                                      Hashtable refHash,
                                      IndentingWriter p )
    throws IOException {
    Enumeration refEnum = refHash.elements();
    while ( refEnum.hasMoreElements() ) {
        Type t = (Type)refEnum.nextElement();
        if ( t.isCompound() ) {
            CompoundType ct = (CompoundType)t;
            if ( ct.isIDLEntity() ) {                          //select IDLEntities
                writeInclude( ct,0,!isThrown,p );
                refHash.remove( ct.getQualifiedName() );     //avoid another #include
            }
        }
    }
}
 
Example 5
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * 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 );
}
}
 
Example 6
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * Write #includes for boxed IDLEntity references.
 * @param refHash Hashtable loaded with referenced types
 * @param p The output stream.
 */
protected void writeIDLEntityIncludes(
                                      Hashtable refHash,
                                      IndentingWriter p )
    throws IOException {
    Enumeration refEnum = refHash.elements();
    while ( refEnum.hasMoreElements() ) {
        Type t = (Type)refEnum.nextElement();
        if ( t.isCompound() ) {
            CompoundType ct = (CompoundType)t;
            if ( ct.isIDLEntity() ) {                          //select IDLEntities
                writeInclude( ct,0,!isThrown,p );
                refHash.remove( ct.getQualifiedName() );     //avoid another #include
            }
        }
    }
}
 
Example 7
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 6 votes
/**
 * 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 );
}
}
 
Example 8
Project: ipack   File: DTLSReliableHandshake.java   View Source Code Vote up 5 votes
private static void resetAll(Hashtable inboundFlight)
{
    Enumeration e = inboundFlight.elements();
    while (e.hasMoreElements())
    {
        ((DTLSReassembler)e.nextElement()).reset();
    }
}
 
Example 9
Project: ipack   File: IETFUtils.java   View Source Code Vote up 5 votes
public static String[] findAttrNamesForOID(
    ASN1ObjectIdentifier oid,
    Hashtable            lookup)
{
    int count = 0;
    for (Enumeration en = lookup.elements(); en.hasMoreElements();)
    {
        if (oid.equals(en.nextElement()))
        {
            count++;
        }
    }

    String[] aliases = new String[count];
    count = 0;

    for (Enumeration en = lookup.keys(); en.hasMoreElements();)
    {
        String key = (String)en.nextElement();
        if (oid.equals(lookup.get(key)))
        {
            aliases[count++] = key;
        }
    }

    return aliases;
}
 
Example 10
Project: openjdk-jdk10   File: IDLGenerator.java   View Source Code Vote up 5 votes
/**
 * 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 );
        }
}
 
Example 11
Project: openjdk-jdk10   File: MapCheck.java   View Source Code Vote up 5 votes
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);
}
 
Example 12
Project: openjdk-jdk10   File: ClassPath.java   View Source Code Vote up 5 votes
/**
 * Returns list of files given a package name and extension.
 */
public Enumeration<ClassFile> getFiles(String pkg, String ext) {
    Hashtable<String, ClassFile> files = new Hashtable<>();
    for (int i = path.length; --i >= 0; ) {
        path[i].fillFiles(pkg, ext, files);
    }
    return files.elements();
}
 
Example 13
Project: jdk8u-jdk   File: BasicPermission.java   View Source Code Vote up 5 votes
/**
 * 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();
        }
    }
}
 
Example 14
Project: OpenJSharp   File: IDLGenerator.java   View Source Code Vote up 5 votes
/**
 * 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 );
    }
}
 
Example 15
Project: monarch   File: MapCheckJUnitTest.java   View Source Code Vote up 5 votes
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);
}
 
Example 16
Project: monarch   File: IntMapCheckJUnitTest.java   View Source Code Vote up 5 votes
static void entest4(Hashtable ht, int size) {
  int sum = 0;
  timer.start("Iterf Enumeration Value", size);
  Enumeration en = ht.elements();
  for (int i = 0; i < size; ++i) {
    if (en.nextElement() != MISSING)
      ++sum;
  }
  timer.finish();
  reallyAssert(sum == size);
}
 
Example 17
Project: jdk8u-jdk   File: ReachableObjects.java   View Source Code Vote up 4 votes
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);
}
 
Example 18
Project: openjdk-jdk10   File: ReachableObjects.java   View Source Code Vote up 4 votes
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);
}
 
Example 19
Project: openjdk-jdk10   File: DnsContext.java   View Source Code Vote up 4 votes
BaseNameClassPairEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
    this.ctx = ctx;
    this.nodes = (nodes != null)
        ? nodes.elements()
        : null;
}
 
Example 20
Project: OpenJSharp   File: ReachableObjects.java   View Source Code Vote up 4 votes
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);
}