@Test public void testCompareLocal() { ComparisonService s = new TimestampComparisonService(TimeZone.getDefault()); final long timestamp = Calendar.getInstance(TimeZone.getDefault()).getTimeInMillis(); assertEquals(Comparison.local, s.compare(new PathAttributes() { @Override public long getModificationDate() { final Calendar c = Calendar.getInstance(TimeZone.getDefault()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); } }, new LocalAttributes("/t") { @Override public long getModificationDate() { return timestamp; } } )); }
@Override public Comparison compare(final Attributes remote, final Attributes local) { if(log.isDebugEnabled()) { log.debug(String.format("Compare timestamp for %s with %s", remote, local)); } if(-1 == remote.getModificationDate()) { log.warn(String.format("No remote modification date available for comparison for %s", remote)); return Comparison.unknown; } if(-1 == local.getModificationDate()) { log.warn(String.format("No local modification date available for comparison for %s", local)); return Comparison.unknown; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).before( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.remote; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).after( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.local; } return Comparison.equal; }
TimestampComparisonService implements ComparisonService { @Override public Comparison compare(final Attributes remote, final Attributes local) { if(log.isDebugEnabled()) { log.debug(String.format("Compare timestamp for %s with %s", remote, local)); } if(-1 == remote.getModificationDate()) { log.warn(String.format("No remote modification date available for comparison for %s", remote)); return Comparison.unknown; } if(-1 == local.getModificationDate()) { log.warn(String.format("No local modification date available for comparison for %s", local)); return Comparison.unknown; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).before( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.remote; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).after( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.local; } return Comparison.equal; } }
TimestampComparisonService implements ComparisonService { @Override public Comparison compare(final Attributes remote, final Attributes local) { if(log.isDebugEnabled()) { log.debug(String.format("Compare timestamp for %s with %s", remote, local)); } if(-1 == remote.getModificationDate()) { log.warn(String.format("No remote modification date available for comparison for %s", remote)); return Comparison.unknown; } if(-1 == local.getModificationDate()) { log.warn(String.format("No local modification date available for comparison for %s", local)); return Comparison.unknown; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).before( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.remote; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).after( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.local; } return Comparison.equal; } TimestampComparisonService(final TimeZone tz); }
TimestampComparisonService implements ComparisonService { @Override public Comparison compare(final Attributes remote, final Attributes local) { if(log.isDebugEnabled()) { log.debug(String.format("Compare timestamp for %s with %s", remote, local)); } if(-1 == remote.getModificationDate()) { log.warn(String.format("No remote modification date available for comparison for %s", remote)); return Comparison.unknown; } if(-1 == local.getModificationDate()) { log.warn(String.format("No local modification date available for comparison for %s", local)); return Comparison.unknown; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).before( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.remote; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).after( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.local; } return Comparison.equal; } TimestampComparisonService(final TimeZone tz); @Override Comparison compare(final Attributes remote, final Attributes local); }
TimestampComparisonService implements ComparisonService { @Override public Comparison compare(final Attributes remote, final Attributes local) { if(log.isDebugEnabled()) { log.debug(String.format("Compare timestamp for %s with %s", remote, local)); } if(-1 == remote.getModificationDate()) { log.warn(String.format("No remote modification date available for comparison for %s", remote)); return Comparison.unknown; } if(-1 == local.getModificationDate()) { log.warn(String.format("No local modification date available for comparison for %s", local)); return Comparison.unknown; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).before( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.remote; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).after( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.local; } return Comparison.equal; } TimestampComparisonService(final TimeZone tz); @Override Comparison compare(final Attributes remote, final Attributes local);  }