package org.sagebionetworks.repo.model.message;

import org.sagebionetworks.repo.model.ObjectType;

/**
 * The change key is a composite of the object type and the object id.
 * 
 * @author John
 *
 */
class ChangeMessageKey {
	
	private ObjectType type;
	private String objectId;
	
	public ChangeMessageKey(ChangeMessage message) {
		if(message == null) throw new IllegalArgumentException("ChangeMessage cannot be null");
		if(message.getObjectId() == null) throw new IllegalArgumentException("ChangeMessage.getObjectId() cannot be null");
		if(message.getObjectType()== null) throw new IllegalArgumentException("ChangeMessage.getObjectType() cannot be null");
		this.type = message.getObjectType();
		this.objectId = message.getObjectId();
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((objectId == null) ? 0 : objectId.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ChangeMessageKey other = (ChangeMessageKey) obj;
		if (objectId == null) {
			if (other.objectId != null)
				return false;
		} else if (!objectId.equals(other.objectId))
			return false;
		if (type != other.type)
			return false;
		return true;
	}
	
}
@@ -274,18 +274,51 @@
 jectId;%0A
+%09private Boolean isModification;%0A
 %09%0A
-
 %09public 
@@ -768,19 +768,73 @@
 ctId();%0A
+%09%09this.isModification = message.getIsModification();%0A
 %09%7D%0A
+%0A
 %09@Overri
@@ -928,21 +928,105 @@
 * result
-%0A%09%09%09%09
+ + ((isModification == null) ? 0 : isModification.hashCode());%0A%09%09result = prime * result 
 + ((obje
@@ -1155,16 +1155,17 @@
 ult;%0A%09%7D%0A
+%0A
 %09@Overri
@@ -1379,16 +1379,179 @@
 y) obj;%0A
+%09%09if (isModification == null) %7B%0A%09%09%09if (other.isModification != null)%0A%09%09%09%09return false;%0A%09%09%7D else if (!isModification.equals(other.isModification))%0A%09%09%09return false;%0A
 %09%09if (ob
@@ -1742,11 +1742,167 @@
 rue;%0A%09%7D%0A
-%09
+%0A%09@Override%0A%09public String toString() %7B%0A%09%09return %22ChangeMessageKey %5Btype=%22 + type + %22, objectId=%22 + objectId + %22, isModification=%22 + isModification + %22%5D%22;%0A%09%7D
 %0A%7D

message key should take isModification into account