|
|
@@ -0,0 +1,79 @@
|
|
|
+/*
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ * @copyright Ranides Atterwim
|
|
|
+ * @license WTFPL
|
|
|
+ * @url http://ranides.net/projects/???
|
|
|
+ */
|
|
|
+package net.ranides.assira.generic;
|
|
|
+
|
|
|
+import net.ranides.assira.collection.HashComparator;
|
|
|
+import net.ranides.assira.generic.IntPair;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ */
|
|
|
+public class TElement {
|
|
|
+
|
|
|
+ private final String id;
|
|
|
+
|
|
|
+ private final int[] hashes;
|
|
|
+
|
|
|
+ private final int[] values;
|
|
|
+
|
|
|
+ public TElement(String id, int[] hashes, int[] values) {
|
|
|
+ this.id = id;
|
|
|
+ this.hashes = hashes.clone();
|
|
|
+ this.values = values.clone();
|
|
|
+ }
|
|
|
+
|
|
|
+ public TElement(String id, IntPair... versions) {
|
|
|
+ this.id = id;
|
|
|
+ this.hashes = new int[]{versions.length};
|
|
|
+ this.values = new int[]{versions.length};
|
|
|
+ for(int i=0; i<versions.length; i++) {
|
|
|
+ hashes[i] = versions[i].getIntKey();
|
|
|
+ values[i] = versions[i].getIntValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return Comparator.STD.hashCode(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object object) {
|
|
|
+ return (object instanceof TElement) && Comparator.STD.equals(this, (TElement)object);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class Comparator implements HashComparator<TElement> {
|
|
|
+
|
|
|
+ public static final HashComparator<TElement> STD = new Comparator(0);
|
|
|
+
|
|
|
+ public static final HashComparator<TElement> ALT = new Comparator(1);
|
|
|
+
|
|
|
+ private final int index;
|
|
|
+
|
|
|
+ public Comparator(int index) {
|
|
|
+ this.index = index;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode(TElement object) {
|
|
|
+ return object.hashes[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(TElement value1, TElement value2) {
|
|
|
+ return value1.values[index] - value2.values[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|