diff options
Diffstat (limited to 'src/cz/crcs/ectester/common/ec/EC_Data.java')
| -rw-r--r-- | src/cz/crcs/ectester/common/ec/EC_Data.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/cz/crcs/ectester/common/ec/EC_Data.java b/src/cz/crcs/ectester/common/ec/EC_Data.java index c048ef7..5fd2f11 100644 --- a/src/cz/crcs/ectester/common/ec/EC_Data.java +++ b/src/cz/crcs/ectester/common/ec/EC_Data.java @@ -14,7 +14,7 @@ import java.util.regex.Pattern; * * @author Jan Jancar johny@neuromancer.sk */ -public abstract class EC_Data { +public abstract class EC_Data implements Comparable<EC_Data> { String id; int count; byte[][] data; @@ -214,4 +214,37 @@ public abstract class EC_Data { } return Arrays.deepHashCode(this.data); } + + @Override + public int compareTo(EC_Data o) { + if (o == this) return 0; + if (this.id != null && o.id != null) { + return this.id.compareTo(o.id); + } else if (this.id == null && o.id == null) { + if (Arrays.equals(this.data, o.data)) { + return 0; + } else { + int minCount = (this.count < o.count) ? this.count : o.count; + for (int i = 0; i < minCount; ++i) { + byte[] thisData = this.data[i]; + byte[] oData = o.data[i]; + int innerMinCount = (thisData.length < oData.length) ? thisData.length : oData.length; + for (int j = 0; j < innerMinCount; ++j) { + if (thisData[j] < oData[j]) { + return -1; + } else if (thisData[j] > oData[j]) { + return 1; + } + } + } + } + } else { + if (this.id == null) { + return -1; + } else { + return 1; + } + } + return 0; + } } |
