Updates to domain objects for Task and TasksList

This commit is contained in:
Andrew Donald Kennedy 2012-02-07 13:48:53 +00:00 committed by danikov
parent 8828daf89b
commit d2dac74148
9 changed files with 74 additions and 62 deletions

View File

@ -55,7 +55,7 @@ public class Entity extends EntityType<Entity> {
public Entity build() {
Entity entity = new Entity(href, name);
entity.setDescription(description);
entity.setTasks(tasks);
entity.setTasksInProgress(tasksInProgress);
entity.setId(id);
entity.setType(type);
entity.setLinks(links);
@ -90,11 +90,11 @@ public class Entity extends EntityType<Entity> {
}
/**
* @see EntityType#getTasks()
* @see EntityType#getTasksInProgress()
*/
@Override
public Builder tasks(TaskList tasks) {
this.tasks = tasks;
public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}

View File

@ -51,13 +51,13 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
@Override
public Builder<T> toBuilder() {
return new Builder<T>().fromEntity(this);
return new Builder<T>().fromEntityType(this);
}
public static class Builder<T extends EntityType<T>> extends ResourceType.Builder<T> {
protected String description;
protected TaskList tasks;
protected TasksInProgress tasksInProgress;
protected String name;
protected String id;
@ -86,10 +86,10 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
}
/**
* @see EntityType#getTasks()
* @see EntityType#getTasksInProgress()
*/
public Builder<T> tasks(TaskList tasks) {
this.tasks = tasks;
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}
@ -97,7 +97,7 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
public EntityType<T> build() {
EntityType<T> entity = new EntityType<T>(href, name);
entity.setDescription(description);
entity.setTasks(tasks);
entity.setTasksInProgress(tasksInProgress);
entity.setId(id);
entity.setType(type);
entity.setLinks(links);
@ -149,14 +149,16 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
}
public Builder<T> fromEntityType(EntityType<T> in) {
return fromResourceType(in).description(in.getDescription()).tasks(in.getTasks()).id(in.getId()).name(in.getName());
return fromResourceType(in)
.description(in.getDescription()).tasksInProgress(in.getTasksInProgress())
.id(in.getId()).name(in.getName());
}
}
@XmlElement(namespace = NS, name = "Description")
private String description;
@XmlElement(namespace = NS, name = "TasksInProgress")
private TaskList tasks;
private TasksInProgress tasksInProgress;
@XmlAttribute
private String id;
@XmlAttribute
@ -185,12 +187,12 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
/**
* A list of queued, running, or recently completed tasks associated with this entity.
*/
public TaskList getTasks() {
return tasks;
public TasksInProgress getTasksInProgress() {
return tasksInProgress;
}
public void setTasks(TaskList tasks) {
this.tasks = tasks;
public void setTasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
}
/**
@ -224,16 +226,18 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
if (!super.equals(o))
return false;
EntityType<?> that = EntityType.class.cast(o);
return super.equals(that) && equal(this.id, that.id) && equal(this.description, that.description) && equal(this.tasks, that.tasks);
return super.equals(that) &&
equal(this.id, that.id) && equal(this.description, that.description) &&
equal(this.tasksInProgress, that.tasksInProgress);
}
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(description, tasks, id, name);
return super.hashCode() + Objects.hashCode(description, tasksInProgress, id, name);
}
@Override
public ToStringHelper string() {
return super.string().add("description", description).add("tasks", tasks).add("id", id).add("name", name);
return super.string().add("description", description).add("tasksInProgress", tasksInProgress).add("id", id).add("name", name);
}
}

View File

@ -93,15 +93,15 @@ public class Link extends ReferenceType<Link> {
}
public Builder fromLink(Link in) {
return fromReference(in).rel(in.getRel());
return fromReferenceType(in).rel(in.getRel());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromReference(ReferenceType<Link> in) {
return Builder.class.cast(super.fromReference(in));
public Builder fromReferenceType(ReferenceType<Link> in) {
return Builder.class.cast(super.fromReferenceType(in));
}
/**

View File

@ -75,7 +75,7 @@ public class Org extends EntityType<Org> {
org.setId(id);
org.setType(type);
org.setLinks(links);
org.setTasks(tasks);
org.setTasksInProgress(tasksInProgress);
return org;
}
@ -107,11 +107,11 @@ public class Org extends EntityType<Org> {
}
/**
* @see EntityType#getTasks()
* @see EntityType#getTasksInProgress()
*/
@Override
public Builder tasks(TaskList tasks) {
this.tasks = tasks;
public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}
@ -152,12 +152,12 @@ public class Org extends EntityType<Org> {
}
@Override
public Builder fromEntity(EntityType<Org> in) {
return Builder.class.cast(super.fromEntity(in));
public Builder fromEntityType(EntityType<Org> in) {
return Builder.class.cast(super.fromEntityType(in));
}
public Builder fromOrg(Org in) {
return fromEntity(in).fullName(in.getFullName());
return fromEntityType(in).fullName(in.getFullName());
}
}

View File

@ -49,7 +49,7 @@ public class ReferenceType<T extends ReferenceType<T>> {
}
public Builder<T> toBuilder() {
return new Builder<T>().fromReference(this);
return new Builder<T>().fromReferenceType(this);
}
public static class Builder<T extends ReferenceType<T>> {

View File

@ -53,7 +53,7 @@ public class ResourceType<T extends ResourceType<T>> {
}
public Builder<T> toBuilder() {
return new Builder<T>().fromResource(this);
return new Builder<T>().fromResourceType(this);
}
public static class Builder<T extends ResourceType<T>> {

View File

@ -183,11 +183,11 @@ public class Task extends EntityType<Task> {
}
/**
* @see EntityType#getTasks()
* @see EntityType#getTasksInProgress()
*/
@Override
public Builder tasks(TaskList tasks) {
this.tasks = tasks;
public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}
@ -228,13 +228,14 @@ public class Task extends EntityType<Task> {
}
@Override
public Builder fromEntity(EntityType<Task> in) {
return Builder.class.cast(super.fromEntity(in));
public Builder fromEntityType(EntityType<Task> in) {
return Builder.class.cast(super.fromEntityType(in));
}
public Builder fromTask(Task in) {
return fromEntity(in).error(in.getError()).org(in.getOrg()).progress(in.getProgress()).status(in.getStatus())
.operation(in.getOperation()).operationName(in.getOperationName());
return fromEntityType(in)
.error(in.getError()).org(in.getOrg()).progress(in.getProgress()).status(in.getStatus())
.operation(in.getOperation()).operationName(in.getOperationName());
}
}

View File

@ -56,7 +56,7 @@ public class TasksInProgress {
/**
* @see TasksInProgress#getTasks()
*/
public Builder tasks(Collection<Task> tasks) {
public Builder tasks(Set<Task> tasks) {
this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks"));
return this;
}
@ -69,11 +69,11 @@ public class TasksInProgress {
return this;
}
public TaskList build() {
return new TaskList(tasks);
public TasksInProgress build() {
return new TasksInProgress(tasks);
}
public Builder fromTaskList(TaskList in) {
public Builder fromTasksInProgress(TasksInProgress in) {
return tasks(in.getTasks());
}
}

View File

@ -22,11 +22,9 @@ import static com.google.common.base.Objects.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*;
import java.util.Collection;
import java.net.URI;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ -39,52 +37,61 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
*/
@XmlRootElement(namespace = NS, name = "TaskList")
@XmlAccessorType(XmlAccessType.FIELD)
public class TaskList {
@XmlRootElement(namespace = NS, name = "TasksList")
public class TasksList extends EntityType<TasksList> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return new Builder();
}
public static class Builder {
public static class Builder extends EntityType.Builder<TasksList> {
protected Set<Task> tasks = Sets.newLinkedHashSet();
/**
* @see TaskList#getTasks()
* @see TasksList#getTasks()
*/
public Builder tasks(Collection<Task> tasks) {
public Builder tasks(Set<Task> tasks) {
this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks"));
return this;
}
/**
* @see TaskList#getTasks()
* @see TasksList#getTasks()
*/
public Builder task(Task task) {
this.tasks.add(checkNotNull(task, "task"));
return this;
}
public TaskList build() {
return new TaskList(tasks);
@Override
public TasksList build() {
TasksList taskslist = new TasksList(href, name, tasks);
taskslist.setDescription(description);
taskslist.setTasksInProgress(tasksInProgress);
taskslist.setId(id);
taskslist.setType(type);
taskslist.setLinks(links);
return taskslist;
}
public Builder fromTaskList(TaskList in) {
public Builder fromTasksList(TasksList in) {
return tasks(in.getTasks());
}
}
protected TaskList() {
protected TasksList() {
// For JAXB and builder use
}
protected TaskList(Set<Task> tasks) {
protected TasksList(URI href, String name, Set<Task> tasks) {
super(href, name);
this.tasks = ImmutableSet.copyOf(tasks);
}
@ -101,17 +108,17 @@ public class TaskList {
return true;
if (o == null || getClass() != o.getClass())
return false;
TaskList that = TaskList.class.cast(o);
return equal(this.tasks, that.tasks);
TasksList that = TasksList.class.cast(o);
return super.equals(that) && equal(this.tasks, that.tasks);
}
@Override
public int hashCode() {
return Objects.hashCode(tasks);
return super.hashCode() + Objects.hashCode(tasks);
}
@Override
public String toString() {
return Objects.toStringHelper("").add("tasks", tasks).toString();
public ToStringHelper string() {
return super.string().add("tasks", tasks);
}
}