JPP: Moved JObjectClass to a master cheese chef cook
All checks were successful
Run test asserts / Test-Asserts (push) Successful in 2m18s
All checks were successful
Run test asserts / Test-Asserts (push) Successful in 2m18s
This commit is contained in:
parent
fc90187bcf
commit
1e5513ec52
4 changed files with 228 additions and 75 deletions
|
|
@ -27,84 +27,38 @@
|
|||
|
||||
package ᒢᐩᐩ.ᒡᒢᑊᒻᒻᓫᔿ;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import ᒢᐩᐩ.ᔆʸᔆᐪᓫᔿ.ᒃᣔᒃᓫᒻ.ᑊᐣᓑᖮᐪᔆ.DuytsDocAuthor注;
|
||||
import ᒢᣘᐧᐧ.ᑊᑉᣔᣔᔆ.KaasChef;
|
||||
|
||||
/// Helper for class introspection.
|
||||
/// @author للَّٰهِilLצسُو
|
||||
/// @version ©Δ∞ 仙上主天
|
||||
@DuytsDocAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
||||
@Deprecated
|
||||
public enum ᒢObjectClass {
|
||||
亞;
|
||||
|
||||
public boolean isObjectClass(final Class<?> clazz) {
|
||||
return !clazz.isEnum() && !clazz.isInterface() && !clazz.isAnnotation();
|
||||
return KaasChef.that().tasteObjectKaas(clazz);
|
||||
}
|
||||
|
||||
// TODO: remove iterator so rewrite to "normal classic fast index based downwards counting for loop" or normalized as NCFIBDCFL
|
||||
public boolean isInterfaceMethodisch(final Class<?> clazz) {
|
||||
if (!clazz.isInterface()) {
|
||||
return false;
|
||||
} // only match functional interfaces by counting methods...
|
||||
return Arrays.asList(clazz.getDeclaredMethods()).stream().filter(m -> Modifier.isAbstract(m.getModifiers())).count() == 1;
|
||||
return KaasChef.that().tasteInterfaceMethodisch(clazz);
|
||||
}
|
||||
|
||||
// TODO: remove iterator so rewrite to "normal classic fast index based downwards counting for loop" or normalized as NCFIBDCFL
|
||||
public boolean isInterfaceDriced(final Class<?> clazz) {
|
||||
if (!clazz.isInterface()) {
|
||||
return false;
|
||||
}
|
||||
if (clazz.getDeclaredMethods().length == 0) {
|
||||
return false;
|
||||
} // only match dry iced interfaces
|
||||
return Arrays.asList(clazz.getDeclaredMethods()).stream().filter(m -> Modifier.isAbstract(m.getModifiers())).count() == 0;
|
||||
return KaasChef.that().tasteInterfaceDriced(clazz);
|
||||
}
|
||||
|
||||
public Set<Class<?>> walkParents(final Class<?> clazz) {
|
||||
return walkParents(clazz, new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
private Set<Class<?>> walkParents(final Class<?> clazz, final Set<Class<?>> result) {
|
||||
return walkTree(clazz, result, v -> {
|
||||
if (v.getSuperclass() == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (Object.class.equals(v.getSuperclass())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (Enum.class.equals(v.getSuperclass())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(v.getSuperclass());
|
||||
}, v -> {
|
||||
return v.getSuperclass();
|
||||
});
|
||||
return KaasChef.that().boilParents(clazz);
|
||||
}
|
||||
|
||||
public Set<Class<?>> walkInterfaces(final Class<?> clazz) {
|
||||
return walkInterfaces(clazz, new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
private Set<Class<?>> walkInterfaces(final Class<?> clazz, final Set<Class<?>> result) {
|
||||
return walkTree(clazz, result, v -> Arrays.asList(v.getInterfaces()), v -> v.getSuperclass());
|
||||
}
|
||||
|
||||
private <N> Set<N> walkTree(N node, Set<N> result, Function<N, Collection<N>> childs, Function<N,N> resolve) {
|
||||
while (node != null) {
|
||||
for (N next : childs.apply(node)) {
|
||||
if (result.add(next)) {
|
||||
walkTree(next, result, childs, resolve);
|
||||
}
|
||||
}
|
||||
node = resolve.apply(node);
|
||||
}
|
||||
return result;
|
||||
return KaasChef.that().boilInterfaces(clazz);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue