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.util.Objects;
27 public class ApiError {
29 private String message;
30 private String fields;
36 public ApiError(int code, String message) {
37 this(code, message, null);
40 public ApiError(int code, String message, String fields) {
42 this.message = message;
46 public int getCode() {
49 public void setCode(int rc) {
52 public String getMessage() {
55 public void setMessage(String message) {
56 this.message = message;
58 public String getFields() {
61 public void setFields(String fields) {
64 public String toString() {
65 return String.format( "code=%d msg=%s fields=%s", this.code, this.message, this.fields );
67 public boolean is2xx() {
69 return code >= 200 && code < 300;
78 public boolean equals(Object o) {
79 if (this == o) return true;
80 if (o == null || getClass() != o.getClass()) return false;
81 ApiError apiError = (ApiError) o;
82 return code == apiError.code &&
83 Objects.equals(message, apiError.message) &&
84 Objects.equals(fields, apiError.fields);
88 public int hashCode() {
89 return Objects.hash(code, message, fields);