VersionNumber implements Comparable<VersionNumber>, ContentName.ComponentProvider { public int compareTo(VersionNumber other) throws ClassCastException { if( null == other ) throw new ClassCastException("Null value"); if( isLessThanUnsigned(_binaryTime, other._binaryTime) ) return -1; if( isLessThanUnsigned(other._binaryTime, _binaryTime) ) return +1; return 0; } VersionNumber();  VersionNumber(CCNTime version);  VersionNumber(long msecSinceEpoch);  VersionNumber(ContentName versionedNamed);  VersionNumber(byte [] versionComponent);  VersionNumber(VersionNumber version1a); byte [] getVersionBytes(); CCNTime getAsTime(); long getAsMillis(); VersionNumber addAndReturn(long count); VersionNumber addMillisecondsAndreturn(long msec); int compareTo(VersionNumber other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); String printAsVersionComponent(); static VersionNumber now(); static VersionNumber getMaximumVersion(); static VersionNumber getMinimumVersion(); boolean before(VersionNumber time); boolean after(VersionNumber time); boolean before(CCNTime time); boolean after(CCNTime time); byte[] getComponent();  }
@Test public void testCompareTo() { Log.info(Log.FAC_TEST, "Started testCompareTo"); int count = 100; long [] values = new long [count]; CCNTime now = CCNTime.now(); long t = now.toBinaryTimeAsLong(); for(int i = 0; i < count; i++) { t += _rnd.nextInt(10000) + 1; values[i] = t; } for(int i = 0; i < count-1; i++) { int pos = _rnd.nextInt(count - i) + i; long x = values[i]; values[i] = values[pos]; values[pos] = x; } TreeSet<VersionNumber> set = new TreeSet<VersionNumber>(); for(long vv : values) { CCNTime tt = CCNTime.fromBinaryTimeAsLong(vv); VersionNumber vn = new VersionNumber(tt); Assert.assertTrue(set.add(vn)); } Iterator<VersionNumber> iter = set.iterator(); VersionNumber prev = null; while(iter.hasNext()) { VersionNumber current = iter.next(); if( null != prev ) { Assert.assertTrue(prev.before(current)); } prev = current; } Log.info(Log.FAC_TEST, "Completed testCompareTo"); }