@Override public boolean acceptsValue( Value value ) { if ( value == null || value == NO_VALUE ) { return false; } if ( value.valueGroup() == valueGroup ) { if ( from != null ) { int compare = Values.COMPARATOR.compare( value, from ); if ( compare < 0 || !fromInclusive && compare == 0 ) { return false; } } if ( to != null ) { int compare = Values.COMPARATOR.compare( value, to ); return compare <= 0 && (toInclusive || compare != 0); } return true; } return false; }
return valueComparator.ternaryCompare( (Value) v1, (Value) v2 ); return Comparison.from( valueComparator.compare( (Value) v1, (Value) v2 ) );
Arrays.sort( expectedValues, Values.COMPARATOR.reversed() );
return valueComparator.ternaryCompare( (Value) v1, (Value) v2 ); return Comparison.from( valueComparator.compare( (Value) v1, (Value) v2 ) );
private Value pickSmaller( Value value1, Value value2 ) { return COMPARATOR.compare( value1, value2 ) < 0 ? value1 : value2; }
@Override public int compare( Object o1, Object o2 ) { return Values.COMPARATOR.compare( Values.of(o1), Values.of(o2) ); } };
@Override public int compare( Object o1, Object o2 ) { return Values.COMPARATOR.compare( Values.of(o1), Values.of(o2) ); } };
@Override public int compare( Number n1, Number n2 ) { return Values.COMPARATOR.compare( Values.numberValue(n1), Values.numberValue(n2) ); } };
void next( Sink sink ) { int c = 0; if ( valuesFromA != null && valuesFromB != null ) { checkArgument( valuesFromA.length == valuesFromB.length, "Expected index and txState values to have same dimensions, but got %d values from index and %d from txState", valuesFromB.length, valuesFromA.length ); for ( int i = 0; c == 0 && i < valuesFromA.length; i++ ) { c = Values.COMPARATOR.compare( valuesFromA[i], valuesFromB[i] ); } } if ( nextFromB == -1 || Integer.signum( c ) == indexOrder ) { sink.acceptSortedMergeJoin( nextFromA, valuesFromA ); nextFromA = -1; valuesFromA = null; } else { sink.acceptSortedMergeJoin( nextFromB, valuesFromB ); nextFromB = -1; valuesFromB = null; } }
@Override public int compareValueTo( ZonedDateTimeIndexKey other ) { int compare = Long.compare( epochSecondUTC, other.epochSecondUTC ); if ( compare == 0 ) { compare = Integer.compare( nanoOfSecond, other.nanoOfSecond ); if ( compare == 0 && // We need to check validity upfront without throwing exceptions, because the PageCursor might give garbage bytes TimeZones.validZoneOffset( zoneOffsetSeconds ) && TimeZones.validZoneOffset( other.zoneOffsetSeconds ) ) { if ( zoneOffsetSeconds != other.zoneOffsetSeconds || zoneId != other.zoneId ) { // In the rare case of comparing the same instant in different time zones, we settle for // mapping to values and comparing using the general values comparator. compare = Values.COMPARATOR.compare( asValue(), other.asValue() ); } } } return compare; }
static int compare( long this_long0, long this_long1, long this_long2, long this_long3, long that_long0, long that_long1, long that_long2, long that_long3 ) { int compare = Long.compare( this_long0, that_long0 ); if ( compare == 0 ) { compare = Integer.compare( (int) this_long1, (int) that_long1 ); if ( compare == 0 && // We need to check validity upfront without throwing exceptions, because the PageCursor might give garbage bytes TimeZones.validZoneOffset( (int) this_long3 ) && TimeZones.validZoneOffset( (int) that_long3 ) ) { // In the rare case of comparing the same instant in different time zones, we settle for // mapping to values and comparing using the general values comparator. compare = Values.COMPARATOR.compare( asValue( this_long0, this_long1, this_long2, this_long3 ), asValue( that_long0, that_long1, that_long2, that_long3 ) ); } } return compare; }
private void assertLessThanOrEqualTo( Value[] o1, Value[] o2 ) { if ( o1 == null || o2 == null ) { return; } int length = Math.min( o1.length, o2.length ); for ( int i = 0; i < length; i++ ) { int compare = Values.COMPARATOR.compare( o1[i], o2[i] ); assertThat( "expected less than or equal to but was " + Arrays.toString( o1 ) + " and " + Arrays.toString( o2 ), compare, lessThanOrEqualTo( 0 ) ); if ( compare != 0 ) { return; } } }
int compareIndexedPropertyValue( KEY key1, KEY key2 ) { return Values.COMPARATOR.compare( key1.asValues()[0], key2.asValues()[0] ); }
@Disabled // only runnable it JVM supports East-Saskatchewan public void shouldCompareRenamedTimeZonesByZoneNumber() { int cmp = Values.COMPARATOR.compare( datetime( 10000, 100, ZoneId.of( "Canada/Saskatchewan" ) ), datetime( 10000, 100, ZoneId.of( "Canada/East-Saskatchewan" ) ) ); assertEquals( 0, cmp, "East-Saskatchewan and Saskatchewan are the same place" ); }
@Test public void shouldHaveSameCompareResultsAsValueCompare() { // given List<Value> values = asValueObjects( objects ); List<NumberIndexKey> numberIndexKeys = asNumberIndexKeys( values ); // when for ( int i = 0; i < values.size(); i++ ) { Value value1 = values.get( i ); NumberIndexKey numberIndexKey1 = numberIndexKeys.get( i ); for ( int j = 0; j < values.size(); j++ ) { // then Value value2 = values.get( j ); NumberIndexKey numberIndexKey2 = numberIndexKeys.get( j ); assertEquals( Values.COMPARATOR.compare( value1, value2 ), layout.compare( numberIndexKey1, numberIndexKey2 ) ); assertEquals( Values.COMPARATOR.compare( value2, value1 ), layout.compare( numberIndexKey2, numberIndexKey1 ) ); } } }
private void assertFoundNodesInOrder( NodeValueIndexCursor node, IndexOrder indexOrder ) { Value currentValue = null; while ( node.next() ) { long nodeReference = node.nodeReference(); Value storedValue = getPropertyValueFromStore( nodeReference ); if ( currentValue != null ) { switch ( indexOrder ) { case ASCENDING: assertTrue( "Requested ordering " + indexOrder + " was not respected.", Values.COMPARATOR.compare( currentValue, storedValue ) <= 0 ); break; case DESCENDING: assertTrue( "Requested ordering " + indexOrder + " was not respected.", Values.COMPARATOR.compare( currentValue, storedValue ) >= 0 ); break; case NONE: // Don't verify break; default: throw new UnsupportedOperationException( "Can not verify ordering for " + indexOrder ); } } currentValue = storedValue; } }
private void assertResultsInOrder( List<Pair<Long,Value>> expected, NodeValueIndexCursor cursor ) { Comparator<Pair<Long,Value>> comparator = indexOrder == IndexOrder.ASCENDING ? ( a, b ) -> Values.COMPARATOR.compare( a.other(), b.other() ) : ( a, b ) -> Values.COMPARATOR.compare( b.other(), a.other() ); expected.sort( comparator ); Iterator<Pair<Long,Value>> expectedRows = expected.iterator(); while ( cursor.next() && expectedRows.hasNext() ) { Pair<Long, Value> expectedRow = expectedRows.next(); assertThat( cursor.nodeReference(), equalTo( expectedRow.first() ) ); for ( int i = 0; i < cursor.numberOfProperties(); i++ ) { Value value = cursor.propertyValue( i ); assertThat( value, equalTo( expectedRow.other() ) ); } } assertFalse( expectedRows.hasNext() ); assertFalse( cursor.next() ); }
vj.writeTo( keyJ ); int expected = Integer.signum( Values.COMPARATOR.compare( vi, vj ) ); assertEquals( format( "comparing %s and %s", vi, vj ), expected, Integer.signum( i - j ) ); assertEquals( format( "comparing %s and %s", vi, vj ), expected, Integer.signum( keyI.compareValueTo( keyJ ) ) );
@ParameterizedTest @MethodSource( "validComparableValueGenerators" ) void mustProduceValidMinimalSplitters( ValueGenerator valueGenerator ) { // Given Value value1 = valueGenerator.next(); Value value2; do { value2 = valueGenerator.next(); } while ( COMPARATOR.compare( value1, value2 ) == 0 ); // When Value left = pickSmaller( value1, value2 ); Value right = left == value1 ? value2 : value1; // Then assertValidMinimalSplitter( left, right ); }
List<IndexEntryUpdate<?>> updates = generateUpdatesFromValues( values ); updateAndCommit( updates ); TreeSet<IndexEntryUpdate> sortedValues = new TreeSet<>( ( u1, u2 ) -> Values.COMPARATOR.compare( u1.values()[0], u2.values()[0] ) ); sortedValues.addAll( updates ); Value from = random.randomValues().nextValueOfType( type ); Value to = random.randomValues().nextValueOfType( type ); if ( Values.COMPARATOR.compare( from, to ) > 0 )