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
14 * and a string which describes a failure reason (if any) in human readable form.
21 * Generates an instance of the Status class.
23 * @param errorCode The status code. If passed as null, code will be
24 * stored as {@code StatusCode.UNDEFINED}
25 * @param description The human readable description of the status. If passed
26 * as null, description will be inferred by the code
28 public Status(StatusCode errorCode, String description) {
29 this.code = (errorCode != null)? errorCode : StatusCode.UNDEFINED;
30 this.description = (description != null)? description : this.code.toString();
34 * Returns the status code
35 * @return the {@code StatusCode} representing the status code
37 public StatusCode getCode() {
42 * Returns a human readable description of the failure if any
43 * @return a string representing the reason of failure
45 public String getDescription() {
50 * Tells whether the status is successful
51 * @return true if the Status code is {@code StatusCode.SUCCESS}
53 public boolean isSuccess() {
54 return code == StatusCode.SUCCESS;
58 public String toString() {
59 return code + ": " + description;
63 public int hashCode() {
66 result = prime * result + ((code == null) ? 0 : code.hashCode());
71 public boolean equals(Object obj) {
76 if (getClass() != obj.getClass())
78 Status other = (Status) obj;
79 if (code != other.code)