X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Futils%2FStatus.java;fp=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Futils%2FStatus.java;h=503e08e714568bc00118d5ad7626fd1ce396b2b7;hp=9893a06e02f2d2179d1dedfa4405d30aefb0f5fe;hb=5ac5f9d4d8f549f152c802de461c766588b992c4;hpb=16a5e410667863944b3e83e9a853401ff55cebb4 diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java index 9893a06e02..503e08e714 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java @@ -10,74 +10,98 @@ package org.opendaylight.controller.sal.utils; /** * Represents the return object of the osgi service interfaces function calls. - * It contains a code {@code StatusCode} representing the result of the call - * and a string which describes a failure reason (if any) in human readable form. + * It contains a code {@code StatusCode} representing the result of the call and + * a string which describes a failure reason (if any) in human readable form. */ public class Status { - StatusCode code; - String description; - - /** - * Generates an instance of the Status class. - * - * @param errorCode The status code. If passed as null, code will be - * stored as {@code StatusCode.UNDEFINED} - * @param description The human readable description of the status. If passed - * as null, description will be inferred by the code - */ - public Status(StatusCode errorCode, String description) { - 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; - } + StatusCode code; + String description; - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((code == null) ? 0 : code.hashCode()); - return result; - } + /** + * Generates an instance of the Status class. This is used as return code + * for internal API2 function calls. This constructor allows to specify, + * beside the Status Code, a custom human readable description to add more + * information about the status. + * + * @param errorCode + * The status code. If passed as null, code will be stored as + * {@code StatusCode.UNDEFINED} + * @param description + * The human readable description of the status. If passed as + * null, description will be inferred by the code + */ + public Status(StatusCode errorCode, String description) { + this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED; + this.description = (description != null) ? description : this.code + .toString(); + } - @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; + } }