### Question:
TupleComparator implements Comparator<Tuple>, ProtoObject<TupleComparatorProto> { public abstract int compare(Tuple o1, Tuple o2);  abstract int compare(Tuple o1, Tuple o2); abstract boolean isAscendingFirstKey();  }### Answer:
@Test public final void testCompare() { Schema schema = SchemaBuilder.builder() .add("col1", Type.INT4) .add("col2", Type.INT4) .add("col3", Type.INT4) .add("col4", Type.INT4) .add("col5", Type.TEXT) .build(); VTuple tuple1 = new VTuple( new Datum[] { DatumFactory.createInt4(9), DatumFactory.createInt4(3), DatumFactory.createInt4(33), DatumFactory.createInt4(4), DatumFactory.createText("abc")}); VTuple tuple2 = new VTuple( new Datum[] { DatumFactory.createInt4(1), DatumFactory.createInt4(25), DatumFactory.createInt4(109), DatumFactory.createInt4(4), DatumFactory.createText("abd")}); SortSpec sortKey1 = new SortSpec(schema.getColumn("col4"), true, false); SortSpec sortKey2 = new SortSpec(schema.getColumn("col5"), true, false); BaseTupleComparator tc = new BaseTupleComparator(schema, new SortSpec[] {sortKey1, sortKey2}); assertEquals(-1, tc.compare(tuple1, tuple2)); assertEquals(1, tc.compare(tuple2, tuple1)); }
@Test public final void testCompare() { Schema schema = new Schema(); schema.addColumn("col1", Type.INT4); schema.addColumn("col2", Type.INT4); schema.addColumn("col3", Type.INT4); schema.addColumn("col4", Type.INT4); schema.addColumn("col5", Type.TEXT); Tuple tuple1 = new VTuple(5); Tuple tuple2 = new VTuple(5); tuple1.put( new Datum[] { DatumFactory.createInt4(9), DatumFactory.createInt4(3), DatumFactory.createInt4(33), DatumFactory.createInt4(4), DatumFactory.createText("abc")}); tuple2.put( new Datum[] { DatumFactory.createInt4(1), DatumFactory.createInt4(25), DatumFactory.createInt4(109), DatumFactory.createInt4(4), DatumFactory.createText("abd")}); SortSpec sortKey1 = new SortSpec(schema.getColumn("col4"), true, false); SortSpec sortKey2 = new SortSpec(schema.getColumn("col5"), true, false); BaseTupleComparator tc = new BaseTupleComparator(schema, new SortSpec[] {sortKey1, sortKey2}); assertEquals(-1, tc.compare(tuple1, tuple2)); assertEquals(1, tc.compare(tuple2, tuple1)); }