Skip to content

Commit

Permalink
GWT client side hasCode methods improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedvede committed Jan 13, 2015
1 parent 7509092 commit cc2a268
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 1 deletion.
Expand Up @@ -189,13 +189,21 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = className != null ? className.hashCode() : 0;
result = ~~result;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = ~~result;
result = 31 * result + (marker ? 1 : 0);
result = ~~result;
result = 31 * result + (shortDescription != null ? shortDescription.hashCode() : 0);
result = ~~result;
result = 31 * result + (description != null ? description.hashCode() : 0);
result = ~~result;
result = 31 * result + (objectAnnotation ? 1 : 0);
result = ~~result;
result = 31 * result + (propertyAnnotation ? 1 : 0);
result = ~~result;
result = 31 * result + (annotationMembers != null ? annotationMembers.hashCode() : 0);
result = ~~result;
return result;
}
}
Expand Up @@ -141,13 +141,21 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = ~~result;
result = 31 * result + (description != null ? description.hashCode() : 0);
result = ~~result;
result = 31 * result + (shortDescription != null ? shortDescription.hashCode() : 0);
result = ~~result;
result = 31 * result + (defaultValue != null ? defaultValue.hashCode() : 0);
result = ~~result;
result = 31 * result + (array ? 1 : 0);
result = ~~result;
result = 31 * result + (className != null ? className.hashCode() : 0);
result = ~~result;
result = 31 * result + (enumMember ? 1 : 0);
result = ~~result;
result = 31 * result + (primitiveType ? 1 : 0);
result = ~~result;
return result;
}
}
Expand Up @@ -120,9 +120,13 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = className != null ? className.hashCode() : 0;
result = ~~result;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = ~~result;
result = 31 * result + (annotationDefinition != null ? annotationDefinition.hashCode() : 0);
result = ~~result;
result = 31 * result + (values != null ? values.hashCode() : 0);
result = ~~result;
return result;
}
}
Expand Up @@ -215,11 +215,17 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = parentProjectName != null ? parentProjectName.hashCode() : 0;
result = ~~result;
result = 31 * result + (dataObjects != null ? dataObjects.hashCode() : 0);
result = ~~result;
result = 31 * result + (sources != null ? sources.hashCode() : 0);
result = ~~result;
result = 31 * result + (externalClasses != null ? externalClasses.hashCode() : 0);
result = ~~result;
result = 31 * result + (deletedDataObjects != null ? deletedDataObjects.hashCode() : 0);
result = ~~result;
result = 31 * result + id;
result = ~~result;
return result;
}
}
Expand Down
Expand Up @@ -330,17 +330,29 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = ~~result;
result = 31 * result + (packageName != null ? packageName.hashCode() : 0);
result = ~~result;
result = 31 * result + (superClassName != null ? superClassName.hashCode() : 0);
result = ~~result;
result = 31 * result + (status != null ? status.hashCode() : 0);
result = ~~result;
result = 31 * result + (originalClassName != null ? originalClassName.hashCode() : 0);
result = ~~result;
result = 31 * result + (properties != null ? properties.hashCode() : 0);
result = ~~result;
result = 31 * result + (annotations != null ? annotations.hashCode() : 0);
result = ~~result;
result = 31 * result + (fingerPrint != null ? fingerPrint.hashCode() : 0);
result = ~~result;
result = 31 * result + (abstractModifier ? 1 : 0);
result = ~~result;
result = 31 * result + (interfaceModifier ? 1 : 0);
result = ~~result;
result = 31 * result + (finalModifier ? 1 : 0);
result = ~~result;
result = 31 * result + (path != null ? path.hashCode() : 0);
result = ~~result;
return result;
}
}
Expand Up @@ -239,14 +239,23 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = className != null ? className.hashCode() : 0;
result = ~~result;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = ~~result;
result = 31 * result + (originalName != null ? originalName.hashCode() : 0);
result = ~~result;
result = 31 * result + (multiple ? 1 : 0);
result = ~~result;
result = 31 * result + (baseType ? 1 : 0);
result = ~~result;
result = 31 * result + (bag != null ? bag.hashCode() : 0);
result = ~~result;
result = 31 * result + modifiers;
result = ~~result;
result = 31 * result + (annotations != null ? annotations.hashCode() : 0);
result = ~~result;
result = 31 * result + (status != null ? status.hashCode() : 0);
result = ~~result;
return result;
}
}
Expand Up @@ -105,9 +105,11 @@ public String getText() {

@Override
public int hashCode() {
return original.hashCode() + text.hashCode()
int result = original.hashCode() + text.hashCode()
+ Boolean.valueOf( isEditing ).hashCode() * 29
+ Boolean.valueOf( isEditingAgain ).hashCode();
result = ~~result;
return result;
}

public boolean isEditing() {
Expand Down
Expand Up @@ -79,8 +79,11 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = item.hashCode();
result = ~~result;
result = 31 * result + itemName.hashCode();
result = ~~result;
result = 31 * result + type.hashCode();
result = ~~result;
return result;
}

Expand Down
Expand Up @@ -82,8 +82,11 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = item != null ? item.hashCode() : 0;
result = ~~result;
result = 31 * result + ( content != null ? content.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( segments != null ? segments.hashCode() : 0 );
result = ~~result;
return result;
}
}
Expand Up @@ -88,7 +88,9 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = serverId.hashCode();
result = ~~result;
result = 31 * result + id.hashCode();
result = ~~result;
return result;
}
}
Expand Up @@ -73,9 +73,13 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = ~~result;
result = 31 * result + ( file != null ? file.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( threaded ? 1 : 0 );
result = ~~result;
result = 31 * result + interval;
result = ~~result;
return result;
}
}
Expand Up @@ -134,14 +134,23 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = ~~result;
result = 31 * result + ( equalsBehavior != null ? equalsBehavior.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( eventProcessingMode != null ? eventProcessingMode.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( kSessions != null ? kSessions.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( includes != null ? includes.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( theDefault ? 1 : 0 );
result = ~~result;
result = 31 * result + ( scope != null ? scope.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( packages != null ? packages.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( declarativeAgenda != null ? declarativeAgenda.hashCode() : 0 );
result = ~~result;
return result;
}
}
Expand Up @@ -139,13 +139,21 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = ~~result;
result = 31 * result + ( type != null ? type.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( clockType != null ? clockType.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( theDefault ? 1 : 0 );
result = ~~result;
result = 31 * result + ( scope != null ? scope.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( workItemHandelerModels != null ? workItemHandelerModels.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( listeners != null ? listeners.hashCode() : 0 );
result = ~~result;
result = 31 * result + ( logger != null ? logger.hashCode() : 0 );
result = ~~result;
return result;
}
}
Expand Up @@ -95,7 +95,9 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = kind != null ? kind.hashCode() : 0;
result = ~~result;
result = 31 * result + ( type != null ? type.hashCode() : 0 );
result = ~~result;
return result;
}
}
Expand Up @@ -98,11 +98,17 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int result = rootPath.hashCode();
result = ~~result;
result = 31 * result + pomXMLPath.hashCode();
result = ~~result;
result = 31 * result + kmoduleXMLPath.hashCode();
result = ~~result;
result = 31 * result + importsPath.hashCode();
result = ~~result;
result = 31 * result + packageNamesWhiteList.hashCode();
result = ~~result;
result = 31 * result + projectName.hashCode();
result = ~~result;
return result;
}
}
Expand Up @@ -240,11 +240,17 @@ public T getValue() {
public int hashCode() {
int hash = 1;
hash = hash * 31 + ( value == null ? 0 : value.hashCode() );
hash = ~~hash;
hash = hash * 31 + rowSpan;
hash = ~~hash;
hash = hash * 31 + ( coordinate == null ? 0 : coordinate.hashCode() );
hash = ~~hash;
hash = hash * 31 + ( mapHtmlToData == null ? 0 : mapHtmlToData.hashCode() );
hash = ~~hash;
hash = hash * 31 + ( mapDataToHtml == null ? 0 : mapDataToHtml.hashCode() );
hash = ~~hash;
hash = hash * 31 + state.hashCode();
hash = ~~hash;
return hash;
}

Expand Down
Expand Up @@ -149,30 +149,38 @@ public int getWidth() {
@Override
public int hashCode() {
int hash = 7;
hash = ~~hash;
hash = 31
* hash
+ columnIndex;
hash = ~~hash;
hash = 31
* hash
+ modelColumn.hashCode();
hash = ~~hash;
hash = 31
* hash
+ isVisible.hashCode();
hash = ~~hash;
hash = 31
* hash
+ isSystemControlled.hashCode();
hash = 31
* hash
+ sortConfig.getSortDirection().hashCode();
hash = ~~hash;
hash = 31
* hash
+ sortConfig.isSortable().hashCode();
hash = ~~hash;
hash = 31
* hash
+ sortConfig.getSortIndex();
hash = ~~hash;
hash = 31
* hash
+ width;
hash = ~~hash;
return hash;
}

Expand Down
Expand Up @@ -66,7 +66,9 @@ public boolean equals( Object o ) {
@Override
public int hashCode() {
int hash = row;
hash = ~~hash;
hash = 31 * hash + col;
hash = ~~hash;
return hash;
}

Expand Down

4 comments on commit cc2a268

@manstis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, did you encounter issues or is this to safe-guard potential issues?

@wmedvede
Copy link
Member Author

@wmedvede wmedvede commented on cc2a268 Jan 14, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurloc
Copy link
Member

@yurloc yurloc commented on cc2a268 Jun 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wmedvede can you explain the effect of hash = ~~hash;? If ~ is a bitwise complement and you do it twice you get the original value. Did you mean to perform a single complement and ~~ is only a typo, or am I missing something?

@manstis
Copy link
Member

@manstis manstis commented on cc2a268 Jun 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurloc Hi Jiri, a while ago (and I'm tying to find the original email) I had problems with hashCode implementations compiled by GWT that led to objects not being found in collections relying on hashCode. I did some hunting and GWT's implementation uses hash = ~~hash in the generated JavaScript. Using the construct above made our hashCode implementations work as expected. I asked on the GWT forums why (or even if) we should use ~~hash.. but nobody ever replied.

Please sign in to comment.