Code example for Time

Methods: after, before

0
			Assert.assertTrue(local || remote);
			if (!local)
				return remoteTime;
			if (!remote) 
				return localTime;
			if (localTime.after(remoteTime))
				return localTime;
			else 
				return remoteTime;
		} 
		 
		protected Time getRemoteModTime() {
			return remoteTime;
		} 
		 
		protected Time getLocalModTime() {
			return localTime;
		} 
 
		protected String getTitle() {
			switch (getState()) { 
			case CONFLICT: 
			case LOCAL_IS_NEWER:
			case LOCAL_ONLY:
			case IN_SYNC:
				return localTitle;
			case REMOTE_IS_NEWER:
				return remoteTitle;
			} 
			Assert.fail(); // unreachable
			return null; 
		} 
		 
		public String toString() {
			return getTitle(); 
		} 
		 
		protected void saveSyncTime(Time time) {
			SharedPreferences.Editor editor = syncPrefs.edit();
			editor.putLong(getUuid().toString(), time.toMillis(false));
			// Log.e(TAG, "saveSyncTime "+getUuid().toString() + " " + time.toMillis(false)); 
			editor.commit();
		} 
	} 
	 
	// The actual sync data 
	protected final LinkedList<SyncItem> data;
	private final SharedPreferences syncPrefs;
 
	// keep authentication data here for convenience 
	protected final QuillAccount account;
	protected String sessionToken;
	 
	public SyncData(SharedPreferences syncPreferences, QuillAccount account) {
		data = new LinkedList<SyncItem>();
		syncPrefs = syncPreferences;
		this.account = account;
		initLocal(); 
	} 
	 
	public SyncData copy() { 
		SyncData s = new SyncData(syncPrefs, account);
		s.sessionToken = sessionToken;
		s.command = command;
		return s;
	} 
	 
	public static class SyncItemComparator implements Comparator<SyncItem> {
		@Override 
		public int compare(SyncItem lhs, SyncItem rhs) {
			SyncData.State lhsState = lhs.getState();
			SyncData.State rhsState = rhs.getState();
			// Conflict is on top 
			if ((!lhsState.equals(State.CONFLICT)) && ( rhsState.equals(State.CONFLICT))) return +1;
			if (( lhsState.equals(State.CONFLICT)) && (!rhsState.equals(State.CONFLICT))) return -1;
 
			// Local-only is next to bottom 
			if (( lhsState.equals(State.LOCAL_ONLY)) && (!rhsState.equals(State.LOCAL_ONLY))) return +1;
			if ((!lhsState.equals(State.LOCAL_ONLY)) && ( rhsState.equals(State.LOCAL_ONLY))) return -1;
 
			// in sync is at bottom 
			if (( lhsState.equals(State.IN_SYNC)) && (!rhsState.equals(State.IN_SYNC))) return +1;
			if ((!lhsState.equals(State.IN_SYNC)) && ( rhsState.equals(State.IN_SYNC))) return -1;
 
			// otherwise sort by time			 
			Time lhsTime = lhs.getLastModTime();
			Time rhsTime = rhs.getLastModTime();
			if (lhsTime.before(rhsTime)) return +1;
			if (lhsTime.after(rhsTime)) return -1;
			 
			// if all else fails, sort by uuid 
			return lhs.getUuid().toString().compareToIgnoreCase(rhs.getUuid().toString());
		} 
	}