private static void findAtLevel(IModelObject mo, List<IConcept> ret, int level, int current, boolean filterAbstract) { IConcept k = KLAB.c(mo.getName()); if (!filterAbstract || !k.isAbstract()) { ret.add(k); } if (level < 0 || level < current) { for (IModelObject o : mo.getChildren()) { if (o instanceof IKnowledgeObject) { findAtLevel(o, ret, level, current + 1, filterAbstract); } } } }
/** * Return a (flat) list of all CONCRETE children up to the passed level of detail, * using the model object (stated) hierarchy and keeping the order of declaration * (depth- first if more levels are involved). * * @param baseType * @param level * @return concrete children at level */ public static List<IConcept> getConcreteChildrenAtLevel(IConcept baseType, int level) { List<IConcept> ret = new ArrayList<>(); INamespace ns = KLAB.MMANAGER.getNamespace(baseType.getConceptSpace()); if (ns == null) { return ret; } IModelObject mo = ns.getModelObject(baseType.getLocalName()); if (mo == null) { return ret; } findAtLevel(mo, ret, level, 0, true); return ret; }
/** * Return a (flat) list of all children up to the passed level of detail, using the * model object (stated) hierarchy and keeping the order of declaration (depth- first * if more levels are involved). Allows abstract concepts in the result - if only * concrete ones are desires, use {@link #getConcreteChildrenAtLevel} instead. * * @param baseType * @param level * @return all children at level */ public static List<IConcept> getChildrenAtLevel(IConcept baseType, int level) { List<IConcept> ret = new ArrayList<>(); INamespace ns = KLAB.MMANAGER.getNamespace(baseType.getConceptSpace()); if (ns == null) { return ret; } IModelObject mo = ns.getModelObject(baseType.getLocalName()); if (mo == null) { return ret; } findAtLevel(mo, ret, level, 0, false); return ret; }