@Override public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) { writeValue( Values.pointValue( crs, coordinate ) ); }
static <T> void assertConsistent( String string, Function<TextValue,T> test ) { TextValue textValue = stringValue( string ); TextValue utf8Value = utf8Value( string.getBytes( UTF_8 ) ); T a = test.apply( textValue ); T b = test.apply( utf8Value ); String errorMsg = format( "operation not consistent for %s", string ); assertThat( errorMsg, a, equalTo( b ) ); assertThat( errorMsg, b, equalTo( a ) ); }
@Test public void testIndexSeekExactWithRangeBySpatial() throws Exception { testIndexSeekExactWithRange( intValue( 100 ), intValue( 10 ), pointValue( WGS84, -10D, -10D ), pointValue( WGS84, -1D, -1D ), pointValue( WGS84, 0D, 0D ), pointValue( WGS84, 1D, 1D ), pointValue( WGS84, 10D, 10D ) ); }
@Test public void testIndexSeekExactWithExistsBySpatialArray() throws Exception { testIndexSeekExactWithExists( pointArray( new PointValue[] {pointValue( Cartesian, 100D, 100D ), pointValue( Cartesian, 101D, 101D )} ), pointArray( new PointValue[] {pointValue( Cartesian, 0D, 0D ), pointValue( Cartesian, 1D, 1D )} ) ); }
@Test void shouldNotEqualVirtualValue() { VirtualValue virtual = new MyVirtualValue( 42 ); assertNotEqual( booleanValue( false ), virtual ); assertNotEqual( byteValue( (byte)0 ), virtual ); assertNotEqual( shortValue( (short)0 ), virtual ); assertNotEqual( intValue( 0 ), virtual ); assertNotEqual( longValue( 0 ), virtual ); assertNotEqual( floatValue( 0.0f ), virtual ); assertNotEqual( doubleValue( 0.0 ), virtual ); assertNotEqual( stringValue( "" ), virtual ); } }
@Test public void shouldSerializeRelationship() throws Throwable { RelationshipValue rel = relationshipValue( 12L, nodeValue( 1L, stringArray(), VirtualValues.EMPTY_MAP ), nodeValue( 2L, stringArray(), VirtualValues.EMPTY_MAP ), stringValue( "KNOWS" ), VirtualValues.map( new String[]{"name", "age"}, new AnyValue[]{stringValue( "Bob" ), intValue( 14 )} ) ); assertThat( serialized( rel ), equalTo( "B1 71 91 B5 52 0C 01 02 85 4B 4E 4F 57 53 A2 84" + lineSeparator() + "6E 61 6D 65 83 42 6F 62 83 61 67 65 0E" ) ); }
@Test public void shouldHandleLists() { // Given ListValue list = list( stringValue( "foo" ), longValue( 42L ), TRUE ); // When list.writeTo( converter ); // Then assertThat( converter.value(), equalTo( Arrays.asList( "foo", 42L, true ) ) ); }
@Override Value asValue( GenericKey state ) { T[] array = arrayCreator.apply( state.arrayLength ); for ( int i = 0; i < state.arrayLength; i++ ) { array[i] = valueFactory.from( state, i ); } return Values.of( array ); }
/** * Multiplication of two doubles * * @param a left-hand operand * @param b right-hand operand * @return a * b */ public static DoubleValue multiply( double a, double b ) { return Values.doubleValue( a * b ); } }
private static RelationshipValue newRelationshipValue() { NodeValue startNode = nodeValue( 24, stringArray( "Person" ), EMPTY_MAP ); NodeValue endNode = nodeValue( 42, stringArray( "Person" ), EMPTY_MAP ); return relationshipValue( 42, startNode, endNode, stringValue( "KNOWS" ), EMPTY_MAP ); } }
@Test void shouldHandleSingleListConcatenation() { // Given ListValue inner = list( stringValue( "foo" ), longValue( 42 ), booleanValue( true ) ); // When ListValue concat = concat( inner ); // Then assertEquals(inner, concat); assertEquals(inner.hashCode(), concat.hashCode()); assertArrayEquals(inner.asArray(), concat.asArray()); }
@Test public void shouldNotGenerateUpdateForMultipleExistingPropertiesAndLabels() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ) .existing( propertyKeyId1, Values.of( "Neo" ) ) .existing( propertyKeyId2, Values.of( 100L ) ) .existing( propertyKeyId3, Values.pointValue( CoordinateReferenceSystem.WGS84, 12.3, 45.6 ) ) .build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotBotherSerializingToRealBytesIfFarFromThreshold() { // given Layout<GenericKey,NativeIndexValue> layout = mock( Layout.class ); doThrow( RuntimeException.class ).when( layout ).newKey(); GenericIndexKeyValidator validator = new GenericIndexKeyValidator( 120, layout ); // when validator.validate( new Value[]{intValue( 10 ), epochDate( 100 ), stringValue( "abc" )} ); // then no exception should have been thrown }
/** * Overflow safe multiplication of two longs * * @param a left-hand operand * @param b right-hand operand * @return a * b */ public static LongValue multiply( long a, long b ) { return longValue( Math.multiplyExact( a, b ) ); }
@Override public Value valueOf( long x ) { return intValue( 10 + (int) x ); } } );
private BoltStateMachineState processRunMessage( RunMessage message, StateMachineContext context ) throws KernelException { long start = context.clock().millis(); StatementProcessor statementProcessor = context.connectionState().getStatementProcessor(); StatementMetadata statementMetadata = statementProcessor.run( message.statement(), message.params() ); long end = context.clock().millis(); context.connectionState().onMetadata( FIELDS_KEY, stringArray( statementMetadata.fieldNames() ) ); context.connectionState().onMetadata( FIRST_RECORD_AVAILABLE_KEY, Values.longValue( end - start ) ); return streamingState; }
private static BooleanValue readBoolean( ByteBuffer chunk, int offset ) { return booleanValue( chunk.get( offset ) != 0 ); }
@Test void shouldHandleTooLargeStartPointInSubstring() { // Given TextValue value = utf8Value( "hello".getBytes( UTF_8 ) ); // When TextValue substring = value.substring( 8, 5 ); // Then assertThat( substring, equalTo( StringValue.EMPTY ) ); }
private static LongArray readLongArray( ByteBuffer bb, int offset ) { final int len = bb.getInt( offset ); offset += Integer.BYTES; final long[] array = new long[len]; for ( int i = 0; i < len; i++ ) { array[i] = bb.getLong( offset ); offset += Long.BYTES; } return longArray( array ); }
private static ListValue extractKeys( DbAccess access, int[] keyIds ) { String[] keysNames = new String[keyIds.length]; for ( int i = 0; i < keyIds.length; i++ ) { keysNames[i] = access.getPropertyKeyName( keyIds[i] ); } return VirtualValues.fromArray( Values.stringArray( keysNames ) ); }