
com.sonymobile.tools.gerrit.gerritevents.dto.events.ChangeBasedEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gerrit-events Show documentation
Show all versions of gerrit-events Show documentation
Java client library for receiving stream-events from Gerrit code review.
As well as performing queries and sending reviews.
The newest version!
/*
* The MIT License
*
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
*
* 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.sonymobile.tools.gerrit.gerritevents.dto.events;
import com.sonymobile.tools.gerrit.gerritevents.GerritQueryHandler;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Change;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.PatchSet;
import net.sf.json.JSONObject;
import java.util.Collections;
import java.util.List;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.CHANGE;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.PATCHSET;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.PATCH_SET;
/**
* Base class for all GeritTriggeredEvents containing a Change.
* @author Tomas Westling <[email protected]>
*/
public abstract class ChangeBasedEvent extends GerritTriggeredEvent {
/**
* The Gerrit change the event is related to.
*/
protected Change change;
/**
* Refers to a specific patchset within a change.
*/
protected PatchSet patchSet;
/**
* The changed files in this patchset.
*/
private transient List files;
/**
* Converts old serialized data to newer construct.
*
* @return itself
*/
@SuppressWarnings("unused")
private Object readResolve() {
if (files != null) {
if (change != null) {
change.setFiles(files);
}
files = null;
}
return this;
}
/**
* The Change.
*
* @return the change.
*/
public Change getChange() {
return change;
}
/**
* The Change.
*
* @param change the change.
*/
public void setChange(Change change) {
this.change = change;
}
/**
* Queries gerrit for the files included in this patch set.
*
* @param gerritQueryHandler the query handler, responsible for the queries to gerrit.
* @return a list of files that are part of this patch set.
*
* @deprecated use {@link Change#getFiles(GerritQueryHandler)} instead.
*/
@Deprecated
public List getFiles(GerritQueryHandler gerritQueryHandler) {
List returned = change.getFiles(gerritQueryHandler);
if (returned == null) {
return Collections.emptyList();
}
return returned;
}
/**
* The patchSet.
*
* @return The patchSet.
*/
public PatchSet getPatchSet() {
return patchSet;
}
/**
* The patchSet.
*
* @param patchset the patchSet.
*/
public void setPatchset(PatchSet patchset) {
this.patchSet = patchset;
}
/**
* Takes a JSON object and fills its internal data-structure.
*
* @param json the JSON Object.
*/
public void fromJson(JSONObject json) {
super.fromJson(json);
if (json.containsKey(CHANGE)) {
change = new Change(json.getJSONObject(CHANGE));
}
if (json.containsKey(PATCH_SET)) {
patchSet = new PatchSet(json.getJSONObject(PATCH_SET));
} else if (json.containsKey(PATCHSET)) {
patchSet = new PatchSet(json.getJSONObject(PATCHSET));
}
}
//CS IGNORE MagicNumber FOR NEXT 15 LINES. REASON: Semi-autogenerated code.
@Override
public int hashCode() {
int result = 0;
if (getEventType() != null) {
result = getEventType().hashCode() * 31;
}
if (change != null) {
result += change.hashCode();
}
result *= 31;
if (patchSet != null) {
result += patchSet.hashCode();
}
return result;
}
@Override
public boolean equals(Object o) {
if (!getClass().isInstance(o)) {
return false;
}
ChangeBasedEvent event = (ChangeBasedEvent)o;
if (getEventType() == null) {
if (event.getEventType() != null) {
return false;
}
} else if (!getEventType().equals(event.getEventType())) {
return false;
}
if (getChange() == null) {
if (event.getChange() != null) {
return false;
}
} else if (!getChange().equals(event.getChange())) {
return false;
}
if (getPatchSet() == null) {
if (event.getPatchSet() != null) {
return false;
}
} else if (!getPatchSet().equals(event.getPatchSet())) {
return false;
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy