Add hash code and equals to NewFullDataSource

This commit is contained in:
James Seibel
2024-03-09 09:06:39 -06:00
parent 244d960ec0
commit e6c985a189
@@ -33,7 +33,6 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
@@ -73,6 +72,8 @@ public class NewFullDataSource implements IDataSource<IDhLevel>
public int levelMinY;
private int cachedHashCode = 0;
/**
* stores how far each column has been generated should start with {@link EDhApiWorldGenerationStep#EMPTY}
* @see EDhApiWorldGenerationStep
@@ -200,6 +201,12 @@ public class NewFullDataSource implements IDataSource<IDhLevel>
this.applyToParent = true;
}
if (dataChanged)
{
// update the hash code
this.generateHashCode();
}
return dataChanged;
}
public boolean updateFromSameDetailLevel(NewFullDataSource inputDataSource, int[] remappedIds)
@@ -623,7 +630,45 @@ public class NewFullDataSource implements IDataSource<IDhLevel>
@Override
public String toString() { return this.pos.toString(); }
@Override
public int hashCode()
{
if (this.cachedHashCode == 0)
{
this.generateHashCode();
}
return this.cachedHashCode;
}
private void generateHashCode()
{
int result = this.pos.hashCode();
result = 31 * result + Arrays.deepHashCode(this.dataPoints);
result = 17 * result + Arrays.hashCode(this.columnGenerationSteps);
this.cachedHashCode = result;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof NewFullDataSource))
{
return false;
}
NewFullDataSource other = (NewFullDataSource) obj;
if (!other.pos.equals(this.pos))
{
return false;
}
else
{
// the positions are the same, use the hash as a quick method
// to determine if the data inside is the same.
// Note: this isn't perfect, but should work well enough for our use case.
return other.hashCode() == this.hashCode();
}
}
//============//
// deprecated //