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

View File

@ -51,13 +51,13 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
@Override @Override
public Builder<T> toBuilder() { 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> { public static class Builder<T extends EntityType<T>> extends ResourceType.Builder<T> {
protected String description; protected String description;
protected TaskList tasks; protected TasksInProgress tasksInProgress;
protected String name; protected String name;
protected String id; 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) { public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) {
this.tasks = tasks; this.tasksInProgress = tasksInProgress;
return this; return this;
} }
@ -97,7 +97,7 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
public EntityType<T> build() { public EntityType<T> build() {
EntityType<T> entity = new EntityType<T>(href, name); EntityType<T> entity = new EntityType<T>(href, name);
entity.setDescription(description); entity.setDescription(description);
entity.setTasks(tasks); entity.setTasksInProgress(tasksInProgress);
entity.setId(id); entity.setId(id);
entity.setType(type); entity.setType(type);
entity.setLinks(links); entity.setLinks(links);
@ -149,14 +149,16 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
} }
public Builder<T> fromEntityType(EntityType<T> in) { 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") @XmlElement(namespace = NS, name = "Description")
private String description; private String description;
@XmlElement(namespace = NS, name = "TasksInProgress") @XmlElement(namespace = NS, name = "TasksInProgress")
private TaskList tasks; private TasksInProgress tasksInProgress;
@XmlAttribute @XmlAttribute
private String id; private String id;
@XmlAttribute @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. * A list of queued, running, or recently completed tasks associated with this entity.
*/ */
public TaskList getTasks() { public TasksInProgress getTasksInProgress() {
return tasks; return tasksInProgress;
} }
public void setTasks(TaskList tasks) { public void setTasksInProgress(TasksInProgress tasksInProgress) {
this.tasks = tasks; this.tasksInProgress = tasksInProgress;
} }
/** /**
@ -224,16 +226,18 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
if (!super.equals(o)) if (!super.equals(o))
return false; return false;
EntityType<?> that = EntityType.class.cast(o); 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 @Override
public int hashCode() { public int hashCode() {
return super.hashCode() + Objects.hashCode(description, tasks, id, name); return super.hashCode() + Objects.hashCode(description, tasksInProgress, id, name);
} }
@Override @Override
public ToStringHelper string() { 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) { public Builder fromLink(Link in) {
return fromReference(in).rel(in.getRel()); return fromReferenceType(in).rel(in.getRel());
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Builder fromReference(ReferenceType<Link> in) { public Builder fromReferenceType(ReferenceType<Link> in) {
return Builder.class.cast(super.fromReference(in)); return Builder.class.cast(super.fromReferenceType(in));
} }
/** /**

View File

@ -75,7 +75,7 @@ public class Org extends EntityType<Org> {
org.setId(id); org.setId(id);
org.setType(type); org.setType(type);
org.setLinks(links); org.setLinks(links);
org.setTasks(tasks); org.setTasksInProgress(tasksInProgress);
return org; return org;
} }
@ -107,11 +107,11 @@ public class Org extends EntityType<Org> {
} }
/** /**
* @see EntityType#getTasks() * @see EntityType#getTasksInProgress()
*/ */
@Override @Override
public Builder tasks(TaskList tasks) { public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasks = tasks; this.tasksInProgress = tasksInProgress;
return this; return this;
} }
@ -152,12 +152,12 @@ public class Org extends EntityType<Org> {
} }
@Override @Override
public Builder fromEntity(EntityType<Org> in) { public Builder fromEntityType(EntityType<Org> in) {
return Builder.class.cast(super.fromEntity(in)); return Builder.class.cast(super.fromEntityType(in));
} }
public Builder fromOrg(Org 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() { public Builder<T> toBuilder() {
return new Builder<T>().fromReference(this); return new Builder<T>().fromReferenceType(this);
} }
public static class Builder<T extends ReferenceType<T>> { 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() { public Builder<T> toBuilder() {
return new Builder<T>().fromResource(this); return new Builder<T>().fromResourceType(this);
} }
public static class Builder<T extends ResourceType<T>> { 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 @Override
public Builder tasks(TaskList tasks) { public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasks = tasks; this.tasksInProgress = tasksInProgress;
return this; return this;
} }
@ -228,12 +228,13 @@ public class Task extends EntityType<Task> {
} }
@Override @Override
public Builder fromEntity(EntityType<Task> in) { public Builder fromEntityType(EntityType<Task> in) {
return Builder.class.cast(super.fromEntity(in)); return Builder.class.cast(super.fromEntityType(in));
} }
public Builder fromTask(Task in) { public Builder fromTask(Task in) {
return fromEntity(in).error(in.getError()).org(in.getOrg()).progress(in.getProgress()).status(in.getStatus()) return fromEntityType(in)
.error(in.getError()).org(in.getOrg()).progress(in.getProgress()).status(in.getStatus())
.operation(in.getOperation()).operationName(in.getOperationName()); .operation(in.getOperation()).operationName(in.getOperationName());
} }
} }

View File

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