java.util.Enumeration.hasMoreElements()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(378)

本文整理了Java中java.util.Enumeration.hasMoreElements()方法的一些代码示例,展示了Enumeration.hasMoreElements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enumeration.hasMoreElements()方法的具体详情如下:
包路径:java.util.Enumeration
类名称:Enumeration
方法名:hasMoreElements

Enumeration.hasMoreElements介绍

[英]Returns whether this Enumeration has more elements.
[中]返回此枚举是否有更多元素。

代码示例

代码示例来源:origin: google/guava

@Override
protected void scanJarFile(ClassLoader classloader, JarFile file) {
 Enumeration<JarEntry> entries = file.entries();
 while (entries.hasMoreElements()) {
  JarEntry entry = entries.nextElement();
  if (entry.isDirectory() || entry.getName().equals(JarFile.MANIFEST_NAME)) {
   continue;
  }
  resources.get(classloader).add(entry.getName());
 }
}

代码示例来源:origin: org.mockito/mockito-core

/**
 * Converts enumeration into iterable
 */
public static <T> Iterable<T> toIterable(Enumeration<T> in) {
  List<T> out = new LinkedList<T>();
  while(in.hasMoreElements()) {
    out.add(in.nextElement());
  }
  return out;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the HTTP status code that this exception resolver will apply for a given
 * resolved error view. Keys are view names; values are status codes.
 * <p>Note that this error code will only get applied in case of a top-level request.
 * It will not be set for an include request, since the HTTP status cannot be modified
 * from within an include.
 * <p>If not specified, the default status code will be applied.
 * @see #setDefaultStatusCode(int)
 */
public void setStatusCodes(Properties statusCodes) {
  for (Enumeration<?> enumeration = statusCodes.propertyNames(); enumeration.hasMoreElements();) {
    String viewName = (String) enumeration.nextElement();
    Integer statusCode = Integer.valueOf(statusCodes.getProperty(viewName));
    this.statusCodes.put(viewName, statusCode);
  }
}

代码示例来源: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: stackoverflow.com

public static void unzip(File zipfile, File directory) throws IOException {
 ZipFile zfile = new ZipFile(zipfile);
 Enumeration<? extends ZipEntry> entries = zfile.entries();
 while (entries.hasMoreElements()) {
  ZipEntry entry = entries.nextElement();
  File file = new File(directory, entry.getName());
  if (entry.isDirectory()) {
   file.mkdirs();
  } else {
   file.getParentFile().mkdirs();
   InputStream in = zfile.getInputStream(entry);
   try {
    copy(in, file);
   } finally {
    in.close();
   }
  }
 }
}

代码示例来源:origin: Blankj/AndroidUtilCode

/**
 * Return the files' path in ZIP file.
 *
 * @param zipFile The ZIP file.
 * @return the files' path in ZIP file
 * @throws IOException if an I/O error has occurred
 */
public static List<String> getFilesPath(final File zipFile)
    throws IOException {
  if (zipFile == null) return null;
  List<String> paths = new ArrayList<>();
  ZipFile zip = new ZipFile(zipFile);
  Enumeration<?> entries = zip.entries();
  while (entries.hasMoreElements()) {
    String entryName = ((ZipEntry) entries.nextElement()).getName();
    if (entryName.contains("../")) {
      System.out.println("entryName: " + entryName + " is dangerous!");
      paths.add(entryName);
    } else {
      paths.add(entryName);
    }
  }
  zip.close();
  return paths;
}

代码示例来源:origin: stackoverflow.com

Enumeration params = request.getParameterNames(); 
while(params.hasMoreElements()){
 String paramName = (String)params.nextElement();
 System.out.println("Parameter Name - "+paramName+", Value - "+request.getParameter(paramName));
}

代码示例来源:origin: stackoverflow.com

final Map <String,Integer> test = new HashMap<String,Integer>();
test.put("one",1);
test.put("two",2);
test.put("three",3);
final Enumeration<String> strEnum = Collections.enumeration(test.keySet());
while(strEnum.hasMoreElements()) {
  System.out.println(strEnum.nextElement());
}

代码示例来源:origin: commons-collections/commons-collections

expected.put("zeroKey", "zero");
expected.put("oneKey", "one");
found.put(entry.getKey(),entry.getValue());
entry = (Map.Entry)(CollectionUtils.get(expected, 1));
found.put(entry.getKey(),entry.getValue());
list.add("zero");
list.add("one");
assertEquals("zero",CollectionUtils.get(list, 0));
assertEquals("one",CollectionUtils.get(list, 1));
vector.addElement("zero");
vector.addElement("one");
Enumeration en = vector.elements();
assertEquals("zero",CollectionUtils.get(en,0));
en = vector.elements();
assertEquals("one",CollectionUtils.get(en,1));
assertTrue(!en.hasMoreElements());

代码示例来源:origin: eclipse-vertx/vert.x

public List<JavaFileObject> find(String packageName) throws IOException {
 String javaPackageName = packageName.replaceAll("\\.", "/");
 List<JavaFileObject> result = new ArrayList<>();
 Enumeration<URL> urlEnumeration = classLoader.getResources(javaPackageName);
 while (urlEnumeration.hasMoreElements()) {
  URL resource = urlEnumeration.nextElement();
  //Need to urldecode it too, since bug in JDK URL class which does not url decode it, so if it contains spaces you are screwed
  final File directory = new File(decodeURIComponent(resource.getFile(), false));
  if (directory.isDirectory()) {
   result.addAll(browseDir(packageName, directory));
  } else {
   result.addAll(browseJar(resource));
  }
 }
 return result;
}

代码示例来源:origin: apache/rocketmq

public Enumeration getCurrentLoggers() {
  Vector<Logger> loggers = new Vector<Logger>(ht.size());
  Enumeration elems = ht.elements();
  while (elems.hasMoreElements()) {
    Object o = elems.nextElement();
    if (o instanceof Logger) {
      Logger logger = (Logger)o;
      loggers.addElement(logger);
    }
  }
  return loggers.elements();
}

代码示例来源: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: spring-projects/spring-framework

@Nullable
private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) {
  if (shouldIgnoreIndex) {
    return null;
  }
  try {
    Enumeration<URL> urls = classLoader.getResources(COMPONENTS_RESOURCE_LOCATION);
    if (!urls.hasMoreElements()) {
      return null;
    }
    List<Properties> result = new ArrayList<>();
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();
      Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
      result.add(properties);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Loaded " + result.size() + "] index(es)");
    }
    int totalCount = result.stream().mapToInt(Properties::size).sum();
    return (totalCount > 0 ? new CandidateComponentsIndex(result) : null);
  }
  catch (IOException ex) {
    throw new IllegalStateException("Unable to load indexes from location [" +
        COMPONENTS_RESOURCE_LOCATION + "]", ex);
  }
}

