TaskID extends org.apache.hadoop.mapred.ID { @Override public int compareTo(ID o) { TaskID that = (TaskID)o; int jobComp = this.jobId.compareTo(that.jobId); if(jobComp == 0) { if(this.type == that.type) { return this.id - that.id; } else { return this.type.compareTo(that.type); } } else return jobComp; } TaskID(JobID jobId, TaskType type, int id);  TaskID(String jtIdentifier, int jobId, TaskType type, int id); @Deprecated  TaskID(JobID jobId, boolean isMap, int id); @Deprecated  TaskID(String jtIdentifier, int jobId, boolean isMap, int id);  TaskID(); JobID getJobID(); @Deprecated boolean isMap(); TaskType getTaskType(); @Override boolean equals(Object o); @Override int compareTo(ID o); @Override String toString(); @Override int hashCode(); @Override void readFields(DataInput in); @Override void write(DataOutput out); static TaskID forName(String str); static char getRepresentingCharacter(TaskType type); static TaskType getTaskType(char c); static String getAllTaskTypes(); static final String TASK_ID_REGEX; static final Pattern taskIdPattern; }
@Test public void testCompareTo() { JobID jobId = new JobID("1234", 1); TaskID taskId1 = new TaskID(jobId, TaskType.REDUCE, 0); TaskID taskId2 = new TaskID(jobId, TaskType.REDUCE, 0); assertEquals("The compareTo() method returned non-zero for two equal " + "task IDs", 0, taskId1.compareTo(taskId2)); taskId2 = new TaskID(jobId, TaskType.MAP, 1); assertTrue("The compareTo() method did not weigh task type more than task " + "ID", taskId1.compareTo(taskId2) > 0); TaskType[] types = TaskType.values(); for (int i = 0; i < types.length; i++) { for (int j = 0; j < types.length; j++) { taskId1 = new TaskID(jobId, types[i], 0); taskId2 = new TaskID(jobId, types[j], 0); if (i == j) { assertEquals("The compareTo() method returned non-zero for two equal " + "task IDs", 0, taskId1.compareTo(taskId2)); } else if (i < j) { assertTrue("The compareTo() method did not order " + types[i] + " before " + types[j], taskId1.compareTo(taskId2) < 0); } else { assertTrue("The compareTo() method did not order " + types[i] + " after " + types[j], taskId1.compareTo(taskId2) > 0); } } } try { taskId1.compareTo(jobId); fail("The compareTo() method allowed comparison to a JobID object"); } catch (ClassCastException ex) { } try { taskId1.compareTo(null); fail("The compareTo() method allowed comparison to a null object"); } catch (NullPointerException ex) { } }