java.util.Collections.enumeration()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(235)

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

Collections.enumeration介绍

[英]Returns an Enumeration on the specified collection.
[中]返回指定集合上的枚举。

代码示例

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

@Override
  public Enumeration<String> getHeaderNames() {
    return Collections.enumeration(this.headers.keySet());
  }
}

代码示例来源:origin: Atmosphere/atmosphere

@Override
  public Enumeration<String> getInitParameterNames() {
    return Collections.enumeration(initParams.values());
  }
}

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

/**
 * Returns an enumeration of all {@code PackagePermission} objects in the
 * container.
 * 
 * @return Enumeration of all {@code PackagePermission} objects.
 */
@Override
public synchronized Enumeration<Permission> elements() {
  List<Permission> all = new ArrayList<Permission>(permissions.values());
  Map<String, PackagePermission> pc = filterPermissions;
  if (pc != null) {
    all.addAll(pc.values());
  }
  return Collections.enumeration(all);
}

代码示例来源: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: ben-manes/caffeine

/** Returns the input stream of the trace data. */
protected InputStream readFiles() throws IOException {
 List<InputStream> inputs = new ArrayList<>(filePaths.size());
 for (String filePath : filePaths) {
  inputs.add(readFile(filePath));
 }
 return new SequenceInputStream(Collections.enumeration(inputs));
}

代码示例来源:origin: org.osgi/org.osgi.compendium

public Enumeration<Object> elements() {
  Collection<Object> values = properties.values();
  List<Object> result = new ArrayList<Object>(values.size() + 1);
  result.add(topic);
  result.addAll(values);
  return Collections.enumeration(result);
}

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

@Override
public Enumeration<String> getParameterNames() {
  if (this.multipartParameterNames == null) {
    initializeMultipart();
  }
  if (this.multipartParameterNames.isEmpty()) {
    return super.getParameterNames();
  }
  // Servlet 3.0 getParameterNames() not guaranteed to include multipart form items
  // (e.g. on WebLogic 12) -> need to merge them here to be on the safe side
  Set<String> paramNames = new LinkedHashSet<>();
  Enumeration<String> paramEnum = super.getParameterNames();
  while (paramEnum.hasMoreElements()) {
    paramNames.add(paramEnum.nextElement());
  }
  paramNames.addAll(this.multipartParameterNames);
  return Collections.enumeration(paramNames);
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public Enumeration<URL> getResources(String name) throws IOException {
  final List<URL> urls = new ArrayList<>();
  for (ClassLoader classLoader : classLoaders) {
    final Enumeration<URL> resources = classLoader.getResources(name);
    if (resources.hasMoreElements()) {
      urls.addAll(Collections.list(resources));
    }
  }
  if (urls.isEmpty() && LOG.isTraceEnabled()) {
    LOG.trace("Resource " + name + " not found.");
  }
  return Collections.enumeration(urls);
}

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

/**
 * Finds all the resources with the given name. This method will first search the class loader of
 * the context class for the resource before searching all other {@link ClassLoader}s.
 *
 * @param contextClass The class whose class loader will first be searched
 * @param name The resource name
 * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for the resource. If no
 *         resources could be found, the enumeration will be empty. Resources that the class
 *         loader doesn't have access to will not be in the enumeration.
 * @throws IOException If I/O errors occur
 * @see ClassLoader#getResources(String)
 */
private Enumeration<URL> getResources(final Class<?> contextClass, final String name)
  throws IOException {
 final LinkedHashSet<URL> urls = new LinkedHashSet<URL>();
 if (contextClass != null) {
  CollectionUtils.addAll(urls, contextClass.getClassLoader().getResources(name));
 }
 for (ClassLoader classLoader : getClassLoaders()) {
  Enumeration<URL> resources = classLoader.getResources(name);
  if (resources != null && resources.hasMoreElements()) {
   CollectionUtils.addAll(urls, resources);
  }
 }
 return Collections.enumeration(urls);
}

代码示例来源:origin: Atmosphere/atmosphere

@Override
public Enumeration<String> getHeaderNames() {
  Set list = new HashSet();
  list.addAll(b.headers.keySet());
  list.addAll(Collections.list(b.request.getHeaderNames()));
  if (b.request != null) {
    Enumeration e = b.request.getAttributeNames();
    while (e.hasMoreElements()) {
      String name = e.nextElement().toString();
      if (name.startsWith(X_ATMOSPHERE)) {
        list.add(name);
      }
    }
  }
  if (b.contentType != null) {
    list.add("Content-Type");
  }
  return Collections.enumeration(list);
}

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

List<InputStream> opened = new ArrayList<InputStream>(files.size());
for (File f : files) 
 opened.add(new FileInputStream(f));
InputStream is = new SequenceInputStream(Collections.enumeration(opened));

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

@Override
public Enumeration<String> getInitParameterNames() {
  return Collections.enumeration(this.initParameters.keySet());
}

代码示例来源:origin: org.osgi/org.osgi.compendium

public Enumeration<String> keys() {
  Collection<String> keys = properties.keySet();
  List<String> result = new ArrayList<String>(keys.size() + 1);
  result.add(EVENT_TOPIC);
  result.addAll(keys);
  return Collections.enumeration(result);
}

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

/**
 * Returns an enumeration of all {@code AdaptPermission} objects in the
 * container.
 * 
 * @return Enumeration of all {@code AdaptPermission} objects.
 */
@Override
public synchronized Enumeration<Permission> elements() {
  List<Permission> all = new ArrayList<Permission>(permissions.values());
  return Collections.enumeration(all);
}

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

/**
 * Returns an enumeration of all the {@code ServicePermission} objects in
 * the container.
 * 
 * @return Enumeration of all the ServicePermission objects.
 */
@Override
public synchronized Enumeration<Permission> elements() {
  List<Permission> all = new ArrayList<Permission>(permissions.values());
  Map<String, ServicePermission> pc = filterPermissions;
  if (pc != null) {
    all.addAll(pc.values());
  }
  return Collections.enumeration(all);
}

代码示例来源:origin: Atmosphere/atmosphere

public Enumeration<String> getInitParameterNames() {
    if (!done.getAndSet(true)) {
      Enumeration en = sc.getInitParameterNames();
      if (en != null) {
        while (en.hasMoreElements()) {
          String name = (String) en.nextElement();
          if (!initParams.containsKey(name)) {
            initParams.put(name, sc.getInitParameter(name));
          }
        }
      }
    }
    return Collections.enumeration(initParams.keySet());
  }
};

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

