package forager.events;

import java.io.IOException;

import galileo.event.Event;
import galileo.serialization.SerializationInputStream;
import galileo.serialization.SerializationOutputStream;

public class TaskSpec implements Event {

    public int taskId;
    public String[] command;

    public TaskSpec(int taskId, String[] command) {
    private List<NetworkDestination> assignments = new ArrayList<>();
        this.taskId = taskId;
        this.command = command;
    }

    public void addAssignment(NetworkDestination host) {
        assignments.add(host);
    }

    public void removeAssignment(NetworkDestination host) {
        assignments.remove(host);
    }

    /**
     * Determine whether the Task associated with this TaskSpec has been
     * assigned to any resources yet.
     *
     * @return true if the Task has been assigned, false otherwise.
     */
    public boolean isAssigned() {
        return assignments.isEmpty() == false;
    }

    public String toString() {
        String str = "[" + taskId + "] ";
        for (String s : command) {
            str += s + " ";
        }
        return str;
    }

    @Deserialize
    public TaskSpec(SerializationInputStream in)
    throws IOException {
        taskId = in.readInt();
        int numArgs = in.readInt();
        command = new String[numArgs];
        for (int i = 0; i < numArgs; ++i) {
            command[i] = in.readString();
        }
    }

    @Override
    public void serialize(SerializationOutputStream out)
    throws IOException {
        out.writeInt(taskId);
        out.writeInt(command.length);
        for (String s : command) {
            out.writeString(s);
        }
    }
}

@@ -50,35 +50,125 @@
 on;%0A
-%0Aimport galileo.event.Event
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport galileo.event.Event;%0Aimport galileo.net.NetworkDestination
 ;%0Aim
@@ -330,19 +330,20 @@
  public 
-int
+long
  taskId;
@@ -356,26 +356,24 @@
 ublic String
-%5B%5D
  command;%0A%0A 
@@ -375,60 +375,8 @@
 d;%0A%0A
-    public TaskSpec(int taskId, String%5B%5D command) %7B%0A
     
@@ -440,16 +440,68 @@
 ist%3C%3E();
+%0A%0A    public TaskSpec(long taskId, String command) %7B
 %0A       
@@ -1091,20 +1091,14 @@
     
-String str =
+return
  %22%5B%22
@@ -1117,101 +1117,18 @@
 %22%5D %22
-;%0A        for (String s : command) %7B%0A            str += s + %22 %22;%0A        %7D%0A        return str
+ + command
 ;%0A  
@@ -1251,143 +1251,24 @@
 read
-Int();%0A        int numArgs = in.readInt();%0A        command = new String%5BnumArgs%5D;%0A        for (int i = 0; i %3C numArgs; ++i) %7B%0A 
+Long();%0A
         
    c
@@ -1267,21 +1267,15 @@
     
-   
 command
-%5Bi%5D
  = i
@@ -1290,26 +1290,16 @@
 ring();%0A
-        %7D%0A
     %7D%0A%0A 
@@ -1410,19 +1410,20 @@
 ut.write
-Int
+Long
 (taskId)
@@ -1445,61 +1445,23 @@
 rite
-Int(command.length);%0A        for (
 String
- s : 
+(
 command)
  %7B%0A 
@@ -1460,52 +1460,9 @@
 and)
- %7B%0A            out.writeString(s);%0A        %7D
+;
 %0A   

Switch to single-string commands and long ids