Java Code Examples for java.util.Hashtable#elements()
The following examples show how to use
java.util.Hashtable#elements() .
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: RemoveValueFromHashtableExample.java From java-n-IDE-for-Android with Apache License 2.0 | 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"); /* 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()); }
Example 2
Source File: IDLGenerator.java From openjdk-8 with GNU General Public License v2.0 | 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 3
Source File: IDLGenerator.java From jdk8u60 with GNU General Public License v2.0 | 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 4
Source File: HeaderTest.java From pinpoint with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: RTPSessionMgr.java From mts with GNU General Public License v3.0 | 6 votes |
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; }
Example 6
Source File: IterateValuesOfHashtableExample.java From java-n-IDE-for-Android with Apache License 2.0 | 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 7
Source File: DTLSReliableHandshake.java From RipplePower with Apache License 2.0 | 5 votes |
private static boolean checkAll(Hashtable inboundFlight) { Enumeration e = inboundFlight.elements(); while (e.hasMoreElements()) { if (((DTLSReassembler)e.nextElement()).getBodyIfComplete() == null) { return false; } } return true; }
Example 8
Source File: IntMapCheckJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 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 9
Source File: BasicPermission.java From openjdk-8-source with GNU General Public License v2.0 | 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 10
Source File: BasicPermission.java From jdk8u_jdk with GNU General Public License v2.0 | 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 11
Source File: IDLGenerator.java From openjdk-8-source with GNU General Public License v2.0 | 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 12
Source File: BasicPermission.java From openjdk-8 with GNU General Public License v2.0 | 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 13
Source File: IDLGenerator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 14
Source File: BasicPermission.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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(); } } }
Example 15
Source File: IDLGenerator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 16
Source File: MapCheckJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 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 17
Source File: ReachableObjects.java From TencentKona-8 with GNU General Public License v2.0 | 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 18
Source File: JCache.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static Enumeration listCacheObjects() { Hashtable h = CacheAccess.getDefault().getCombinedView(); return h.elements(); }
Example 19
Source File: PircBot.java From Atomic with GNU General Public License v3.0 | 4 votes |
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); } } }
Example 20
Source File: ReachableObjects.java From openjdk-jdk8u with GNU General Public License v2.0 | 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); }