Navigation Menu

Skip to content

Commit

Permalink
Added support for equals and hashCode to node wrapper objects
Browse files Browse the repository at this point in the history
  • Loading branch information
leenata committed Jul 11, 2013
1 parent ebbdb50 commit 6ee31d2
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
45 changes: 45 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/FedoraResource.java
Expand Up @@ -350,4 +350,49 @@ public void addVersionLabel(final String label) throws RepositoryException {
public boolean isNew() {
return node.isNew();
}

/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 5;
int result = 1;
result = prime * result
+ ((listener == null) ? 0 : listener.hashCode());
result = prime * result + ((node == null) ? 0 : node.hashCode());
return result;
}

/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof FedoraResource)) {
return false;
}
FedoraResource other = (FedoraResource) obj;
if (listener == null) {
if (other.listener != null) {
return false;
}
} else if (!listener.equals(other.listener)) {
return false;
}
if (node == null) {
if (other.node != null) {
return false;
}
} else if (!node.equals(other.node)) {
return false;
}
return true;
}
}
48 changes: 48 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/Transaction.java
Expand Up @@ -152,4 +152,52 @@ public void updateExpiryDate() {
}
this.expires.setTimeInMillis(System.currentTimeMillis() + duration);
}

@Override
public int hashCode() {
final int prime = 5;
int result = 1;
result = prime * result
+ ((session == null) ? 0 : session.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((state == null) ? 0 : state.hashCode());

return result;
}

public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Transaction)) {
return false;
}
Transaction other = (Transaction) obj;
if (session == null) {
if (other.session != null) {
return false;
}
} else if (!session.equals(other.session)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (state == null) {
if (other.state != null) {
return false;
}
} else if (!state.equals(other.state)) {
return false;
}

return true;
}
}
39 changes: 39 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/TxAwareSession.java
Expand Up @@ -70,4 +70,43 @@ public Object invoke(final Object proxy, final Method method,
return method.invoke(session, args);
}
}

@Override
public int hashCode() {
final int prime = 5;
int result = 1;
result = prime * result
+ ((txId == null) ? 0 : txId.hashCode());
result = prime * result + ((session == null) ? 0 : session.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof TxAwareSession)) {
return false;
}
TxAwareSession other = (TxAwareSession) obj;
if (txId == null) {
if (other.txId != null) {
return false;
}
} else if (!txId.equals(other.txId)) {
return false;
}
if (session == null) {
if (other.session != null) {
return false;
}
} else if (!session.equals(other.session)) {
return false;
}
return true;
}
}

0 comments on commit 6ee31d2

Please sign in to comment.