Compare commits
No commits in common. "c0da5ee75daca8794b67f63a42772b374ad079f7" and "2cd14d4a5dc9ff32d9847344fd8205de30bce491" have entirely different histories.
c0da5ee75d
...
2cd14d4a5d
@ -6,7 +6,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "net.tomatentum.cutin"
|
group = "net.tomatentum.cutin"
|
||||||
version = "0.1.1" + (if (!project.hasProperty("release")) ("-" + getGitHash()) else "")
|
version = "0.1.0" + (if (!project.hasProperty("release")) ("-" + getGitHash()) else "")
|
||||||
description = "A lightweight Reflection abstraction specifically but not exclusively made for tueem/Marinara."
|
description = "A lightweight Reflection abstraction specifically but not exclusively made for tueem/Marinara."
|
||||||
plugins.withType<JavaPlugin> {
|
plugins.withType<JavaPlugin> {
|
||||||
tasks.withType<Jar>().configureEach {
|
tasks.withType<Jar>().configureEach {
|
||||||
|
@ -6,7 +6,6 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.ReflectedMethod;
|
import net.tomatentum.cutin.ReflectedMethod;
|
||||||
import net.tomatentum.cutin.ReflectedMethodFactory;
|
import net.tomatentum.cutin.ReflectedMethodFactory;
|
||||||
@ -22,22 +21,15 @@ public class LoneMethodContainer<I extends Object> implements MethodContainer<I>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodContainer<I> addMethod(ReflectedMethod<I> method) {
|
public void addMethods(ReflectedMethod<I>... methods) {
|
||||||
this.methodStore.put(method.identifier(), method);
|
for (ReflectedMethod<I> reflectedMethod : methods)
|
||||||
return this;
|
this.methodStore.put(reflectedMethod.identifier(), reflectedMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodContainer<I> addMethods(Object containingObject, Method... methods) {
|
public void addMethods(Object containingObject, Method... methods) {
|
||||||
for (Method method : methods)
|
for (Method method : methods)
|
||||||
this.factory.produce(method, containingObject)
|
this.addMethods(this.factory.produce(method, containingObject));
|
||||||
.ifPresent(this::addMethod);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<I> identifiers() {
|
|
||||||
return methodStore.keySet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,26 +3,17 @@ package net.tomatentum.cutin.container;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.tomatentum.cutin.ReflectedMethod;
|
import net.tomatentum.cutin.ReflectedMethod;
|
||||||
|
|
||||||
public interface MethodContainer<I extends Object> {
|
public interface MethodContainer<I extends Object> {
|
||||||
|
|
||||||
MethodContainer<I> addMethod(ReflectedMethod<I> method);
|
void addMethods(ReflectedMethod<I>... methods);
|
||||||
default MethodContainer<I> addMethods(ReflectedMethod<I>[] methods) {
|
void addMethods(Object containingObject, Method... methods);
|
||||||
for (ReflectedMethod<I> reflectedMethod : methods) {
|
default void addAllMethods(Object containingObject) {
|
||||||
this.addMethod(reflectedMethod);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
MethodContainer<I> addMethods(Object containingObject, Method... methods);
|
|
||||||
default MethodContainer<I> addAllMethods(Object containingObject) {
|
|
||||||
this.addMethods(containingObject, containingObject.getClass().getDeclaredMethods());
|
this.addMethods(containingObject, containingObject.getClass().getDeclaredMethods());
|
||||||
return this;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
Set<I> identifiers();
|
|
||||||
Collection<ReflectedMethod<I>> methods();
|
Collection<ReflectedMethod<I>> methods();
|
||||||
Collection<ReflectedMethod<I>> findFor(I identifier);
|
Collection<ReflectedMethod<I>> findFor(I identifier);
|
||||||
Optional<ReflectedMethod<I>> findFirstFor(I identifier);
|
Optional<ReflectedMethod<I>> findFirstFor(I identifier);
|
||||||
|
@ -5,7 +5,6 @@ import java.util.Collection;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -25,28 +24,20 @@ public class MultiMethodContainer<I extends Object> implements MethodContainer<I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodContainer<I> addMethod(ReflectedMethod<I> method) {
|
public void addMethods(ReflectedMethod<I>... methods) {
|
||||||
|
for (ReflectedMethod<I> rMethod : methods) {
|
||||||
Optional<Entry<I>> oentry = this.entries.stream()
|
Optional<Entry<I>> oentry = this.entries.stream()
|
||||||
.filter(e -> method.identifier().equals(e.identifier()))
|
.filter(e -> rMethod.identifier().equals(e.identifier()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
Entry<I> entry = oentry.orElse(new Entry<>(method.identifier())).addMethod(method);
|
Entry<I> entry = oentry.orElse(new Entry<>(rMethod.identifier())).addMethod(rMethod);
|
||||||
if (oentry.isEmpty()) this.entries.add(entry);
|
if (oentry.isEmpty()) this.entries.add(entry);
|
||||||
return this;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodContainer<I> addMethods(Object containingObject, Method... methods) {
|
public void addMethods(Object containingObject, Method... methods) {
|
||||||
for (Method method : methods)
|
for (Method method : methods)
|
||||||
this.factory.produce(method, containingObject)
|
this.addMethods(this.factory.produce(method, containingObject));
|
||||||
.ifPresent(this::addMethod);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<I> identifiers() {
|
|
||||||
return entries().stream()
|
|
||||||
.map(Entry::identifier)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,10 +63,6 @@ public class MultiMethodContainer<I extends Object> implements MethodContainer<I
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<Entry<I>> entries() {
|
|
||||||
return this.entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static record Entry<I extends Object>(I identifier, Set<ReflectedMethod<I>> methods) {
|
public static record Entry<I extends Object>(I identifier, Set<ReflectedMethod<I>> methods) {
|
||||||
|
|
||||||
public Entry(I identifier) {
|
public Entry(I identifier) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user