001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.rc;
020
021import java.util.Objects;
022
023/**
024 * Result Code implementation
025 */
026public class SimpleRC implements RC {
027    private String rc;
028    private String display;
029
030    private SimpleRC() {
031
032    }
033
034    /**
035     * Constructs a SimpleRC carrying only the response code.
036     *
037     * @param rc response code (must not be {@code null})
038     * @throws NullPointerException if {@code rc} is {@code null}
039     */
040    public SimpleRC(String rc) {
041        this.rc = rc;
042        if (rc == null)
043            throw new NullPointerException ();
044    }
045
046    /**
047     * Constructs a SimpleRC with a response code and a human-readable display string.
048     *
049     * @param rc response code (must not be {@code null})
050     * @param display optional display string
051     */
052    public SimpleRC (String rc, String display) {
053        this(rc);
054        this.display = display;
055    }
056    public String rc() {
057        return rc;
058    }
059    public String display() {
060        return display;
061    }
062
063    @Override
064    public boolean equals(Object o) {
065        if (this == o) return true;
066        if (o == null || getClass() != o.getClass()) return false;
067        SimpleRC simpleRC = (SimpleRC) o;
068        return Objects.equals(rc, simpleRC.rc) &&
069          Objects.equals(display, simpleRC.display);
070    }
071
072    @Override
073    public int hashCode() {
074        return Objects.hash(rc, display);
075    }
076
077    @Override
078    public String toString() {
079        return "SimpleRC{" +
080          "rc='" + rc + '\'' +
081          ", display='" + display + '\'' +
082          '}';
083    }
084}