diff: do not rely on Change.hashCode implementation

follow-up: ea6a028
This commit is contained in:
Aleksey Pivovarov
2016-12-07 18:31:55 +03:00
parent 4ac9d4360e
commit d2e1b438c6
2 changed files with 10 additions and 2 deletions
@@ -241,7 +241,7 @@ public abstract class CacheChangeProcessor extends CacheDiffRequestProcessor<Cac
@Override
public int hashCode() {
return change.hashCode();
return ChangeDiffRequestProducer.hashCode(change);
}
@Override
@@ -92,7 +92,7 @@ public class ChangeDiffRequestProducer implements DiffRequestProducer {
public static boolean isEquals(@NotNull Change change1, @NotNull Change change2) {
if (!Comparing.equal(ChangesUtil.getBeforePath(change1), ChangesUtil.getBeforePath(change2)) ||
!Comparing.equal(ChangesUtil.getAfterPath(change1), ChangesUtil.getAfterPath(change2))) {
// we use Change.hashCode(), so removing this check might violate comparison contract
// we use file paths for hashCode, so removing this check might violate comparison contract
return false;
}
@@ -123,6 +123,14 @@ public class ChangeDiffRequestProducer implements DiffRequestProducer {
return false;
}
public static int hashCode(@NotNull Change change) {
return hashCode(change.getBeforeRevision()) + 31 * hashCode(change.getAfterRevision());
}
private static int hashCode(@Nullable ContentRevision revision) {
return revision != null ? revision.getFile().hashCode() : 0;
}
@Nullable
public static ChangeDiffRequestProducer create(@Nullable Project project, @NotNull Change change) {
return create(project, change, Collections.<Key, Object>emptyMap());