From 175944c085864ec38f780163ef9cea087dd12db3 Mon Sep 17 00:00:00 2001
From: brutzman <brutzman@nps.edu>
Date: Sun, 5 Sep 2021 15:48:11 -0700
Subject: [PATCH] initial draft support class with stub methods and accessors
 for record structures

---
 .../OpenDis7Examples/SimulationManager.java   | 296 ++++++++++++++++++
 1 file changed, 296 insertions(+)
 create mode 100644 examples/src/OpenDis7Examples/SimulationManager.java

diff --git a/examples/src/OpenDis7Examples/SimulationManager.java b/examples/src/OpenDis7Examples/SimulationManager.java
new file mode 100644
index 0000000000..21bbab5181
--- /dev/null
+++ b/examples/src/OpenDis7Examples/SimulationManager.java
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2008-2021, 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
+ */
+package OpenDis7Examples;
+
+import java.util.ArrayList;
+
+/**
+ * Manage overall simulation choreography for a DIS exercise
+ * @author brutzman
+ */
+public class SimulationManager 
+{
+    private ArrayList<RecordType>      entityRecordList = new ArrayList<>();
+    private ArrayList<RecordType>        hostRecordList = new ArrayList<>();
+    private ArrayList<RecordType> applicationRecordList = new ArrayList<>();
+    
+    /**
+     * Start the simulation according to specifications
+     */
+    public void SimulationStart()
+    {
+        // TODO
+    }
+    /**
+     * Pause the simulation according to specifications
+     */
+    public void SimulationPause()
+    {
+        // TODO
+    }
+    /**
+     * Resume the simulation according to specifications
+     */
+    public void SimulationResume()
+    {
+        // TODO
+    }
+    /**
+     * Stop the simulation according to specifications
+     */
+    public void SimulationStop()
+    {
+        // TODO
+    }
+    
+    /**
+     * Simple simulation record type
+     */
+    public class RecordType
+    {
+        private int    id          = -1;
+        private String name        = new String();
+        private String description = new String();
+        private String reference   = new String();
+    
+        /**
+         * Constructor for new record
+         * @param id   identifying number
+         * @param name common name
+         * @param description longer description
+         * @param reference   formal reference for this record, if any
+         */
+        public RecordType (int id, String name, String description, String reference)
+        {
+            this.id          = id;
+            this.name        = name;
+            this.description = description;
+            this.reference   = reference;
+        }
+        /**
+         * Utility constructor for new record, description and reference remain blank
+         * @param id   identifying number
+         * @param name common name
+         */
+        public RecordType (int id, String name)
+        {
+            this.id          = id;
+            this.name        = name;
+            this.description = "";
+            this.reference   = "";
+        }
+        
+        /**
+         * Simple representation of record
+         * @return id,name,"description"
+         */
+        @Override
+        public String toString()
+        {
+            return "id" + "," + name + ",\"" + description + "\"";
+        }
+
+        /**
+         * @return the id
+         */
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param newID the id to set
+         */
+        public void setId(int newID) {
+            this.id = newID;
+        }
+
+        /**
+         * @return the name
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param newName the name to set
+         */
+        public void setName(String newName) {
+            this.name = newName;
+        }
+
+        /**
+         * @return the description
+         */
+        public String getDescription() {
+            return description;
+        }
+
+        /**
+         * @param newDescription the description to set
+         */
+        public void setDescription(String newDescription) {
+            this.description = newDescription;
+        }
+
+        /**
+         * @return the reference
+         */
+        public String getReference() {
+            return reference;
+        }
+
+        /**
+         * @param newReference the reference to set
+         */
+        public void setReference(String newReference) {
+            this.reference = newReference;
+        }
+    }
+
+    /**
+     * Get a single entityRecord from list
+     * @param index which record to retrieve
+     * @return the record matching this index
+     */
+    public RecordType getEntityRecordByIndex(int index) 
+    {
+        if (entityRecordList.isEmpty())
+        {
+            System.err.println ("*** getEntityRecordByIndex list is empty, unable to get index=" + index);
+            return null;
+        }
+        else if (entityRecordList.size() <= index)
+        {
+            System.err.println ("*** getEntityRecordByIndex list has size=" + entityRecordList.size() + ", unable to get index=" + index);
+            return null;
+        }
+        else if (index < 0)
+        {
+            System.err.println ("*** getEntityRecordByIndex cannot retrieve illegal index=" + index);
+            return null;
+        }
+        else return entityRecordList.get(index);
+    }
+
+    /**
+     * Get a single hostRecord from list
+     * @param index which record to retrieve
+     * @return the record matching this index
+     */
+    public RecordType getHostRecordByIndex(int index) 
+    {
+        if (hostRecordList.isEmpty())
+        {
+            System.err.println ("*** getHostRecordByIndex list is empty, unable to get index=" + index);
+            return null;
+        }
+        else if (hostRecordList.size() <= index)
+        {
+            System.err.println ("*** getHostRecordByIndex list has size=" + hostRecordList.size() + ", unable to get index=" + index);
+            return null;
+        }
+        else if (index < 0)
+        {
+            System.err.println ("*** getHostRecordByIndex cannot retrieve illegal index=" + index);
+            return null;
+        }
+        else return hostRecordList.get(index);
+    }
+
+    /**
+     * Get a single applicationRecord from list
+     * @param index which record to retrieve
+     * @return the record matching this index
+     */
+    public RecordType getApplicationRecordByIndex(int index) 
+    {
+        if (applicationRecordList.isEmpty())
+        {
+            System.err.println ("*** getApplicationRecordByIndex list is empty, unable to get index=" + index);
+            return null;
+        }
+        else if (applicationRecordList.size() <= index)
+        {
+            System.err.println ("*** getApplicationRecordByIndex list has size=" + applicationRecordList.size() + ", unable to get index=" + index);
+            return null;
+        }
+        else if (index < 0)
+        {
+            System.err.println ("*** getApplicationRecordByIndex cannot retrieve illegal index=" + index);
+            return null;
+        }
+        else return applicationRecordList.get(index);
+    }
+
+    /**
+     * Get a single entityRecord from list matching ID
+     * @param valueOfInterest id for record to retrieve
+     * @return the record matching this ID
+     */
+    public RecordType getEntityRecordByID(int valueOfInterest) 
+    {
+        for (RecordType entity : entityRecordList)
+        {
+            if (entity.getId() == valueOfInterest)
+                return entity;
+        }
+        System.err.println ("*** getEntityRecordByID cannot find id=" + valueOfInterest);
+        return null;
+    }
+    /**
+     * Get a single hostRecord from list matching ID
+     * @param valueOfInterest id for record to retrieve
+     * @return the record matching this ID
+     */
+    public RecordType getHostRecordByID(int valueOfInterest) 
+    {
+        for (RecordType host : hostRecordList)
+        {
+            if (host.getId() == valueOfInterest)
+                return host;
+        }
+        System.err.println ("*** getHostRecordByID cannot find id=" + valueOfInterest);
+        return null;
+    }
+    /**
+     * Get a single applicationRecord from list matching ID
+     * @param valueOfInterest id for record to retrieve
+     * @return the record matching this ID
+     */
+    public RecordType getApplicationRecordByID(int valueOfInterest) 
+    {
+        for (RecordType application : applicationRecordList)
+        {
+            if (application.getId() == valueOfInterest)
+                return application;
+        }
+        System.err.println ("*** getApplicationRecordByID cannot find id=" + valueOfInterest);
+        return null;
+    }
+
+    /**
+     * Provide entire entityRecordList
+     * @return the entityRecordList
+     */
+    public ArrayList<RecordType> getEntityRecordList() {
+        return entityRecordList;
+    }
+
+    /**
+     * Provide entire hostRecordList
+     * @return the hostRecordList
+     */
+    public ArrayList<RecordType> getHostRecordList() {
+        return hostRecordList;
+    }
+
+    /**
+     * Provide entire applicationRecordList
+     * @return the applicationRecordList
+     */
+    public ArrayList<RecordType> getApplicationRecordList() {
+        return applicationRecordList;
+    }
+}
-- 
GitLab