public static ListValue asListOfEdges( Iterable<Relationship> rels ) { return VirtualValues.list( StreamSupport.stream( rels.spliterator(), false ) .map( ValueUtils::fromRelationshipProxy ).toArray( RelationshipValue[]::new ) ); }
public static ListValue asListOfEdges( Relationship[] rels ) { RelationshipValue[] relValues = new RelationshipValue[rels.length]; for ( int i = 0; i < relValues.length; i++ ) { relValues[i] = fromRelationshipProxy( rels[i] ); } return VirtualValues.list( relValues ); }
public static ListValue nodes( AnyValue in ) { if ( in instanceof PathValue ) { return VirtualValues.list( ((PathValue) in).nodes() ); } else { throw new CypherTypeException( format( "Expected %s to be a path.", in ), null ); } }
public static ListValue relationships( AnyValue in ) { if ( in instanceof PathValue ) { return VirtualValues.list( ((PathValue) in).relationships() ); } else { throw new CypherTypeException( format( "Expected %s to be a path.", in ), null ); } }
@Override public ListValue split( String separator ) { if ( separator.equals( stringValue() ) ) { return EMPTY_SPLIT; } else { return list( Values.stringValue( stringValue() ) ); } }
public static ListValue list( Object... objects ) { AnyValue[] values = new AnyValue[objects.length]; for ( int i = 0; i < objects.length; i++ ) { values[i] = toAnyValue( objects[i] ); } return VirtualValues.list( values ); }
private <T extends AnyValue> ListValue randomList( Function<Integer,T> randomValueGenerator ) { AnyValue[] values = random.ints( RANDOM_LISTS_TO_TEST, 1, RANDOM_LIST_MAX_SIZE ) .mapToObj( randomValueGenerator::apply ) .toArray( AnyValue[]::new ); return list( values ); }
@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 ) ) ); }
@Test void shouldHandleMaps() { // Given Map<String,Object> map = MapUtil.map( "a", Arrays.asList( "foo", 42 ) ); // When AnyValue anyValue = ValueUtils.of( map ); // Then assertThat( anyValue, instanceOf( MapValue.class ) ); MapValue mapValue = (MapValue) anyValue; assertThat( mapValue.get( "a" ), equalTo( VirtualValues.list( stringValue( "foo" ), intValue( 42 ) ) ) ); assertThat( mapValue.size(), equalTo( 1 ) ); }
@Test void shouldHandleLists() { // Given PrettyPrinter printer = new PrettyPrinter(); ListValue list = VirtualValues.list( stringValue( "foo" ), byteValue( (byte) 42 ) ); // When list.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "[\"foo\", 42]" ) ); }
@Test void shouldHandleNodeValue() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray( "L1", "L2", "L3" ), props( "foo", intValue( 42 ), "bar", list( intValue( 1337 ), stringValue( "baz" ) ) ) ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42 :L1:L2:L3 {bar: [1337, \"baz\"], foo: 42})" ) ); }
@Test void shouldHandleNodeValueWithoutLabels() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray(), props( "foo", intValue( 42 ), "bar", list( intValue( 1337 ), stringValue( "baz" ) ) ) ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42 {bar: [1337, \"baz\"], foo: 42})" ) ); }
@Test void shouldHandleNegativeStep() { ListValue range = range( 11L, 5L, -3L ); ListValue expected = list( longValue( 11L ), longValue( 8L ), longValue( 5L ) ); assertEquals( range, expected ); assertEquals( range.hashCode(), expected.hashCode() ); } }
@Test void shouldHandleRangeWithBiggerSteps() { ListValue range = range( 5L, 11L, 3L ); ListValue expected = list( longValue( 5L ), longValue( 8L ), longValue( 11L ) ); assertEquals( range, expected ); assertEquals( range.hashCode(), expected.hashCode() ); }
@Test void shouldHandleEmptyAppend() { // Given ListValue inner = list( longValue( 5L ), longValue( 6L ), longValue( 7L ), longValue( 8L ), longValue( 9L ), longValue( 10L ), longValue( 11L ) ); // When ListValue appended = inner.append( ); // Then assertListValuesEquals( appended, inner ); }
@Test void shouldHandleEmptyPrepend() { // Given ListValue inner = list( longValue( 5L ), longValue( 6L ), longValue( 7L ), longValue( 8L ), longValue( 9L ), longValue( 10L ), longValue( 11L ) ); // When ListValue prepend = inner.prepend( ); // Then assertListValuesEquals( prepend, inner ); }
@Test void shouldHandleSingleItemList() { // Given ListValue inner = list( longValue( 5L ) ); // When ListValue reverse = inner.reverse(); // Then assertEquals( inner, reverse ); assertEquals( inner.hashCode(), reverse.hashCode() ); assertArrayEquals( inner.asArray(), reverse.asArray() ); }
@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 void shouldHandleRangeWithStepOne() { ListValue range = range( 5L, 11L, 1L ); ListValue expected = list( longValue( 5L ), longValue( 6L ), longValue( 7L ), longValue( 8L ), longValue( 9L ), longValue( 10L ), longValue( 11L ) ); assertEquals( range, expected ); assertEquals( range.hashCode(), expected.hashCode() ); }