package simulator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/**
 * Simulator for System of Systems
 * Environment Class
 * Raise actions that are handled by CSs
 * Send a message to CSs that the action is raised
 */
public class Environment {

    /**
     * 필요한 자료구조
     * 1. 각 CS의 capability list
     * 2. 현재 각 Action 의 진행 상황
     */

    private ArrayList<Constituent> csList = null;
    private ArrayList<Action> actionList = null;
    private HashMap<String, Action.Status> statusHashMap = null;

    public Environment(Constituent[] CSs, Action[] actions){
        this.csList = new ArrayList<Constituent>();
        Collections.addAll(this.csList, CSs);
        this.actionList = new ArrayList<Action>();
        Collections.addAll(this.actionList, actions);
        this.statusHashMap = new HashMap<String, Action.Status>();
    }

    /**
     * 랜덤하게 Action 생성하는 메소드
     * 발생된 메소드를 각 CS에게 메시지로 전달하는 메소드
     * CS에 의해 처리된 메소드를 제거하는 메소드
     */

    /**
     * Randomly generate actions that are not raised
     * Raise the action whose status is exactly not_raised
     * If the number of actions to be raised is 0, then no action is raised.
     */
    public void generateAction(){
        int numPossibleActions = 0;
    }

    /**
     * Notify randomly generated actions to CSs
     */
    public void notifyCS(){

    }

    /**
     * Update the status of actions executed by CSs
     * @param actionList the list of actions that are changed its status
     */
    public void updateActionStatus(ArrayList<Action> actionList){
        for(Action a : actionList){
            Action.Status newStatus = a.getStatus();
            this.statusHashMap.remove(a.getName());
            this.statusHashMap.put(a.getName(), newStatus);
        }
    }
}

@@ -34,73 +34,9 @@
 til.
-ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.HashMap
+*
 ;%0A%0A/
@@ -354,32 +354,46 @@
 %3E csList = null;
+ // %EB%AA%A8%EB%93%A0 CS list
 %0A    private Arr
@@ -425,16 +425,34 @@
  = null;
+ // %EB%AA%A8%EB%93%A0 Action List
 %0A    pri
@@ -1213,34 +1213,1217 @@
     
-int numPossibleActions = 0
+/**%0A         * 1. Count the number of possible actions to be raised%0A         * 2. Generate a random number that how many actions will be raised%0A         * 3. Shuffle the possible action list and pick actions%0A         */%0A        ArrayList%3CString%3E possibleActionList = new ArrayList%3CString%3E();%0A        for(Map.Entry%3CString, Action.Status%3E entry: this.statusHashMap.entrySet())%7B%0A            if(entry.getValue() == Action.Status.Not_raised)%7B%0A                possibleActionList.add(entry.getKey());%0A            %7D%0A        %7D%0A%0A        Random randomGenerator = new Random();%0A        int numRaisingActions = randomGenerator.nextInt(possibleActionList.size()+1);%0A        ArrayList%3CAction%3E selectedActionList = new ArrayList%3CAction%3E();%0A        Collections.shuffle(possibleActionList);%0A        for(int i = 0; i %3C numRaisingActions; i--)%7B%0A            String actionName = possibleActionList.get(i);%0A            for(Action a : this.actionList)%7B%0A                if(a.getName().equalsIgnoreCase(actionName))%7B%0A                    a.setStatus(Action.Status.Raised);%0A                    selectedActionList.add(a);%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A%0A        updateActionStatus(selectedActionList)
 ;%0A  
@@ -2669,29 +2669,30 @@
     */%0A    p
-ublic
+rivate
  void update

Environment randomly generate the actions