下面列出了java.util.Collections#enumeration ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Get enumeration of header _names. Returns an enumeration of strings representing the header
* _names for this request.
*/
public Enumeration<String> getFieldNames()
{
final Enumeration<?> buffers = Collections.enumeration(_names.keySet());
return new Enumeration<String>()
{
public String nextElement()
{
return buffers.nextElement().toString();
}
public boolean hasMoreElements()
{
return buffers.hasMoreElements();
}
};
}
@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<String>();
Enumeration<String> paramEnum = super.getParameterNames();
while (paramEnum.hasMoreElements()) {
paramNames.add(paramEnum.nextElement());
}
paramNames.addAll(this.multipartParameterNames);
return Collections.enumeration(paramNames);
}
@Test
public void testSimpleWithEFormat() {
String textToParse = "# Minimalistic line:\n" +
"\n"+
"metric_without_labels 1.7560473e+07\n";
Parser subject = new Parser(textToParse);
HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
// creating expected result
LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
List<Sample> samples = new LinkedList<>();
Sample sample = new Sample("metric_without_labels", new LinkedList<String>(), new LinkedList<String>(), 1.7560473e+07);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.UNTYPED, "", samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public Enumeration getParameterNames() {
List<String> finalParameterNames = new ArrayList<String>();
ArrayList<String> requestParameterNames = Collections.list(super.getParameterNames());
for (String parameterName : requestParameterNames) {
if (!excludeParams.matcher(parameterName).matches()) {
finalParameterNames.add(parameterName);
}
}
return Collections.enumeration(finalParameterNames);
}
/**
* Returns an enumeration of all the PropertyPermission objects in the
* container.
*
* @return an enumeration of all the PropertyPermission objects.
*/
@SuppressWarnings("unchecked")
public Enumeration<Permission> elements() {
// Convert Iterator of Map values into an Enumeration
synchronized (this) {
/**
* Casting to rawtype since Enumeration<PropertyPermission>
* cannot be directly cast to Enumeration<Permission>
*/
return (Enumeration)Collections.enumeration(perms.values());
}
}
@Override
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);
}
@Override
public Enumeration<String> getPropertyNames() {
String meth = "getPropertyNames";
Object[] args = {};
String[] strs = { "val1", "val2" };
Enumeration<String> ret = Collections.enumeration(Arrays.asList(strs));
retVal = ret;
checkArgs(meth, args);
return ret;
}
@Override
public Enumeration<String> getHeaders(String name) {
Map.Entry<String, List<String>> header = getHeaderEntry(name);
if (header == null || header.getValue() == null) {
return Collections.enumeration(Collections.<String>emptyList());
}
return Collections.enumeration(header.getValue());
}
/** Enumeration of all registered components.
* @return enumeration of CloneableTopComponent
*/
public Enumeration<CloneableTopComponent> getComponents() {
Set<CloneableTopComponent> components;
synchronized (LOCK) {
components = new HashSet<CloneableTopComponent>(componentSet);
}
return Collections.enumeration(components);
}
/**
* Will return header names which were in original request and will append
* all the header names which were in authentication request cache entry
*/
@Override
public Enumeration<String> getHeaderNames() {
List<String> list = new ArrayList<String>();
for (Enumeration<String> headerNames = super.getHeaderNames(); headerNames.
hasMoreElements(); ) {
list.add(headerNames.nextElement());
}
for (String keys : modifiableHeaders.keySet()) {
list.add(keys);
}
return Collections.enumeration(list);
}
public void test_enumerationLjava_util_Collection() {
// Test for method java.util.Enumeration
// java.util.Collections.enumeration(java.util.Collection)
TreeSet ts = new TreeSet();
ts.addAll(s);
Enumeration e = Collections.enumeration(ts);
int count = 0;
while (e.hasMoreElements()) {
assertEquals("Returned incorrect enumeration", e.nextElement(),
objArray[count++]);
}
assertEquals("Enumeration missing elements: " + count, objArray.length,
count);
}
/**
* Returns an enumeration of all the FilePermission objects in the
* container.
*
* @return an enumeration of all the FilePermission objects.
*/
public Enumeration elements() {
// Convert Iterator into Enumeration
synchronized (this) {
return Collections.enumeration(perms);
}
}
@Override
public Enumeration<String> getAttributeNames() {
return Collections.enumeration(routingContext.data().keySet());
}
@Override
public Enumeration<String> getInitParameterNames() {
return Collections.enumeration(this.initParameters.keySet());
}
@Override
public Enumeration<String> getHeaderNames() {
return Collections.enumeration(this.headers.keySet());
}
public Enumeration<TreeNode> children() {
List<TreeNode> addressTreeNodes = getAddressTreeNodes();
return Collections.enumeration(addressTreeNodes);
}
@Override
public Enumeration<String> getAttributeNames() {
return Collections.enumeration(attributes.keySet());
}
@Override
public Enumeration<?> propertyNames() {
return Collections.enumeration(propertyNames);
}
@Override
public Enumeration<String> getAttributeNames() {
return Collections.enumeration(new LinkedHashSet<>(this.attributes.keySet()));
}
@Override
public Enumeration<String> getAttributeNames() {
return Collections.enumeration(attributes.keySet());
}