[OLINGO-735] Remove reflection equals from client item

This commit is contained in:
Christian Amend 2015-08-19 09:27:31 +02:00
parent 73f717d551
commit a1731b7efe
16 changed files with 751 additions and 43 deletions

View File

@ -47,4 +47,39 @@ public abstract class AbstractClientPayload extends ClientItem {
public void setContextURL(final URI contextURL) {
this.contextURL = contextURL;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((contextURL == null) ? 0 : contextURL.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof AbstractClientPayload)) {
return false;
}
AbstractClientPayload other = (AbstractClientPayload) obj;
if (contextURL == null) {
if (other.contextURL != null) {
return false;
}
} else if (!contextURL.equals(other.contextURL)) {
return false;
}
return true;
}
@Override
public String toString() {
return "AbstractClientPayload [contextURL=" + contextURL + "super[" + super.toString() + "]]";
}
}

View File

@ -18,11 +18,6 @@
*/
package org.apache.olingo.client.api.domain;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* Abstract representation of an OData entity property value.
*/
@ -103,18 +98,40 @@ public abstract class AbstractClientValue implements ClientValue {
return isCollection() ? (ClientCollectionValue<OV>) this : null;
}
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof AbstractClientValue)) {
return false;
}
AbstractClientValue other = (AbstractClientValue) obj;
if (typeName == null) {
if (other.typeName != null) {
return false;
}
} else if (!typeName.equals(other.typeName)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
final int prime = 31;
int result = 1;
result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
return result;
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
return "AbstractClientValue [typeName=" + typeName + "]";
}
}

View File

@ -65,4 +65,39 @@ public class ClientInlineEntity extends ClientLink {
public ClientEntity getEntity() {
return entity;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((entity == null) ? 0 : entity.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientInlineEntity)) {
return false;
}
ClientInlineEntity other = (ClientInlineEntity) obj;
if (entity == null) {
if (other.entity != null) {
return false;
}
} else if (!entity.equals(other.entity)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientInlineEntity [entity=" + entity + "super[" + super.toString() + "]]";
}
}

View File

@ -36,7 +36,7 @@ public class ClientInlineEntitySet extends ClientLink {
* @param entitySet entity set.
*/
public ClientInlineEntitySet(final URI uri, final ClientLinkType type,
final String title, final ClientEntitySet entitySet) {
final String title, final ClientEntitySet entitySet) {
super(uri, type, title);
this.entitySet = entitySet;
@ -52,7 +52,7 @@ public class ClientInlineEntitySet extends ClientLink {
* @param entitySet entity set.
*/
public ClientInlineEntitySet(final URI baseURI, final String href,
final ClientLinkType type, final String title, final ClientEntitySet entitySet) {
final ClientLinkType type, final String title, final ClientEntitySet entitySet) {
super(baseURI, href, type, title);
this.entitySet = entitySet;
@ -66,4 +66,40 @@ public class ClientInlineEntitySet extends ClientLink {
public ClientEntitySet getEntitySet() {
return entitySet;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((entitySet == null) ? 0 : entitySet.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientInlineEntitySet)) {
return false;
}
ClientInlineEntitySet other = (ClientInlineEntitySet) obj;
if (entitySet == null) {
if (other.entitySet != null) {
return false;
}
} else if (!entitySet.equals(other.entitySet)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientInlineEntitySet [entitySet=" + entitySet + "super[" + super.toString() + "]]";
}
}

View File

@ -20,23 +20,11 @@ package org.apache.olingo.client.api.domain;
import java.net.URI;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract representation of OData entities and links.
*/
public abstract class ClientItem {
/**
* Logger.
*/
protected static final Logger LOG = LoggerFactory.getLogger(ClientItem.class);
/**
* OData entity name/type.
*/
@ -79,18 +67,48 @@ public abstract class ClientItem {
this.link = link;
}
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ClientItem)) {
return false;
}
ClientItem other = (ClientItem) obj;
if (link == null) {
if (other.link != null) {
return false;
}
} else if (!link.equals(other.link)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
final int prime = 31;
int result = 1;
result = prime * result + ((link == null) ? 0 : link.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
return "ClientItem [name=" + name + ", link=" + link + "]";
}
}

View File

@ -68,4 +68,47 @@ public abstract class AbstractClientEntitySet extends AbstractClientPayload impl
public void setCount(final int count) {
this.count = count;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((count == null) ? 0 : count.hashCode());
result = prime * result + ((next == null) ? 0 : next.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof AbstractClientEntitySet)) {
return false;
}
AbstractClientEntitySet other = (AbstractClientEntitySet) obj;
if (count == null) {
if (other.count != null) {
return false;
}
} else if (!count.equals(other.count)) {
return false;
}
if (next == null) {
if (other.next != null) {
return false;
}
} else if (!next.equals(other.next)) {
return false;
}
return true;
}
@Override
public String toString() {
return "AbstractClientEntitySet [next=" + next + ", count=" + count + "super[" + super.toString() + "]]";
}
}

View File

@ -120,5 +120,38 @@ public class ClientCollectionValueImpl<OV extends ClientValue> extends AbstractC
return values.isEmpty();
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((values == null) ? 0 : values.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientCollectionValueImpl)) {
return false;
}
ClientCollectionValueImpl<?> other = (ClientCollectionValueImpl<?>) obj;
if (values == null) {
if (other.values != null) {
return false;
}
} else if (!values.equals(other.values)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientCollectionValueImpl [values=" + values + "super[" + super.toString() + "]]";
}
}

