// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.tasktrees.treeimpl; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; /** *
* this is the default implementation of the interface {@link ITask}. It * does not do anything fancy except implementing the interface. *
* * @author Patrick Harms */ abstract class Task implements ITask { /** ** default serial version UID *
*/ private static final long serialVersionUID = 1L; /** ** used as a counter to generate new ids for each newly created task. May overflow. *
*/ private static int temporalId = 0; /** ** the id of the task (unique throughout the system as long as {@link #temporalId} does not * overflow. *
*/ private int id; /** ** a human readable type of the task (used for visualization purposes) *
*/ private String type; /** ** a human readable description of the task *
*/ private String description; /** ** the instances of this task *
*/ private Collection* the execution variants of this task *
*/ private Collection* constructs a new task with a new id. The id is generated using the {@link #getNewId()} * method *
* * @param type the human readable type of the task * * @throws IllegalArgumentException in the case the provided type is null */ Task(String type) { this.id = getNewId(); this.type = type; if (type == null) { throw new IllegalArgumentException("type must not be null"); } } /** ** creates a new id for a task using {@link #temporalId} by incrementing it an returning its * current value. Resets the counter if {@link Integer.MAX_VALUE} is reached. *
* * @return a new unique id for a task as long as {@link #temporalId} does not overflow */ private static synchronized int getNewId() { if (temporalId == Integer.MAX_VALUE) { temporalId = 0; } return temporalId++; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#geId() */ @Override public int getId() { return id; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getType() */ @Override public String getType() { return type; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getDescription() */ @Override public String getDescription() { return description; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getInstances() */ @Override public Collection* internally used to set the human readable description of the task *
* * @param description the new human readable description of the task */ void setDescription(String description) { this.description = description; } /** ** internally used to remove an instance from this task *
* * @param instance the instance to be removed from this task */ synchronized void removeInstance(ITaskInstance instance) { this.instances.remove(instance); this.executionVariants = null; } /** ** internally used to add an instance to this task *
* * @param instance the instance belonging to this task */ synchronized void addInstance(ITaskInstance instance) { this.instances.add(instance); this.executionVariants = null; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#accept(ITaskVisitor) */ @Override public void accept(ITaskVisitor visitor) { visitor.visit(this); } /** * */ private void determineExecutionVariants(Collection