package hudson.plugins.promoted_builds;

import hudson.model.Cause;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.console.HyperlinkNote;

/**
 * Cause used to indicate that a build was triggered by a promotion.  Extends
 * UpstreamCause so that existing build steps can use "the upstream build that
 * triggered this build" (or something like that).
 */
public class PromotionCause extends Cause.UpstreamCause {
    /** The name of the promotion process. */
    private String promotionProcessName;

    /** URL to the promotion. */
    private String promotionBuildUrl;

    /** The build number of the promotion */
    private int promotionBuildNumber;

    /* package */ PromotionCause(final Promotion promotion, final Run promotedBuild) {
        super(promotedBuild);
        
        promotionProcessName = promotion.getParent().getName();
        promotionBuildUrl = promotion.getUrl();
        promotionBuildNumber = promotion.getNumber();
    }
    
    // {{{ getShortDescription
    /** {@inheritDoc} */
    @Override
    public String getShortDescription() {
        return Messages.PromotionCause_ShortDescription(
            promotionProcessName + " #" + promotionBuildNumber,
            getUpstreamProject(),
            Integer.toString(getUpstreamBuild())
        );
    }
    // }}}
    
    // {{{ print
    /** {@inheritDoc} */
    @Override
    public void print(final TaskListener listener) {
        listener.getLogger().println(
            Messages.PromotionCause_ShortDescription(
                HyperlinkNote.encodeTo('/' + promotionBuildUrl,  promotionProcessName + " #" + promotionBuildNumber),
                HyperlinkNote.encodeTo('/' + getUpstreamUrl(), getUpstreamProject()),
                HyperlinkNote.encodeTo('/' + getUpstreamUrl() + getUpstreamBuild(), Integer.toString(getUpstreamBuild()))
            )
        );
    }
    // }}}

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + super.hashCode();
        hash = 53 * hash + (this.promotionProcessName != null ? this.promotionProcessName.hashCode() : 0);
        hash = 53 * hash + (this.promotionBuildUrl != null ? this.promotionBuildUrl.hashCode() : 0);
        hash = 53 * hash + this.promotionBuildNumber;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PromotionCause other = (PromotionCause) obj;
        if ((this.promotionProcessName == null) ? (other.promotionProcessName != null) : !this.promotionProcessName.equals(other.promotionProcessName)) {
            return false;
        }
        if ((this.promotionBuildUrl == null) ? (other.promotionBuildUrl != null) : !this.promotionBuildUrl.equals(other.promotionBuildUrl)) {
            return false;
        }
        if (this.promotionBuildNumber != other.promotionBuildNumber) {
            return false;
        }
        return true;
    }
    
    
}

@@ -158,16 +158,43 @@
 kNote;%0A%0A
+import java.util.Objects;%0A%0A
 /**%0A * C
@@ -2666,86 +2666,24 @@
 if (
-(this.promotionProcessName == null) ? (other.promotionProcessName != null) : !
+!Objects.equals(
 this
@@ -2703,24 +2703,18 @@
 cessName
-.equals(
+, 
 other.pr
@@ -2788,80 +2788,24 @@
 if (
-(this.promotionBuildUrl == null) ? (other.promotionBuildUrl != null) : !
+!Objects.equals(
 this
@@ -2822,24 +2822,18 @@
 BuildUrl
-.equals(
+, 
 other.pr

Simplify some equality checks with Objects.equals.