View File

@ -201,4 +201,64 @@ public class ClientComplexValueImpl extends AbstractClientValue implements Clien
public int size() {
return fields.size();
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
result = prime * result + ((associationLinks == null) ? 0 : associationLinks.hashCode());
result = prime * result + ((fields == null) ? 0 : fields.hashCode());
result = prime * result + ((navigationLinks == null) ? 0 : navigationLinks.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientComplexValueImpl)) {
return false;
}
ClientComplexValueImpl other = (ClientComplexValueImpl) obj;
if (annotations == null) {
if (other.annotations != null) {
return false;
}
} else if (!annotations.equals(other.annotations)) {
return false;
}
if (associationLinks == null) {
if (other.associationLinks != null) {
return false;
}
} else if (!associationLinks.equals(other.associationLinks)) {
return false;
}
if (fields == null) {
if (other.fields != null) {
return false;
}
} else if (!fields.equals(other.fields)) {
return false;
}
if (navigationLinks == null) {
if (other.navigationLinks != null) {
return false;
}
} else if (!navigationLinks.equals(other.navigationLinks)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientComplexValueImpl [navigationLinks=" + navigationLinks + ", associationLinks=" + associationLinks
+ ", annotations=" + annotations + ", fields=" + fields + "super[" + super.toString() + "]]";
}
}

View File

@ -51,4 +51,43 @@ public class ClientDeletedEntityImpl extends ClientItem implements ClientDeleted
this.reason = reason;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((reason == null) ? 0 : reason.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientDeletedEntityImpl)) {
return false;
}
ClientDeletedEntityImpl other = (ClientDeletedEntityImpl) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (reason != other.reason) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientDeletedEntityImpl [id=" + id + ", reason=" + reason + "super[" + super.toString() + "]]";
}
}

View File

@ -57,4 +57,55 @@ public class ClientDeltaImpl extends ClientEntitySetImpl implements ClientDelta
return deletedLinks;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((addedLinks == null) ? 0 : addedLinks.hashCode());
result = prime * result + ((deletedEntities == null) ? 0 : deletedEntities.hashCode());
result = prime * result + ((deletedLinks == null) ? 0 : deletedLinks.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientDeltaImpl)) {
return false;
}
ClientDeltaImpl other = (ClientDeltaImpl) obj;
if (addedLinks == null) {
if (other.addedLinks != null) {
return false;
}
} else if (!addedLinks.equals(other.addedLinks)) {
return false;
}
if (deletedEntities == null) {
if (other.deletedEntities != null) {
return false;
}
} else if (!deletedEntities.equals(other.deletedEntities)) {
return false;
}
if (deletedLinks == null) {
if (other.deletedLinks != null) {
return false;
}
} else if (!deletedLinks.equals(other.deletedLinks)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientDeltaImpl [deletedEntities=" + deletedEntities + ", addedLinks=" + addedLinks + ", deletedLinks="
+ deletedLinks + "super[" + super.toString() + "]]";
}
}

