2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.dbcapi.model;
23 import javax.xml.bind.annotation.XmlRootElement;
24 import java.io.Serializable;
25 import java.util.Objects;
28 public class ApiError implements Serializable {
30 private String message;
31 private String fields;
37 public ApiError(int code, String message) {
38 this(code, message, null);
41 public ApiError(int code, String message, String fields) {
43 this.message = message;
47 public int getCode() {
50 public void setCode(int rc) {
53 public String getMessage() {
56 public void setMessage(String message) {
57 this.message = message;
59 public String getFields() {
62 public void setFields(String fields) {
65 public String toString() {
66 return String.format( "code=%d msg=%s fields=%s", this.code, this.message, this.fields );
68 public boolean is2xx() {
70 return code >= 200 && code < 300;
79 public boolean equals(Object o) {
80 if (this == o) return true;
81 if (o == null || getClass() != o.getClass()) return false;
82 ApiError apiError = (ApiError) o;
83 return code == apiError.code &&
84 Objects.equals(message, apiError.message) &&
85 Objects.equals(fields, apiError.fields);
89 public int hashCode() {
90 return Objects.hash(code, message, fields);