diff --git a/.gitignore b/.gitignore index f337696a355703faf5d3e461fae483f1c7961795..cdde71e8288b6733b6449c09f9fe85573e424156 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,6 @@ /examples/DisShooting/nbproject/private/ /examples/DisDemo/nbproject/private/ /examples/DisDemo/build/ -/examples/DisDemo/dist/ \ No newline at end of file +/examples/DisDemo/dist/ +/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/private/ +/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/build/ diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/ExampleSimulationProgramDuran.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/ExampleSimulationProgramDuran.java new file mode 100644 index 0000000000000000000000000000000000000000..a602e022b833670fb7df1d866b3c09c6b7626f96 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/ExampleSimulationProgramDuran.java @@ -0,0 +1,504 @@ +/** + * Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. + * This work is provided under a BSD open-source license, see project license.html and license.txt + * @author brutzman@nps.edu + */ +package MV3500Cohort2022MayJune.homework2.Duran; + +import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; +import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.pdus.*; +import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; +import edu.nps.moves.dis7.utilities.DisTime; +import edu.nps.moves.dis7.utilities.PduFactory; +import edu.nps.moves.dis7.utilities.SimulationManager; +import edu.nps.moves.dis7.utilities.stream.PduRecorder; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** The purpose of this inheritable class is to provide an easily modifiable example simulation program + * that includes DIS-capable entities performing tasks of interest, and then reporting activity via PDUs + * to the network. + * Default program initialization includes PDU recording turned on by default. + * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt">ExampleSimulationProgramLog.txt</a> + */ +public class ExampleSimulationProgramDuran +{ + private boolean verboseComments = true; + static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3"; + static final int NETWORK_PORT_DEFAULT = 3000; + String networkAddress = NETWORK_ADDRESS_DEFAULT; + int networkPort = NETWORK_PORT_DEFAULT; + String thisHostName = "localhost"; + String DEFAULT_OUTPUT_DIRECTORY = "./pduLog"; + + /** seconds for real-time execution (not simulation time, which may or may not be the same) */ + double currentTimeStep = 2.0; // seconds + /** initial simulation time */ + double initialTime = 0.0; + /** current simulation time */ + double simulationTime; + + /** + * Output prefix to help with logging by identifying this class (can be overridden in subclass). + */ + protected static String TRACE_PREFIX; + + /* Declare DIS Protocol Data Unit (PDU) classes for simulation entities */ + + DisTime.TimestampStyle timestampStyle = DisTime.TimestampStyle.IEEE_ABSOLUTE; + PduFactory pduFactory = new PduFactory(timestampStyle); + + /** EntityID settings for entity 1 */ + protected EntityID entityID_1 = new EntityID(); + /** EntityID settings for entity 2 */ + protected EntityID entityID_2 = new EntityID(); + /** ESPDU for entity 1 */ + protected EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu(); + /** ESPDU for entity 2 */ + protected EntityStatePdu entityStatePdu_2 = pduFactory.makeEntityStatePdu(); + /** FirePdu for entity 1 first weapon (if any) */ + protected FirePdu firePdu_1a = pduFactory.makeFirePdu(); + /** FirePdu for entity 1 second weapon (if any) */ + protected FirePdu firePdu_1b = pduFactory.makeFirePdu(); + /** MunitionDescriptor for these weapons */ + protected MunitionDescriptor munitionDescriptor1 = new MunitionDescriptor(); + + /** this class instantiated as an object */ + SimulationManager simulationManager = new SimulationManager(); + + /** Get ready, get set... initialize simulation entities + */ + public void initializeSimulationEntities() + { + // Your model setup: define participants. who's who in this zoo? + // Assuming you keep track of entity objects... here is some support for for Entity 1. + + // PDU objects are already created, now set their values. + entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID; + + entityID_2.setSiteID(1).setApplicationID(2).setEntityID(4); // made-up example ID; + // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? + + entityStatePdu_1.setEntityID(entityID_1); + entityStatePdu_1.setForceId(ForceID.FRIENDLY); + entityStatePdu_1.setEntityType(new _001Poseidon()); // note import statement above + entityStatePdu_1.setMarking("Entity #1"); + entityStatePdu_1.getMarkingString(); // check + + entityStatePdu_2.setEntityID(entityID_2); + entityStatePdu_2.setForceId(ForceID.OPPOSING); + entityStatePdu_2.setEntityType(new _002Triton()); // note import statement above + entityStatePdu_2.setMarking("Entity #2"); + + // TODO how should we customize this munition? what is it for your simulation? + munitionDescriptor1.setQuantity(1); + firePdu_1a.setDescriptor(munitionDescriptor1).setRange(1000.0f); + + // TODO simulation management PDUs for startup, planning to design special class support +// simulationManager.addEntity(); + simulationManager.setDescriptor("ExampleSimulationProgram"); + simulationManager.addHost(thisHostName); + simulationManager.setDisThreadedNetworkInterface(disNetworkInterface); + } + + /** + * This runSimulationLoops() method is for you, a customizable programmer-modifiable + * code block for defining and running a new simulation of interest. + * + * Welcome! Other parts of this program handle bookkeeping and plumbing tasks so that + * you can focus on your model entities and activities. + * Expandable support includes DIS EntityStatePdu, FirePdu and CommentPdu all available for + * modification and sending in a simulation loop. + * Continuous improvement efforts seek to make this program as easy and straightforward + * as possible for DIS simulationists to use and adapt. + * All of the other methods are setup, teardown and configuration that you may find + * interesting, even helpful, but don't really have to worry about. + */ + @SuppressWarnings("SleepWhileInLoop") // yes we do that + public void runSimulationLoops () + { + try + { + final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out there! also avoid infinite loops. + int simulationLoopCount = 0; // variable, initialized at 0 + boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet? + + // TODO reset Clock Time to today's date and timestamp to zero, providing consistent outputs for each simulation run + + pduRecorder.setVerbose(true); + + initializeSimulationEntities(); + + simulationManager.simulationJoin(); + simulationManager.simulationStart(); + + // =================================================================================================== + // loop the simulation while allowed, programmer can set additional conditions to break out and finish + while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet? + { + simulationLoopCount++; // good practice: increment loop counter as first action in that loop + + // ============================================================================================= + // * your own simulation code starts here! * + // ============================================================================================= + + // are there any other variables to modify at the beginning of your loop? + + // compute a track, update an ESPDU, whatever it is that your model is doing... + + // Where is my entity? Insert changes in position; this sample only changes X position. + entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + 1.0); // 1m per timestep + + // decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoot at! + + // etc. etc. your code goes here for your simulation of interest + + // something happens between my simulation entities, la de da de da... + System.out.println ("... My simulation just did something, no really..."); + System.out.flush(); + + + // make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending) + narrativeMessage1 = "MV3500 ExampleSimulationProgram"; + narrativeMessage2 = "runSimulation() loop " + simulationLoopCount; + narrativeMessage3 = ""; // intentionally blank for testing + + // your loop termination condition goes here + if (simulationLoopCount > 4) // for example + { + simulationComplete = true; + } + // ============================================================================================= + // * your own simulation code is finished here! * + // ============================================================================================= + + // staying synchronized with timestep: wait duration for elapsed time in this loop + // Thread.sleep needs a (long) parameter for milliseconds, which are clumsy to use sometimes + Thread.sleep((long)(currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds + System.out.println ("... [Pausing for " + currentTimeStep + " seconds]"); + + // OK now send the status PDUs for this loop, and then continue + System.out.println ("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); + System.out.flush(); + sendAllPdusForLoopTimestep(entityStatePdu_1, firePdu_1a, currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + sendSinglePdu(entityStatePdu_2); // me too i.e. 2! + System.out.println ("... [PDUs successfully sent for this loop]"); + System.out.flush(); + + // =============================== + // current loop now finished, check whether to terminate if simulation complete, otherwise continue + if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good + { + System.out.println ("... [loop termination condition met, simulationComplete=" + simulationComplete + "]"); // ", final loopCount=" + loopCount + + System.out.flush(); + break; + } + } // end of simulation loop + // =================================================================================================== + + narrativeMessage2 = "runSimulation() completed successfully"; // all done + sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + System.out.println ("... [final CommentPdu successfully sent for simulation]"); + + // TODO simulation management PDUs + simulationManager.simulationStop(); + simulationManager.simulationLeave(); + } + catch (InterruptedException iex) // handle any exception that your code might choose to provoke! + { + Logger.getLogger(ExampleSimulationProgramDuran.class.getName()).log(Level.SEVERE, null, iex); + } + } + /* **************************** infrastructure code, modification is seldom needed ************************* */ + + String narrativeMessage1 = new String(); + String narrativeMessage2 = new String(); + String narrativeMessage3 = new String(); + + /* VariableRecordType enumerations have potential use with CommentPdu logs */ + /* TODO contrast to EntityType */ + VariableRecordType descriptionComment = VariableRecordType.DESCRIPTION; + VariableRecordType narrativeComment = VariableRecordType.COMPLETE_EVENT_REPORT; + VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS; + VariableRecordType currentTimeStepComment = VariableRecordType.APPLICATION_TIMESTEP; + VariableRecordType otherComment = VariableRecordType.OTHER; + + // class variables + DisThreadedNetworkInterface disNetworkInterface; + DisThreadedNetworkInterface.PduListener pduListener; + Pdu receivedPdu; + PduRecorder pduRecorder; + + /** + * Constructor design goal: additional built-in initialization conveniences can go here + * to keep student efforts focused on the runSimulation() method. + */ + public ExampleSimulationProgramDuran() + { + DisTime.setTimestampStyle(timestampStyle); + + try + { + thisHostName = InetAddress.getLocalHost().getHostName(); + System.out.println(TRACE_PREFIX + "thisHostName=" + thisHostName); + } + catch (UnknownHostException uhe) + { + System.out.println(TRACE_PREFIX + thisHostName + "not connected to network: " + uhe.getMessage()); + } + } + + /** + * Utility Constructor that allows your example simulation program to override default network address and port + * @param address network address to use + * @param port corresponding network port to use + */ + public ExampleSimulationProgramDuran(String address, int port) + { + super(); + + setNetworkAddress(address); + + setNetworkPort(port); + } + + /** + * get current networkAddress as a string + * @return the networkAddress + */ + public String getNetworkAddress() + { + return networkAddress; + } + /** + * set current networkAddress using a string + * @param newNetworkAddress the networkAddress to set + */ + public final void setNetworkAddress(String newNetworkAddress) + { + this.networkAddress = newNetworkAddress; + } + + /** + * get current networkPort + * @return the networkPort + */ + public int getNetworkPort() + { + return networkPort; + } + /** + * set current networkPort + * @param newNetworkPort the networkPort to set + */ + public final void setNetworkPort(int newNetworkPort) + { + this.networkPort = newNetworkPort; + } + /** + * Get timestampStyle used by PduFactory + * @return current timestampStyle + */ + public DisTime.TimestampStyle getTimestampStyle() + { + return timestampStyle; + } + /** + * Set timestampStyle used by PduFactory + * @param newTimestampStyle the timestampStyle to set + * @return same object to permit progressive setters + */ + public ExampleSimulationProgramDuran setTimestampStyle(DisTime.TimestampStyle newTimestampStyle) + { + timestampStyle = newTimestampStyle; + DisTime.setTimestampStyle(newTimestampStyle); + return this; + } + + /** + * Initialize network interface, choosing best available network interface + */ + public void setUpNetworkInterface() + { + disNetworkInterface = new DisThreadedNetworkInterface(getNetworkAddress(), getNetworkPort()); + disNetworkInterface.setDescriptor ("ExampleSimulationProgram pdu looping"); + + System.out.println("Network confirmation:" + + " address=" + disNetworkInterface.getAddress()+ // disNetworkInterface.getMulticastGroup() + + " port=" + disNetworkInterface.getPort()); // + disNetworkInterface.getDisPort()); + pduListener = new DisThreadedNetworkInterface.PduListener() + { + /** Callback handler for listener */ + @Override + public void incomingPdu(Pdu newPdu) + { + receivedPdu = newPdu; + } + }; + disNetworkInterface.addListener(pduListener); + + String outputDirectory = DEFAULT_OUTPUT_DIRECTORY; + System.out.println("Beginning pdu save to directory " + outputDirectory); + pduRecorder = new PduRecorder(outputDirectory, getNetworkAddress(), getNetworkPort()); // assumes save + pduRecorder.setEncodingPduLog(PduRecorder.ENCODING_PLAINTEXT); + pduRecorder.setVerbose(true); // either sending, receiving or both + pduRecorder.start(); // begin running + } + + /** All done, release network resources */ + public void tearDownNetworkInterface() + { + pduRecorder.stop(); // handles disNetworkInterface.close(), tears down threads and sockets + } + + /** + * Send a single Protocol Data Unit (PDU) of any type + * @param pdu the pdu to send + */ + protected void sendSinglePdu(Pdu pdu) + { + try + { + disNetworkInterface.send(pdu); + Thread.sleep(100); // TODO consider refactoring the wait logic and moving externally + } + catch (InterruptedException ex) + { + System.err.println(this.getClass().getName() + " Error sending PDU: " + ex.getLocalizedMessage()); + System.exit(1); + } + } + + /** + * Send Comment PDU + * @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments + * @param commentType enumeration value describing purpose of the narrative comment + * @param comments String array of narrative comments + */ + public void sendCommentPdu(VariableRecordType commentType, + // vararg... variable-length set of String comments can optionally follow + String... comments) + { + sendAllPdusForLoopTimestep (null, null, commentType, comments); + } + + /** + * Send EntityState, Fire, Comment PDUs that got updated for this loop, reflecting state of current simulation timestep. + * @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments + * @param entityStatePdu the ESPDU to send, if any + * @param firePdu the FirePDU to send, if any + * @param commentType enumeration value describing purpose of the narrative comment + * @param comments String array of narrative comments + */ + public void sendAllPdusForLoopTimestep(EntityStatePdu entityStatePdu, + FirePdu firePdu, + VariableRecordType commentType, + // vararg... variable-length set of String comments can optionally follow + String... comments) + { + if (entityStatePdu != null) + sendSinglePdu(entityStatePdu); + + if (firePdu != null) + sendSinglePdu(firePdu); // bang + + if ((comments != null) && (comments.length > 0)) + { + ArrayList<String> newCommentsList = new ArrayList<>(); + for (String comment : comments) + { + if (!comment.isEmpty()) + { + newCommentsList.add(comment); // OK found something to send + } + } + if (!newCommentsList.isEmpty()) + { + if (commentType == null) + commentType = otherComment; // fallback value otherComment + // now build the commentPdu from these string inputs, thus constructing a narrative entry + CommentPdu commentPdu = pduFactory.makeCommentPdu(commentType, newCommentsList.toArray(new String[0])); // comments); + sendSinglePdu(commentPdu); + if (isVerboseComments()) + { + System.out.println("*** [Narrative comment sent: " + commentType.name() + "] " + newCommentsList.toString()); + System.out.flush(); + } + } + } + } + + /** + * test for verboseComments mode + * @return whether verboseComments mode is enabled + */ + public boolean isVerboseComments() { + return verboseComments; + } + + /** + * set verboseComments mode + * @param newVerboseComments whether verboseComments mode is enabled + */ + public void setVerboseComments(boolean newVerboseComments) { + this.verboseComments = newVerboseComments; + } + + /** + * Initial execution via main() method: handle args array of command-line initialization (CLI) arguments here + * @param args command-line parameters: network address and port + */ + protected void handleArgs (String[] args) + { + // initial execution: handle args array of initialization arguments here + if (args.length == 2) + { + if ((args[0] != null) && !args[0].isEmpty()) + thisProgram.setNetworkAddress(args[0]); + if ((args[1] != null) && !args[1].isEmpty()) + thisProgram.setNetworkPort(Integer.parseInt(args[1])); + } + else if (args.length != 0) + { + System.err.println("Usage: " + thisProgram.getClass().getSimpleName() + " [address port]"); + System.exit(-1); + } + } + + /** Locally instantiable copy of program, can be subclassed. */ + protected static ExampleSimulationProgramDuran thisProgram; + + /** + * Main method is first executed when a program instance is loaded. + * @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a> + * @param args command-line parameters: network address and port. + * Command-line arguments are an array of optional String parameters that are passed from execution environment during invocation + */ + public static void main(String[] args) + { + TRACE_PREFIX = "[" + ExampleSimulationProgramDuran.class.getName() + "] "; + + System.out.println(TRACE_PREFIX + "main() started..."); + + thisProgram = new ExampleSimulationProgramDuran(); // creates instance of self within static main() method + + thisProgram.handleArgs (args); // process command-line invocation arguments + + thisProgram.setUpNetworkInterface(); + +// thisProgram.pduRecorder.setDescriptor (TRACE_PREFIX.replace("[","").replace("]","") + " pduRecorder"); + + thisProgram.runSimulationLoops(); // ... your simulation execution code goes in there ... + + thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering + + System.out.println(TRACE_PREFIX + "complete."); // report successful completion + + System.exit(0); // ensure all threads and sockets released + } +} diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/ExampleTrackInterpolationDuran.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/ExampleTrackInterpolationDuran.java new file mode 100644 index 0000000000000000000000000000000000000000..302adbc7b7eaf455d48f4aad0cd1c0a8b91d0c57 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/ExampleTrackInterpolationDuran.java @@ -0,0 +1,260 @@ +/** + * Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. + * This work is provided under a BSD open-source license, see project license.html and license.txt + * + * @author brutzman@nps.edu + */ +package MV3500Cohort2022MayJune.homework2.Duran; + +import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; +import edu.nps.moves.dis7.enumerations.ForceID; +import edu.nps.moves.dis7.pdus.EntityStatePdu; +import edu.nps.moves.dis7.pdus.Pdu; +import edu.nps.moves.dis7.pdus.Vector3Double; +import edu.nps.moves.dis7.utilities.DisTime; +import edu.nps.moves.dis7.utilities.stream.X3dCreateInterpolators; +import edu.nps.moves.dis7.utilities.stream.X3dCreateLineSet; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * The purpose of this program is to provide an easily modifiable example + * simulation for networked entity tracks and presentation, including + * DIS-capable entities doing tasks and reporting them to the network. + * Default settings include PDU recording turned on by default. + * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/ExampleTrackInterpolationLog.txt">ExampleTrackInterpolationLog.txt</a> + * @see <a href="https://calhoun.nps.edu/handle/10945/65436">REPEATABLE UNIT TESTING OF DISTRIBUTED INTERACTIVE SIMULATION (DIS) PROTOCOL BEHAVIOR STREAMS USING WEB STANDARDS</a> by Tobias Brennenstuhl, Masters Thesis, Naval Postgraduate School (NPS), June 2020 + * @see <a href="https://gitlab.nps.edu/Savage/SavageTheses/-/tree/master/BrennenstuhlTobias">https://gitlab.nps.edu/Savage/SavageTheses/-/tree/master/BrennenstuhlTobias</a> + */ +public class ExampleTrackInterpolationDuran extends ExampleSimulationProgramDuran +{ + // -------------------- Begin Variables for X3D autogenerated code + private X3dCreateInterpolators x3dInterpolators = new X3dCreateInterpolators(); + private X3dCreateLineSet x3dLineSet = new X3dCreateLineSet(); + private byte[] globalByteBufferForX3dInterpolators = null; + // -------------------- End Variables for X3D autogenerated code + + ArrayList<Pdu> pduSentList = new ArrayList<>(); + + /** + * This runSimulationLoops() method is a programmer-modifiable method for + * defining and running a new simulation of interest. Welcome! Other parts + * of this program handle bookkeeping and plumbing tasks so that you can + * focus on your model entities and activities. Expandable support includes + * DIS EntityStatePdu, FirePdu and CommentPdu all available for modification + * and sending in a simulation loop. Continuous improvement efforts seek to + * make this program as easy and straightforward as possible for DIS + * simulationists to use and adapt. All of the other methods are setup, + * teardown and configuration that you may find interesting, even helpful, + * but don't really have to worry about. + */ + @SuppressWarnings("SleepWhileInLoop") // yes we do that + @Override // indicates that this method supercedes corresponding superclass method + public void runSimulationLoops() + { + try + { + final int SIMULATION_MAX_LOOP_COUNT = 50; // be deliberate out there! also avoid infinite loops. + int simulationLoopCount = 0; // variable, initialized at 0 + boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet? + + // TODO reset Clock Time to today's date and timestamp to zero, providing consistent outputs for each simulation run + DisTime.setEpochLvcNow(); + simulationTime = initialTime - currentTimeStep; // pre-initialization for first loop + + initializeSimulationEntities(); + + // use declared PDU objects and set their values. + entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID; + // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? + + pduRecorder.setVerbose(false); + pduRecorder.hasVerboseOutput(); // debug check + + EntityStatePdu espdu_1 = pduFactory.makeEntityStatePdu(); + espdu_1.setEntityID(entityID_1); + espdu_1.setForceId(ForceID.FRIENDLY); + espdu_1.setEntityType(new _001Poseidon()); // note import statement above + espdu_1.setMarking("track path"); +// espdu_1.clearMarking(); // test +// espdu_1.getMarkingString(); // trace +// espdu_1.setEntityLocation(new Vector3Double().setX(0).setY(0).setZ(0)); // long form + espdu_1.setEntityLocation(0, 0, 0); // utility method + + float speedEntity_1 = 1.0f; // meters/second + EntityStatePdu.Direction directionEntity_1 = EntityStatePdu.Direction.NORTH; + + PduTrack pduTrack_1 = new PduTrack(); + pduTrack_1.setDescriptor("testing 123"); + pduTrack_1.setDefaultWaypointInterval(1.0f); // overrides timestamps + pduTrack_1.setAddLineBreaksWithinKeyValues(true); + pduTrack_1.setAuthor("Don Brutzman"); + pduTrack_1.setX3dModelName("ExampleTrackInterpolation.x3d"); + pduTrack_1.setX3dModelIdentifier("https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/ExampleTrackInterpolation.x3d"); + pduTrack_1.addPdu(espdu_1); // initial location + + // OK send initial PDUs prior to loop + if (pduRecorder.hasVerboseOutput()) + System.out.println("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); + sendSinglePdu(espdu_1); +// sendCommentPdu(currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + pduSentList.add(espdu_1); + reportPdu(simulationLoopCount, espdu_1.getEntityLocation(), directionEntity_1); + + // TODO simulation management PDUs for startup, planning to design special class support + // =================================================================================================== + // loop the simulation while allowed, programmer can set additional conditions to break out and finish + while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet? + { + simulationLoopCount++; // good practice: increment loop counter as first action in that loop + simulationTime += currentTimeStep; // good practice: update clock along with loop index + + // ============================================================================================= + // * your own simulation code starts here! * + // ============================================================================================= + // are there any other variables to modify at the beginning of your loop? + // compute a track, update an ESPDU, whatever it is that your model is doing... + + // Pick direction, change each 10 seconds, traverse a box. No physics. Walk a box! + if (simulationLoopCount <= 10) + directionEntity_1 = EntityStatePdu.Direction.NORTH; + else if (simulationLoopCount <= 20) + directionEntity_1 = EntityStatePdu.Direction.EAST; + else if (simulationLoopCount <= 30) + directionEntity_1 = EntityStatePdu.Direction.SOUTH; + else // if (simulationLoopCount <= 40) + directionEntity_1 = EntityStatePdu.Direction.WEST; + + // use utility method to simply update velocity vector using speed value and direction + espdu_1.setEntityLinearVelocity(speedEntity_1, directionEntity_1); + + // Where is my entity? Insert changes in position; this sample only changes X position. + espdu_1.advanceEntityLocation(currentTimeStep); + + // make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending) + narrativeMessage1 = "MV3500 TrackSimulationProgram"; + narrativeMessage2 = "runSimulation() loop " + simulationLoopCount + " at time " + simulationTime; + narrativeMessage3 = ""; // intentionally blank for testing + + // your loop termination condition goes here + if (simulationLoopCount > 40) // for example + { + simulationComplete = true; + } + // ============================================================================================= + // * your own simulation code is finished here! * + // ============================================================================================= + + // staying synchronized with timestep: wait duration for elapsed time in this loop + // Thread.sleep needs a (long) parameter for milliseconds, which are clumsy to use sometimes + if (false) // real-time operation or simulation speedup + { + Thread.sleep((long) (currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds + System.out.println(TRACE_PREFIX + "Pausing for " + currentTimeStep + " seconds"); + } + + // OK now send the status PDUs for this loop, and then continue + if (pduRecorder.hasVerboseOutput()) + System.out.println("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); + sendSinglePdu(espdu_1); + sendCommentPdu(currentTimeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + if (pduRecorder.hasVerboseOutput()) + System.out.println(TRACE_PREFIX + "PDUs successfully sent for this loop"); + pduSentList.add(espdu_1); + pduTrack_1.addPdu(espdu_1); + Vector3Double location = espdu_1.getEntityLocation(); + reportPdu(simulationLoopCount, location, directionEntity_1); + + // =============================== + // current loop now finished, check whether to terminate if simulation complete, otherwise continue + if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good + { + System.out.println(TRACE_PREFIX + "loop termination condition met, simulationComplete=" + simulationComplete); // ", final loopCount=" + loopCount + + break; + } + } // end of simulation loop + // =================================================================================================== + System.out.println(TRACE_PREFIX + "all PDUs successfully sent for this loop (pduSentList.size()=" + pduSentList.size() + " total)"); + + // track analysis + System.out.println(TRACE_PREFIX + "pduTrack_1 initialLocation=" + pduTrack_1.getInitialLocation() + ", latestLocation=" + pduTrack_1.getLatestLocation()); + pduTrack_1.sortPdus() + .createRawWaypoints(); + + System.out.println("pduTrack_1 getEspduCount()=" + pduTrack_1.getEspduCount()); + System.out.println("pduTrack_1 duration = " + pduTrack_1.getTotalDurationSeconds() + " seconds = " + + pduTrack_1.getTotalDurationTicks() + " ticks"); + System.out.println("================================="); + System.out.println(pduTrack_1.createX3dModel()); + System.out.println("================================="); + + narrativeMessage2 = "runSimulation() completed successfully"; // all done + sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + if (pduRecorder.hasVerboseOutput()) + System.out.println(TRACE_PREFIX + "final CommentPdu successfully sent for simulation"); + // TODO simulation management PDUs + } + catch (InterruptedException iex) // handle any exception that your code might choose to provoke! + { + Logger.getLogger(ExampleTrackInterpolationDuran.class.getName()).log(Level.SEVERE, null, iex); + } + } + + /** + * Report current PDU information to console + * @param simulationLoopCount current loop index + * @param location current location + * @param directionEntity current direction + * @return same object to permit progressive setters + */ + public ExampleTrackInterpolationDuran reportPdu(int simulationLoopCount, Vector3Double location, EntityStatePdu.Direction directionEntity) + { + System.out.println (String.format("%2d ", simulationLoopCount) + "Entity location=(" + + String.format("%4.1f", location.getX()) + ", " + + String.format("%4.1f", location.getY()) + ", " + + String.format("%4.1f", location.getZ()) + ") " + + String.format("%-5s", directionEntity.name()) +// + " " + espdu_1.getEntityLinearVelocity().toString() + ); + return this; + } + + /* Default constructors used unless otherwise defined/overridden. */ + /** + * Main method is first executed when a program instance is loaded. + * + * @see + * <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java + * Tutorials: A Closer Look at the "Hello World!" Application</a> + * @param args command-line arguments are an array of optional String + * parameters that are passed from execution environment during invocation + */ + public static void main(String[] args) + { + TRACE_PREFIX = "[" + ExampleTrackInterpolationDuran.class.getName() + "] "; + + System.out.println(TRACE_PREFIX + "main() started..."); + + thisProgram = new ExampleTrackInterpolationDuran(); // creates instance of self within static main() method + + thisProgram.handleArgs (args); // process command-line invocation arguments + + thisProgram.setUpNetworkInterface(); + + thisProgram.pduRecorder.setDescriptor (TRACE_PREFIX.replace("[","").replace("]","") + " pduRecorder"); + + thisProgram.pduRecorder.setVerbose(false); + thisProgram.setVerboseComments(false); + thisProgram.disNetworkInterface.setVerbose(false); + + thisProgram.runSimulationLoops(); // ... your simulation execution code goes in there ... + + thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering + + System.out.println(TRACE_PREFIX + "complete."); // report successful completion + + System.exit(0); // ensure all threads and sockets released + } + +} diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/PduTrack.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/PduTrack.java new file mode 100644 index 0000000000000000000000000000000000000000..61a7159852d5a52117479d7a4428abdadd99fbf0 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Duran/PduTrack.java @@ -0,0 +1,1042 @@ +/* +Copyright (c) 1995-2022 held by the author(s). All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the names of the Naval Postgraduate School (NPS) + Modeling Virtual Environments and Simulation (MOVES) Institute + https://www.nps.edu and https://www.nps.edu/web/moves + nor the names of its contributors may be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ +// TODO move into opendis7 distribution tree in package edu.nps.moves.dis7.utilities.stream; + +package MV3500Cohort2022MayJune.homework2.Duran; + +import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; +import edu.nps.moves.dis7.enumerations.DisPduType; +import edu.nps.moves.dis7.enumerations.ForceID; +import edu.nps.moves.dis7.pdus.EntityID; +import edu.nps.moves.dis7.pdus.EntityStatePdu; +import edu.nps.moves.dis7.pdus.EulerAngles; +import edu.nps.moves.dis7.pdus.Pdu; +import edu.nps.moves.dis7.pdus.Vector3Double; +import edu.nps.moves.dis7.utilities.DisTime; +import edu.nps.moves.dis7.utilities.PduFactory; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Create a track from DIS ESPDUs + * @author brutzman + */ +public class PduTrack +{ + private String descriptor = new String(); + private ArrayList<Pdu> pduList = new ArrayList<>(); + private EntityStatePdu initialEspdu; + private EntityStatePdu latestEspdu; + private Vector3Double initialLocation; + private Vector3Double latestLocation; + + /** waypoint timelineList in seconds */ + private ArrayList<Float> timelineList = new ArrayList<>(); + private ArrayList<Vector3Double> waypointsList = new ArrayList<>(); + private ArrayList<EulerAngles> eulerAnglesList = new ArrayList<>(); + + private String author = new String(); + private String x3dModelIdentifier = new String(); + private String x3dModelName = "PduTrackInterpolation.x3d"; + private float defaultWaypointInterval = -1; + private float durationSeconds = -1; + private String x3dTimeSensorDEF = new String(); + private String x3dPositionInterpolatorDEF = new String(); + private String x3dOrientationInterpolatorDEF = new String(); + private boolean addLineBreaksWithinKeyValues = false; + /** what kind of timestamp is being used */ + public DisTime.TimestampStyle timestampStyle = DisTime.TimestampStyle.IEEE_ABSOLUTE; + /** direct access to pduFactory for creating new PDU instances */ + protected PduFactory pduFactory = new PduFactory(timestampStyle); + private LocalDateTime recordingStart; + private LocalDateTime recordingStop; + private String todaysDateString = new String(); + + /** direct access to byteArrayOutputStream */ + protected ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + /** direct access to DataOutputStream */ + protected DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + private String TRACE_PREFIX = "[" + (PduTrack.class.getSimpleName()) + "] "; + + /** + * Constructor for PduTrack + */ + public PduTrack() + { + // initialization code here + + // https://docs.oracle.com/javase/tutorial/datetime/TOC.html + // https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/package-summary.html + // https://stackoverflow.com/questions/5175728/how-to-get-the-current-date-time-in-java/5175900 (scroll down to java.time) + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMMM yyyy"); + todaysDateString = LocalDate.now().format(formatter); +// System.out.println(TRACE_PREFIX + "today=" + todayString); + } + + /** + * Set timestampStyle used by PduFactory + * @param newTimestampStyle new value to set + */ + public PduTrack(DisTime.TimestampStyle newTimestampStyle) + { + timestampStyle = newTimestampStyle; + DisTime.setTimestampStyle(newTimestampStyle); + // automatic super invocation: return PduTrack(); + } + + /** + * Get simple descriptor (such as parent class name) for this SimulationManager, used in trace statements + * @return simple descriptor name + */ + public String getDescriptor() + { + return descriptor; + } + /** + * Set new simple descriptor (such as parent class name) for this SimulationManager, used in trace statements + * @param newDescriptor simple descriptor name for this interface + * @return same object to permit progressive setters */ + public PduTrack setDescriptor(String newDescriptor) + { + if (newDescriptor != null) + this.descriptor = newDescriptor.trim(); + TRACE_PREFIX = "[" + (PduTrack.class.getSimpleName() + " " + descriptor) + "] "; + return this; + } + /** + * Get timestampStyle used by PduFactory + * @return current timestampStyle + */ + public DisTime.TimestampStyle getTimestampStyle() + { + return timestampStyle; + } + /** + * Set timestampStyle used by PduFactory + * @param newTimestampStyle the timestampStyle to set + * @return same object to permit progressive setters + */ + public PduTrack setTimestampStyle(DisTime.TimestampStyle newTimestampStyle) + { + this.timestampStyle = newTimestampStyle; + DisTime.setTimestampStyle(newTimestampStyle); + return this; + } + + /** + * Determine initial location, reset to (0 0 0) if not found + * @return current initialLocation + */ + public Vector3Double getInitialLocation() { + if (initialLocation == null) + { + System.out.println (TRACE_PREFIX + "getInitialLocation() not found, isTrackEmpty()=" + isTrackEmpty() + ", returning 0 0 0"); + return new Vector3Double(); + } + return initialLocation; + } + /** + * Determine current location, reset to (0 0 0) if not found + * @return current latestLocation + */ + public Vector3Double getLatestLocation() { + if (latestLocation == null) + { + System.out.println (TRACE_PREFIX + "getLatestLocation() not found, isTrackEmpty()=" + isTrackEmpty() + ", returning 0 0 0"); + return new Vector3Double(); + } + return latestLocation; + } + /** + * Get individual Pdu from pduList, index must not exceed existing pduList size + * @param index for pdu of interest + * @return pdu of interest + */ + public Pdu getPdu(int index) throws IndexOutOfBoundsException + { + if ((index >= pduList.size()) || (index < 0)) + { + System.out.println (TRACE_PREFIX + "getPdu(" + index + ") out of bounds, pduList.size()=" + pduList.size()); + // then throw exception + } + return pduList.get(index); + } + /** + * get current pduList + * @return current pduList + */ + public ArrayList<Pdu> getPduList() { + return pduList; + } + /** + * get current waypointsList + * @return current waypointsList + */ + public ArrayList<Vector3Double> getWaypointsList() { + return waypointsList; + } + /** + * current eulerAnglesList + * @return current eulerAnglesList + */ + public ArrayList<EulerAngles> getEulerAnglesList() { + return eulerAnglesList; + } + /** + * Time in seconds corresponding to each PDU + * @return current timelineList + */ + public ArrayList<Float> getTimelineList() { + return timelineList; + } + /** + * Add PDU, typically ESPDU + * @param newPdu new Pdu to add, typically ESPDU + * @return same object to permit progressive setters + */ + public PduTrack addPdu(Pdu newPdu) + { + if (newPdu.getPduType() == DisPduType.ENTITY_STATE) + { +//// EntityStatePdu deepCopyEspdu = new EntityStatePdu(); +// EntityStatePdu deepCopyEspdu = pduFactory.makeEntityStatePdu(); +// deepCopyEspdu.setTimestamp (((EntityStatePdu)newPdu).getTimestamp()); +// deepCopyEspdu.setMarking (((EntityStatePdu)newPdu).getMarking()); +// deepCopyEspdu.setEntityID (((EntityStatePdu)newPdu).getEntityID()); +// deepCopyEspdu.setForceId (((EntityStatePdu)newPdu).getForceId()); +// deepCopyEspdu.setEntityType (((EntityStatePdu)newPdu).getEntityType()); +// deepCopyEspdu.setEntityLocation (((EntityStatePdu)newPdu).getEntityLocation()); +// deepCopyEspdu.setEntityOrientation(((EntityStatePdu)newPdu).getEntityOrientation()); + + EntityStatePdu deepCopyEspdu = ((EntityStatePdu)newPdu).copy(); + pduList.add(deepCopyEspdu); +// alternative trials: +// pduList.add(((EntityStatePdu)newPdu).copyDataOutputStream()); +// pduList.add(((EntityStatePdu)newPdu).copy()); + + if (initialLocation == null) + { + initialEspdu = deepCopyEspdu; // must save object since pduList might contain more than ESPDUs + initialLocation = deepCopyEspdu.getEntityLocation(); + } + latestEspdu = deepCopyEspdu; // must save object since pduList might contain more than ESPDUs + latestLocation = deepCopyEspdu.getEntityLocation(); + } + else pduList.add(newPdu); // TODO copy() - careful, must be a new object and not a reference + return this; + } + /** + * clear all PDUs + * @return same object to permit progressive setters + */ + public PduTrack clearPduLists() + { + getPduList().clear(); + waypointsList.clear(); + eulerAnglesList.clear(); + timelineList.clear(); + initialEspdu = null; + latestEspdu = null; + initialLocation = null; + latestLocation = null; + return this; + } + + private String normalizeNameToken(String candidateDEF) + { + return candidateDEF.replace(" ", "").replace("-", "") + .replace("(", "").replace(")", "") + .replace("[", "").replace("])", ""); + } + + /** + * Provide DEF value if not defined by program + * @return current x3dTimeSensorDEF + */ + public String getX3dTimeSensorDEF() { + if (x3dTimeSensorDEF.isEmpty()) + x3dTimeSensorDEF = normalizeNameToken(getDescriptor()) + "Clock"; + return x3dTimeSensorDEF; + } + + /** + * Set DEF value for X3D node + * @param x3dTimeSensorDEF the x3dTimeSensorDEF to set + */ + public void setX3dTimeSensorDEF(String x3dTimeSensorDEF) { + this.x3dTimeSensorDEF = normalizeNameToken(x3dTimeSensorDEF); + } + + /** + * Provide DEF value if not defined by program + * @return current x3dPositionInterpolatorDEF + */ + public String getX3dPositionInterpolatorDEF() { + if (x3dPositionInterpolatorDEF.isEmpty()) + x3dPositionInterpolatorDEF = normalizeNameToken(getDescriptor()) + "Positions"; + return x3dPositionInterpolatorDEF; + } + + /** + * Set DEF value for X3D node + * @param x3dPositionInterpolatorDEF the x3dPositionInterpolatorDEF to set + */ + public void setX3dPositionInterpolatorDEF(String x3dPositionInterpolatorDEF) { + this.x3dPositionInterpolatorDEF = normalizeNameToken(x3dPositionInterpolatorDEF); + } + + /** + * Provide DEF value if not defined by program + * @return current x3dOrientationInterpolatorDEF + */ + public String getX3dOrientationInterpolatorDEF() { + if (x3dOrientationInterpolatorDEF.isEmpty()) + x3dOrientationInterpolatorDEF = normalizeNameToken(getDescriptor()) + "Orientations"; + return x3dOrientationInterpolatorDEF; + } + + /** + * Set DEF value for X3D node + * @param x3dOrientationInterpolatorDEF the x3dOrientationInterpolatorDEF to set + */ + public void setX3dOrientationInterpolatorDEF(String x3dOrientationInterpolatorDEF) { + this.x3dOrientationInterpolatorDEF = normalizeNameToken(x3dOrientationInterpolatorDEF); + } + + /** + * Sort all PDUs by timestamp + * @see <a href="https://stackoverflow.com/questions/16252269/how-to-sort-an-arraylist">StackOverflow: How to sort an ArrayList?</a> + * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/doc-files/coll-overview.html">Collections Framework Overview</a> + * @return same object to permit progressive setters + */ + public PduTrack sortPdus() + { + Collections.sort(pduList, new Comparator<Pdu>() { + @Override + public int compare(Pdu lhs, Pdu rhs) + { + // -1 less than, 1 greater than, 0 equal + if (lhs.occursBefore(rhs)) + return -1; + else if (lhs.occursSameTime(rhs)) + return 0; + else return 1; + } + }); + return this; + } + /** + * Reverse order of PDU list + * @see <a href="https://stackoverflow.com/questions/10766492/what-is-the-simplest-way-to-reverse-an-arraylist">StackOverflow: What is the Simplest Way to Reverse an ArrayList?</a> + * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/doc-files/coll-overview.html">Collections Framework Overview</a> + * @return same object to permit progressive setters + */ + public PduTrack reversePdus() + { + Collections.reverse(pduList); + return this; + } + + /** + * Determine whether any ESPDUs have been received by this track + * @return whether track is empty + */ + public boolean isTrackEmpty() + { + return (getEspduCount() == 0); + } + /** + * Count ESPDUs in pduList + * @return number of ESPDUs in pduList + */ + public int getEspduCount() + { + int counter = 0; + for (Pdu nextPdu : getPduList()) + { + if (nextPdu.getPduType() == DisPduType.ENTITY_STATE) + counter += 1; + } + return counter; + } + /** + * Compute track duration in timestamp ticks + * @return duration in timestamp ticks between initial and final ESPDU timestamps in waypointList + */ + public int getTotalDurationTicks() + { + int initialTime = -1; + int finalTime = -1; + int durationTicks = -1; // used if pduList is empty + + // must skip through pduList since non-ESPDU PDUs may be present + for (Pdu nextPdu : getPduList()) + { + if (nextPdu.getPduType() == DisPduType.ENTITY_STATE) + { + if (initialTime == -1) + initialTime = nextPdu.getTimestamp(); + finalTime = nextPdu.getTimestamp(); + } + } + if ((initialTime >= 0) && (finalTime >= 0)) + durationTicks = (finalTime - initialTime); + if (getPduList().isEmpty()) + { + System.out.println(TRACE_PREFIX + "getTrackDuration() computed illegal duration=" + durationTicks + " due to empty pdu list"); + } + else if ((durationTicks <= 0) && (defaultWaypointInterval <= 0)) + { + System.out.println(TRACE_PREFIX + "getTrackDuration() computed illegal duration=" + durationTicks + " due to illegal pdu list"); + } + return durationTicks; + } + /** + * Compute track duration in seconds + * @return duration in seconds between initial and final ESPDU timestamps in waypointList + */ + public float getTotalDurationSeconds() + { + if (defaultWaypointInterval > 0) + { + return getEspduCount() * defaultWaypointInterval; + } + else if (getTotalDurationTicks() < 0) + durationSeconds = getTotalDurationTicks() * 1.0f; // TODO convert + return durationSeconds; + } + /** + * Create waypoints and angles using all ESPDU points, with no linear regression or array reduction. + * @return same object to permit progressive setters + */ + public PduTrack createRawWaypoints() + { + // https://stackoverflow.com/questions/6536094/java-arraylist-copy + + timelineList.clear(); + waypointsList.clear(); + eulerAnglesList.clear(); + float clock = 0.0f; + for (int i = 0; i < pduList.size(); i++) + { + Pdu nextPdu = pduList.get(i); + if (nextPdu.getPduType() == DisPduType.ENTITY_STATE) + { + EntityStatePdu espdu = (EntityStatePdu)nextPdu; + if (defaultWaypointInterval > 0) + { + timelineList.add(clock); + clock += defaultWaypointInterval; + } + else + { + timelineList.add(espdu.getTimestamp() * 1.0f); // TODO convert + } + waypointsList.add(espdu.getEntityLocation()); + eulerAnglesList.add(espdu.getEntityOrientation()); + } + } + return this; + } + /** + * Utility method to create TimeSensor + * @return TimeSensor string in XML format + */ + public String createX3dTimeSensorString() + { + StringBuilder sb = new StringBuilder(); + sb.append(" <TimeSensor"); + sb.append(" DEF='").append(getX3dTimeSensorDEF()).append("'"); + sb.append(" cycleInterval='").append(String.valueOf(getTotalDurationSeconds())).append("'"); + sb.append(" loop='true'"); + sb.append("/>").append("\n"); + + return sb.toString(); + } + /** + * Create PositionInterpolator from Pdu list + * @return X3D PositionInterpolator as string + */ + public String createX3dPositionInterpolatorString() + { + StringBuilder sb = new StringBuilder(); + sb.append(" <PositionInterpolator"); + sb.append(" DEF='").append(getX3dPositionInterpolatorDEF()).append("'"); + sb.append(" key='"); + for (int i = 0; i < timelineList.size(); i++) + { + float nextDuration = timelineList.get(i) * 1.0f; // TODO convert + sb.append(String.valueOf(nextDuration)); + if (i < timelineList.size() - 1) + sb.append(" "); + } + sb.append("'"); + sb.append(" keyValue='"); + for (int i = 0; i < waypointsList.size(); i++) + { + if (hasAddLineBreaksWithinKeyValues()) + sb.append("\n"); + Vector3Double nextPosition = waypointsList.get(i); + sb.append(String.valueOf(nextPosition.getX())).append(" ") + .append(String.valueOf(nextPosition.getY())).append(" ") + .append(String.valueOf(nextPosition.getZ())); + if (i < waypointsList.size() - 1) + sb.append(","); + } + sb.append("'"); + sb.append("/>").append("\n"); + + return sb.toString(); + } + /** + * Create OrientationInterpolator from Pdu list + * TODO preliminary support only includes horizontal rotation. + * @return X3D OrientationInterpolator as string + */ + public String createX3dOrientationInterpolatorString() + { + StringBuilder sb = new StringBuilder(); + sb.append(" <OrientationInterpolator"); + sb.append(" DEF='").append(getX3dOrientationInterpolatorDEF()).append("'"); + sb.append(" key='"); + for (int i = 0; i < timelineList.size(); i++) + { + float nextDuration = timelineList.get(i) * 1.0f; // TODO convert + sb.append(String.valueOf(nextDuration)); + if (i < timelineList.size() - 1) + sb.append(" "); + } + sb.append("'"); + sb.append(" keyValue='"); + for (int i = 0; i < eulerAnglesList.size(); i++) + { + if (hasAddLineBreaksWithinKeyValues()) + sb.append("\n"); + EulerAngles nextEulerAngle = new EulerAngles(); + float axisX = 0.0f; + float axisY = 1.0f; + float axisZ = 0.0f; + float angle = 0.0f; // radians + + nextEulerAngle = eulerAnglesList.get(i); + angle = nextEulerAngle.getTheta(); + + sb.append(String.valueOf(axisX)).append(" ") + .append(String.valueOf(axisY)).append(" ") + .append(String.valueOf(axisZ)).append(" ") + .append(String.valueOf(angle)); + if (i < eulerAnglesList.size() - 1) + sb.append(","); + } + sb.append("'"); + sb.append("/>").append("\n"); + + return sb.toString(); + } + + /** + * Get name of author used as creator of X3D model + * @return current author + */ + public String getAuthor() { + return author; + } + + /** + * Set name of author used as creator of X3D model + * @param author the author to set + */ + public void setAuthor(String author) { + if (author == null) + author = new String(); + author = author.trim(); + this.author = author; + } + + /** + * Get name of online url identifier for X3D model + * @return current x3dModelIdentifier + */ + public String getX3dModelIdentifier() { + return x3dModelIdentifier; + } + + /** + * Set name of online url identifier for X3D model + * @param x3dModelIdentifier the x3dModelIdentifier to set + */ + public void setX3dModelIdentifier(String x3dModelIdentifier) { + if (x3dModelIdentifier == null) + x3dModelIdentifier = new String(); + x3dModelIdentifier = x3dModelIdentifier.trim(); + if (!x3dModelIdentifier.startsWith("http://") && !x3dModelIdentifier.startsWith("https://")) + System.out.println(TRACE_PREFIX + "warning, identifier typically begins with https:// or http://"); + else this.x3dModelIdentifier = x3dModelIdentifier; + } + + /** + * File name for X3D model production + * @return current x3dModelName + */ + public String getX3dModelName() { + return x3dModelName; + } + /** + * File name for X3D model production + * @param x3dModelName the x3dModelName to set + */ + public void setX3dModelName(String x3dModelName) { + if (x3dModelName == null) + x3dModelName = new String(); + x3dModelName = x3dModelName.trim(); + this.x3dModelName = x3dModelName; + } + + /** + * Verbose (but more readable) output of numeric arrays in X3D model + * @return current addLineBreaksWithinKeyValues + */ + public boolean hasAddLineBreaksWithinKeyValues() { + return addLineBreaksWithinKeyValues; + } + + /** + * Verbose (but more readable) output of numeric arrays in X3D model + * @param addLineBreaksWithinKeyValues the addLineBreaksWithinKeyValues to set + */ + public void setAddLineBreaksWithinKeyValues(boolean addLineBreaksWithinKeyValues) { + this.addLineBreaksWithinKeyValues = addLineBreaksWithinKeyValues; + } + /** + * Create full X3D interpolator model from Pdu list, assembling sections of scene graph + * @return X3D model as string + */ + public String createX3dModel() + { + StringBuilder sb = new StringBuilder(); + sb.append(createX3dModelHeaderString()); + sb.append(createX3dTimeSensorString()); + sb.append(createX3dPositionInterpolatorString()); + sb.append(createX3dOrientationInterpolatorString()); + sb.append(createX3dRoutesGeometryFooterString()); + return sb.toString(); + } + /** + * Create PositionInterpolator from Pdu list + * @return X3D PositionInterpolator as string + */ + public String createX3dModelHeaderString() + { + StringBuilder sb = new StringBuilder(); + + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n"); + sb.append("<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 4.0//EN\" \"https://www.web3d.org/specifications/x3d-4.0.dtd\">").append("\n"); + sb.append("<X3D profile='Interchange' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>").append("\n"); + sb.append(" <head>").append("\n"); + if (!getX3dModelName().isEmpty()) + sb.append(" <meta content='").append(getX3dModelName()).append("' name='title'/>").append("\n"); + sb.append(" <meta content='Conversion of ESPDU track into X3D animation interpolators and LineSet.' name='description'/>").append("\n"); + + sb.append(" <meta content='1 January 2022' name='created'/>").append("\n"); + sb.append(" <meta content='").append(todaysDateString).append("' name='modified'/>").append("\n"); + if (!getAuthor().isEmpty()) + sb.append(" <meta content='").append(getAuthor()).append("' name='creator'/>").append("\n"); + if (!getX3dModelIdentifier().isEmpty()) + sb.append(" <meta content='").append(getX3dModelIdentifier()).append("' name='identifier'/>").append("\n"); + + sb.append(" <meta content='PduTrack utility, opendis7-java Library https://github.com/open-dis/opendis7-java' name='generator'/>").append("\n"); + sb.append(" <meta content='NPS MOVES MV3500 Networked Graphics https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500' name='reference'/>").append("\n"); + sb.append(" <meta content='X3D Resources https://www.web3d.org/x3d/content/examples/X3dResources.html' name='reference'/>").append("\n"); + sb.append(" <meta content='X3D Scene Authoring Hints https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html' name='reference'/>").append("\n"); + sb.append(" <meta content='X3D Tooltips https://www.web3d.org/x3d/tooltips/X3dTooltips.html' name='reference'/>").append("\n"); + sb.append(" <meta content='X3D Validator https://savage.nps.edu/X3dValidator' name='reference'/>").append("\n"); + sb.append(" <meta content='Open source https://raw.githubusercontent.com/open-dis/opendis7-java/master/license.html' name='license'/>").append("\n"); + sb.append(" </head>").append("\n"); + sb.append(" <Scene>").append("\n"); + sb.append(" <WorldInfo title='PduTrackInterpolation.x3d'/>").append("\n"); + + return sb.toString(); + } + /** + * Create X3D ROUTEs and footer to connect TimeSensor to interpolators + * @return X3D PositionInterpolator as string + */ + public String createX3dRoutesGeometryFooterString() + { + StringBuilder sb = new StringBuilder(); + + sb.append(" <ROUTE fromField='fraction_changed' fromNode='") + .append(getX3dTimeSensorDEF()) + .append("' toField='set_fraction' toNode='") + .append(getX3dPositionInterpolatorDEF()) + .append("'/>").append("\n"); + sb.append(" <ROUTE fromField='fraction_changed' fromNode='") + .append(getX3dTimeSensorDEF()) + .append("' toField='set_fraction' toNode='") + .append(getX3dOrientationInterpolatorDEF()) + .append("'/>").append("\n"); + + sb.append(" <Shape>").append("\n"); + sb.append(" <Appearance DEF='TrackAppearance'>").append("\n"); + sb.append(" <Material emissiveColor='0.2 0.8 0.8'/>").append("\n"); + sb.append(" </Appearance>").append("\n"); + sb.append(" <LineSet vertexCount='").append(waypointsList.size()).append("'>").append("\n"); + sb.append(" <Coordinate point='"); + for (int i = 0; i < waypointsList.size(); i++) + { + if (hasAddLineBreaksWithinKeyValues()) + sb.append("\n"); + Vector3Double nextPosition = waypointsList.get(i); + sb.append(String.valueOf(nextPosition.getX())).append(" ") + .append(String.valueOf(nextPosition.getY())).append(" ") + .append(String.valueOf(nextPosition.getZ())); + if (i < waypointsList.size() - 1) + sb.append(","); + } + sb.append("'/>").append("\n"); + sb.append(" </LineSet>").append("\n"); + sb.append(" </Shape>").append("\n"); + sb.append(" <Transform DEF='AnimationTransform'>").append("\n"); + sb.append(" <Transform rotation='0 0 1 1.57'>").append("\n"); + sb.append(" <Shape>").append("\n"); + sb.append(" <Appearance USE='TrackAppearance'/>").append("\n"); + sb.append(" <Cone bottomRadius='0.5'/>").append("\n"); + sb.append(" </Shape>").append("\n"); + sb.append(" </Transform>").append("\n"); + sb.append(" </Transform>").append("\n"); + sb.append(" <ROUTE fromField='value_changed' fromNode='") + .append(getX3dPositionInterpolatorDEF()) + .append("' toField='translation' toNode='AnimationTransform'/>").append("\n"); + sb.append(" <ROUTE fromField='value_changed' fromNode='") + .append(getX3dOrientationInterpolatorDEF()) + .append("' toField='rotation' toNode='AnimationTransform'/>").append("\n"); + + sb.append(" </Scene>").append("\n"); + sb.append("</X3D>").append("\n"); + + return sb.toString(); + } + + /** + * get defaultWaypointInterval + * @return current wayPointInterval + */ + public float getDefaultWaypointInterval() { + return defaultWaypointInterval; + } + + /** + * Set uniform waypoint interval (currently for testing) + * @param newWaypointInterval the wayPointInterval to set, in seconds, must be greater than zero + * @return same object to permit progressive setters */ + public PduTrack setDefaultWaypointInterval(float newWaypointInterval) { + if (newWaypointInterval > 0.0) + this.defaultWaypointInterval = newWaypointInterval; + else + { + System.out.println(TRACE_PREFIX + "error in setWaypointInterval(newWaypointInterval=" + newWaypointInterval + ") must be greater than zero"); + return this; + } + + float clock = 0.0f; + if (!timelineList.isEmpty()) + { + ArrayList<Float> newTimelineList = new ArrayList<>(); + for (int i = 0; i < getEspduCount(); i++) + { + newTimelineList.add(clock); + clock += defaultWaypointInterval; + } + timelineList = newTimelineList; // TO Array copy? + } + return this; + } + /** whether or not to insert commas between hex values */ + private boolean insertCommas = true; + /** + * determine whether comma insertion is turned on + * @return whether or not to insert commas between hex values + */ + public boolean hasInsertCommas() { + return insertCommas; + } + /** + * set whether comma insertion is turned on + * @param insertCommas the insertCommas value to set + */ + public void setInsertCommas(boolean insertCommas) { + this.insertCommas = insertCommas; + } + /** + * Convert byte array to hex string + * @param bytes input data + * @param insertCommas whether to insert commas between hex values + * @return hex string + */ + public String bytesToHex(byte[] bytes, boolean insertCommas) + { + this.setInsertCommas(insertCommas); + return bytesToHex(bytes); + } + /** + * Convert byte array to hex string + * @param bytes input data + * @see <a href="https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java">https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java</a> + * @return hex string + */ + public static String bytesToHex(byte[] bytes) + { + boolean insertCommas = true; + final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); + char[] hexChars = new char[bytes.length * 2]; + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = HEX_ARRAY[v >>> 4]; + hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; +// if (!(hexChars[j * 2] == '0')) // omit leading zero + sb.append(hexChars[j * 2]); + sb.append(hexChars[j * 2 + 1]); + if (insertCommas && (j < bytes.length - 1)) + sb.append(", "); + } + return sb.toString(); + } + /** + * Report current PDU information to console + * @param anEspdu EntityStatePdu of interest + * @return same object to permit progressive setters + */ + public PduTrack reportPdu(EntityStatePdu anEspdu) + { + System.out.println ( + String.format("%s", anEspdu.getMarkingString().trim()) + ", " + + DisTime.convertToString(anEspdu.getTimestamp()) + " (" + + String.format("%08d", anEspdu.getTimestamp()) + "), " + + "EntityID=(" + + anEspdu.getEntityID().getSiteID() + ", " + + anEspdu.getEntityID().getApplicationID() + ", " + + anEspdu.getEntityID().getEntityID() + "), " + + "location=(" + + String.format("%4.1f", anEspdu.getEntityLocation().getX()) + ", " + + String.format("%4.1f", anEspdu.getEntityLocation().getY()) + ", " + + String.format("%4.1f", anEspdu.getEntityLocation().getZ()) + ")" +// + " " + espdu_1.getEntityLinearVelocity().toString() + ); + return this; + } + + /** Flush all buffers to reduce console scrambling while threaded + */ + protected void flushBuffers() + { + try + { + dataOutputStream.flush(); + byteArrayOutputStream.flush(); + byteArrayOutputStream.reset(); + System.err.flush(); + System.out.flush(); + } + catch (IOException ioe) + { + System.out.println(TRACE_PREFIX + "flushBuffers() IOException: " + ioe.getMessage()); + } + } + + /** Self test to check basic operation, invoked by main() + */ + @SuppressWarnings("SleepWhileInLoop") + public void selfTest() + { + final int TOTAL_PDUS = 5; + System.out.println(TRACE_PREFIX + "selfTest() start..."); + + PduTrack pduTrack = new PduTrack(); + pduTrack.setDescriptor("PduTrack Self Test"); + pduTrack.setAuthor("Don Brutzman"); + pduTrack.setX3dModelIdentifier("https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/PduTrackInterpolation.x3d"); + pduTrack.setDefaultWaypointInterval(1.0f); // experimentation with timestamp values + + DisTime.setEpochLvcNow(); + recordingStart = LocalDateTime.now(); + Instant epoch = DisTime.getEpochLvc(); + System.out.println(TRACE_PREFIX + "DisTime.hasEpochLvc()=" + DisTime.hasEpochLvc() + + ", DisTime.getEpochLvc()=" + epoch + + ", Instant.now()=" + Instant.now()); + + EntityID entityID_123 = new EntityID(); + entityID_123.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID; + // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? + + for (int i = 0; i < TOTAL_PDUS; i++) // create espdus and add each to track pduList + { +// EntityStatePdu espdu = new EntityStatePdu(); + EntityStatePdu espdu = pduFactory.makeEntityStatePdu(); // TODO check Pdu.Type + espdu.setTimestamp(DisTime.getCurrentDisTimestamp()); // chooses appropriate version + espdu.setMarking("ESPDU " + i); + espdu.setEntityLocation(i, i, i); + espdu.setEntityOrientation(0, (float)(45.0 * Math.PI / 180.0), 0); + espdu.setEntityID(entityID_123); + espdu.setForceId(ForceID.FRIENDLY); + espdu.setEntityType(new _001Poseidon()); // note import statement above + pduTrack.addPdu(espdu); // create copy + reportPdu(espdu); + try + { + Thread.sleep(100l); + } + catch (InterruptedException ie) + { + System.out.println(TRACE_PREFIX + "exceptional sleep dulay when generating ESPDUs: " + ie.getMessage()); + } + } +// System.out.println(TRACE_PREFIX + "reversePdus() then sortPdus() to test track operations"); +// pduTrack.reversePdus(); // test +// pduTrack.sortPdus(); // restore + pduTrack.createRawWaypoints(); // copies all ESPDU points to waypoints + + System.out.println(TRACE_PREFIX + "getEspduCount()=" + pduTrack.getEspduCount()); + System.out.println(TRACE_PREFIX + "getDefaultWaypointInterval()=" + pduTrack.getDefaultWaypointInterval()); + System.out.println(TRACE_PREFIX + "getTotalDurationSeconds()=" + pduTrack.getTotalDurationSeconds()); + + System.out.println("================================="); + System.out.println("PduTrack pduList marshalling checks"); + System.out.println("= = = = = = = = = = = = = = = = ="); + try + { +// int BYTE_BUFFER_SIZE = 400; // TODO what is expected max buffer size? + for (int i = 0; i < TOTAL_PDUS; i++) + { + Pdu pdu = pduTrack.getPduList().get(i); + if (!(pdu instanceof EntityStatePdu)) + continue; // skip remainder of this loop + EntityStatePdu espdu = (EntityStatePdu) pdu; + System.out.println("espdu from pduTrack pduList"); + reportPdu(espdu); + byte[] byteArray = espdu.marshal(); + System.out.println("espdu.marshal() byteArray: " + bytesToHex(byteArray)); + flushBuffers(); + + ByteBuffer byteBuffer = ByteBuffer.allocate(byteArray.length); + espdu.marshal(byteBuffer); + System.out.println("espdu.marshal(byteBuffer): " + bytesToHex(byteBuffer.array())); + flushBuffers(); + + espdu.marshal(dataOutputStream); + byte[] byteArrayDOS = byteArrayOutputStream.toByteArray(); + System.out.println("espdu.marshal(dataOutputStream): " + bytesToHex(byteArrayDOS)); + flushBuffers(); + + System.out.println(); // - - - - - - - - - - - - - - - - - + + System.out.println("espdu.copyByteBuffer()"); + reportPdu(espdu.copyByteBuffer()); + byte[] byteArrayCopy = espdu.copyByteBuffer().marshal(); + System.out.println("espdu.copyByteBuffer().marshal() byteArray: " + bytesToHex(byteArrayCopy)); + flushBuffers(); + + ByteBuffer byteBufferCopy = ByteBuffer.allocate(byteArray.length); // TODO is there a better way to reset? + espdu.copyByteBuffer().marshal(byteBufferCopy); + System.out.println("espdu.copyByteBuffer().marshal(byteBufferCopy): " + bytesToHex(byteBufferCopy.array())); + flushBuffers(); + + espdu.copyByteBuffer().marshal(dataOutputStream); + byte[] byteArrayDosCopy = byteArrayOutputStream.toByteArray(); + System.out.println("espdu.copyByteBuffer().marshal(dataOutputStream): " + bytesToHex(byteArrayDosCopy)); + flushBuffers(); + + System.out.println(); // - - - - - - - - - - - - - - - - - + + System.out.println("espdu.copyDataOutputStream()"); + reportPdu(espdu.copyDataOutputStream()); + byte[] byteArrayCopyDOS = espdu.copyDataOutputStream().marshal(); + System.out.println("espdu.copyDataOutputStream().marshal() byteArray: " + bytesToHex(byteArrayCopyDOS)); + flushBuffers(); + + ByteBuffer byteBufferCopyDOS = ByteBuffer.allocate(byteArray.length); // TODO is there a better way to reset? + espdu.copyDataOutputStream().marshal(byteBufferCopyDOS); + System.out.println("espdu.copyDataOutputStream().marshal(byteBufferCopy): " + bytesToHex(byteBufferCopyDOS.array())); + flushBuffers(); + + espdu.copyDataOutputStream().marshal(dataOutputStream); + byte[] byteArrayDosCopy2 = byteArrayOutputStream.toByteArray(); + System.out.println("espdu.copyDataOutputStream().marshal(dataOutputStream): " + bytesToHex(byteArrayDosCopy2)); + flushBuffers(); + System.out.println(); + + System.out.println("= = = = = = = = = = = = = = = = ="); + } + } + catch(Exception e) + { + System.out.println(TRACE_PREFIX + "Marshalling test exception: " + e.getMessage()); + } + System.out.println("================================="); + pduTrack.setAddLineBreaksWithinKeyValues(true); + System.out.println(pduTrack.createX3dModel()); // + System.out.println("================================="); + + recordingStop = LocalDateTime.now(); + System.out.println(TRACE_PREFIX + "selfTest() complete."); + } + + /** + * Main method for testing. + * @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a> + * @param args [address, port, descriptor] command-line arguments are an array of optional String parameters that are passed from execution environment during invocation + */ + public static void main(String[] args) + { + System.out.println("*** PduTrack.main() self test started..."); + + PduTrack pduTrack = new PduTrack(); + + pduTrack.setDescriptor("main() self test"); + + pduTrack.selfTest(); + + System.out.println("*** PduTrack.main() self test complete."); + } + +} diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/build.xml b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..1facf5ca648a3402b352399ca02d8e1c15ebebae --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/build.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- You may freely edit this file. See commented blocks below for --> +<!-- some examples of how to customize the build. --> +<!-- (If you delete it and reopen the project it will be recreated.) --> +<!-- By default, only the Clean and Build commands use this build script. --> +<!-- Commands such as Run, Debug, and Test only use this build script if --> +<!-- the Compile on Save feature is turned off for the project. --> +<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> +<!-- in the project's Project Properties dialog box.--> +<project name="Homework2" default="default" basedir="."> + <description>Builds, tests, and runs the project Homework2.</description> + <import file="nbproject/build-impl.xml"/> + <!-- + + There exist several targets which are by default empty and which can be + used for execution of your tasks. These targets are usually executed + before and after some main targets. They are: + + -pre-init: called before initialization of project properties + -post-init: called after initialization of project properties + -pre-compile: called before javac compilation + -post-compile: called after javac compilation + -pre-compile-single: called before javac compilation of single file + -post-compile-single: called after javac compilation of single file + -pre-compile-test: called before javac compilation of JUnit tests + -post-compile-test: called after javac compilation of JUnit tests + -pre-compile-test-single: called before javac compilation of single JUnit test + -post-compile-test-single: called after javac compilation of single JUunit test + -pre-jar: called before JAR building + -post-jar: called after JAR building + -post-clean: called after cleaning build products + + (Targets beginning with '-' are not intended to be called on their own.) + + Example of inserting an obfuscator after compilation could look like this: + + <target name="-post-compile"> + <obfuscate> + <fileset dir="${build.classes.dir}"/> + </obfuscate> + </target> + + For list of available properties check the imported + nbproject/build-impl.xml file. + + + Another way to customize the build is by overriding existing main targets. + The targets of interest are: + + -init-macrodef-javac: defines macro for javac compilation + -init-macrodef-junit: defines macro for junit execution + -init-macrodef-debug: defines macro for class debugging + -init-macrodef-java: defines macro for class execution + -do-jar: JAR building + run: execution of project + -javadoc-build: Javadoc generation + test-report: JUnit report generation + + An example of overriding the target for project execution could look like this: + + <target name="run" depends="Homework2-impl.jar"> + <exec dir="bin" executable="launcher.exe"> + <arg file="${dist.jar}"/> + </exec> + </target> + + Notice that the overridden target depends on the jar target and not only on + the compile target as the regular run target does. Again, for a list of available + properties which you can use, check the target you are overriding in the + nbproject/build-impl.xml file. + + --> +</project> diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/manifest.mf b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/manifest.mf new file mode 100644 index 0000000000000000000000000000000000000000..328e8e5bc3b7f1f7bad2bc0751a933e00c801983 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/build-impl.xml b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/build-impl.xml new file mode 100644 index 0000000000000000000000000000000000000000..fb67440de460c532dfdb60e8f8ba722d056b0bb6 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/build-impl.xml @@ -0,0 +1,1799 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +*** GENERATED FROM project.xml - DO NOT EDIT *** +*** EDIT ../build.xml INSTEAD *** + +For the purpose of easier reading the script +is divided into following sections: + + - initialization + - compilation + - jar + - execution + - debugging + - javadoc + - test compilation + - test execution + - test debugging + - applet + - cleanup + + --> +<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="Homework2-impl"> + <fail message="Please build using Ant 1.8.0 or higher."> + <condition> + <not> + <antversion atleast="1.8.0"/> + </not> + </condition> + </fail> + <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/> + <!-- + ====================== + INITIALIZATION SECTION + ====================== + --> + <target name="-pre-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-pre-init" name="-init-private"> + <property file="nbproject/private/config.properties"/> + <property file="nbproject/private/configs/${config}.properties"/> + <property file="nbproject/private/private.properties"/> + </target> + <target depends="-pre-init,-init-private" name="-init-user"> + <property file="${user.properties.file}"/> + <!-- The two properties below are usually overridden --> + <!-- by the active platform. Just a fallback. --> + <property name="default.javac.source" value="1.6"/> + <property name="default.javac.target" value="1.6"/> + </target> + <target depends="-pre-init,-init-private,-init-user" name="-init-project"> + <property file="nbproject/configs/${config}.properties"/> + <property file="nbproject/project.properties"/> + </target> + <target name="-init-modules-supported"> + <condition property="modules.supported.internal" value="true"> + <not> + <matches pattern="1\.[0-8](\..*)?" string="${javac.source}"/> + </not> + </condition> + </target> + <target depends="-init-modules-supported" if="modules.supported.internal" name="-init-macrodef-modulename"> + <macrodef name="modulename" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute name="property"/> + <attribute name="sourcepath"/> + <sequential> + <loadresource property="@{property}" quiet="true"> + <javaresource classpath="@{sourcepath}" name="module-info.java" parentFirst="false"/> + <filterchain> + <stripjavacomments/> + <linecontainsregexp> + <regexp pattern="module .* \{"/> + </linecontainsregexp> + <tokenfilter> + <linetokenizer/> + <replaceregex flags="s" pattern="(\s*module\s+)(\S*)(\s*\{.*)" replace="\2"/> + </tokenfilter> + <striplinebreaks/> + </filterchain> + </loadresource> + </sequential> + </macrodef> + </target> + <target depends="-init-modules-supported,-init-macrodef-modulename" if="modules.supported.internal" name="-init-source-module-properties"> + <fail message="Java 9 support requires Ant 1.10.0 or higher."> + <condition> + <not> + <antversion atleast="1.10.0"/> + </not> + </condition> + </fail> + <j2seproject3:modulename property="module.name" sourcepath="${src.dir}"/> + <condition property="named.module.internal"> + <and> + <isset property="module.name"/> + <length length="0" string="${module.name}" when="greater"/> + </and> + </condition> + <condition property="unnamed.module.internal"> + <not> + <isset property="named.module.internal"/> + </not> + </condition> + <property name="javac.modulepath" value=""/> + <property name="run.modulepath" value="${javac.modulepath}"/> + <property name="module.build.classes.dir" value="${build.classes.dir}"/> + <property name="debug.modulepath" value="${run.modulepath}"/> + <property name="javac.upgrademodulepath" value=""/> + <property name="run.upgrademodulepath" value="${javac.upgrademodulepath}"/> + <condition else="" property="javac.systemmodulepath.cmd.line.arg" value="--system '${javac.systemmodulepath}'"> + <and> + <isset property="javac.systemmodulepath"/> + <length length="0" string="${javac.systemmodulepath}" when="greater"/> + </and> + </condition> + <property name="dist.jlink.dir" value="${dist.dir}/jlink"/> + <property name="dist.jlink.output" value="${dist.jlink.dir}/${application.title}"/> + <property name="module.name" value=""/> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property,-init-modules-supported" name="-do-init"> + <j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/> + <j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/> + <j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/> + <j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/> + <condition property="platform.javac" value="${platform.home}/bin/javac"> + <equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/> + </condition> + <property name="platform.javac" value="${platform.javac.tmp}"/> + <j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/> + <condition property="platform.java" value="${platform.home}/bin/java"> + <equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/> + </condition> + <property name="platform.java" value="${platform.java.tmp}"/> + <j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/> + <condition property="platform.javadoc" value="${platform.home}/bin/javadoc"> + <equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/> + </condition> + <property name="platform.javadoc" value="${platform.javadoc.tmp}"/> + <condition property="platform.invalid" value="true"> + <or> + <contains string="${platform.javac}" substring="$${platforms."/> + <contains string="${platform.java}" substring="$${platforms."/> + <contains string="${platform.javadoc}" substring="$${platforms."/> + </or> + </condition> + <fail unless="platform.home">Must set platform.home</fail> + <fail unless="platform.bootcp">Must set platform.bootcp</fail> + <fail unless="platform.java">Must set platform.java</fail> + <fail unless="platform.javac">Must set platform.javac</fail> + <fail if="platform.invalid"> + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + </fail> + <available file="${manifest.file}" property="manifest.available"/> + <condition property="splashscreen.available"> + <and> + <not> + <equals arg1="${application.splash}" arg2="" trim="true"/> + </not> + <available file="${application.splash}"/> + </and> + </condition> + <condition property="main.class.available"> + <and> + <isset property="main.class"/> + <not> + <equals arg1="${main.class}" arg2="" trim="true"/> + </not> + </and> + </condition> + <condition property="profile.available"> + <and> + <isset property="javac.profile"/> + <length length="0" string="${javac.profile}" when="greater"/> + <not> + <matches pattern="1\.[0-7](\..*)?" string="${javac.source}"/> + </not> + </and> + </condition> + <condition property="do.archive"> + <or> + <not> + <istrue value="${jar.archive.disabled}"/> + </not> + <istrue value="${not.archive.disabled}"/> + </or> + </condition> + <condition property="do.archive+manifest.available"> + <and> + <isset property="manifest.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="do.archive+main.class.available"> + <and> + <isset property="main.class.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="do.archive+splashscreen.available"> + <and> + <isset property="splashscreen.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="do.archive+profile.available"> + <and> + <isset property="profile.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="have.tests"> + <or> + <available file="${test.src.dir}"/> + </or> + </condition> + <condition property="have.sources"> + <or> + <available file="${src.dir}"/> + </or> + </condition> + <condition property="netbeans.home+have.tests"> + <and> + <isset property="netbeans.home"/> + <isset property="have.tests"/> + </and> + </condition> + <condition property="no.javadoc.preview"> + <and> + <isset property="javadoc.preview"/> + <isfalse value="${javadoc.preview}"/> + </and> + </condition> + <property name="run.jvmargs" value=""/> + <property name="run.jvmargs.ide" value=""/> + <property name="javac.compilerargs" value=""/> + <property name="work.dir" value="${basedir}"/> + <condition property="no.deps"> + <and> + <istrue value="${no.dependencies}"/> + </and> + </condition> + <property name="javac.debug" value="true"/> + <property name="javadoc.preview" value="true"/> + <property name="application.args" value=""/> + <property name="source.encoding" value="${file.encoding}"/> + <property name="runtime.encoding" value="${source.encoding}"/> + <property name="manifest.encoding" value="${source.encoding}"/> + <condition property="javadoc.encoding.used" value="${javadoc.encoding}"> + <and> + <isset property="javadoc.encoding"/> + <not> + <equals arg1="${javadoc.encoding}" arg2=""/> + </not> + </and> + </condition> + <property name="javadoc.encoding.used" value="${source.encoding}"/> + <property name="includes" value="**"/> + <property name="excludes" value=""/> + <property name="do.depend" value="false"/> + <condition property="do.depend.true"> + <istrue value="${do.depend}"/> + </condition> + <path id="endorsed.classpath.path" path="${endorsed.classpath}"/> + <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'"> + <and> + <isset property="endorsed.classpath"/> + <not> + <equals arg1="${endorsed.classpath}" arg2="" trim="true"/> + </not> + </and> + </condition> + <condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}"> + <isset property="profile.available"/> + </condition> + <property name="jar.index" value="false"/> + <property name="jar.index.metainf" value="${jar.index}"/> + <property name="copylibs.rebase" value="true"/> + <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/> + <condition property="junit.available"> + <or> + <available classname="org.junit.Test" classpath="${run.test.classpath}"/> + <available classname="junit.framework.Test" classpath="${run.test.classpath}"/> + </or> + </condition> + <condition property="testng.available"> + <available classname="org.testng.annotations.Test" classpath="${run.test.classpath}"/> + </condition> + <condition property="junit+testng.available"> + <and> + <istrue value="${junit.available}"/> + <istrue value="${testng.available}"/> + </and> + </condition> + <condition else="testng" property="testng.mode" value="mixed"> + <istrue value="${junit+testng.available}"/> + </condition> + <condition else="" property="testng.debug.mode" value="-mixed"> + <istrue value="${junit+testng.available}"/> + </condition> + <property name="java.failonerror" value="true"/> + </target> + <target name="-post-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check"> + <fail unless="src.dir">Must set src.dir</fail> + <fail unless="test.src.dir">Must set test.src.dir</fail> + <fail unless="build.dir">Must set build.dir</fail> + <fail unless="dist.dir">Must set dist.dir</fail> + <fail unless="build.classes.dir">Must set build.classes.dir</fail> + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail> + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail> + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail> + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail> + <fail unless="dist.jar">Must set dist.jar</fail> + </target> + <target name="-init-macrodef-property"> + <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties,-init-source-module-properties" if="modules.supported.internal" name="-init-macrodef-javac-with-module"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <attribute default="${javac.modulepath}" name="modulepath"/> + <attribute default="${javac.upgrademodulepath}" name="upgrademodulepath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${javac.processormodulepath}" name="processormodulepath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="sourcepath" unless:set="named.module.internal"/> + <attribute default="${src.dir}" if:set="named.module.internal" name="sourcepath"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <condition property="warn.excludes.internal"> + <and> + <isset property="named.module.internal"/> + <length length="0" string="@{excludes}" trim="true" when="greater"/> + </and> + </condition> + <echo if:set="warn.excludes.internal" level="warning" message="The javac excludes are not supported in the JDK 9 Named Module."/> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <mkdir dir="@{apgeneratedsrcdir}"/> + <condition property="processormodulepath.set"> + <resourcecount count="0" when="greater"> + <path> + <pathelement path="@{processormodulepath}"/> + </path> + </resourcecount> + </condition> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <modulepath> + <path path="@{modulepath}"/> + </modulepath> + <upgrademodulepath> + <path path="@{upgrademodulepath}"/> + </upgrademodulepath> + <compilerarg line="${javac.systemmodulepath.cmd.line.arg}"/> + <compilerarg line="${javac.profile.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <compilerarg if:set="processormodulepath.set" value="--processor-module-path"/> + <compilerarg if:set="processormodulepath.set" path="@{processormodulepath}"/> + <compilerarg unless:set="processormodulepath.set" value="-processorpath"/> + <compilerarg path="@{processorpath}:${empty.dir}" unless:set="processormodulepath.set"/> + <compilerarg line="${ap.processors.internal}"/> + <compilerarg line="${annotation.processing.processor.options}"/> + <compilerarg value="-s"/> + <compilerarg path="@{apgeneratedsrcdir}"/> + <compilerarg line="${ap.proc.none.internal}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties,-init-source-module-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors" unless="modules.supported.internal"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <attribute default="${javac.modulepath}" name="modulepath"/> + <attribute default="${javac.upgrademodulepath}" name="upgrademodulepath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="sourcepath"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <mkdir dir="@{apgeneratedsrcdir}"/> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/> + <compilerarg line="${javac.profile.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <compilerarg value="-processorpath"/> + <compilerarg path="@{processorpath}:${empty.dir}"/> + <compilerarg line="${ap.processors.internal}"/> + <compilerarg line="${annotation.processing.processor.options}"/> + <compilerarg value="-s"/> + <compilerarg path="@{apgeneratedsrcdir}"/> + <compilerarg line="${ap.proc.none.internal}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties,-init-source-module-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <attribute default="${javac.modulepath}" name="modulepath"/> + <attribute default="${javac.upgrademodulepath}" name="upgrademodulepath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="sourcepath"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/> + <compilerarg line="${javac.profile.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-javac-with-module,-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac"> + <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <sequential> + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + </depend> + </sequential> + </macrodef> + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${build.classes.dir}" name="destdir"/> + <sequential> + <fail unless="javac.includes">Must set javac.includes</fail> + <pathconvert pathsep="${line.separator}" property="javac.includes.binary"> + <path> + <filelist dir="@{destdir}" files="${javac.includes}"/> + </path> + <globmapper from="*.java" to="*.class"/> + </pathconvert> + <tempfile deleteonexit="true" property="javac.includesfile.binary"/> + <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/> + <delete> + <files includesfile="${javac.includesfile.binary}"/> + </delete> + <delete> + <fileset file="${javac.includesfile.binary}"/> + </delete> + </sequential> + </macrodef> + </target> + <target if="${junit.available}" name="-init-macrodef-junit-init"> + <condition else="false" property="nb.junit.batch" value="true"> + <and> + <istrue value="${junit.available}"/> + <not> + <isset property="test.method"/> + </not> + </and> + </condition> + <condition else="false" property="nb.junit.single" value="true"> + <and> + <istrue value="${junit.available}"/> + <isset property="test.method"/> + </and> + </condition> + </target> + <target name="-init-test-properties"> + <property name="test.binaryincludes" value="<nothing>"/> + <property name="test.binarytestincludes" value=""/> + <property name="test.binaryexcludes" value=""/> + </target> + <target depends="-init-modules-supported" if="modules.supported.internal" name="-init-macrodef-junit-prototype-with-module"> + <macrodef name="junit-prototype" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <element name="customizePrototype" optional="true"/> + <sequential> + <property name="junit.forkmode" value="perTest"/> + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}"> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + <modulepath> + <path path="${run.test.modulepath}"/> + </modulepath> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg value="-ea"/> + <jvmarg line="${run.test.jvmargs}"/> + <customizePrototype/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-modules-supported" name="-init-macrodef-junit-prototype-without-module" unless="modules.supported.internal"> + <macrodef name="junit-prototype" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <element name="customizePrototype" optional="true"/> + <sequential> + <property name="junit.forkmode" value="perTest"/> + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}"> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg value="-ea"/> + <customizePrototype/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-test-properties,-init-macrodef-junit-prototype-with-module,-init-macrodef-junit-prototype-without-module" if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}"> + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <j2seproject3:junit-prototype> + <customizePrototype> + <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/> + <customize/> + </customizePrototype> + </j2seproject3:junit-prototype> + </sequential> + </macrodef> + </target> + <target depends="-init-test-properties,-init-macrodef-junit-prototype-with-module,-init-macrodef-junit-prototype-without-module" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}"> + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <j2seproject3:junit-prototype> + <customizePrototype> + <batchtest todir="${build.test.results.dir}"> + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}"> + <filename name="${test.binarytestincludes}"/> + </fileset> + </batchtest> + <customize/> + </customizePrototype> + </j2seproject3:junit-prototype> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/> + <target if="${testng.available}" name="-init-macrodef-testng"> + <macrodef name="testng" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}"> + <isset property="test.method"/> + </condition> + <union id="test.set"> + <fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + </union> + <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/> + <testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="Homework2" testname="TestNG tests" workingDir="${work.dir}"> + <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/> + <propertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </propertyset> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <customize/> + </testng> + </sequential> + </macrodef> + </target> + <target name="-init-macrodef-test-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <echo>No tests executed.</echo> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <j2seproject3:junit excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </j2seproject3:junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng" if="${testng.available}" name="-init-macrodef-testng-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <j2seproject3:testng excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </j2seproject3:testng> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-test-impl,-init-macrodef-junit-impl,-init-macrodef-testng-impl" name="-init-macrodef-test"> + <macrodef name="test" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <sequential> + <j2seproject3:test-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + </customize> + </j2seproject3:test-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-debug-impl"> + <macrodef name="test-debug-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customizeDebuggee" optional="true"/> + <sequential> + <j2seproject3:junit excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize> + <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/> + <customizeDebuggee/> + </customize> + </j2seproject3:junit> + </sequential> + </macrodef> + </target> + <target if="${testng.available}" name="-init-macrodef-testng-debug"> + <macrodef name="testng-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <element name="customize2" optional="true"/> + <sequential> + <condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}"> + <isset property="test.method"/> + </condition> + <condition else="-suitename Homework2 -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}"> + <matches pattern=".*\.xml" string="@{testClass}"/> + </condition> + <delete dir="${build.test.results.dir}" quiet="true"/> + <mkdir dir="${build.test.results.dir}"/> + <j2seproject3:debug classname="org.testng.TestNG" classpath="${debug.test.classpath}"> + <customizeDebuggee> + <customize2/> + <jvmarg value="-ea"/> + <arg line="${testng.debug.mode}"/> + <arg line="-d ${build.test.results.dir}"/> + <arg line="-listener org.testng.reporters.VerboseReporter"/> + <arg line="${testng.cmd.args}"/> + </customizeDebuggee> + </j2seproject3:debug> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng-debug" if="${testng.available}" name="-init-macrodef-testng-debug-impl"> + <macrodef name="testng-debug-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <element implicit="true" name="customize2" optional="true"/> + <sequential> + <j2seproject3:testng-debug testClass="@{testClass}" testMethod="@{testMethod}"> + <customize2/> + </j2seproject3:testng-debug> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-debug-impl" if="${junit.available}" name="-init-macrodef-test-debug-junit"> + <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <sequential> + <j2seproject3:test-debug-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customizeDebuggee> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + </customizeDebuggee> + </j2seproject3:test-debug-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng-debug-impl" if="${testng.available}" name="-init-macrodef-test-debug-testng"> + <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <sequential> + <j2seproject3:testng-debug-impl testClass="@{testClass}" testMethod="@{testMethod}"> + <customize2> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + </customize2> + </j2seproject3:testng-debug-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/> + <!-- + pre NB7.2 profiling section; consider it deprecated + --> + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/> + <target if="profiler.info.jvmargs.agent" name="-profile-pre-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="profiler.info.jvmargs.agent" name="-profile-post-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="profiler.info.jvmargs.agent" name="-profile-init-macrodef-profile"> + <macrodef name="resolve"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${env.@{value}}"/> + </sequential> + </macrodef> + <macrodef name="profile"> + <attribute default="${main.class}" name="classname"/> + <element name="customize" optional="true"/> + <sequential> + <property environment="env"/> + <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/> + <java classname="@{classname}" dir="${profiler.info.dir}" failonerror="${java.failonerror}" fork="true" jvm="${profiler.info.jvm}"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg line="${profiler.info.jvmargs}"/> + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> + <arg line="${application.args}"/> + <classpath> + <path path="${run.classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" if="profiler.info.jvmargs.agent" name="-profile-init-check"> + <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail> + <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail> + </target> + <!-- + end of pre NB7.2 profiling section + --> + <target depends="-init-debug-args" name="-init-macrodef-nbjpda"> + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="${main.class}" name="name"/> + <attribute default="${debug.modulepath}" name="modulepath"/> + <attribute default="${debug.classpath}" name="classpath"/> + <attribute default="" name="stopclassname"/> + <sequential> + <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}"> + <modulepath> + <path path="@{modulepath}"/> + </modulepath> + <classpath> + <path path="@{classpath}"/> + </classpath> + <bootclasspath> + <path path="${platform.bootcp}"/> + </bootclasspath> + </nbjpdastart> + </sequential> + </macrodef> + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="${build.classes.dir}" name="dir"/> + <sequential> + <nbjpdareload> + <fileset dir="@{dir}" includes="${fix.classes}"> + <include name="${fix.includes}*.class"/> + </fileset> + </nbjpdareload> + </sequential> + </macrodef> + </target> + <target name="-init-debug-args"> + <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem"> + <os family="windows"/> + </condition> + <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}"> + <isset property="debug.transport"/> + </condition> + </target> + <target depends="-init-debug-args" name="-init-macrodef-debug"> + <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${module.name}" name="modulename"/> + <attribute default="${main.class}" name="classname"/> + <attribute default="${debug.modulepath}" name="modulepath"/> + <attribute default="${debug.classpath}" name="classpath"/> + <element name="customizeDebuggee" optional="true"/> + <sequential> + <j2seproject1:java classname="@{classname}" classpath="@{classpath}" modulename="@{modulename}" modulepath="@{modulepath}"> + <customize> + <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/> + <customizeDebuggee/> + </customize> + </j2seproject1:java> + </sequential> + </macrodef> + </target> + <target depends="-init-source-module-properties" if="named.module.internal" name="-init-macrodef-java-with-module"> + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="${module.name}" name="modulename"/> + <attribute default="${main.class}" name="classname"/> + <attribute default="${run.modulepath}" name="modulepath"/> + <attribute default="${run.upgrademodulepath}" name="upgrademodulepath"/> + <attribute default="${run.classpath}" name="classpath"/> + <attribute default="jvm" name="jvm"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}" module="@{modulename}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + <modulepath> + <pathelement path="@{modulepath}"/> + <pathelement location="${module.build.classes.dir}"/> + </modulepath> + <upgrademodulepath> + <path path="@{upgrademodulepath}"/> + </upgrademodulepath> + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/> + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target depends="-init-source-module-properties" if="unnamed.module.internal" name="-init-macrodef-java-with-unnamed-module"> + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="" name="modulename"/> + <attribute default="${main.class}" name="classname"/> + <attribute default="${run.modulepath}" name="modulepath"/> + <attribute default="${run.upgrademodulepath}" name="upgrademodulepath"/> + <attribute default="${run.classpath}" name="classpath"/> + <attribute default="jvm" name="jvm"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + <modulepath> + <path path="@{modulepath}"/> + </modulepath> + <upgrademodulepath> + <path path="@{upgrademodulepath}"/> + </upgrademodulepath> + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/> + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target depends="-init-source-module-properties" name="-init-macrodef-java-without-module" unless="modules.supported.internal"> + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="" name="modulename"/> + <attribute default="${main.class}" name="classname"/> + <attribute default="" name="modulepath"/> + <attribute default="${run.classpath}" name="classpath"/> + <attribute default="jvm" name="jvm"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/> + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + <classpath> + <path path="@{classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-java-with-module, -init-macrodef-java-with-unnamed-module, -init-macrodef-java-without-module" name="-init-macrodef-java"/> + <target name="-init-macrodef-copylibs"> + <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${manifest.file}" name="manifest"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/> + <pathconvert property="run.classpath.without.build.classes.dir"> + <path path="${run.classpath}"/> + <map from="${build.classes.dir.resolved}" to=""/> + </pathconvert> + <pathconvert pathsep=" " property="jar.classpath"> + <path path="${run.classpath.without.build.classes.dir}"/> + <chainedmapper> + <flattenmapper/> + <filtermapper> + <replacestring from=" " to="%20"/> + </filtermapper> + <globmapper from="*" to="lib/*"/> + </chainedmapper> + </pathconvert> + <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/> + <copylibs compress="${jar.compress}" excludeFromCopy="${copylibs.excludes}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" manifestencoding="UTF-8" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> + <fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/> + <manifest> + <attribute name="Class-Path" value="${jar.classpath}"/> + <customize/> + </manifest> + </copylibs> + </sequential> + </macrodef> + </target> + <target name="-init-presetdef-jar"> + <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1"> + <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifestencoding="UTF-8"> + <j2seproject1:fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/> + </jar> + </presetdef> + </target> + <target name="-init-ap-cmdline-properties"> + <property name="annotation.processing.enabled" value="true"/> + <property name="annotation.processing.processors.list" value=""/> + <property name="annotation.processing.processor.options" value=""/> + <property name="annotation.processing.run.all.processors" value="true"/> + <property name="javac.processorpath" value="${javac.classpath}"/> + <property name="javac.test.processorpath" value="${javac.test.classpath}"/> + <condition property="ap.supported.internal" value="true"> + <not> + <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/> + </not> + </condition> + </target> + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported"> + <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}"> + <isfalse value="${annotation.processing.run.all.processors}"/> + </condition> + <condition else="" property="ap.proc.none.internal" value="-proc:none"> + <isfalse value="${annotation.processing.enabled}"/> + </condition> + </target> + <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline"> + <property name="ap.cmd.line.internal" value=""/> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-test,-init-macrodef-test-debug,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/> + <!-- + =================== + COMPILATION SECTION + =================== + --> + <target name="-deps-jar-init" unless="built-jar.properties"> + <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/> + <delete file="${built-jar.properties}" quiet="true"/> + </target> + <target if="already.built.jar.${basedir}" name="-warn-already-built-jar"> + <echo level="warn" message="Cycle detected: Homework2 was already built"/> + </target> + <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps"> + <mkdir dir="${build.dir}"/> + <touch file="${built-jar.properties}" verbose="false"/> + <property file="${built-jar.properties}" prefix="already.built.jar."/> + <antcall target="-warn-already-built-jar"/> + <propertyfile file="${built-jar.properties}"> + <entry key="${basedir}" value=""/> + </propertyfile> + </target> + <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/> + <target depends="init" name="-check-automatic-build"> + <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/> + </target> + <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build"> + <antcall target="clean"> + <param name="no.dependencies" value="true"/> + </antcall> + </target> + <target depends="init,deps-jar" name="-pre-pre-compile"> + <mkdir dir="${build.classes.dir}"/> + </target> + <target name="-pre-compile"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="do.depend.true" name="-compile-depend"> + <pathconvert property="build.generated.subdirs"> + <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </pathconvert> + <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/> + </target> + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile"> + <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/> + <copy todir="${build.classes.dir}"> + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target if="has.persistence.xml" name="-copy-persistence-xml"> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy todir="${build.classes.dir}/META-INF"> + <fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/> + </copy> + </target> + <target name="-post-compile"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/> + <target name="-pre-compile-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single"> + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> + <j2seproject3:force-recompile/> + <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}, module-info.java" sourcepath="${src.dir}"/> + </target> + <target name="-post-compile-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/> + <!-- + ==================== + JAR BUILDING SECTION + ==================== + --> + <target depends="init" name="-pre-pre-jar"> + <dirname file="${dist.jar}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + </target> + <target name="-pre-jar"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile" name="-check-module-main-class"> + <pathconvert property="main.class.file"> + <string value="${main.class}"/> + <unpackagemapper from="*" to="*.class"/> + </pathconvert> + <condition property="do.module.main.class"> + <and> + <isset property="main.class.available"/> + <available file="${build.classes.dir}/module-info.class"/> + <available file="${build.classes.dir}/${main.class.file}"/> + <isset property="libs.CopyLibs.classpath"/> + <available classname="org.netbeans.modules.java.j2seproject.moduletask.ModuleMainClass" classpath="${libs.CopyLibs.classpath}"/> + </and> + </condition> + </target> + <target depends="-check-module-main-class" if="do.module.main.class" name="-set-module-main-class"> + <taskdef classname="org.netbeans.modules.java.j2seproject.moduletask.ModuleMainClass" classpath="${libs.CopyLibs.classpath}" name="modulemainclass"/> + <modulemainclass failonerror="false" mainclass="${main.class}" moduleinfo="${build.classes.dir}/module-info.class"/> + </target> + <target depends="init" if="do.archive" name="-do-jar-create-manifest" unless="manifest.available"> + <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/> + <touch file="${tmp.manifest.file}" verbose="false"/> + </target> + <target depends="init" if="do.archive+manifest.available" name="-do-jar-copy-manifest"> + <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/> + <copy encoding="${manifest.encoding}" file="${manifest.file}" outputencoding="UTF-8" tofile="${tmp.manifest.file}"/> + </target> + <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass"> + <manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update"> + <attribute name="Main-Class" value="${main.class}"/> + </manifest> + </target> + <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+profile.available" name="-do-jar-set-profile"> + <manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update"> + <attribute name="Profile" value="${javac.profile}"/> + </manifest> + </target> + <target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-set-splashscreen"> + <basename file="${application.splash}" property="splashscreen.basename"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/> + <manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update"> + <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/> + </manifest> + </target> + <target depends="init,compile" name="-check-do-mkdist"> + <condition property="do.mkdist"> + <and> + <isset property="do.archive"/> + <isset property="libs.CopyLibs.classpath"/> + <not> + <istrue value="${mkdist.disabled}"/> + </not> + <not> + <available file="${build.classes.dir}/module-info.class"/> + </not> + </and> + </condition> + </target> + <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.mkdist" name="-do-jar-copylibs"> + <j2seproject3:copylibs manifest="${tmp.manifest.file}"/> + <echo level="info">To run this application from the command line without Ant, try:</echo> + <property location="${dist.jar}" name="dist.jar.resolved"/> + <echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo> + </target> + <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.archive" name="-do-jar-jar" unless="do.mkdist"> + <j2seproject1:jar manifest="${tmp.manifest.file}"/> + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/> + <property location="${dist.jar}" name="dist.jar.resolved"/> + <condition else="${dist.jar.resolved}" property="jar.usage.message.class.path.replacement" value=""> + <isset property="named.module.internal"/> + </condition> + <pathconvert property="run.classpath.with.dist.jar"> + <path path="${run.classpath}"/> + <map from="${build.classes.dir.resolved}" to="${jar.usage.message.class.path.replacement}"/> + </pathconvert> + <pathconvert property="run.modulepath.with.dist.jar"> + <path location="${dist.jar.resolved}"/> + <path path="${run.modulepath}"/> + <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/> + </pathconvert> + <condition else="${run.modulepath}" property="jar.usage.message.run.modulepath.with.dist.jar" value="${run.modulepath.with.dist.jar}"> + <isset property="named.module.internal"/> + </condition> + <condition else="" property="jar.usage.message.module.path" value=" -p ${jar.usage.message.run.modulepath.with.dist.jar}"> + <and> + <isset property="modules.supported.internal"/> + <length length="0" string="${jar.usage.message.run.modulepath.with.dist.jar}" when="greater"/> + </and> + </condition> + <condition else="" property="jar.usage.message.class.path" value=" -cp ${run.classpath.with.dist.jar}"> + <length length="0" string="${run.classpath.with.dist.jar}" when="greater"/> + </condition> + <condition else="/${main.class}" property="jar.usage.message.main.class.class.selector" value=""> + <isset property="do.module.main.class"/> + </condition> + <condition else=" ${main.class}" property="jar.usage.message.main.class" value=" -m ${module.name}${jar.usage.message.main.class.class.selector}"> + <isset property="named.module.internal"/> + </condition> + <condition else="" property="jar.usage.message" value="To run this application from the command line without Ant, try:${line.separator}${platform.java}${jar.usage.message.module.path}${jar.usage.message.class.path}${jar.usage.message.main.class}"> + <isset property="main.class.available"/> + </condition> + <condition else="debug" property="jar.usage.level" value="info"> + <isset property="main.class.available"/> + </condition> + <echo level="${jar.usage.level}" message="${jar.usage.message}"/> + </target> + <target depends="-do-jar-copylibs" if="do.archive" name="-do-jar-delete-manifest"> + <delete> + <fileset file="${tmp.manifest.file}"/> + </delete> + </target> + <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-do-jar-jar,-do-jar-delete-manifest" name="-do-jar-without-libraries"/> + <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-do-jar-copylibs,-do-jar-delete-manifest" name="-do-jar-with-libraries"/> + <target name="-post-jar"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-jar,-set-module-main-class,-do-jar-without-libraries,-do-jar-with-libraries,-post-jar" name="-do-jar"/> + <target depends="init,compile,-pre-jar,-do-jar,-post-jar,deploy" description="Build JAR." name="jar"/> + <!-- + ================= + DEPLOY SECTION + ================= + --> + <target name="-pre-deploy"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init" name="-check-jlink"> + <condition property="do.jlink.internal"> + <and> + <istrue value="${do.jlink}"/> + <isset property="do.archive"/> + <isset property="named.module.internal"/> + </and> + </condition> + </target> + <target depends="init,-do-jar,-post-jar,-pre-deploy,-check-jlink" if="do.jlink.internal" name="-do-deploy"> + <delete dir="${dist.jlink.dir}" failonerror="false" quiet="true"/> + <property name="jlink.launcher.name" value="${application.title}"/> + <condition else="${module.name}" property="jlink.add.modules" value="${module.name},${jlink.additionalmodules}"> + <and> + <isset property="jlink.additionalmodules"/> + <length length="0" string="${jlink.additionalmodules}" when="greater"/> + </and> + </condition> + <condition property="jlink.do.strip.internal"> + <and> + <isset property="jlink.strip"/> + <istrue value="${jlink.strip}"/> + </and> + </condition> + <condition property="jlink.do.additionalparam.internal"> + <and> + <isset property="jlink.additionalparam"/> + <length length="0" string="${jlink.additionalparam}" when="greater"/> + </and> + </condition> + <condition property="jlink.do.launcher.internal"> + <and> + <istrue value="${jlink.launcher}"/> + <isset property="main.class.available"/> + </and> + </condition> + <property name="platform.jlink" value="${platform.home}/bin/jlink"/> + <property name="jlink.systemmodules.internal" value="${platform.home}/jmods"/> + <exec executable="${platform.jlink}"> + <arg value="--module-path"/> + <arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.jar}"/> + <arg value="--add-modules"/> + <arg value="${jlink.add.modules}"/> + <arg if:set="jlink.do.strip.internal" value="--strip-debug"/> + <arg if:set="jlink.do.launcher.internal" value="--launcher"/> + <arg if:set="jlink.do.launcher.internal" value="${jlink.launcher.name}=${module.name}/${main.class}"/> + <arg if:set="jlink.do.additionalparam.internal" line="${jlink.additionalparam}"/> + <arg value="--output"/> + <arg value="${dist.jlink.output}"/> + </exec> + </target> + <target name="-post-deploy"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-do-jar,-post-jar,-pre-deploy,-do-deploy,-post-deploy" name="deploy"/> + <!-- + ================= + EXECUTION SECTION + ================= + --> + <target depends="init,compile" description="Run a main class." name="run"> + <j2seproject1:java> + <customize> + <arg line="${application.args}"/> + </customize> + </j2seproject1:java> + </target> + <target name="-do-not-recompile"> + <property name="javac.includes.binary" value=""/> + </target> + <target depends="init,compile-single" name="run-single"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <j2seproject1:java classname="${run.class}"/> + </target> + <target depends="init,compile-test-single" name="run-test-with-main"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/> + </target> + <!-- + ================= + DEBUGGING SECTION + ================= + --> + <target depends="init" if="netbeans.home" name="-debug-start-debugger"> + <j2seproject1:nbjpdastart name="${debug.class}"/> + </target> + <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test"> + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/> + </target> + <target depends="init,compile" name="-debug-start-debuggee"> + <j2seproject3:debug> + <customizeDebuggee> + <arg line="${application.args}"/> + </customizeDebuggee> + </j2seproject3:debug> + </target> + <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/> + <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto"> + <j2seproject1:nbjpdastart stopclassname="${main.class}"/> + </target> + <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/> + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single"> + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail> + <j2seproject3:debug classname="${debug.class}"/> + </target> + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/> + <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test"> + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail> + <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/> + </target> + <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/> + <target depends="init" name="-pre-debug-fix"> + <fail unless="fix.includes">Must set fix.includes</fail> + <property name="javac.includes" value="${fix.includes}.java"/> + </target> + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix"> + <j2seproject1:nbjpdareload/> + </target> + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/> + <!-- + ================= + PROFILING SECTION + ================= + --> + <!-- + pre NB7.2 profiler integration + --> + <target depends="profile-init,compile" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.classpath}"/> + </classpath> + </nbprofiledirect> + <profile/> + </target> + <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="profiler.info.jvmargs.agent" name="-profile-single-pre72"> + <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.classpath}"/> + </classpath> + </nbprofiledirect> + <profile classname="${profile.class}"/> + </target> + <target depends="profile-init,compile-single" if="profiler.info.jvmargs.agent" name="-profile-applet-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.classpath}"/> + </classpath> + </nbprofiledirect> + <profile classname="sun.applet.AppletViewer"> + <customize> + <arg value="${applet.url}"/> + </customize> + </profile> + </target> + <target depends="-init-macrodef-junit,profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + </nbprofiledirect> + <j2seproject3:junit excludes="${excludes}" includes="${includes}" testincludes="${profile.class}" testmethods=""> + <customize> + <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/> + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg line="${profiler.info.jvmargs}"/> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + </customize> + </j2seproject3:junit> + </target> + <!-- + end of pre NB72 profiling section + --> + <target if="netbeans.home" name="-profile-check"> + <condition property="profiler.configured"> + <or> + <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-agentpath:"/> + <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-javaagent:"/> + </or> + </condition> + </target> + <target depends="-profile-check,-profile-pre72" description="Profile a project in the IDE." if="profiler.configured" name="profile" unless="profiler.info.jvmargs.agent"> + <startprofiler/> + <antcall target="run"/> + </target> + <target depends="-profile-check,-profile-single-pre72" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-single" unless="profiler.info.jvmargs.agent"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <startprofiler/> + <antcall target="run-single"/> + </target> + <target depends="-profile-test-single-pre72" description="Profile a selected test in the IDE." name="profile-test-single"/> + <target depends="-profile-check" description="Profile a selected test in the IDE." if="profiler.configured" name="profile-test" unless="profiler.info.jvmargs"> + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail> + <startprofiler/> + <antcall target="test-single"/> + </target> + <target depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-test-with-main"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <startprofiler/> + <antcall target="run-test-with-main"/> + </target> + <target depends="-profile-check,-profile-applet-pre72" if="profiler.configured" name="profile-applet" unless="profiler.info.jvmargs.agent"> + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail> + <startprofiler/> + <antcall target="run-applet"/> + </target> + <!-- + =============== + JAVADOC SECTION + =============== + --> + <target depends="init" if="have.sources" name="-javadoc-build"> + <mkdir dir="${dist.javadoc.dir}"/> + <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}"> + <and> + <isset property="endorsed.classpath.cmd.line.arg"/> + <not> + <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/> + </not> + </and> + </condition> + <exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output"> + <arg value="-version"/> + </exec> + <condition else="" property="bug5101868workaround" value="*.java"> + <matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/> + </condition> + <condition else="" property="javadoc.html5.cmd.line.arg" value="-html5"> + <and> + <isset property="javadoc.html5"/> + <available file="${platform.home}${file.separator}lib${file.separator}jrt-fs.jar"/> + </and> + </condition> + <javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}"> + <classpath> + <path path="${javac.classpath}"/> + </classpath> + <fileset dir="${src.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}"> + <filename name="**/*.java"/> + </fileset> + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="**/*.java"/> + <exclude name="*.java"/> + </fileset> + <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/> + <arg line="${javadoc.html5.cmd.line.arg}"/> + </javadoc> + <copy todir="${dist.javadoc.dir}"> + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> + <filename name="**/doc-files/**"/> + </fileset> + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="**/doc-files/**"/> + </fileset> + </copy> + </target> + <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview"> + <nbbrowse file="${dist.javadoc.dir}/index.html"/> + </target> + <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/> + <!-- + ========================= + TEST COMPILATION SECTION + ========================= + --> + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test"> + <mkdir dir="${build.test.classes.dir}"/> + </target> + <target name="-pre-compile-test"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-init-source-module-properties" if="named.module.internal" name="-init-test-javac-module-properties-with-module"> + <j2seproject3:modulename property="test.module.name" sourcepath="${test.src.dir}"/> + <condition else="${empty.dir}" property="javac.test.sourcepath" value="${test.src.dir}"> + <and> + <isset property="test.module.name"/> + <length length="0" string="${test.module.name}" when="greater"/> + </and> + </condition> + <condition else="--patch-module ${module.name}=${test.src.dir} --add-reads ${module.name}=ALL-UNNAMED" property="javac.test.compilerargs" value="--add-reads ${test.module.name}=ALL-UNNAMED"> + <and> + <isset property="test.module.name"/> + <length length="0" string="${test.module.name}" when="greater"/> + </and> + </condition> + </target> + <target depends="-init-source-module-properties" if="named.module.internal" name="-init-test-run-module-properties"> + <condition else="${module.name}" property="run.test.addexport.source.module.internal" value="${test.module.name}"> + <and> + <isset property="test.module.name"/> + <length length="0" string="${test.module.name}" when="greater"/> + </and> + </condition> + <fileset dir="${build.test.classes.dir}" id="run.test.packages.internal" includes="**/*.class"/> + <property location="${build.test.classes.dir}" name="build.test.classes.dir.abs.internal"/> + <pathconvert pathsep=" " property="run.test.addexports.internal" refid="run.test.packages.internal"> + <chainedmapper> + <regexpmapper from="^(.*)\Q${file.separator}\E.*\.class$$" to="\1"/> + <filtermapper> + <uniqfilter/> + <replacestring from="${build.test.classes.dir.abs.internal}" to=""/> + </filtermapper> + <cutdirsmapper dirs="1"/> + <packagemapper from="*" to="--add-exports ${run.test.addexport.source.module.internal}/*=ALL-UNNAMED"/> + </chainedmapper> + </pathconvert> + <condition else="--patch-module ${module.name}=${build.test.classes.dir} --add-modules ${module.name} --add-reads ${module.name}=ALL-UNNAMED ${run.test.addexports.internal}" property="run.test.jvmargs" value="--add-modules ${test.module.name} --add-reads ${test.module.name}=ALL-UNNAMED ${run.test.addexports.internal}"> + <and> + <isset property="test.module.name"/> + <length length="0" string="${test.module.name}" when="greater"/> + </and> + </condition> + </target> + <target depends="-init-source-module-properties" name="-init-test-module-properties-without-module" unless="named.module.internal"> + <property name="javac.test.sourcepath" value="${empty.dir}"/> + <property name="javac.test.compilerargs" value=""/> + <property name="run.test.jvmargs" value=""/> + </target> + <target depends="-init-test-javac-module-properties-with-module,-init-test-module-properties-without-module" name="-init-test-module-properties"/> + <target if="do.depend.true" name="-compile-test-depend"> + <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/> + </target> + <target depends="init,deps-jar,compile,-init-test-module-properties,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test"> + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" modulepath="${javac.test.modulepath}" processorpath="${javac.test.processorpath}" sourcepath="${javac.test.sourcepath}" srcdir="${test.src.dir}"> + <customize> + <compilerarg line="${javac.test.compilerargs}"/> + </customize> + </j2seproject3:javac> + <copy todir="${build.test.classes.dir}"> + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-test"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/> + <target name="-pre-compile-test-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,compile,-init-test-module-properties,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single"> + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> + <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/> + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}, module-info.java" modulepath="${javac.test.modulepath}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"> + <customize> + <compilerarg line="${javac.test.compilerargs}"/> + </customize> + </j2seproject3:javac> + <copy todir="${build.test.classes.dir}"> + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-test-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/> + <!-- + ======================= + TEST EXECUTION SECTION + ======================= + --> + <target depends="init" if="have.tests" name="-pre-test-run"> + <mkdir dir="${build.test.results.dir}"/> + </target> + <target depends="init,compile-test,-init-test-run-module-properties,-pre-test-run" if="have.tests" name="-do-test-run"> + <j2seproject3:test includes="${includes}" testincludes="**/*Test.java"/> + </target> + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init" if="have.tests" name="test-report"/> + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/> + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/> + <target depends="init" if="have.tests" name="-pre-test-run-single"> + <mkdir dir="${build.test.results.dir}"/> + </target> + <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-do-test-run-single"> + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail> + <j2seproject3:test excludes="" includes="${test.includes}" testincludes="${test.includes}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-method"> + <fail unless="test.class">Must select some files in the IDE or set test.class</fail> + <fail unless="test.method">Must select some method in the IDE or set test.method</fail> + <j2seproject3:test excludes="" includes="${javac.includes}" testincludes="${test.class}" testmethods="${test.method}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method" if="have.tests" name="-post-test-run-single-method"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single,-do-test-run-single-method,-post-test-run-single-method" description="Run single unit test." name="test-single-method"/> + <!-- + ======================= + TEST DEBUGGING SECTION + ======================= + --> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test"> + <fail unless="test.class">Must select one file in the IDE or set test.class</fail> + <j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test-method"> + <fail unless="test.class">Must select one file in the IDE or set test.class</fail> + <fail unless="test.method">Must select some method in the IDE or set test.method</fail> + <j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testMethod="${test.method}" testincludes="${test.class}" testmethods="${test.method}"/> + </target> + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test"> + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/> + </target> + <target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/> + <target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/> + <target depends="debug-test-method" name="debug-single-method"/> + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test"> + <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/> + </target> + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/> + <!-- + ========================= + APPLET EXECUTION SECTION + ========================= + --> + <target depends="init,compile-single" name="run-applet"> + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail> + <j2seproject1:java classname="sun.applet.AppletViewer"> + <customize> + <arg value="${applet.url}"/> + </customize> + </j2seproject1:java> + </target> + <!-- + ========================= + APPLET DEBUGGING SECTION + ========================= + --> + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet"> + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail> + <j2seproject3:debug classname="sun.applet.AppletViewer"> + <customizeDebuggee> + <arg value="${applet.url}"/> + </customizeDebuggee> + </j2seproject3:debug> + </target> + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/> + <!-- + =============== + CLEANUP SECTION + =============== + --> + <target name="-deps-clean-init" unless="built-clean.properties"> + <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/> + <delete file="${built-clean.properties}" quiet="true"/> + </target> + <target if="already.built.clean.${basedir}" name="-warn-already-built-clean"> + <echo level="warn" message="Cycle detected: Homework2 was already built"/> + </target> + <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps"> + <mkdir dir="${build.dir}"/> + <touch file="${built-clean.properties}" verbose="false"/> + <property file="${built-clean.properties}" prefix="already.built.clean."/> + <antcall target="-warn-already-built-clean"/> + <propertyfile file="${built-clean.properties}"> + <entry key="${basedir}" value=""/> + </propertyfile> + </target> + <target depends="init" name="-do-clean"> + <delete dir="${build.dir}"/> + <delete dir="${dist.jlink.output}"/> + <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/> + </target> + <target name="-post-clean"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/> + <target name="-check-call-dep"> + <property file="${call.built.properties}" prefix="already.built."/> + <condition property="should.call.dep"> + <and> + <not> + <isset property="already.built.${call.subproject}"/> + </not> + <available file="${call.script}"/> + </and> + </condition> + </target> + <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep"> + <ant antfile="${call.script}" inheritall="false" target="${call.target}"> + <propertyset> + <propertyref prefix="transfer."/> + <mapper from="transfer.*" to="*" type="glob"/> + </propertyset> + </ant> + </target> +</project> diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/project.properties b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/project.properties new file mode 100644 index 0000000000000000000000000000000000000000..fac0d058edf60706a70a6720c4723467d001d67e --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/project.properties @@ -0,0 +1,98 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Homework2 +application.vendor=nick +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Homework2.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/Homework2 +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.OpenDIS.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=17 +javac.target=17 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=Homework2 +main.class=homework2.Homework2 +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_17 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/project.xml b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4513a7f4a8cf4c6c8e1cd6cff515c009738af4e4 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/nbproject/project.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.java.j2seproject</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/j2se-project/3"> + <name>Homework2</name> + <explicit-platform explicit-source-supported="true"/> + <source-roots> + <root id="src.dir"/> + </source-roots> + <test-roots> + <root id="test.src.dir"/> + </test-roots> + </data> + </configuration> +</project> diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/pduLog/PduCaptureLog.dislog b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/pduLog/PduCaptureLog.dislog new file mode 100644 index 0000000000000000000000000000000000000000..6f85601956ba66fab5db89fcd47653274789a577 --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/pduLog/PduCaptureLog.dislog @@ -0,0 +1,25 @@ +# Start, ENCODING_PLAINTEXT, [PduRecorder] 20220602_042950, DIS capture file, ./pduLog/PduCaptureLog.dislog +0,0,0,0,0,0,0,0,7,4,11,5,127,82,0,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 # DisPduType 11 CREATE_ENTITY +0,0,0,0,1,-123,71,-99,7,4,11,5,127,82,0,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 # DisPduType 11 CREATE_ENTITY +0,0,0,0,61,100,106,-58,7,1,1,1,127,81,-61,-25,0,-112,40,0,0,1,0,2,0,3,1,0,1,3,0,-51,62,2,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,-16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,49,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,0,67,86,59,118,7,1,2,2,127,81,-33,-35,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,122,0,0 # DisPduType 02 FIRE +0,0,0,0,73,-42,-88,-27,7,1,22,5,127,104,114,-81,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,0,-8,77,86,51,53,48,48,32,69,120,97,109,112,108,101,83,105,109,117,108,97,116,105,111,110,80,114,111,103,114,97,109,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,49,0,0 # DisPduType 22 COMMENT +0,0,0,0,79,117,-108,98,7,1,1,1,127,81,-56,-111,0,-112,40,0,0,1,0,2,0,4,2,0,1,3,0,-51,62,2,2,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,50,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,0,-111,13,-82,-27,7,1,1,1,127,81,-61,-25,0,-112,40,0,0,1,0,2,0,3,1,0,1,3,0,-51,62,2,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,49,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,0,-105,5,-37,95,7,1,2,2,127,81,-33,-35,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,122,0,0 # DisPduType 02 FIRE +0,0,0,0,-99,13,-109,-62,7,1,22,5,127,-126,6,117,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,0,-8,77,86,51,53,48,48,32,69,120,97,109,112,108,101,83,105,109,117,108,97,116,105,111,110,80,114,111,103,114,97,109,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,50,0,0 # DisPduType 22 COMMENT +0,0,0,0,-93,11,53,-13,7,1,1,1,127,81,-56,-111,0,-112,40,0,0,1,0,2,0,4,2,0,1,3,0,-51,62,2,2,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,50,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,0,-28,-95,-50,53,7,1,1,1,127,81,-61,-25,0,-112,40,0,0,1,0,2,0,3,1,0,1,3,0,-51,62,2,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,49,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,0,-22,-104,1,104,7,1,2,2,127,81,-33,-35,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,122,0,0 # DisPduType 02 FIRE +0,0,0,0,-16,-80,-35,-6,7,1,22,5,127,-101,-121,-105,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,0,-8,77,86,51,53,48,48,32,69,120,97,109,112,108,101,83,105,109,117,108,97,116,105,111,110,80,114,111,103,114,97,109,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,51,0,0 # DisPduType 22 COMMENT +0,0,0,0,-10,-113,-108,35,7,1,1,1,127,81,-56,-111,0,-112,40,0,0,1,0,2,0,4,2,0,1,3,0,-51,62,2,2,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,50,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,1,56,56,102,115,7,1,1,1,127,81,-61,-25,0,-112,40,0,0,1,0,2,0,3,1,0,1,3,0,-51,62,2,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,49,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,1,62,31,-116,58,7,1,2,2,127,81,-33,-35,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,122,0,0 # DisPduType 02 FIRE +0,0,0,1,68,29,-21,33,7,1,22,5,127,-75,13,99,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,0,-8,77,86,51,53,48,48,32,69,120,97,109,112,108,101,83,105,109,117,108,97,116,105,111,110,80,114,111,103,114,97,109,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,52,0,0 # DisPduType 22 COMMENT +0,0,0,1,74,20,117,-69,7,1,1,1,127,81,-56,-111,0,-112,40,0,0,1,0,2,0,4,2,0,1,3,0,-51,62,2,2,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,50,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,1,-117,-80,50,113,7,1,1,1,127,81,-61,-25,0,-112,40,0,0,1,0,2,0,3,1,0,1,3,0,-51,62,2,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,49,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,1,-111,-90,25,49,7,1,2,2,127,81,-33,-35,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,122,0,0 # DisPduType 02 FIRE +0,0,0,1,-105,-93,58,106,7,1,22,5,127,-50,-114,-123,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,0,-8,77,86,51,53,48,48,32,69,120,97,109,112,108,101,83,105,109,117,108,97,116,105,111,110,80,114,111,103,114,97,109,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,53,0,0 # DisPduType 22 COMMENT +0,0,0,1,-99,-88,91,-101,7,1,1,1,127,81,-56,-111,0,-112,40,0,0,1,0,2,0,4,2,0,1,3,0,-51,62,2,2,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,32,69,110,116,105,116,121,32,35,50,0,0,0,0 # DisPduType 01 ENTITY_STATE +0,0,0,1,-93,-96,-52,-77,7,1,22,5,127,-46,55,63,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,9,90,-90,0,0,0,-8,77,86,51,53,48,48,32,69,120,97,109,112,108,101,83,105,109,117,108,97,116,105,111,110,80,114,111,103,114,97,109,0,0,9,90,-90,0,0,1,48,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,99,111,109,112,108,101,116,101,100,32,115,117,99,99,101,115,115,102,117,108,108,121,0,0 # DisPduType 22 COMMENT +# Finish, ENCODING_PLAINTEXT, [PduRecorder] 20220602_042958, DIS capture file, ./pduLog/PduCaptureLog.dislog diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/src/homework2/Homework2.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/src/homework2/Homework2.java new file mode 100644 index 0000000000000000000000000000000000000000..68fb659ef20448cf9f291765e3329c84b53503ea --- /dev/null +++ b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/Homework2/src/homework2/Homework2.java @@ -0,0 +1,358 @@ +/** + * Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. + * This work is provided under a BSD open-source license, see project license.html and license.txt + * @author brutzman@nps.edu + */ +package homework2; + +// Java is an abomination. + +import edu.nps.moves.dis7.entities.swe.platform.surface._001Poseidon; +import edu.nps.moves.dis7.entities.swe.platform.surface._002Triton; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.pdus.*; +import edu.nps.moves.dis7.utilities.DisChannel; +import edu.nps.moves.dis7.utilities.PduFactory; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.MappedByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** The purpose of this inheritable class is to provide an easily modifiable example simulation program + * that includes DIS-capable entities performing tasks of interest, and then reporting activity via PDUs + * to the network. + * Default program initialization includes PDU recording turned on by default. + * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/ExampleSimulationProgramLog.txt">ExampleSimulationProgramLog.txt</a> + */ +public class Homework2 +{ + /* **************************** infrastructure code, modification is seldom needed ************************* */ + + private String descriptor = this.getClass().getSimpleName(); + protected DisChannel disChannel; + protected PduFactory pduFactory; + + /** seconds for real-time execution (not simulation time, which may or may not be .the same) */ + double currentTimeStep = 1.0; // seconds + /** initial simulation time */ + double initialTime = 0.0; + /** current simulation time */ + double simulationTime; + String narrativeMessage1 = new String(); + String narrativeMessage2 = new String(); + String narrativeMessage3 = new String(); + + /** EntityID settings for entity 1 */ + protected EntityID entityID_1 = new EntityID(); + /** EntityID settings for entity 2 */ + protected EntityID entityID_2 = new EntityID(); + /** ESPDU for entity 1 */ + protected EntityStatePdu entityStatePdu_1; + /** ESPDU for entity 2 */ + protected EntityStatePdu entityStatePdu_2; + /** FirePdu for entity 1 first weapon (if any) */ + protected FirePdu firePdu_1a; + /** FirePdu for entity 1 second weapon (if any) */ + protected FirePdu firePdu_1b; + /** MunitionDescriptor for these weapons */ + protected MunitionDescriptor munitionDescriptor1; + + /** + * Constructor to create an instance of this class. + * Design goal: additional built-in initialization conveniences can go here + * to keep your efforts focused on the runSimulation() method. + */ + // base constructor is not invoked automatically by other constructors + // https://stackoverflow.com/questions/581873/best-way-to-handle-multiple-constructors-in-java + public Homework2() + { + initialize(); + } + public Homework2(String newDescriptor) + { + descriptor = newDescriptor; + initialize(); + } + /** + * Utility Constructor that allows your example simulation program to override default network address and port + * @param address network address to use + * @param port corresponding network port to use + */ + public Homework2(String address, int port) + { + disChannel.setNetworkAddress(address); + disChannel.setNetworkPort (port); + initialize(); + } + + /** Initialize channel setup for OpenDis7 and report a test PDU */ + private void initialize() + { + initializeDisChannel(); // must come first + initializeSimulationEntities(); + + disChannel.join(); // TODO further functionality expected + // additional constructor initialization goes here + } + + /** Initialize channel setup for OpenDis7 and report a test PDU */ + private void initializeDisChannel() + { + if (disChannel == null) + disChannel = new DisChannel(); + else + { + disChannel.printlnTRACE ("*** warning, duplicate invocation of initializeDisChannel() ignored"); + return; + } + pduFactory = disChannel.getPduFactory(); + disChannel.setDescriptor(this.getClass().getSimpleName()); // ExampleSimulationProgram might be a superclass + disChannel.setUpNetworkInterface(); + disChannel.printlnTRACE ("disChannel.getNetworkAddress()=" + disChannel.getNetworkAddress() + + ", getNetworkPort()=" + disChannel.getNetworkPort()); + +// disChannel.sendCommentPdu(VariableRecordType.OTHER, "ArrivalProcessOpenDis7 initialized"); // hello channel + } + + /** Get ready, get set... initialize simulation entities + */ + public void initializeSimulationEntities() + { + if (pduFactory == null) + pduFactory = disChannel.getPduFactory(); + entityStatePdu_1 = pduFactory.makeEntityStatePdu(); + entityStatePdu_2 = pduFactory.makeEntityStatePdu(); + firePdu_1a = pduFactory.makeFirePdu(); + firePdu_1b = pduFactory.makeFirePdu(); + munitionDescriptor1 = new MunitionDescriptor(); + + // Your model setup: define participants. who's who in this zoo? + // Assuming you keep track of entity objects... here is some support for for Entity 1. + + // PDU objects are already created, now set their values. + entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID; + disChannel.addEntity(entityID_1); + + entityID_2.setSiteID(1).setApplicationID(2).setEntityID(4); // made-up example ID; + disChannel.addEntity(entityID_2); + // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? + + entityStatePdu_1.setEntityID(entityID_1); + entityStatePdu_1.setForceId(ForceID.FRIENDLY); + entityStatePdu_1.setEntityType(new _001Poseidon()); // note import statement above + entityStatePdu_1.setMarking("Entity #1"); + entityStatePdu_1.getMarkingString(); // check left justified... + + entityStatePdu_2.setEntityID(entityID_2); + entityStatePdu_2.setForceId(ForceID.OPPOSING); + entityStatePdu_2.setEntityType(new _002Triton()); // note import statement above + entityStatePdu_2.setMarking("Entity #2"); + + // TODO how should we customize this munition? what is it for your simulation? + munitionDescriptor1.setQuantity(1); + firePdu_1a.setDescriptor(munitionDescriptor1).setRange(1000.0f); + } + + /** + * This runSimulationLoops() method is for you, a customizable programmer-modifiable + * code block for defining and running a new simulation of interest. + * + * Welcome! Other parts of this program handle bookkeeping and plumbing tasks so that + * you can focus on your model entities and activities. + * Expandable support includes DIS EntityStatePdu, FirePdu and CommentPdu all available for + * modification and sending in a simulation loop. + * Continuous improvement efforts seek to make this program as easy and straightforward + * as possible for DIS simulationists to use and adapt. + * All of the other methods are setup, teardown and configuration that you may find + * interesting, even helpful, but don't really have to worry about. + */ + @SuppressWarnings("SleepWhileInLoop") // yes we do that + public void runSimulationLoops () + { + try + { + final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out there! also avoid infinite loops. + int simulationLoopCount = 0; // variable, initialized at 0 + boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet? + + // TODO reset Clock Time to today's date and timestamp to zero, providing consistent outputs for each simulation run + + disChannel.getPduRecorder().setVerbose(true); + + // =================================================================================================== + // loop the simulation while allowed, programmer can set additional conditions to break out and finish + while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet? + { + simulationLoopCount++; // good practice: increment loop counter as first action in that loop + + // ============================================================================================= + // * your own simulation code starts here! ***************************************************** + // ============================================================================================= + + // are there any other variables to modify at the beginning of your loop? + + // compute a track, update an ESPDU, whatever it is that your model is doing... + + // Where is my entity? Insert changes in position; this sample only changes X position. + entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + 1.0); // 1m per timestep + + DataOutputStream data_input = new DataOutputStream(); + data_input.writeChars("Entity on fire"); + + SetDataPdu entity_on_fire_pdu = new SetDataPdu(); + List<VariableDatum> edata = new ArrayList<VariableDatum>(); + VariableDatum datum = new VariableDatum(); + datum.marshal(data_input); + edata.add(datum); + entity_on_fire_pdu.setVariableDatums(edata); + disChannel.sendSinglePdu(entity_on_fire_pdu); + data_input.close(); + + // make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending) + narrativeMessage1 = "MV3500 ExampleSimulationProgram"; + narrativeMessage2 = "runSimulation() loop " + simulationLoopCount; + narrativeMessage3 = ""; // intentionally blank for testing + + // your loop termination condition goes here + if (simulationLoopCount > 4) // for example + { + simulationComplete = true; + } + // ============================================================================================= + // * your own simulation code is finished here! ************************************************ + // ============================================================================================= + + // staying synchronized with timestep: wait duration for elapsed time in this loop + // Thread.sleep needs a (long) parameter for milliseconds, which are clumsy to use sometimes + Thread.sleep((long)(currentTimeStep * 1000)); // units of seconds * (1000 msec/sec) = milliseconds + System.out.println ("... [Pausing for " + currentTimeStep + " seconds]"); + + // OK now send the status PDUs for this loop, and then continue + System.out.println ("sending PDUs of interest for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); + System.out.flush(); + + sendAllPdusForLoopTimestep(entityStatePdu_1, + firePdu_1a, + disChannel.currentTimeStepCommentType, narrativeMessage1, narrativeMessage2, narrativeMessage3); + disChannel.sendSinglePdu(entityStatePdu_2); // me too i.e. 2! + + System.out.println ("... [PDUs of interest successfully sent for this loop]"); + System.out.flush(); + + // =============================== + // current loop now finished, check whether to terminate if simulation complete, otherwise continue + if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good + { + System.out.println ("... [loop termination condition met, simulationComplete=" + simulationComplete + "]"); // ", final loopCount=" + loopCount + + System.out.flush(); + break; + } + } // end of simulation loop + // ===================================================================================================// =================================================================================================== + + narrativeMessage2 = "runSimulation() completed successfully"; // all done + disChannel.sendCommentPdu(disChannel.narrativeCommentType, narrativeMessage1, narrativeMessage2, narrativeMessage3); + System.out.println ("... [final=completion CommentPdu successfully sent for simulation]"); + + disChannel.leave(); + } + catch (InterruptedException iex) // handle any exception that your code might choose to provoke! + { + Logger.getLogger(Homework2.class.getSimpleName()).log(Level.SEVERE, null, iex); + } + } + + /** + * Send EntityState, Fire, Comment PDUs that got updated for this loop, reflecting state of current simulation timestep. + * @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments + * @param entityStatePdu the ESPDU to send, if any + * @param firePdu the FirePDU to send, if any + * @param commentType enumeration value describing purpose of the narrative comment + * @param comments String array of narrative comments + */ + public void sendAllPdusForLoopTimestep(EntityStatePdu entityStatePdu, + FirePdu firePdu, + VariableRecordType commentType, + // vararg... variable-length set of String comments can optionally follow + String... comments) + { + if (entityStatePdu != null) + disChannel.sendSinglePdu(entityStatePdu); + + if (firePdu != null) + disChannel.sendSinglePdu(firePdu); // bang + + disChannel.sendCommentPdu(commentType, comments); // empty comments are filtered + } + + /** + * Initial execution via main() method: handle args array of command-line initialization (CLI) arguments here + * @param args command-line parameters: network address and port + */ + protected void handleArgs (String[] args) + { + // initial execution: handle args array of initialization arguments here + if (args.length == 2) + { + if ((args[0] != null) && !args[0].isEmpty()) + thisProgram.disChannel.setNetworkAddress(args[0]); + if ((args[1] != null) && !args[1].isEmpty()) + thisProgram.disChannel.setNetworkPort(Integer.parseInt(args[1])); + } + else if (args.length != 0) + { + System.err.println("Usage: " + thisProgram.getClass().getSimpleName() + " [address port]"); + System.exit(-1); + } + } + + /** + * Get simple descriptor (such as parent class name) for this network interface, used in trace statements + * @return simple descriptor name + */ + public String getDescriptor() { + return descriptor; + } + + /** + * Set new simple descriptor (such as parent class name) for this network interface, used in trace statements + * @param newDescriptor simple descriptor name for this interface + */ + public void setDescriptor(String newDescriptor) { + if (newDescriptor == null) + newDescriptor = ""; + this.descriptor = newDescriptor; + } + + /** Locally instantiable copy of program, can be subclassed. */ + protected static Homework2 thisProgram; + + /** + * Main method is first executed when a program instance is loaded. + * @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a> + * @param args command-line parameters: network address and port. + * Command-line arguments are an array of optional String parameters that are passed from execution environment during invocation + */ + public static void main(String[] args) + { + thisProgram = new Homework2("test constructor"); // create instance of self within static main() method + + thisProgram.disChannel.printlnTRACE("main() started..."); + + thisProgram.handleArgs (args); // process command-line invocation arguments + + thisProgram.runSimulationLoops(); // ... your simulation execution code goes in there ... + + thisProgram.disChannel.tearDownNetworkInterface(); // make sure no processes are left lingering + + thisProgram.disChannel.printlnTRACE("complete."); // report successful completion + + System.exit(0); // ensure all threads and sockets released + } +} diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/pom.xml b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/pom.xml deleted file mode 100644 index ab19a7dddab8ed486ba8793a1791fc19181b7c8d..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>com.mycompany</groupId> - <artifactId>RoyerHomework2</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>12</maven.compiler.source> - <maven.compiler.target>12</maven.compiler.target> - </properties> -</project> \ No newline at end of file diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/src/main/java/royer/homework2/TCPPeer.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/src/main/java/royer/homework2/TCPPeer.java deleted file mode 100644 index 551af66db99130ee6135986082b9f155b32c5bf9..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/src/main/java/royer/homework2/TCPPeer.java +++ /dev/null @@ -1,89 +0,0 @@ -package royer.homework2; - -import java.net.*; -import java.io.*; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * - * @author nick - */ -public class TCPPeer { - private ServerSocket server_socket = null; - private Socket client_socket = null; - - private PrintWriter out_stream = null; - private BufferedReader in_stream = null; - - private boolean is_server = true; - - public boolean isServer() { - return is_server; - } - - public TCPPeer(int port, String ip) throws IOException { - is_server = (ip.equals("")); - if (is_server) { - server_socket = new ServerSocket(port); - client_socket = server_socket.accept(); - - } else { - // Client - client_socket = new Socket(ip, port); - } - - in_stream = new BufferedReader(new InputStreamReader(client_socket.getInputStream())); - out_stream = new PrintWriter(client_socket.getOutputStream(), true); - - should_stop.set(false); - - start(); - } - - void start() { - if (is_server) { - while(!should_stop.get()) { - try { - String msg = in_stream.readLine(); - // if (msg == null || msg.equals("")) - // continue; - System.out.println("Server received \"" + msg + "\""); - out_stream.println("OK"); - if (msg.equals("--quit")) - stop_connection(); - } catch (IOException ex) { - - } - } - } - } - - private final AtomicBoolean should_stop = new AtomicBoolean(false); - - public void stop_connection() { - should_stop.set(true); - } - - public TCPPeer(int port) throws IOException { - this(port, ""); - } - - public void close() throws IOException { - System.out.println("Closing " + (is_server ? "Server" : "Client")); - in_stream.close(); - out_stream.close(); - client_socket.close(); - if (is_server) { - server_socket.close(); - } else { - - } - } - - public String send(String msg) throws IOException { - out_stream.println(msg); - String response = in_stream.readLine(); - System.out.println((is_server ? "Server" : "Client") + " sending \"" + msg + "\": " + response); - return response; - } -} diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/src/main/java/royer/homework2/Tester.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/src/main/java/royer/homework2/Tester.java deleted file mode 100644 index 5e3032b01e42866e324d5b7496163c9b490d5cc9..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/src/main/java/royer/homework2/Tester.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package royer.homework2; - -import java.io.*; - -/** - * - * @author nick - */ -public class Tester { - - private static class ServerThread extends Thread { - private TCPPeer server = null; - int port = 0; - public ServerThread(int port) { - super(); - this.port = port; - } - - @Override - public void run() { - try { - server = new TCPPeer(port); - server.close(); - Thread.currentThread().interrupt(); - } catch (Exception ioex) { - System.err.println(ioex.toString()); - } - } - } - - public static void main(String[] args) { - - int test_port = 6668; - - try { - System.out.println("Setting up"); - ServerThread st = new ServerThread(test_port); - st.start(); - TCPPeer client = new TCPPeer(test_port, "127.0.0.1"); - System.out.println("Setup complete"); - client.send("Test"); - - client.send("--quit"); - client.close(); - st.join(); - - System.out.println("Done"); - } catch (Exception ex) { - System.err.println(ex.toString()); - } - } -} diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/TCPPeer.class b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/TCPPeer.class deleted file mode 100644 index c2a2699cf29f7560a8cdc86cca629210e46a0329..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/TCPPeer.class and /dev/null differ diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/Tester$ServerThread.class b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/Tester$ServerThread.class deleted file mode 100644 index 29e799fc67d687b5068c5316558acf22a7d6bef4..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/Tester$ServerThread.class and /dev/null differ diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/Tester.class b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/Tester.class deleted file mode 100644 index 04d5d5f7339a67bb6aa264e0e6284a78940ddf84..0000000000000000000000000000000000000000 Binary files a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/classes/royer/homework2/Tester.class and /dev/null differ diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index b8c08f64ab97714bf06250711c33796abc82298b..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1,2 +0,0 @@ -royer/homework2/Tester.class -royer/homework2/TCPPeer.class diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index a2b22bf32a251d7f87b1e22cba24f76bcf01c678..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/RoyerHomework2/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1,2 +0,0 @@ -/home/nick/Documents/NPS/Quarter 4/MV3500/Homework 2/RoyerHomework2/src/main/java/royer/homework2/Tester.java -/home/nick/Documents/NPS/Quarter 4/MV3500/Homework 2/RoyerHomework2/src/main/java/royer/homework2/TCPPeer.java diff --git a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/package-info.java b/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/package-info.java deleted file mode 100644 index 68d490841f110b6dcf4b8986e796b7ccb1edcb5b..0000000000000000000000000000000000000000 --- a/assignments/src/MV3500Cohort2022MayJune/homework2/Royer/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * ExampleSimpleSimulation program-modification homework assignment supporting the NPS MOVES MV3500 Networked Graphics course. - * - * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/tree/master/assignments">networkedGraphicsMV3500 assignments</a> - * @see java.lang.Package - * @see <a href="https://stackoverflow.com/questions/22095487/why-is-package-info-java-useful">StackOverflow: why-is-package-info-java-useful</a> - * @see <a href="https://stackoverflow.com/questions/624422/how-do-i-document-packages-in-java">StackOverflow: how-do-i-document-packages-in-java</a> - */ - -package MV3500Cohort2022MayJune.homework2.Royer; diff --git a/examples/nbproject/build-impl.xml b/examples/nbproject/build-impl.xml index d46126d16b7fecd42bcb7497c73fdb2019786db0..43a7ccc69d0a89abab8e390e5b03c431bdb4e002 100644 --- a/examples/nbproject/build-impl.xml +++ b/examples/nbproject/build-impl.xml @@ -46,8 +46,8 @@ is divided into following sections: <property file="${user.properties.file}"/> <!-- The two properties below are usually overridden --> <!-- by the active platform. Just a fallback. --> - <property name="default.javac.source" value="1.8"/> - <property name="default.javac.target" value="1.8"/> + <property name="default.javac.source" value="1.6"/> + <property name="default.javac.target" value="1.6"/> </target> <target depends="-pre-init,-init-private,-init-user" name="-init-project"> <property file="nbproject/configs/${config}.properties"/> diff --git a/examples/nbproject/genfiles.properties b/examples/nbproject/genfiles.properties index 844247ef6079c2d65d0812b2dd00618149439610..a3f479b7dda7f6503288c0c0539f20df57f34a6f 100644 --- a/examples/nbproject/genfiles.properties +++ b/examples/nbproject/genfiles.properties @@ -3,6 +3,6 @@ build.xml.script.CRC32=b64626c8 build.xml.stylesheet.CRC32=f85dc8f2@1.91.1.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=74d8ac35 -nbproject/build-impl.xml.script.CRC32=e75c0d85 -nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.102.0.48 +nbproject/build-impl.xml.data.CRC32=dec2cf1d +nbproject/build-impl.xml.script.CRC32=7c2cd7eb +nbproject/build-impl.xml.stylesheet.CRC32=d549e5cc@1.98.0.48