View File

@ -75,4 +75,64 @@ public class ClientDeltaLinkImpl extends ClientItem implements ClientDeltaLink {
return annotations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
result = prime * result + ((relationship == null) ? 0 : relationship.hashCode());
result = prime * result + ((source == null) ? 0 : source.hashCode());
result = prime * result + ((target == null) ? 0 : target.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientDeltaLinkImpl)) {
return false;
}
ClientDeltaLinkImpl other = (ClientDeltaLinkImpl) obj;
if (annotations == null) {
if (other.annotations != null) {
return false;
}
} else if (!annotations.equals(other.annotations)) {
return false;
}
if (relationship == null) {
if (other.relationship != null) {
return false;
}
} else if (!relationship.equals(other.relationship)) {
return false;
}
if (source == null) {
if (other.source != null) {
return false;
}
} else if (!source.equals(other.source)) {
return false;
}
if (target == null) {
if (other.target != null) {
return false;
}
} else if (!target.equals(other.target)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientDeltaLinkImpl [source=" + source + ", relationship=" + relationship + ", target=" + target
+ ", annotations=" + annotations + "super[" + super.toString() + "]]";
}
}

View File

@ -295,4 +295,143 @@ public class ClientEntityImpl extends AbstractClientPayload implements ClientEnt
public List<ClientAnnotation> getAnnotations() {
return annotations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
result = prime * result + ((associationLinks == null) ? 0 : associationLinks.hashCode());
result = prime * result + ((eTag == null) ? 0 : eTag.hashCode());
result = prime * result + ((editLink == null) ? 0 : editLink.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((mediaContentSource == null) ? 0 : mediaContentSource.hashCode());
result = prime * result + ((mediaContentType == null) ? 0 : mediaContentType.hashCode());
result = prime * result + ((mediaETag == null) ? 0 : mediaETag.hashCode());
result = prime * result + ((mediaEditLinks == null) ? 0 : mediaEditLinks.hashCode());
result = prime * result + (mediaEntity ? 1231 : 1237);
result = prime * result + ((navigationLinks == null) ? 0 : navigationLinks.hashCode());
result = prime * result + ((operations == null) ? 0 : operations.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientEntityImpl)) {
return false;
}
ClientEntityImpl other = (ClientEntityImpl) obj;
if (annotations == null) {
if (other.annotations != null) {
return false;
}
} else if (!annotations.equals(other.annotations)) {
return false;
}
if (associationLinks == null) {
if (other.associationLinks != null) {
return false;
}
} else if (!associationLinks.equals(other.associationLinks)) {
return false;
}
if (eTag == null) {
if (other.eTag != null) {
return false;
}
} else if (!eTag.equals(other.eTag)) {
return false;
}
if (editLink == null) {
if (other.editLink != null) {
return false;
}
} else if (!editLink.equals(other.editLink)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (mediaContentSource == null) {
if (other.mediaContentSource != null) {
return false;
}
} else if (!mediaContentSource.equals(other.mediaContentSource)) {
return false;
}
if (mediaContentType == null) {
if (other.mediaContentType != null) {
return false;
}
} else if (!mediaContentType.equals(other.mediaContentType)) {
return false;
}
if (mediaETag == null) {
if (other.mediaETag != null) {
return false;
}
} else if (!mediaETag.equals(other.mediaETag)) {
return false;
}
if (mediaEditLinks == null) {
if (other.mediaEditLinks != null) {
return false;
}
} else if (!mediaEditLinks.equals(other.mediaEditLinks)) {
return false;
}
if (mediaEntity != other.mediaEntity) {
return false;
}
if (navigationLinks == null) {
if (other.navigationLinks != null) {
return false;
}
} else if (!navigationLinks.equals(other.navigationLinks)) {
return false;
}
if (operations == null) {
if (other.operations != null) {
return false;
}
} else if (!operations.equals(other.operations)) {
return false;
}
if (properties == null) {
if (other.properties != null) {
return false;
}
} else if (!properties.equals(other.properties)) {
return false;
}
if (typeName == null) {
if (other.typeName != null) {
return false;
}
} else if (!typeName.equals(other.typeName)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientEntityImpl [id=" + id + ", eTag=" + eTag + ", mediaEntity=" + mediaEntity + ", mediaContentType="
+ mediaContentType + ", mediaContentSource=" + mediaContentSource + ", mediaETag=" + mediaETag + ", editLink="
+ editLink + ", properties=" + properties + ", annotations=" + annotations + ", typeName=" + typeName
+ ", navigationLinks=" + navigationLinks + ", associationLinks=" + associationLinks + ", mediaEditLinks="
+ mediaEditLinks + ", operations=" + operations + "super[" + super.toString() + "]]";
}
}

View File

@ -62,4 +62,55 @@ public class ClientEntitySetImpl extends AbstractClientEntitySet implements Clie
return annotations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
result = prime * result + ((deltaLink == null) ? 0 : deltaLink.hashCode());
result = prime * result + ((entities == null) ? 0 : entities.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientEntitySetImpl)) {
return false;
}
ClientEntitySetImpl other = (ClientEntitySetImpl) obj;
if (annotations == null) {
if (other.annotations != null) {
return false;
}
} else if (!annotations.equals(other.annotations)) {
return false;
}
if (deltaLink == null) {
if (other.deltaLink != null) {
return false;
}
} else if (!deltaLink.equals(other.deltaLink)) {
return false;
}
if (entities == null) {
if (other.entities != null) {
return false;
}
} else if (!entities.equals(other.entities)) {
return false;
}
return true;
}
@Override
public String toString() {
return "ClientEntitySetImpl [deltaLink=" + deltaLink + ", entities=" + entities + ", annotations=" + annotations
+ "super[" + super.toString() + "]]";
}
}

