/* Generated from Java with JSweet 2.3.7 - http://www.jsweet.org */
/**
 * @param {string} ref Encapsulated reference string. MUST NOT be null.
 * @class
 * @author Jakub Senko <jsenko@redhat.com>
 */
var Reference = /** @class */ (function () {
    function Reference(ref) {
        if (this.ref === undefined)
            this.ref = null;
        if (this.abs === undefined)
            this.abs = null;
        if (this.rel === undefined)
            this.rel = null;
        if (ref == null)
            throw Object.defineProperty(new Error(), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
        this.ref = ref;
        var parts = ref.split("#");
        if (parts.length === 0) {
            this.abs = ref;
            this.rel = null;
        }
        else if (parts.length === 2) {
            this.abs = /* equals */ (function (o1, o2) { if (o1 && o1.equals) {
                return o1.equals(o2);
            }
            else {
                return o1 === o2;
            } })("", parts[0]) ? null : parts[0];
            this.rel = "#" + parts[1];
        }
        else {
            throw Object.defineProperty(new Error("Wrong reference format."), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
        }
    }
    /**
     * @return {string} the original/full reference string.
     */
    Reference.prototype.getRef = function () {
        return this.ref;
    };
    Reference.prototype.getAbsPart = function () {
        return this.abs;
    };
    Reference.prototype.getRelPart = function () {
        return this.rel;
    };
    Reference.prototype.isRelative = function () {
        return this.abs == null;
    };
    /**
     * @return {string} a `name` of the referenced component, as parsed from the reference string.
     * @throws java.lang.RuntimeException if the reference does not contain relative part
     */
    Reference.prototype.getName = function () {
        if (this.rel == null)
            throw Object.defineProperty(new Error("No relative part in the reference."), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.Exception'] });
        var parts = this.rel.split("/");
        return parts[parts.length - 1];
    };
    /**
     * @param {Reference} that other reference
     * @return {Reference} a new reference with the absolute part copied form the other one,
     * and relative from this one
     */
    Reference.prototype.withAbsoluteFrom = function (that) {
        if (that.getAbsPart() == null)
            throw Object.defineProperty(new Error(), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
        return new Reference(that.abs + this.rel);
    };
    /**
     *
     * @param {*} o
     * @return {boolean}
     */
    Reference.prototype.equals = function (o) {
        if (this === o)
            return true;
        if (o == null || this.constructor !== o.constructor)
            return false;
        var reference = o;
        return /* equals */ (function (o1, o2) { if (o1 && o1.equals) {
            return o1.equals(o2);
        }
        else {
            return o1 === o2;
        } })(this.ref, reference.ref);
    };
    /**
     *
     * @return {number}
     */
    Reference.prototype.hashCode = function () {
        return /* hashCode */ (function (o) { if (o.hashCode) {
            return o.hashCode();
        }
        else {
            return o.toString().split('').reduce(function (prevHash, currVal) { return (((prevHash << 5) - prevHash) + currVal.charCodeAt(0)) | 0; }, 0);
        } })(this.ref);
    };
    return Reference;
}());
export { Reference };
Reference["__class"] = "io.apicurio.datamodels.openapi.visitors.dereference.Reference";
//# sourceMappingURL=Reference.js.map