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

com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events.PatchsetCreated Maven / Gradle / Ivy

The newest version!
/*
 *  The MIT License
 *
 *  Copyright 2010 Sony Ericsson Mobile Communications.
 *
 *  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 com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events;

import com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.GerritEventType;
import com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.GerritJsonEvent;
import com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.attr.Change;
import com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.attr.PatchSet;
import com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events.lifecycle.GerritEventLifecycle;
import net.sf.json.JSONObject;

import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.GerritEventKeys.CHANGE;
import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.GerritEventKeys.PATCH_SET;

/**
 * A DTO representation of the patchset-created Gerrit Event.
 * @author Robert Sandell <[email protected]>
 */
public class PatchsetCreated extends GerritEventLifecycle implements GerritJsonEvent {

    /**
     * The Gerrit change the event is related to.
     */
    private Change change;

    /**
     * Refers to a specific patchset within a change.
     */
    private PatchSet patchSet;

    @Override
    public GerritEventType getEventType() {
        return GerritEventType.PATCHSET_CREATED;
    }

    @Override
    public void fromJson(JSONObject json) {
        if (json.containsKey(CHANGE)) {
            change = new Change(json.getJSONObject(CHANGE));
        }
        if (json.containsKey(PATCH_SET)) {
            this.patchSet = new PatchSet(json.getJSONObject(PATCH_SET));
        }
    }

    /**
     * The Gerrit change the event is related to.
     * @return the change.
     */
    public Change getChange() {
        return change;
    }

    /**
     * The Gerrit change the event is related to.
     * @param change the change.
     */
    public void setChange(Change change) {
        this.change = change;
    }

    /**
     * Refers to a specific patchset within a change.
     * @return the patchSet.
     */
    public PatchSet getPatchSet() {
        return patchSet;
    }

    /**
     * Refers to a specific patchset within a change.
     * @param patchset the patchSet.
     */
    public void setPatchset(PatchSet patchset) {
        this.patchSet = patchset;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof PatchsetCreated) {
            return equals((PatchsetCreated)obj);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        //CS IGNORE MagicNumber FOR NEXT 5 LINES. REASON: Autogenerated Code.
        //CS IGNORE AvoidInlineConditionals FOR NEXT 5 LINES. REASON: Autogenerated Code.
        int hash = 5;
        hash = 83 * hash + (this.change != null ? this.change.hashCode() : 0);
        hash = 83 * hash + (this.patchSet != null ? this.patchSet.hashCode() : 0);
        return hash;
    }

    /**
     * Implementation specific equals.
     * @param obj the object to compare.
     * @see #equals(java.lang.Object)
     * @return true if equals
     */
    public boolean equals(PatchsetCreated obj) {
        return change.equals(obj.change) && patchSet.equals(obj.patchSet);
    }

    @Override
    public String toString() {
        return "PatchsetCreated: " + change + " " + patchSet;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy