diff options
| author | J08nY | 2018-03-06 01:21:02 +0100 |
|---|---|---|
| committer | J08nY | 2018-03-06 01:21:02 +0100 |
| commit | 7c40e8f0f22e8bcfed34f64820cd90355822ca9f (patch) | |
| tree | c30863aa76b56ba5cdc71414dc41e85d01d9de06 /src/cz/crcs/ectester/common/ec/EC_Data.java | |
| parent | b91887bac1f20597a06e789360374a4731ece5da (diff) | |
| download | ECTester-7c40e8f0f22e8bcfed34f64820cd90355822ca9f.tar.gz ECTester-7c40e8f0f22e8bcfed34f64820cd90355822ca9f.tar.zst ECTester-7c40e8f0f22e8bcfed34f64820cd90355822ca9f.zip | |
Order EC data nicely, also helps ordering tests in some suites.
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; + } } |
