本文整理了Java中java.util.Hashtable.keys()
方法的一些代码示例,展示了Hashtable.keys()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hashtable.keys()
方法的具体详情如下:
包路径:java.util.Hashtable
类名称:Hashtable
方法名:keys
[英]Returns an enumeration on the keys of this Hashtable instance. The results of the enumeration may be affected if the contents of this Hashtable are modified.
[中]返回此哈希表实例的键的枚举。如果修改此哈希表的内容,枚举结果可能会受到影响。
代码示例来源:origin: log4j/log4j
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();
}
代码示例来源:origin: stackoverflow.com
Hashtable<Integer, String> table = ...
Enumeration<Integer> enumKey = table.keys();
while(enumKey.hasMoreElements()) {
Integer key = enumKey.nextElement();
String val = table.get(key);
if(key==0 && val.equals("0"))
table.remove(key);
}
代码示例来源:origin: org.slf4j/jcl-over-slf4j
/**
* 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);
}
代码示例来源:origin: gocd/gocd
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());
}
代码示例来源:origin: commons-collections/commons-collections
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));
}
代码示例来源:origin: stackoverflow.com
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();
}
代码示例来源:origin: wildfly/wildfly
/**
* 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);
}
代码示例来源:origin: spring-projects/spring-framework
@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"));
}
代码示例来源:origin: pentaho/pentaho-kettle
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;
}
代码示例来源:origin: robovm/robovm
/**
* 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);
}
代码示例来源:origin: oblac/jodd
@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();});
}
代码示例来源:origin: xalan/xalan
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);
}
}
}
代码示例来源:origin: robovm/robovm
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;
}
代码示例来源:origin: i2p/i2p.i2p
/**
* @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();
}
}
代码示例来源:origin: log4j/log4j
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);
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: plutext/docx4j
/**
* 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
}
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
}
代码示例来源:origin: xalan/xalan
/**
* 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());
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* 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 );
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!