feat(container): add MethodContainers
This commit is contained in:
3 files changed
+186
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package net.tomatentum.cutin.container;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.tomatentum.cutin.ReflectedMethod;
|
||||
import net.tomatentum.cutin.ReflectedMethodFactory;
|
||||
|
||||
public class LoneMethodContainer<I extends Object> implements MethodContainer<I> {
|
||||
|
||||
private Map<I, ReflectedMethod<I>> methodStore;
|
||||
private ReflectedMethodFactory factory;
|
||||
|
||||
public LoneMethodContainer(ReflectedMethodFactory factory) {
|
||||
this.methodStore = new HashMap<>();
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMethods(ReflectedMethod<I>... methods) {
|
||||
for (ReflectedMethod<I> reflectedMethod : methods)
|
||||
this.methodStore.put(reflectedMethod.identifier(), reflectedMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMethods(Object containingObject, Method... methods) {
|
||||
for (Method method : methods)
|
||||
this.addMethods(this.factory.produce(method, containingObject));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ReflectedMethod<I>> methods() {
|
||||
return this.methodStore.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ReflectedMethod<I>> findFor(I identifier) {
|
||||
return Arrays.asList(this.methodStore.get(identifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ReflectedMethod<I>> findFirstFor(I identifier) {
|
||||
return findFor(identifier).stream().findFirst();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user