Dolda2000 GitWeb
/
jglob.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
01e70f6
)
Added ability to implicitly cast instances from the Loader.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Tue, 12 Mar 2013 21:39:00 +0000
(22:39 +0100)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Tue, 12 Mar 2013 21:39:00 +0000
(22:39 +0100)
src/dolda/jglob/Loader.java
patch
|
blob
|
blame
|
history
diff --git
a/src/dolda/jglob/Loader.java
b/src/dolda/jglob/Loader.java
index
528c3fb
..
82a47b5
100644
(file)
--- a/
src/dolda/jglob/Loader.java
+++ b/
src/dolda/jglob/Loader.java
@@
-8,7
+8,6
@@
import java.lang.annotation.*;
public class Loader {
private final Class<? extends Annotation> an;
private final ClassLoader cl;
public class Loader {
private final Class<? extends Annotation> an;
private final ClassLoader cl;
- private final Map<Class<?>, Object> instances = new HashMap<Class<?>, Object>();
private Loader(Class<? extends Annotation> annotation, ClassLoader loader) {
this.an = annotation;
private Loader(Class<? extends Annotation> annotation, ClassLoader loader) {
this.an = annotation;
@@
-113,21
+112,21
@@
public class Loader {
});
}
});
}
- public
Iterable<?> instances(
) {
- return(new Iterable<
Object
>() {
- public Iterator<
Object
> iterator() {
- return(new Iterator<
Object
>() {
+ public
<T> Iterable<T> instances(final Class<T> cast
) {
+ return(new Iterable<
T
>() {
+ public Iterator<
T
> iterator() {
+ return(new Iterator<
T
>() {
private final Iterator<Class<?>> classes = classes().iterator();
private final Iterator<Class<?>> classes = classes().iterator();
- private
Object
n = null;
+ private
T
n = null;
public boolean hasNext() {
while(n == null) {
if(!classes.hasNext())
return(false);
Class<?> cl = classes.next();
public boolean hasNext() {
while(n == null) {
if(!classes.hasNext())
return(false);
Class<?> cl = classes.next();
-
Object
inst;
+
T
inst;
try {
try {
- inst = c
l.newInstance(
);
+ inst = c
ast.cast(cl.newInstance()
);
} catch(InstantiationException e) {
throw(new GlobInstantiationException(e));
} catch(IllegalAccessException e) {
} catch(InstantiationException e) {
throw(new GlobInstantiationException(e));
} catch(IllegalAccessException e) {
@@
-138,10
+137,10
@@
public class Loader {
return(true);
}
return(true);
}
- public
Object
next() {
+ public
T
next() {
if(!hasNext())
throw(new NoSuchElementException());
if(!hasNext())
throw(new NoSuchElementException());
-
Object
r = n;
+
T
r = n;
n = null;
return(r);
}
n = null;
return(r);
}
@@
-152,6
+151,10
@@
public class Loader {
});
}
});
}
+ public Iterable<?> instances() {
+ return(instances(Object.class));
+ }
+
public static Loader get(Class<? extends Annotation> annotation, ClassLoader loader) {
return(new Loader(annotation, loader));
}
public static Loader get(Class<? extends Annotation> annotation, ClassLoader loader) {
return(new Loader(annotation, loader));
}