### Question:
TupleComparator implements Comparator<Tuple>, ProtoObject<TupleComparatorProto> { @Override public int compare(Tuple tuple1, Tuple tuple2) { for (int i = 0; i < sortKeyIds.length; i++) { left = tuple1.get(sortKeyIds[i]); right = tuple2.get(sortKeyIds[i]); if (left instanceof NullDatum || right instanceof NullDatum) { if (!left.equals(right)) { if (left instanceof NullDatum) { compVal = 1; } else if (right instanceof NullDatum) { compVal = -1; } if (nullFirsts[i]) { if (compVal != 0) { compVal *= -1; } } } else { compVal = 0; } } else { if (asc[i]) { compVal = left.compareTo(right); } else { compVal = right.compareTo(left); } } if (compVal < 0 || compVal > 0) { return compVal; } } return 0; } TupleComparator(Schema schema, SortSpec[] sortKeys);  TupleComparator(TupleComparatorProto proto); boolean isAscendingFirstKey(); @Override int compare(Tuple tuple1, Tuple tuple2); @Override int hashCode(); @Override boolean equals(Object obj); @Override TupleComparatorProto getProto();  }### Answer:
@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); TupleComparator tc = new TupleComparator(schema, new SortSpec[] {sortKey1, sortKey2}); assertEquals(-1, tc.compare(tuple1, tuple2)); assertEquals(1, tc.compare(tuple2, tuple1)); }