@Test public void testCompareTo() { MockContact contact2 = new MockContact("K", "2"); List<MockContact> list = new ArrayList<>(); list.add(contact); list.add(contact2); Collections.sort(list); assertEquals(contact, list.get(0)); MockMessage m = new MockMessage("m1"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } MockMessage m2 = new MockMessage("m2"); System.out.println("m1 time:" + m.getTime() + " m2 time: " + m2.getTime()); contact2.setLastMessage(m2); Collections.sort(list); assertEquals(contact2, list.get(0)); contact.setLastMessage(m); Collections.sort(list); assertEquals(contact2, list.get(0)); contact2.setLastMessage(null); Collections.sort(list); assertEquals(contact, list.get(0)); }
public int compareTo(AbstractContact that) { int ret = 0; if (this.lastMessage != null) { if (that.lastMessage != null) { IMessage m1 = this.lastMessage; IMessage m2 = that.lastMessage; long diff = (m2.getTime() - m1.getTime()); if (diff > 0) { ret = 1; } else if (diff < 0) { ret = -1; } } else { ret = -1; } } else if (that.lastMessage != null) { ret = 1; } return ret; }
AbstractContact implements IContact { public int compareTo(AbstractContact that) { int ret = 0; if (this.lastMessage != null) { if (that.lastMessage != null) { IMessage m1 = this.lastMessage; IMessage m2 = that.lastMessage; long diff = (m2.getTime() - m1.getTime()); if (diff > 0) { ret = 1; } else if (diff < 0) { ret = -1; } } else { ret = -1; } } else if (that.lastMessage != null) { ret = 1; } return ret; } }
AbstractContact implements IContact { public int compareTo(AbstractContact that) { int ret = 0; if (this.lastMessage != null) { if (that.lastMessage != null) { IMessage m1 = this.lastMessage; IMessage m2 = that.lastMessage; long diff = (m2.getTime() - m1.getTime()); if (diff > 0) { ret = 1; } else if (diff < 0) { ret = -1; } } else { ret = -1; } } else if (that.lastMessage != null) { ret = 1; } return ret; }  }
AbstractContact implements IContact { public int compareTo(AbstractContact that) { int ret = 0; if (this.lastMessage != null) { if (that.lastMessage != null) { IMessage m1 = this.lastMessage; IMessage m2 = that.lastMessage; long diff = (m2.getTime() - m1.getTime()); if (diff > 0) { ret = 1; } else if (diff < 0) { ret = -1; } } else { ret = -1; } } else if (that.lastMessage != null) { ret = 1; } return ret; }  boolean isUnknown(); void setUnknown(boolean unknown); boolean isNewbie(); void setNewbie(boolean newbie); IMessage getLastMessage(); void setLastMessage(IMessage lastMessage); int getUnread(); void setUnread(int unread); void clearUnRead(); void increaceUnRead(); int compareTo(AbstractContact that); }
AbstractContact implements IContact { public int compareTo(AbstractContact that) { int ret = 0; if (this.lastMessage != null) { if (that.lastMessage != null) { IMessage m1 = this.lastMessage; IMessage m2 = that.lastMessage; long diff = (m2.getTime() - m1.getTime()); if (diff > 0) { ret = 1; } else if (diff < 0) { ret = -1; } } else { ret = -1; } } else if (that.lastMessage != null) { ret = 1; } return ret; }  boolean isUnknown(); void setUnknown(boolean unknown); boolean isNewbie(); void setNewbie(boolean newbie); IMessage getLastMessage(); void setLastMessage(IMessage lastMessage); int getUnread(); void setUnread(int unread); void clearUnRead(); void increaceUnRead(); int compareTo(AbstractContact that);  }