Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright SpringSource Inc 2007,2009.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.springsource.util.common;
An IterableEnumeration wraps an java.util.Enumeration in an implementation of java.lang.Iterable thereby allowing the Enumeration to be used in a for-each loop.

 Enumeration<Foo> enumeration = ...
 IterableEnumeration<Foo> foos = new IterableEnumeration<Foo>(enumeration);
 
 for (Foo foo : foos) {
     // Do something with foo
 }
 

Note: as Enumerations do not support entry removal the java.util.Iterator returned by iterator() does not support the optional remove method: invocation of the method will result in an java.lang.UnsupportedOperationException being thrown. Concurrent Semantics
This class is not thread-safe.

Parameters:
<T> the element type of the enumeration
Since:
Jersey
public class IterableEnumeration<T> implements Iterable<T> {
    
    private final Iterator<T> iterator;
    
    
Creates a new IterableEnumeration backed by the supplied Enumeration

Parameters:
enumeration The Enumeration to be made iterable.
    public IterableEnumeration(Enumeration<T> enumeration) {
        this. = new EnumerationIterator<T>(enumeration);
    }

    
Returns the Enumeration-backed Iterator.

Note: as Enumerations do not support entry removal the returned java.util.Iterator does not support the optional remove method: invocation of the method will result in an java.lang.UnsupportedOperationException being thrown.

    public Iterator<T> iterator() {
        return ;
    }
    
    private class EnumerationIterator<E> implements Iterator<E> {
        
        private final Enumeration<E> enumeration;
        
        private EnumerationIterator(Enumeration<E> enumeration) {
            this. = enumeration;
        }
        public boolean hasNext() {
            return this..hasMoreElements();
        }
        public E next() {
            return this..nextElement();
        }
        public void remove() {
            throw new UnsupportedOperationException();
            
        }       
    }
New to GrepCode? Check out our FAQ X