/**
 * {@inheritDoc}
 */
@Override
public Enumeration<URL> getResources(String name) throws IOException {
 // First get resources from this classloader
 List<URL> resources = Collections.list(findResources(name));
 // Then add resources from the parent
 if (getParent() != null) {
  Enumeration<URL> parentResources = getParent().getResources(name);
  if (parentResources.hasMoreElements()) {
   resources.addAll(Collections.list(parentResources));
  }
 }
 return Collections.enumeration(resources);
}

代码示例来源:origin: org.netbeans.api/org-openide-util-lookup

private boolean ensureNext() {
  for (;;) {
    if (en != null && en.hasMoreElements()) {
      return true;
    }
    if (isEmpty()) {
      return false;
    }
    Node n2 = poll();
    if (n2.children != null) {
      addAll(n2.children);
    }
    if (n2.items != null && !n2.items.isEmpty()) {
      en = Collections.enumeration(n2.items);
    }
  }
}

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

@Override
public Enumeration getParameterNames() {
  Set<String> paramNames = new LinkedHashSet<>();
  paramNames.addAll(formParams.keySet());
  Enumeration<String> original = super.getParameterNames();
  while (original.hasMoreElements()) {
    paramNames.add(original.nextElement());
  }
  return Collections.enumeration(paramNames);
}

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

/**
 * Gets the current contents of this byte stream as a Input Stream. The
 * returned stream is backed by buffers of <code>this</code> stream,
 * avoiding memory allocation and copy, thus saving space and time.<br>
 *
 * @return the current contents of this output stream.
 * @see java.io.ByteArrayOutputStream#toByteArray()
 * @see #reset()
 * @since 2.5
 */
public synchronized InputStream toInputStream() {
  int remaining = count;
  if (remaining == 0) {
    return new ClosedInputStream();
  }
  final List<ByteArrayInputStream> list = new ArrayList<>(buffers.size());
  for (final byte[] buf : buffers) {
    final int c = Math.min(buf.length, remaining);
    list.add(new ByteArrayInputStream(buf, 0, c));
    remaining -= c;
    if (remaining == 0) {
      break;
    }
  }
  reuseBuffers = false;
  return new SequenceInputStream(Collections.enumeration(list));
}

相关文章

Collections类方法