All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.kth.iss.ug2.Ug2TicketInformation Maven / Gradle / Ivy

/*
 * MIT License
 *
 * Copyright (c) 2017 Kungliga Tekniska högskolan
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package se.kth.iss.ug2;

import java.util.Date;

public class Ug2TicketInformation {

    private Ug2ObjectHandle subject;
    private Ug2ObjectHandle issuer;
    private Ug2ObjectHandle receiver;
    private final Date creationTime;
    private final String ticketId;

    @SuppressWarnings("unused")
    private Ug2TicketInformation() {
        creationTime = new Date();
        ticketId = null;
    }

    public Ug2TicketInformation(Ug2ObjectHandle subj, Ug2ObjectHandle iss, Ug2ObjectHandle recv, String id) {
        setSubject(subj);
        setIssuer(iss);
        setReceiver(recv);
        ticketId = id;
        creationTime = new Date();
    }

    public Ug2TicketInformation(Ug2ObjectHandle subj, Ug2ObjectHandle iss, Ug2ObjectHandle recv, String id, long created) {
        setSubject(subj);
        setIssuer(iss);
        setReceiver(recv);
        ticketId = id;
        creationTime = new Date(created);
    }

    public Ug2TicketInformation(Ug2TicketInformation ti) {

        if (ti == null) {
            creationTime = new Date(0);
            setSubject(null);
            setIssuer(null);
            setReceiver(null);
            ticketId = null;
        } else {
            creationTime = new Date(ti.creationTime().getTime());
            setSubject(ti.subject());
            setIssuer(ti.issuer());
            setReceiver(ti.receiver());
            ticketId = ti.id();
        }
    }

    private void setSubject(Ug2ObjectHandle subj) {
        subject = new Ug2ObjectHandle(subj);
    }

    private void setIssuer(Ug2ObjectHandle iss) {
        issuer = new Ug2ObjectHandle(iss);
    }

    private void setReceiver(Ug2ObjectHandle recv) {
        receiver = new Ug2ObjectHandle(recv);
    }

    public Ug2ObjectHandle subject() {
        return new Ug2ObjectHandle(subject);
    }

    public Ug2ObjectHandle issuer() {
        return new Ug2ObjectHandle(issuer);
    }

    public Ug2ObjectHandle receiver() {
        return new Ug2ObjectHandle(receiver);
    }

    public Date creationTime() {
        return new Date(creationTime.getTime());
    }

    public String id() {
        if (ticketId != null)
            return ticketId;

        return null;
    }

    @Override
    public String toString()
    {
        return (new StringBuilder())
                .append("Subject: ")
                .append(subject.toString())
                .append(", Issuer: ")
                .append(issuer.toString())
                .append(", Receiver: ")
                .append(receiver.toString())
                .append(", Creation time: ")
                .append(creationTime.toString())
                .toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy