public SortedKeyEnumeration(Hashtable ht) { Enumeration f = ht.keys(); Vector keys = new Vector(ht.size()); for (int i, last = 0; f.hasMoreElements(); ++last) { String key = (String) f.nextElement(); for (i = 0; i < last; ++i) { String s = (String) keys.get(i); if (key.compareTo(s) <= 0) break; } keys.add(i, key); } e = keys.elements(); }
/** * Return an array containing the names of all currently defined configuration * attributes. If there are no such attributes, a zero length array is * returned. */ @SuppressWarnings("unchecked") public String[] getAttributeNames() { List<String> names = new ArrayList<String>(); Enumeration<String> keys = attributes.keys(); while (keys.hasMoreElements()) { names.add((String) keys.nextElement()); } String results[] = new String[names.size()]; for (int i = 0; i < results.length; i++) { results[i] = (String) names.get(i); } return (results); }
private void setupClassesInBundle(String... classes) throws MalformedURLException, ClassNotFoundException { Hashtable<URL, String> classFileEntries = new Hashtable<>(); for (String aClass : classes) { classFileEntries.put(new URL("file:///" + aClass), ""); } when(bundle.findEntries("/", "*.class", true)).thenReturn(classFileEntries.keys()); }
public void testToListWithHashtable() { Hashtable expected = new Hashtable(); expected.put("one", new Integer(1)); expected.put("two", new Integer(2)); expected.put("three", new Integer(3)); // validate elements. List actualEltList = EnumerationUtils.toList(expected.elements()); Assert.assertEquals(expected.size(), actualEltList.size()); Assert.assertTrue(actualEltList.contains(new Integer(1))); Assert.assertTrue(actualEltList.contains(new Integer(2))); Assert.assertTrue(actualEltList.contains(new Integer(3))); List expectedEltList = new ArrayList(); expectedEltList.add(new Integer(1)); expectedEltList.add(new Integer(2)); expectedEltList.add(new Integer(3)); Assert.assertTrue(actualEltList.containsAll(expectedEltList)); // validate keys. List actualKeyList = EnumerationUtils.toList(expected.keys()); Assert.assertEquals(expected.size(), actualEltList.size()); Assert.assertTrue(actualKeyList.contains("one")); Assert.assertTrue(actualKeyList.contains("two")); Assert.assertTrue(actualKeyList.contains("three")); List expectedKeyList = new ArrayList(); expectedKeyList.add("one"); expectedKeyList.add("two"); expectedKeyList.add("three"); Assert.assertTrue(actualKeyList.containsAll(expectedKeyList)); }
private static String getPostParamString(Hashtable<String, String> params) { if(params.size() == 0) return ""; StringBuffer buf = new StringBuffer(); Enumeration<String> keys = params.keys(); while(keys.hasMoreElements()) { buf.append(buf.length() == 0 ? "" : "&"); String key = keys.nextElement(); buf.append(key).append("=").append(params.get(key)); } return buf.toString(); }
/** * Return an array containing the names of all currently defined configuration * attributes. If there are no such attributes, a zero length array is * returned. */ @SuppressWarnings("unchecked") public String[] getAttributeNames() { List<String> names = new ArrayList<String>(); Enumeration<String> keys = attributes.keys(); while (keys.hasMoreElements()) { names.add((String) keys.nextElement()); } String results[] = new String[names.size()]; for (int i = 0; i < results.length; i++) { results[i] = (String) names.get(i); } return (results); }
@Test public void testContains() { assertFalse(CollectionUtils.contains((Iterator<String>) null, "myElement")); assertFalse(CollectionUtils.contains((Enumeration<String>) null, "myElement")); assertFalse(CollectionUtils.contains(new LinkedList<String>().iterator(), "myElement")); assertFalse(CollectionUtils.contains(new Hashtable<String, Object>().keys(), "myElement")); List<String> list = new LinkedList<>(); list.add("myElement"); assertTrue(CollectionUtils.contains(list.iterator(), "myElement")); Hashtable<String, String> ht = new Hashtable<>(); ht.put("myElement", "myValue"); assertTrue(CollectionUtils.contains(ht.keys(), "myElement")); }
public String[] getUsedFields() { Hashtable<String, String> fields = new Hashtable<String, String>(); getUsedFields( fields ); String[] retval = new String[fields.size()]; Enumeration<String> keys = fields.keys(); int i = 0; while ( keys.hasMoreElements() ) { retval[i] = keys.nextElement(); i++; } return retval; }
/** * Return an array containing the names of all currently defined * configuration attributes. If there are no such attributes, a zero * length array is returned. */ public String[] getAttributeNames() { Vector names = new Vector(); Enumeration keys = attributes.keys(); while (keys.hasMoreElements()) { names.addElement((String) keys.nextElement()); } String results[] = new String[names.size()]; for (int i = 0; i < results.length; i++) { results[i] = (String) names.elementAt(i); } return (results); }
@Test void testAsIterator_with_data() throws Exception { final Hashtable<String, String> input = new Hashtable<>(); input.put("jodd", "makes fun!"); input.put("headline", "The Unbearable Lightness of Java"); input.put("aim", "And enjoy the coding"); final Iterator<String> actual = CollectionUtil.asIterator(input.keys()); // asserts assertNotNull(actual); // next #1 assertTrue(actual.hasNext()); String key = actual.next(); assertTrue(input.containsKey(key)); // next #2 assertTrue(actual.hasNext()); key = actual.next(); assertTrue(input.containsKey(key)); // next #3 assertTrue(actual.hasNext()); key = actual.next(); assertTrue(input.containsKey(key)); // no more elements assertFalse(actual.hasNext()); assertThrows(NoSuchElementException.class, () -> {actual.next();}); }
private void appendTemplateCode(InstructionList body) { final Enumeration templates = _neededTemplates.keys(); while (templates.hasMoreElements()) { final Object iList = _templateILs.get(templates.nextElement()); if (iList != null) { body.append((InstructionList)iList); } } }
MappingRecord getMappingFromURI(String uri) { MappingRecord foundMap = null; Enumeration prefixes = m_namespaces.keys(); while (prefixes.hasMoreElements()) { String prefix = (String) prefixes.nextElement(); MappingRecord map2 = getMappingFromPrefix(prefix); if (map2 != null && (map2.m_uri).equals(uri)) { foundMap = map2; break; } } return foundMap; }
/** * @return List of request parameter names * @throws IllegalStateException if the request is too large */ public Enumeration<String> getParameterNames() { if (isMultiPartRequest) { if( cachedParameterNames == null ) { cachedParameterNames = new Hashtable<String, Integer>(); try { Integer DUMMY = Integer.valueOf(0); for (Part p : httpRequest.getParts()) { cachedParameterNames.put(p.getName(), DUMMY); } } catch (IOException ioe) { log(ioe); } catch (ServletException se) { log(se); } catch (IllegalStateException ise) { log(ise); throw ise; } } return cachedParameterNames.keys(); } else { return httpRequest.getParameterNames(); } }
Enumeration enumeration = ht.keys(); while(enumeration.hasMoreElements() && (misses <= 4)) { Thread t = (Thread) enumeration.nextElement(); if(t.isAlive()) { misses++; Thread t = (Thread) v.elementAt(i); LogLog.debug("Lazy NDC removal for thread [" + t.getName() + "] ("+ ht.size() + ")."); ht.remove(t);
/** * Given a namespace uri, and the namespaces mappings for the * current element, return the current prefix for that uri. * * @param uri the namespace URI to be search for * @return an existing prefix that maps to the given URI, null if no prefix * maps to the given namespace URI. */ public String lookupPrefix(String uri) { String foundPrefix = null; Enumeration prefixes = m_namespaces.keys(); while (prefixes.hasMoreElements()) { String prefix = (String) prefixes.nextElement(); String uri2 = lookupNamespace(prefix); if (uri2 != null && uri2.equals(uri)) { foundPrefix = prefix; break; } } return foundPrefix; }
/** * Removes the mapping associated to the specified prefix. * * @param prefix The prefix which mapping should be removed. */ private void removeIfNeeded(String prefix) { // remove the previous mapping to the prefix if (this.prefixMapping.containsValue(prefix)) { Object key = null; for (Enumeration<String> e = this.prefixMapping.keys(); e.hasMoreElements();) { key = e.nextElement(); if (this.prefixMapping.get(key).equals(prefix)) { break; } } this.prefixMapping.remove(key); // we know key should have a value } }
/** * Given a namespace uri, get all prefixes bound to the Namespace URI in the current scope. * * @param uri the namespace URI to be search for * @return An array of Strings which are * all prefixes bound to the namespace URI in the current scope. * An array of zero elements is returned if no prefixes map to the given * namespace URI. */ public String[] lookupAllPrefixes(String uri) { java.util.ArrayList foundPrefixes = new java.util.ArrayList(); Enumeration prefixes = m_namespaces.keys(); while (prefixes.hasMoreElements()) { String prefix = (String) prefixes.nextElement(); String uri2 = lookupNamespace(prefix); if (uri2 != null && uri2.equals(uri)) { foundPrefixes.add(prefix); } } String[] prefixArray = new String[foundPrefixes.size()]; foundPrefixes.toArray(prefixArray); return prefixArray; } }
/** * This method starts at a given node, traverses all namespace mappings, * and assembles a list of all prefixes that (for the given node) maps * to _ANY_ namespace URI. Used by literal result elements to determine */ public Enumeration getNamespaceScope(SyntaxTreeNode node) { Hashtable all = new Hashtable(); while (node != null) { Hashtable mapping = node.getPrefixMapping(); if (mapping != null) { Enumeration prefixes = mapping.keys(); while (prefixes.hasMoreElements()) { String prefix = (String)prefixes.nextElement(); if (!all.containsKey(prefix)) { all.put(prefix, mapping.get(prefix)); } } } node = node.getParent(); } return(all.keys()); }
/** * Clear out all entries of database with a certain name * * @param dbname * The name of the database for which we want to clear the cache or null if we want to clear it all. */ public void clear( String dbname ) { if ( dbname == null ) { cache = new Hashtable<DBCacheEntry, RowMetaInterface>(); setActive(); } else { Enumeration<DBCacheEntry> keys = cache.keys(); while ( keys.hasMoreElements() ) { DBCacheEntry entry = keys.nextElement(); if ( entry.sameDB( dbname ) ) { // Same name: remove it! cache.remove( entry ); } } } }