Fix hashcodes

This commit is contained in:
Andrea Cavalli 2022-07-19 02:45:20 +02:00
parent 81762197bb
commit 320ec98cab
14 changed files with 90 additions and 13 deletions

View File

@ -31,6 +31,9 @@ public class ClassConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(stringRepresenter, data); int hash = 0;
hash += ConfigUtils.hashCode(stringRepresenter);
hash += ConfigUtils.hashCode(data);
return hash;
} }
} }

View File

@ -0,0 +1,26 @@
package it.cavallium.data.generator;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
class ConfigUtils {
static int hashCode(Map<?, ?> map) {
if (map == null) return 0;
return map
.entrySet()
.stream()
.map(e -> ConfigUtils.hashCode(e.getKey()) + ConfigUtils.hashCode(e.getValue()))
.reduce(0, Integer::sum);
}
static int hashCode(Collection<?> collection) {
if (collection == null) return 0;
return collection.stream().map(ConfigUtils::hashCode).reduce(0, Integer::sum);
}
static int hashCode(Object collection) {
return Objects.hashCode(collection);
}
}

View File

@ -45,6 +45,9 @@ public class CustomTypesConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(javaClass, serializer); int hash = 0;
hash += ConfigUtils.hashCode(javaClass);
hash += ConfigUtils.hashCode(serializer);
return hash;
} }
} }

View File

@ -20,6 +20,8 @@ public class DetailsConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(changelog); int hash = 0;
hash += ConfigUtils.hashCode(changelog);
return hash;
} }
} }

View File

@ -27,6 +27,10 @@ public class InterfaceDataConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(extendInterfaces, commonData, commonGetters); int hash = 0;
hash += ConfigUtils.hashCode(extendInterfaces);
hash += ConfigUtils.hashCode(commonData);
hash += ConfigUtils.hashCode(commonGetters);
return hash;
} }
} }

View File

@ -34,6 +34,10 @@ public class MoveDataConfiguration implements TransformationConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(transformClass, from, to); int hash = 0;
hash += ConfigUtils.hashCode(transformClass);
hash += ConfigUtils.hashCode(from);
hash += ConfigUtils.hashCode(to);
return hash;
} }
} }

View File

@ -35,6 +35,10 @@ public class NewDataConfiguration implements TransformationConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(transformClass, to, initializer); int hash = 0;
hash += ConfigUtils.hashCode(transformClass);
hash += ConfigUtils.hashCode(to);
hash += ConfigUtils.hashCode(initializer);
return hash;
} }
} }

View File

@ -31,6 +31,9 @@ public class RemoveDataConfiguration implements TransformationConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(transformClass, from); int hash = 0;
hash += ConfigUtils.hashCode(transformClass);
hash += ConfigUtils.hashCode(from);
return hash;
} }
} }

View File

@ -36,7 +36,10 @@ public class SerializeCodeBlockGenerator {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(before, after); int hash = 0;
hash += ConfigUtils.hashCode(before);
hash += ConfigUtils.hashCode(after);
return hash;
} }

View File

@ -24,6 +24,11 @@ public class SourcesGeneratorConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(currentVersion, interfacesData, versions, refs); int hash = 0;
hash += ConfigUtils.hashCode(currentVersion);
hash += ConfigUtils.hashCode(interfacesData);
hash += ConfigUtils.hashCode(versions);
hash += ConfigUtils.hashCode(refs);
return hash;
} }
} }

View File

@ -26,6 +26,11 @@ public class SourcesGeneratorConfigurationRefs {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(superTypes, customTypes, classes, transformations); int hash = 0;
hash += ConfigUtils.hashCode(superTypes);
hash += ConfigUtils.hashCode(customTypes);
hash += ConfigUtils.hashCode(classes);
hash += ConfigUtils.hashCode(transformations);
return hash;
} }
} }

View File

@ -35,6 +35,10 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(transformClass, from, upgrader); int hash = 0;
hash += ConfigUtils.hashCode(transformClass);
hash += ConfigUtils.hashCode(from);
hash += ConfigUtils.hashCode(upgrader);
return hash;
} }
} }

View File

@ -30,6 +30,12 @@ public class VersionConfiguration {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(details, superTypes, customTypes, classes, transformations); int hash = 0;
hash += ConfigUtils.hashCode(details);
hash += ConfigUtils.hashCode(superTypes);
hash += ConfigUtils.hashCode(customTypes);
hash += ConfigUtils.hashCode(classes);
hash += ConfigUtils.hashCode(transformations);
return hash;
} }
} }

View File

@ -79,6 +79,11 @@ public class VersionTransformation {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(moveData, removeData, upgradeData, newData); int hash = 0;
hash += ConfigUtils.hashCode(moveData);
hash += ConfigUtils.hashCode(removeData);
hash += ConfigUtils.hashCode(upgradeData);
hash += ConfigUtils.hashCode(newData);
return hash;
} }
} }