- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Status other = (Status) obj;
- if (code != other.code)
- return false;
- return true;
- }
+ /**
+ * Generates an instance of the Status class based on the passed StatusCode
+ * only. The description field of the Status object will be inferred by the
+ * status code.
+ *
+ * @param errorCode
+ * The status code. If passed as null, code will be stored as
+ * {@code StatusCode.UNDEFINED}
+ */
+ public Status(StatusCode errorCode) {
+ this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
+ this.description = (description != null) ? description : this.code
+ .toString();
+ }
+
+ /**
+ * Returns the status code
+ *
+ * @return the {@code StatusCode} representing the status code
+ */
+ public StatusCode getCode() {
+ return code;
+ }
+
+ /**
+ * Returns a human readable description of the failure if any
+ *
+ * @return a string representing the reason of failure
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Tells whether the status is successful
+ *
+ * @return true if the Status code is {@code StatusCode.SUCCESS}
+ */
+ public boolean isSuccess() {
+ return code == StatusCode.SUCCESS;
+ }
+
+ @Override
+ public String toString() {
+ return code + ": " + description;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((code == null) ? 0 : code.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Status other = (Status) obj;
+ if (code != other.code)
+ return false;
+ return true;
+ }