public static int compare( UUID u1, UUID u2 ) { return UUIDComparator.staticCompare( u1, u2 ); }
static TreeSet<UUID> add( TreeSet<UUID> a, UUID uuid, boolean reversed, int limit ) { if ( a == null ) { a = new TreeSet<UUID>( new UUIDComparator() ); } if ( uuid == null ) { return a; } // if we have less than the limit, just add it if ( a.size() < limit ) { a.add( uuid ); } else if ( reversed ) { // if reversed, we want to add more recent messages // and eject the oldest if ( UUIDComparator.staticCompare( uuid, a.first() ) > 0 ) { a.pollFirst(); a.add( uuid ); } } else { // add older messages and eject the newset if ( UUIDComparator.staticCompare( uuid, a.last() ) < 0 ) { a.pollLast(); a.add( uuid ); } } return a; }
public static List<UUID> sort( List<UUID> uuids ) { Collections.sort( uuids, new UUIDComparator() ); return uuids; } }
protected final static int compareULongs(long l1, long l2) { int diff = compareUInts((int) (l1 >> 32), (int) (l2 >> 32)); if (diff == 0) { diff = compareUInts((int) l1, (int) l2); } return diff; }
diff = compareULongs(u1.timestamp(), u2.timestamp()); if (diff == 0) { diff = compareULongs(u1.getLeastSignificantBits(), u2.getLeastSignificantBits()); diff = compareULongs(u1.getMostSignificantBits(), u2.getMostSignificantBits()); if (diff == 0) { diff = compareULongs(u1.getLeastSignificantBits(), u2.getLeastSignificantBits());
public static List<UUID> sort( List<UUID> uuids ) { Collections.sort( uuids, new UUIDComparator() ); return uuids; } }
protected final static int compareULongs(long l1, long l2) { int diff = compareUInts((int) (l1 >> 32), (int) (l2 >> 32)); if (diff == 0) { diff = compareUInts((int) l1, (int) l2); } return diff; }
diff = compareULongs(u1.timestamp(), u2.timestamp()); if (diff == 0) { diff = compareULongs(u1.getLeastSignificantBits(), u2.getLeastSignificantBits()); diff = compareULongs(u1.getMostSignificantBits(), u2.getMostSignificantBits()); if (diff == 0) { diff = compareULongs(u1.getLeastSignificantBits(), u2.getLeastSignificantBits());
public static int compare( UUID u1, UUID u2 ) { return UUIDComparator.staticCompare( u1, u2 ); }
static TreeSet<UUID> mergeAnd( TreeSet<UUID> a, TreeSet<UUID> b, boolean reversed, int limit ) { TreeSet<UUID> mergeSet = new TreeSet<UUID>( new UUIDComparator() ); if ( a == null ) { return mergeSet; } if ( b == null ) { return mergeSet; } for ( UUID uuid : b ) { if ( a.contains( b ) ) { add( mergeSet, uuid, reversed, limit ); } } return mergeSet; }
@Override public int compareTo( final Id o ) { int compare = UUIDComparator.staticCompare( uuid, o.getUuid() ); if(compare == 0){ compare = type.compareTo( o.getType() ); } return compare; } }
static TreeSet<UUID> mergeOr( TreeSet<UUID> a, TreeSet<UUID> b, boolean reversed, int limit ) { TreeSet<UUID> mergeSet = new TreeSet<UUID>( new UUIDComparator() ); if ( ( a == null ) && ( b == null ) ) { return mergeSet; } else if ( a == null ) { return b; } else if ( b == null ) { return a; } add( mergeSet, a, reversed, limit ); add( mergeSet, b, reversed, limit ); return mergeSet; }
public static int compare( Message m1, Message m2 ) { if ( ( m1 == null ) && ( m2 == null ) ) { return 0; } else if ( m1 == null ) { return -1; } else if ( m2 == null ) { return 1; } return UUIDComparator.staticCompare( m1.getUuid(), m2.getUuid() ); }
QueueBounds bounds = getQueueBounds( queueId ); UUIDComparator comparator = query.isReversed() ? new ReverseUUIDComparator() : new UUIDComparator();
/** * Validate that each UUID is greater than than it's previous entry when comparing them */ public void validateOrder() { for(int i = 0; i < toGenerate -1; i ++){ int comparison = UUIDComparator.staticCompare( results.get( i ), results.get( i+1 ) ); assertTrue(comparison < 0); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static int compareIndexedValues( Object o1, Object o2 ) { o1 = toIndexableValue( o1 ); o2 = toIndexableValue( o2 ); if ( ( o1 == null ) && ( o2 == null ) ) { return 0; } else if ( o1 == null ) { return -1; } else if ( o2 == null ) { return 1; } int c1 = indexValueCode( o1 ); int c2 = indexValueCode( o2 ); if ( c1 == c2 ) { if ( o1 instanceof UUID ) { UUIDComparator.staticCompare( ( UUID ) o1, ( UUID ) o2 ); } else if ( o1 instanceof Comparable ) { return ( ( Comparable ) o1 ).compareTo( o2 ); } } return c1 - c2; } }
@Override public int compare( final MarkedEdge first, final MarkedEdge second ) { int compare = Long.compare( first.getTimestamp(), second.getTimestamp() ) * -1; if(compare == 0){ final Id firstId = getId( first ); final Id secondId = getId( second ); compare = UUIDComparator.staticCompare( firstId.getUuid(), secondId.getUuid() ) * -1; if(compare == 0){ compare = firstId.getType().compareTo( secondId.getType() ); } } return compare; }
@Override public int compare( final UniqueValue o1, final UniqueValue o2 ) { return UUIDComparator.staticCompare( o1.getEntityVersion(), o2.getEntityVersion() ) * -1; } }
@Test public void validateComparatorValues(){ //smaller UUID first = UUIDGenerator.newTimeUUID(); //larger UUID second = UUIDGenerator.newTimeUUID(); /** * Returns < 0 when the first is smaller */ assertTrue( UUIDComparator.staticCompare(first, second) < 0); /** * Returns > 0 when the first argument is larger */ assertTrue( UUIDComparator.staticCompare( second, first ) > 0); UUID equal = UUID.fromString( first.toString() ); /** * Returns 0 when they're equal */ assertTrue(UUIDComparator.staticCompare( first, equal ) == 0); }
/** * Validate each candidate results vs the data loaded from cass */ private void validate( final FilterResult<Candidate> filterCandidate ) { final CandidateResult candidateResult = filterCandidate.getValue().getCandidateResult(); final SearchEdge searchEdge = filterCandidate.getValue().getSearchEdge(); final MvccLogEntry logEntry = versionSet.getMaxVersion( candidateResult.getId() ); final UUID candidateVersion = candidateResult.getVersion(); final UUID entityVersion = logEntry.getVersion(); final Id entityId = logEntry.getEntityId(); //entity is newer than ES version if ( UUIDComparator.staticCompare( entityVersion, candidateVersion ) > 0 ) { logger.warn( "Deindexing stale entity on edge {} for entityId {} and version {}", searchEdge, entityId, entityVersion ); batch.deindex( searchEdge, entityId, entityVersion ); return; } //ES is newer than cass, it means we haven't repaired the record in Cass, we don't want to //remove the ES record, since the read in cass should cause a read repair, just ignore if ( UUIDComparator.staticCompare( candidateVersion, entityVersion ) > 0 ) { logger.warn( "Found a newer version in ES over cassandra for edge {} for entityId {} and version {}. Repair should be run", searchEdge, entityId, entityVersion ); } //they're the same add it final FilterResult<Id> result = new FilterResult<>( entityId, filterCandidate.getPath() ); results.add( result ); } }