2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.utils;
12 * Represents the return object of the osgi service interfaces function calls.
13 * It contains a code {@code StatusCode} representing the result of the call and
14 * a string which describes a failure reason (if any) in human readable form.
21 * Generates an instance of the Status class. This is used as return code
22 * for internal API2 function calls. This constructor allows to specify,
23 * beside the Status Code, a custom human readable description to add more
24 * information about the status.
27 * The status code. If passed as null, code will be stored as
28 * {@code StatusCode.UNDEFINED}
30 * The human readable description of the status. If passed as
31 * null, description will be inferred by the code
33 public Status(StatusCode errorCode, String description) {
34 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
35 this.description = (description != null) ? description : this.code
40 * Generates an instance of the Status class based on the passed StatusCode
41 * only. The description field of the Status object will be inferred by the
45 * The status code. If passed as null, code will be stored as
46 * {@code StatusCode.UNDEFINED}
48 public Status(StatusCode errorCode) {
49 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
50 this.description = (description != null) ? description : this.code
55 * Returns the status code
57 * @return the {@code StatusCode} representing the status code
59 public StatusCode getCode() {
64 * Returns a human readable description of the failure if any
66 * @return a string representing the reason of failure
68 public String getDescription() {
73 * Tells whether the status is successful
75 * @return true if the Status code is {@code StatusCode.SUCCESS}
77 public boolean isSuccess() {
78 return code == StatusCode.SUCCESS;
82 public String toString() {
83 return code + ": " + description;
87 public int hashCode() {
90 result = prime * result + ((code == null) ? 0 : code.hashCode());
95 public boolean equals(Object obj) {
100 if (getClass() != obj.getClass())
102 Status other = (Status) obj;
103 if (code != other.code)