Added the diff_traces method the compare to board wirings
This commit is contained in:
parent
fceeeac07c
commit
f3d43a8eba
|
@ -35,12 +35,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
import eu.mihosoft.freerouting.datastructures.ShapeTree.TreeEntry;
|
||||
|
||||
|
@ -90,14 +85,21 @@ public class BasicBoard implements java.io.Serializable
|
|||
insert_outline(p_outline_shapes, p_outline_cl_class_no);
|
||||
}
|
||||
|
||||
private byte[] serialize()
|
||||
private byte[] serialize(boolean basicProfile)
|
||||
{
|
||||
try
|
||||
{
|
||||
var output_stream = new ByteArrayOutputStream();
|
||||
var object_stream = new ObjectOutputStream(output_stream);
|
||||
|
||||
object_stream.writeObject(this);
|
||||
if (basicProfile) {
|
||||
object_stream.writeObject(this.get_traces());
|
||||
object_stream.writeObject(this.get_vias());
|
||||
object_stream.writeObject(this.item_list);
|
||||
} else {
|
||||
object_stream.writeObject(this);
|
||||
}
|
||||
|
||||
object_stream.close();
|
||||
|
||||
return output_stream.toByteArray();
|
||||
|
@ -127,15 +129,15 @@ public class BasicBoard implements java.io.Serializable
|
|||
|
||||
public BasicBoard clone()
|
||||
{
|
||||
return deserialize(this.serialize());
|
||||
return deserialize(this.serialize(false));
|
||||
}
|
||||
|
||||
|
||||
public String get_hash()
|
||||
{
|
||||
try
|
||||
{
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
digest.update(this.serialize());
|
||||
digest.update(this.serialize(true));
|
||||
byte[] hashedBytes = digest.digest();
|
||||
|
||||
return convert_byte_array_to_hex_string(hashedBytes);
|
||||
|
@ -147,6 +149,27 @@ public class BasicBoard implements java.io.Serializable
|
|||
return null;
|
||||
}
|
||||
|
||||
public int diff_traces(BasicBoard compare_to)
|
||||
{
|
||||
int result = 0;
|
||||
HashSet<Integer> traceIds = new HashSet<Integer>();
|
||||
for (Trace trace : this.get_traces()) {
|
||||
traceIds.add(trace.get_id_no());
|
||||
}
|
||||
|
||||
for (Trace trace : compare_to.get_traces()) {
|
||||
if (!traceIds.contains(trace.get_id_no()))
|
||||
{
|
||||
result++;
|
||||
} else {
|
||||
traceIds.remove(trace.get_id_no());
|
||||
}
|
||||
}
|
||||
result += traceIds.size();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String convert_byte_array_to_hex_string(byte[] arrayBytes) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < arrayBytes.length; i++) {
|
||||
|
|
Loading…
Reference in New Issue