use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.UnParameterization in project elki by elki-project.
the class DocumentParameters method buildParameterIndex.
private static void buildParameterIndex(Map<Class<?>, List<Parameter<?>>> byclass, Map<OptionID, List<Pair<Parameter<?>, Class<?>>>> byopt) {
final ArrayList<TrackedParameter> options = new ArrayList<>();
ExecutorService es = Executors.newSingleThreadExecutor();
List<Class<?>> objs = ELKIServiceRegistry.findAllImplementations(Object.class, false, true);
Collections.sort(objs, new ELKIServiceScanner.ClassSorter());
Class<?> appc = appBaseClass();
for (final Class<?> cls : objs) {
// Doesn't have a proper name?
if (cls.getCanonicalName() == null) {
continue;
}
// constructors / parameterizers and may start AWT threads - skip them.
if (appc != null && appc.isAssignableFrom(cls)) {
continue;
}
UnParameterization config = new UnParameterization();
TrackParameters track = new TrackParameters(config, cls);
try {
// Wait up to one second.
es.submit(new //
FutureTask<Object>(new Instancer(cls, track, options), //
null)).get(1L, TimeUnit.SECONDS);
} catch (TimeoutException e) {
LOG.warning("Timeout on instantiating " + cls.getName());
es.shutdownNow();
throw new RuntimeException(e);
} catch (Exception e) {
LOG.warning("Error instantiating " + cls.getName(), e.getCause());
continue;
}
}
LOG.debug("Documenting " + options.size() + " parameter instances.");
for (TrackedParameter pp : options) {
if (pp.getOwner() == null || pp.getParameter() == null) {
LOG.debugFiner("Null: " + pp.getOwner() + " " + pp.getParameter());
continue;
}
Class<?> c = (Class<?>) ((pp.getOwner() instanceof Class) ? pp.getOwner() : pp.getOwner().getClass());
Parameter<?> o = pp.getParameter();
// just collect unique occurrences
{
List<Parameter<?>> byc = byclass.get(c);
boolean inlist = false;
if (byc != null) {
for (Parameter<?> par : byc) {
if (par.getOptionID() == o.getOptionID()) {
inlist = true;
break;
}
}
}
if (!inlist) {
List<Parameter<?>> ex = byclass.get(c);
if (ex == null) {
byclass.put(c, ex = new ArrayList<>());
}
ex.add(o);
}
}
{
List<Pair<Parameter<?>, Class<?>>> byo = byopt.get(o.getOptionID());
boolean inlist = false;
if (byo != null) {
for (Pair<Parameter<?>, Class<?>> pair : byo) {
if (pair.second.equals(c)) {
inlist = true;
break;
}
}
}
if (!inlist) {
List<Pair<Parameter<?>, Class<?>>> ex = byopt.get(o.getOptionID());
if (ex == null) {
byopt.put(o.getOptionID(), ex = new ArrayList<>());
}
ex.add(new Pair<Parameter<?>, Class<?>>(o, c));
}
}
}
}
Aggregations