Search in sources :

Example 1 with Identified

use of pcgen.cdom.base.Identified in project pcgen by PCGen.

the class CoreUtils method getLoadID.

private static <T> String getLoadID(T obj) {
    if (obj instanceof Identified) {
        Identified l = (Identified) obj;
        String name = l.getDisplayName();
        String id = obj.getClass().getSimpleName() + ": " + name;
        if (!l.getKeyName().equals(name)) {
            id = id + " [" + l.getKeyName() + "]";
        }
        return id;
    } else if (obj instanceof QualifiedObject) {
        QualifiedObject<?> qo = (QualifiedObject<?>) obj;
        return getLoadID(qo.getRawObject());
    } else if (obj instanceof CDOMReference) {
        CDOMReference<?> ref = (CDOMReference<?>) obj;
        return ref.getReferenceClass().getSimpleName() + " Primitive: " + ref.getLSTformat(false);
    } else {
        return obj.getClass().getSimpleName() + ": " + obj.toString();
    }
}
Also used : Identified(pcgen.cdom.base.Identified) QualifiedObject(pcgen.core.QualifiedObject) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 2 with Identified

use of pcgen.cdom.base.Identified in project pcgen by PCGen.

the class CoreUtils method buildCoreDebugList.

static <T> List<CoreViewNodeFacade> buildCoreDebugList(PlayerCharacter pc, CorePerspective pers) {
    CharID id = pc.getCharID();
    List<CoreViewNodeFacade> coreViewList = new ArrayList<>();
    Collection<Object> locations = CorePerspectiveDB.getLocations(pers);
    MapToList<Object, FacetView<T>> sources = new HashMapToList<>();
    Map<FacetView<T>, CoreViewNodeBase> facetToNode = new HashMap<>();
    /*
		 * Create the nodes that are part of this perspective.
		 */
    for (Object location : locations) {
        //Create (w/ identifier)
        FacetView<T> view = CorePerspectiveDB.getView(pers, location);
        CoreViewNodeBase node = new LocationCoreViewNode<>(location);
        facetToNode.put(view, node);
        coreViewList.add(node);
        //Store what facets listen to my content (for use later)
        for (Object listener : view.getChildren()) {
            Object lView = CorePerspectiveDB.getViewOfFacet(listener);
            Object src = (lView == null) ? listener : lView;
            sources.addToListFor(src, view);
        }
        Collection<Object> parents = CorePerspectiveDB.getVirtualParents(view);
        if (parents != null) {
            for (Object parent : parents) {
                FacetView<T> parentView = CorePerspectiveDB.getViewOfFacet(parent);
                if (parentView == null) {
                    Logging.errorPrint("Expected " + parent + " to be a registered Facet in Perspective " + pers);
                }
                sources.addToListFor(view, parentView);
            }
        }
    }
    for (Object location : locations) {
        FacetView<T> view = CorePerspectiveDB.getView(pers, location);
        CoreViewNodeBase node = facetToNode.get(view);
        /*
			 * Check the source of each child to identify if:
			 * 
			 * (a) The source is a Loadable that can thus be identified as such
			 * 
			 * (b) The source is a known facet (and thus is identified as such)
			 * 
			 * (c) the source is not something recognized
			 */
        for (T obj : view.getSet(id)) {
            List<String> sourceDesc = new ArrayList<>();
            for (Object src : view.getSources(id, obj)) {
                if (src instanceof Identified) {
                    sourceDesc.add(getLoadID(src));
                } else {
                    FacetView<Object> srcView = CorePerspectiveDB.getViewOfFacet(src);
                    if (srcView == null) {
                        //Not a recognized view
                        sourceDesc.add("Orphaned [" + src.getClass().getSimpleName() + "]");
                    } else if (facetToNode.get(srcView) == null) {
                        //A View, but not part of this perspective
                        sourceDesc.add("Other Perspective [" + CorePerspectiveDB.getPerspectiveOfFacet(src) + ": " + srcView.getDescription() + "]");
                    }
                }
            }
            //Insert the contents of the facet as children of this node
            ObjectCoreViewNode<T> sourceNode = new ObjectCoreViewNode<>(pc, obj, sourceDesc);
            sourceNode.addGrantedByNode(node);
            coreViewList.add(sourceNode);
        }
    }
    /*
		 * For each location, put sources as children in the tree
		 */
    for (Object location : locations) {
        FacetView<T> view = CorePerspectiveDB.getView(pers, location);
        CoreViewNodeBase node = facetToNode.get(view);
        List<FacetView<T>> facetInputs = sources.getListFor(view);
        if (facetInputs != null) {
            for (FacetView<T> facet : facetInputs) {
                facetToNode.get(facet).addGrantedByNode(node);
            }
        }
    }
    return coreViewList;
}
Also used : Identified(pcgen.cdom.base.Identified) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FacetView(pcgen.cdom.meta.FacetView) CharID(pcgen.cdom.enumeration.CharID) CoreViewNodeFacade(pcgen.facade.core.CoreViewNodeFacade) HashMapToList(pcgen.base.util.HashMapToList) PrereqObject(pcgen.cdom.base.PrereqObject) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) CoreViewNodeBase(pcgen.cdom.meta.CoreViewNodeBase)

Aggregations

Identified (pcgen.cdom.base.Identified)2 QualifiedObject (pcgen.core.QualifiedObject)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashMapToList (pcgen.base.util.HashMapToList)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 PrereqObject (pcgen.cdom.base.PrereqObject)1 CharID (pcgen.cdom.enumeration.CharID)1 CoreViewNodeBase (pcgen.cdom.meta.CoreViewNodeBase)1 FacetView (pcgen.cdom.meta.FacetView)1 CoreViewNodeFacade (pcgen.facade.core.CoreViewNodeFacade)1