aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-09-23 07:43:43 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-09-23 07:43:43 +0200
commit21ea5eeca8448c8880a3f2d975dee3107e3175b3 (patch)
treeda324c234213102b5148fc43b0da82169cf9179c /src/lombok/core
parentec38e1a51be7d0d807faa15b7c1504063c1061d6 (diff)
downloadlombok-21ea5eeca8448c8880a3f2d975dee3107e3175b3.tar.gz
lombok-21ea5eeca8448c8880a3f2d975dee3107e3175b3.tar.bz2
lombok-21ea5eeca8448c8880a3f2d975dee3107e3175b3.zip
Slight tweak to SpiLoadUtil: It now returns iterables instead of iterators.
Diffstat (limited to 'src/lombok/core')
-rw-r--r--src/lombok/core/SpiLoadUtil.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/lombok/core/SpiLoadUtil.java b/src/lombok/core/SpiLoadUtil.java
index c28f8c23..9f047c22 100644
--- a/src/lombok/core/SpiLoadUtil.java
+++ b/src/lombok/core/SpiLoadUtil.java
@@ -61,7 +61,7 @@ public class SpiLoadUtil {
*
* @param target class to find implementations for.
*/
- public static <C> Iterator<C> findServices(Class<C> target) throws IOException {
+ public static <C> Iterable<C> findServices(Class<C> target) throws IOException {
return findServices(target, Thread.currentThread().getContextClassLoader());
}
@@ -75,7 +75,7 @@ public class SpiLoadUtil {
* @param loader The classloader object to use to both the spi discovery files, as well as the loader to use
* to make the returned instances.
*/
- public static <C> Iterator<C> findServices(final Class<C> target, final ClassLoader loader) throws IOException {
+ public static <C> Iterable<C> findServices(final Class<C> target, final ClassLoader loader) throws IOException {
Enumeration<URL> resources = loader.getResources("META-INF/services/" + target.getName());
final Set<String> entries = new LinkedHashSet<String>();
while ( resources.hasMoreElements() ) {
@@ -84,21 +84,25 @@ public class SpiLoadUtil {
}
final Iterator<String> names = entries.iterator();
- return new Iterator<C>() {
- public boolean hasNext() {
- return names.hasNext();
- }
-
- public C next() {
- try {
- return target.cast(Class.forName(names.next(), true, loader).newInstance());
- } catch ( Throwable t ) {
- throw Lombok.sneakyThrow(t);
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
+ return new Iterable<C> () {
+ @Override public Iterator<C> iterator() {
+ return new Iterator<C>() {
+ @Override public boolean hasNext() {
+ return names.hasNext();
+ }
+
+ @Override public C next() {
+ try {
+ return target.cast(Class.forName(names.next(), true, loader).newInstance());
+ } catch ( Throwable t ) {
+ throw Lombok.sneakyThrow(t);
+ }
+ }
+
+ @Override public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
}
};
}