View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.vcloud.domain.internal;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.net.URI;
24  import java.util.Date;
25  
26  import javax.annotation.Nullable;
27  
28  import org.jclouds.vcloud.VCloudMediaType;
29  import org.jclouds.vcloud.domain.ReferenceType;
30  import org.jclouds.vcloud.domain.Task;
31  import org.jclouds.vcloud.domain.TaskStatus;
32  import org.jclouds.vcloud.domain.VCloudError;
33  
34  /**
35   * 
36   * @author Adrian Cole
37   * 
38   */
39  public class TaskImpl extends ReferenceTypeImpl implements Task {
40  
41     private final String operation;
42     private final TaskStatus status;
43     private final Date startTime;
44     @Nullable
45     private final Date endTime;
46     @Nullable
47     private final Date expiryTime;
48     private final ReferenceType owner;
49     @Nullable
50     private final VCloudError error;
51  
52     public TaskImpl(URI id, String operation, TaskStatus status, Date startTime, @Nullable Date endTime,
53              @Nullable Date expiryTime, ReferenceType owner, VCloudError error) {
54        super(null, VCloudMediaType.TASK_XML, id);
55        this.operation = operation;
56        this.status = checkNotNull(status, "status");
57        this.startTime = startTime;
58        this.endTime = endTime;
59        this.expiryTime = expiryTime;
60        this.owner = owner;
61        this.error = error;
62     }
63  
64     @Override
65     public TaskStatus getStatus() {
66        return status;
67     }
68  
69     @Override
70     public Date getStartTime() {
71        return startTime;
72     }
73  
74     @Override
75     public ReferenceType getOwner() {
76        return owner;
77     }
78  
79     @Override
80     public Date getEndTime() {
81        return endTime;
82     }
83  
84     @Override
85     public VCloudError getError() {
86        return error;
87     }
88  
89     @Override
90     public String toString() {
91        return "TaskImpl [endTime=" + endTime + ", error=" + error + ", expiryTime=" + expiryTime + ", operation="
92                 + operation + ", owner=" + owner + ", startTime=" + startTime + ", status=" + status + ", getHref()="
93                 + getHref() + ", getName()=" + getName() + ", getType()=" + getType() + ", toString()="
94                 + super.toString() + ", getClass()=" + getClass() + "]";
95     }
96  
97     public Date getExpiryTime() {
98        return expiryTime;
99     }
100 
101    @Override
102    public String getOperation() {
103       return operation;
104    }
105 
106    @Override
107    public int hashCode() {
108       final int prime = 31;
109       int result = super.hashCode();
110       result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
111       result = prime * result + ((error == null) ? 0 : error.hashCode());
112       result = prime * result + ((expiryTime == null) ? 0 : expiryTime.hashCode());
113       result = prime * result + ((operation == null) ? 0 : operation.hashCode());
114       result = prime * result + ((owner == null) ? 0 : owner.hashCode());
115       result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
116       result = prime * result + ((status == null) ? 0 : status.hashCode());
117       return result;
118    }
119 
120    @Override
121    public boolean equals(Object obj) {
122       if (this == obj)
123          return true;
124       if (!super.equals(obj))
125          return false;
126       if (getClass() != obj.getClass())
127          return false;
128       TaskImpl other = (TaskImpl) obj;
129       if (endTime == null) {
130          if (other.endTime != null)
131             return false;
132       } else if (!endTime.equals(other.endTime))
133          return false;
134       if (error == null) {
135          if (other.error != null)
136             return false;
137       } else if (!error.equals(other.error))
138          return false;
139       if (expiryTime == null) {
140          if (other.expiryTime != null)
141             return false;
142       } else if (!expiryTime.equals(other.expiryTime))
143          return false;
144       if (operation == null) {
145          if (other.operation != null)
146             return false;
147       } else if (!operation.equals(other.operation))
148          return false;
149       if (owner == null) {
150          if (other.owner != null)
151             return false;
152       } else if (!owner.equals(other.owner))
153          return false;
154       if (startTime == null) {
155          if (other.startTime != null)
156             return false;
157       } else if (!startTime.equals(other.startTime))
158          return false;
159       if (status == null) {
160          if (other.status != null)
161             return false;
162       } else if (!status.equals(other.status))
163          return false;
164       return true;
165    }
166 
167 }