package forager.events;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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

public class TaskSpec implements Event {

    public long taskId;
    public String command;

    private List<NetworkDestination> assignments = new ArrayList<>();

    public TaskSpec(long taskId, String command) {
        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() {
        return "[" + taskId + "] " + command;
    }

    @Deserialize
    public TaskSpec(SerializationInputStream in)
    throws IOException {
        taskId = in.readLong();
        command = in.readString();
    }

    @Override
    public void serialize(SerializationOutputStream out)
    throws IOException {
        out.writeLong(taskId);
        out.writeString(command);
    }
}

@@ -374,20 +374,18 @@
 nd;%0A
-%0A
     p
-rivate
+ublic
  Lis
@@ -517,24 +517,24 @@
 d = taskId;%0A
+
         this
@@ -564,494 +564,8 @@
  %7D%0A%0A
-    public void addAssignment(NetworkDestination host) %7B%0A        assignments.add(host);%0A    %7D%0A%0A    public void removeAssignment(NetworkDestination host) %7B%0A        assignments.remove(host);%0A    %7D%0A%0A    /**%0A     * Determine whether the Task associated with this TaskSpec has been%0A     * assigned to any resources yet.%0A     *%0A     * @return true if the Task has been assigned, false otherwise.%0A     */%0A    public boolean isAssigned() %7B%0A        return assignments.isEmpty() == false;%0A    %7D%0A%0A
     

Remove assignment encapsulation