71 */ 72 boolean hasMoreElements(); 73 74 /** 75 * Returns the next element of this enumeration if this enumeration 76 * object has at least one more element to provide. 77 * 78 * @return the next element of this enumeration. 79 * @throws NoSuchElementException if no more elements exist. 80 */ 81 E nextElement(); 82 83 /** 84 * Returns an {@link Iterator} that traverses the remaining elements 85 * covered by this enumeration. Traversal is undefined if any methods 86 * are called on this enumeration after the call to {@code asIterator}. 87 * 88 * @apiNote 89 * This method is intended to help adapt code that produces 90 * {@code Enumeration} instances to code that consumes {@code Iterator} 91 * instances. For example, the {@link java.util.jar.JarFile#entries 92 * JarFile.entries()} method returns an {@code Enumeration<JarEntry>}. 93 * This can be turned into an {@code Iterator}, and then the 94 * {@code forEachRemaining()} method can be used: 95 * 96 * <pre>{@code 97 * JarFile jarFile = ... ; 98 * jarFile.entries().asIterator().forEachRemaining(entry -> { ... }); 99 * }</pre> 100 * 101 * (Note that there is also a {@link java.util.jar.JarFile#stream 102 * JarFile.stream()} method that returns a {@code Stream} of entries, 103 * which may be more convenient in some cases.) 104 * 105 * @implSpec 106 * The default implementation returns an {@code Iterator} whose 107 * {@link Iterator#hasNext hasNext} method calls this Enumeration's 108 * {@code hasMoreElements} method, whose {@link Iterator#next next} 109 * method calls this Enumeration's {@code nextElement} method, and 110 * whose {@link Iterator#remove remove} method throws 111 * {@code UnsupportedOperationException}. 112 * 113 * @return an Iterator representing the remaining elements of this Enumeration 114 * 115 * @since 9 116 */ 117 default Iterator<E> asIterator() { 118 return new Iterator<>() { 119 @Override public boolean hasNext() { 120 return hasMoreElements(); 121 } | 71 */ 72 boolean hasMoreElements(); 73 74 /** 75 * Returns the next element of this enumeration if this enumeration 76 * object has at least one more element to provide. 77 * 78 * @return the next element of this enumeration. 79 * @throws NoSuchElementException if no more elements exist. 80 */ 81 E nextElement(); 82 83 /** 84 * Returns an {@link Iterator} that traverses the remaining elements 85 * covered by this enumeration. Traversal is undefined if any methods 86 * are called on this enumeration after the call to {@code asIterator}. 87 * 88 * @apiNote 89 * This method is intended to help adapt code that produces 90 * {@code Enumeration} instances to code that consumes {@code Iterator} 91 * instances. For example, the {@link java.util.jar.JarFile#entries() 92 * JarFile.entries()} method returns an {@code Enumeration<JarEntry>}. 93 * This can be turned into an {@code Iterator}, and then the 94 * {@code forEachRemaining()} method can be used: 95 * 96 * <pre>{@code 97 * JarFile jarFile = ... ; 98 * jarFile.entries().asIterator().forEachRemaining(entry -> { ... }); 99 * }</pre> 100 * 101 * (Note that there is also a {@link java.util.jar.JarFile#stream() 102 * JarFile.stream()} method that returns a {@code Stream} of entries, 103 * which may be more convenient in some cases.) 104 * 105 * @implSpec 106 * The default implementation returns an {@code Iterator} whose 107 * {@link Iterator#hasNext hasNext} method calls this Enumeration's 108 * {@code hasMoreElements} method, whose {@link Iterator#next next} 109 * method calls this Enumeration's {@code nextElement} method, and 110 * whose {@link Iterator#remove remove} method throws 111 * {@code UnsupportedOperationException}. 112 * 113 * @return an Iterator representing the remaining elements of this Enumeration 114 * 115 * @since 9 116 */ 117 default Iterator<E> asIterator() { 118 return new Iterator<>() { 119 @Override public boolean hasNext() { 120 return hasMoreElements(); 121 } |