PieceTreeCompiler - PendulumProject2020/PendulumProject GitHub Wiki
Version: 0.1.9+
public class PieceTreeCompiler
This class belongs to the main
package.
This class belongs to the Methodological layer.
The PieceTreeCompiler class carries out Piece Tree assembly in three steps:
ADD: The PieceTreeCompiler must first recognize the Piece subclasses it needs to assimilate. In this step, the static methods findAndAddObjectPieces and findAndAddMethodPieces are called with the full names of the classes. These methods will find the classes based on their names, add the classes to a list, create a map between simple class names and class objects, and create Piece projections encapsulating the Piece subclasses.
LOAD: Based on the available Piece bodies and slots, the PieceTreeCompiler assembles a Piece Tree from a root Piece. Each time it joins a PieceProjection onto the Piece Tree, it will only allow the PieceProjection to stay on the Piece Tree if it successfully fills all its slots (i.e. a depth-first search that must succeed at every step in order to continue). After all regular slots are filled up, it will try to assimilate leftover Piece projections by fitting them to mega-slots of Piece projections on the Piece Tree.
ACTIVATE: The PieceTreeCompiler iterates through the Piece projections on the Piece Tree. For each such Piece projection, the PieceTreeCompiler checks that all its dependent Piece subclasses have projections on the Piece Tree. This condition must be satisfied for all Piece projections on the Piece Tree.
After all three steps have been completed successfully, the program can call the "run" method on the root Piece. This transfers agency to the root Piece and brings the program out of the Methodological layer.
private static ArrayList<Class<Piece>> objectPieceList
The list of ObjectPiece subclasses that have been ADDED.
private static ArrayList<Class<Piece>> methodPieceList
The list of MethodPiece subclasses that have been ADDED.
private static Map<String, Class<Piece>> objectPieceNameToClassMap
The map from the simple names of ObjectPiece subclasses to the class objects.
private static Map<String, Class<Piece>> methodPieceNameToClassMap
The map from the simple names of MethodPiece subclasses to the class objects.
private static Map<Class<Piece>, Map<Class<Piece>, DataSet>> pieceClassToStaticDataSupersetMap
The collection of class-specific variables (in the form of data-sets) belonging to some piece class and associated with some other piece class.
private static Map<Class<?>, Map<String, DataSet>> pieceClassToStaticNamedDataSupersetMap
The collection of class-specific variables (in the form of data-sets) belonging to some piece class and associated with a name.
private static Class<Piece> rootClass
The Piece subclass occupying the root slot.
private static Map<Class<Piece>, PieceProjection> pieceClassToProjectionMap
The map from Piece subclasses to their respective Piece projections.
public static ArrayList<Class<Piece>> findAndAddObjectPieces(ArrayList<String> objectPieceNames)
Receives a list of ObjectPiece subclass names (each including package name); Attempts to find the class object for each of the names; If successful, adds the class object to the objectPieceList field, updates the objectPieceNameToClassMap field by creating a new entry with the simple class name as the key and the class object as the value, and updates the pieceClassToProjectionMap field by creating a new entry with the class object as the key and a newly created PieceProjection encapsulating the class object as the value.
public static ArrayList<Class<Piece>> findAndAddObjectPieces(String...objectPieceNames)
Receives a list of ObjectPiece subclass names (each including package name); Attempts to find the class object for each of the names; If successful, adds the class object to the objectPieceList field, updates the objectPieceNameToClassMap field by creating a new entry with the simple class name as the key and the class object as the value, and updates the pieceClassToProjectionMap field by creating a new entry with the class object as the key and a newly created PieceProjection encapsulating the class object as the value.
public static ArrayList<Class<Piece>> findAndAddMethodPieces(ArrayList<String> methodPieceNames)
Receives a list of MethodPiece subclass names (each including package name); Attempts to find the class object for each of the names; If successful, adds the class object to the methodPieceList field, updates the methodPieceNameToClassMap field by creating a new entry with the simple class name as the key and the class object as the value, and updates the pieceClassToProjectionMap field by creating a new entry with the class object as the key and a newly created PieceProjection encapsulating the class object as the value.
public static ArrayList<Class<Piece>> findAndAddMethodPieces(String...methodPieceNames)
Receives a list of MethodPiece subclass names (each including package name); Attempts to find the class object for each of the names; If successful, adds the class object to the methodPieceList field, updates the methodPieceNameToClassMap field by creating a new entry with the simple class name as the key and the class object as the value, and updates the pieceClassToProjectionMap field by creating a new entry with the class object as the key and a newly created PieceProjection encapsulating the class object as the value.
public static boolean loadPieceTree(Class<Piece> rootClass1)
Fits rootClass1 to the root slot. Using the already-established lists of Piece subclasses and Piece projections, constructs a Piece Tree by finding a matching piece for each empty slot. After all regular slots on the Piece Tree have been filled, attempts to join leftover PieceProjections to mega-slots.
public static boolean tryHostingAnyFreePieceToAMegaSlot()
Attempts to find PieceProjections not on the Piece Tree and join them to the mega-slots of those on the Piece Tree.
public static boolean loadPieceTree(String rootClassName)
Fits the Piece subclass corresponding to rootClassName to the root slot. Using the already-established lists of Piece subclasses and Piece projections, constructs a Piece Tree by finding a matching piece for each empty slot. After all regular slots on the Piece Tree have been filled, attempts to join leftover PieceProjections to mega-slots.
public static boolean tryToFillAllSlots(PieceProjection pieceProjection)
Attempts to fill all slots of pieceProjection, and repeats this method for each slot occupant. Returns true if all descendants of pieceProjection on the Piece Tree have their slots completely filled. Returns false otherwise.
public static PieceProjection GetFitFor(PieceProjection pieceProjection, String slotName)
Attempts to find a Piece projection that can fit the slot slotName of pieceProjection. If a candidate is found, fit the candidate to the slot and return the candidate. If not, return null.
public static Class<Piece> getSingleMethodSlotOccupant(Class<?> host, String slotName)
Returns the occupant of the method slot named slotName on host. If there are multiple method slots of the same name, returns the first occupant.
public static Class<Piece> getSingleObjectSlotOccupant(Class<?> host, String slotName)
Returns the occupant of the object slot named slotName on host. If there are multiple object slots of the same name, returns the first occupant.
public static DataSet extractAsDataSet(Class<?> requester, Class<?> target)
Returns the class-specific variable belonging to requester and associated with target.
public static DataSet extractAsDataSet(Class<?> requester, String parameterName)
Returns the class-specific variable belonging to requester and associated with parameterName.
public static Class<Piece> getObjectPieceClass(String objectPieceName)
Returns the ObjectPiece subclass having the simple name objectPieceName.
public static Class<Piece> getMethodPieceClass(String methodPieceName)
Returns the MethodPiece subclass having the simple name methodPieceName.
public static ArrayList<Class<Piece>> getObjectPieceList()
public static void setObjectPieceList(ArrayList<Class<Piece>> objectPieceList)
public static ArrayList<Class<Piece>> getMethodPieceList()
public static void setMethodPieceList(ArrayList<Class<Piece>> methodPieceList)
public static Map<Class<Piece>, Map<Class<Piece>, DataSet>> getPieceClassToStaticDataSupersetMap()
public static void setPieceClassToStaticDataSupersetMap(Map<Class<Piece>, Map<Class<Piece>, DataSet>> pieceClassToStaticDataSupersetMap)
public static Class<Piece> getRootClass()
public static void setRootClass(Class<Piece> rootClass)
public static void setPieceClassToProjectionMap(Map<Class<Piece>, PieceProjection> pieceClassToProjectionMap )
public static Map<Class<Piece>, PieceProjection> getPieceClassToProjectionMap()
public static Map<Class<?>, Map<String, DataSet>> getPieceClassToStaticNamedDataSupersetMap()
public static void setPieceClassToStaticNamedDataSupersetMap(Map<Class<?>, Map<String, DataSet>> pieceClassToStaticNamedDataSupersetMap)