View File

@ -56,4 +56,33 @@ public class ClientEnumValueImpl extends AbstractClientValue implements ClientEn
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientEnumValueImpl)) {
return false;
}
ClientEnumValueImpl other = (ClientEnumValueImpl) obj;
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -230,4 +230,46 @@ public class ClientPrimitiveValueImpl extends AbstractClientValue implements Cli
return false;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((typeKind == null) ? 0 : typeKind.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof ClientPrimitiveValueImpl)) {
return false;
}
ClientPrimitiveValueImpl other = (ClientPrimitiveValueImpl) obj;
if (type == null) {
if (other.type != null) {
return false;
}
} else if (!type.equals(other.type)) {
return false;
}
if (typeKind != other.typeKind) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -33,7 +33,6 @@ import java.util.List;
public final class ClientPropertyImpl implements ClientProperty, ClientAnnotatable, ClientValuable {
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
private final String name;
private final ClientValue value;
@ -116,35 +115,56 @@ public final class ClientPropertyImpl implements ClientProperty, ClientAnnotatab
}
@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (obj == null) {
return false;
}
ClientPropertyImpl that = (ClientPropertyImpl) o;
if (annotations != null ? !annotations.equals(that.annotations) : that.annotations != null) {
if (!(obj instanceof ClientPropertyImpl)) {
return false;
}
if (name != null ? !name.equals(that.name) : that.name != null) {
ClientPropertyImpl other = (ClientPropertyImpl) obj;
if (annotations == null) {
if (other.annotations != null) {
return false;
}
} else if (!annotations.equals(other.annotations)) {
return false;
}
if (value != null ? !value.equals(that.value) : that.value != null) {
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return !(valuable != null ? !valuable.equals(that.valuable) : that.valuable != null);
if (valuable == null) {
if (other.valuable != null) {
return false;
}
} else if (!valuable.equals(other.valuable)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = annotations != null ? annotations.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (value != null ? value.hashCode() : 0);
result = 31 * result + (valuable != null ? valuable.hashCode() : 0);
final int prime = 31;
int result = 1;
result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((valuable == null) ? 0 : valuable.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}