001/*
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.validation;
021
022import org.apache.commons.lang3.builder.EqualsBuilder;
023import org.apache.commons.lang3.builder.HashCodeBuilder;
024import org.apache.commons.lang3.builder.ToStringBuilder;
025import org.apache.commons.lang3.builder.ToStringStyle;
026
027public class SingleValidationMessage {
028
029        private Integer myLocationCol;
030        private Integer myLocationLine;
031        private String myLocationString;
032        private String myMessage;
033        private String myMessageId;
034        private ResultSeverityEnum mySeverity;
035
036        /**
037         * Constructor
038         */
039        public SingleValidationMessage() {
040                super();
041        }
042
043        @Override
044        public boolean equals(Object obj) {
045                if (this == obj) {
046                        return true;
047                }
048                if (obj == null) {
049                        return false;
050                }
051                if (!(obj instanceof SingleValidationMessage)) {
052                        return false;
053                }
054                SingleValidationMessage other = (SingleValidationMessage) obj;
055                EqualsBuilder b = new EqualsBuilder();
056                b.append(myLocationCol, other.myLocationCol);
057                b.append(myLocationLine, other.myLocationLine);
058                b.append(myLocationString, other.myLocationString);
059                b.append(myMessage, other.myMessage);
060                b.append(mySeverity, other.mySeverity);
061                return b.isEquals();
062        }
063
064        public Integer getLocationCol() {
065                return myLocationCol;
066        }
067
068        public Integer getLocationLine() {
069                return myLocationLine;
070        }
071
072        public String getLocationString() {
073                return myLocationString;
074        }
075
076        public String getMessage() {
077                return myMessage;
078        }
079
080        public String getMessageId() {
081                return myMessageId;
082        }
083
084        public ResultSeverityEnum getSeverity() {
085                return mySeverity;
086        }
087
088        @Override
089        public int hashCode() {
090                HashCodeBuilder b = new HashCodeBuilder();
091                b.append(myLocationCol);
092                b.append(myLocationCol);
093                b.append(myLocationString);
094                b.append(myMessage);
095                b.append(mySeverity);
096                return b.toHashCode();
097        }
098
099        public void setLocationCol(Integer theLocationCol) {
100                myLocationCol = theLocationCol;
101        }
102
103        public void setLocationLine(Integer theLocationLine) {
104                myLocationLine = theLocationLine;
105        }
106
107        public void setLocationString(String theLocationString) {
108                myLocationString = theLocationString;
109        }
110
111        public void setMessage(String theMessage) {
112                myMessage = theMessage;
113        }
114
115        public void setMessageId(String messageId) {
116                myMessageId = messageId;
117        }
118
119        public void setSeverity(ResultSeverityEnum theSeverity) {
120                mySeverity = theSeverity;
121        }
122
123        @Override
124        public String toString() {
125                ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
126                if (myLocationCol != null || myLocationLine != null) {
127                        b.append("col", myLocationCol);
128                        b.append("row", myLocationLine);
129                }
130                if (myLocationString != null) {
131                        b.append("locationString", myLocationString);
132                }
133                b.append("message", myMessage);
134                if (myMessageId != null) {
135                        b.append(myMessageId);
136                }
137                if (mySeverity != null) {
138                        b.append("severity", mySeverity.getCode());
139                }
140                return b.toString();
141        }
142
143}