代码示例来源:origin: skylot/jadx

private static List<String> getZipFileList(File file) {
  List<String> filesList = new ArrayList<>();
  try (ZipFile zipFile = new ZipFile(file)) {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      filesList.add(entry.getName());
    }
  } catch (Exception e) {
    LOG.error("Error read zip file '{}'", file.getAbsolutePath(), e);
  }
  return filesList;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the mappings of bean keys to a comma-separated list of method names.
 * The property key should match the bean key and the property value should match
 * the list of method names. When searching for method names for a bean, Spring
 * will check these mappings first.
 * @param mappings the mappings of bean keys to method names
 */
public void setMethodMappings(Properties mappings) {
  this.methodMappings = new HashMap<>();
  for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
    String beanKey = (String) en.nextElement();
    String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
    this.methodMappings.put(beanKey, new HashSet<>(Arrays.asList(methodNames)));
  }
}

代码示例来源:origin: stackoverflow.com

java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
java.util.Enumeration enumEntries = jar.entries();
while (enumEntries.hasMoreElements()) {
  java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement();
  java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
  if (file.isDirectory()) { // if its a directory, create it
    f.mkdir();
    continue;
  }
  java.io.InputStream is = jar.getInputStream(file); // get the input stream
  java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
  while (is.available() > 0) {  // write contents of 'is' to 'fos'
    fos.write(is.read());
  }
  fos.close();
  is.close();
}

代码示例来源:origin: stackoverflow.com

Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
 String headerName = (String)headerNames.nextElement();
 System.out.println("Header Name - " + headerName + ", Value - " + request.getHeader(headerName));
}

代码示例来源:origin: log4j/log4j

/**
  Returns all the currently defined categories in this hierarchy as
  an {@link java.util.Enumeration Enumeration}.
  <p>The root logger is <em>not</em> included in the returned
  {@link Enumeration}.  */
public
Enumeration getCurrentLoggers() {
 // The accumlation in v is necessary because not all elements in
 // ht are Logger objects as there might be some ProvisionNodes
 // as well.
 Vector v = new Vector(ht.size());
 Enumeration elems = ht.elements();
 while(elems.hasMoreElements()) {
  Object o = elems.nextElement();
  if(o instanceof Logger) {
 v.addElement(o);
  }
 }
 return v.elements();
}

代码示例来源:origin: alibaba/druid

public void setColumnMargin(int margin) {
  this.margin = margin;
  Enumeration<Object> enumeration = vector.elements();
  while (enumeration.hasMoreElements()) {
    Object obj = enumeration.nextElement();
    if (obj instanceof ColumnGroup) {
      ((ColumnGroup) obj).setColumnMargin(margin);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

protected final HttpHeaders getRequestHeaders(MockHttpServletRequest request) {
  HttpHeaders headers = new HttpHeaders();
  Enumeration<?> names = request.getHeaderNames();
  while (names.hasMoreElements()) {
    String name = (String) names.nextElement();
    Enumeration<String> values = request.getHeaders(name);
    while (values.hasMoreElements()) {
      headers.add(name, values.nextElement());
    }
  }
  return headers;
}

相关文章

微信公众号

最新文章

更多