![JAR search and dependency download from the Maven repository](/logo.png)
org.ggp.base.util.reflection.ProjectSearcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alloy-ggp-base Show documentation
Show all versions of alloy-ggp-base Show documentation
A modified version of the GGP-Base library for Alloy.
The newest version!
package org.ggp.base.util.reflection;
import java.lang.reflect.Modifier;
import org.ggp.base.apps.kiosk.GameCanvas;
import org.ggp.base.player.gamer.Gamer;
import org.reflections.Reflections;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
public class ProjectSearcher {
private ProjectSearcher() {
}
public static void main(String[] args)
{
System.out.println(GAMERS);
System.out.println(GAME_CANVASES);
}
private static final Reflections REFLECTIONS = new Reflections();
public static final LoadedClasses GAMERS = new LoadedClasses(Gamer.class);
public static final LoadedClasses GAME_CANVASES = new LoadedClasses(GameCanvas.class);
public static final ImmutableSet> getAllClassesThatAre(Class klass) {
return new LoadedClasses(klass).getConcreteClasses();
}
public static class LoadedClasses {
private static Predicate> IS_CONCRETE_CLASS = new Predicate>() {
@Override
public boolean apply(Class> klass) {
return !Modifier.isAbstract(klass.getModifiers());
}
};
private final Class interfaceClass;
private final ImmutableSet> allClasses;
private final ImmutableSet> concreteClasses;
private LoadedClasses(Class interfaceClass) {
this.interfaceClass = interfaceClass;
this.allClasses = ImmutableSet.copyOf(REFLECTIONS.getSubTypesOf(interfaceClass));
this.concreteClasses = ImmutableSet.copyOf(Sets.filter(allClasses, IS_CONCRETE_CLASS));
}
public Class getInterfaceClass() {
return interfaceClass;
}
public ImmutableSet> getConcreteClasses() {
return concreteClasses;
}
public ImmutableSet> getAllClasses() {
return allClasses;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("allClasses", allClasses)
.add("interfaceClass", interfaceClass)
.add("concreteClasses", concreteClasses)
.toString();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy