public static ListValue asListValue( Iterable<?> collection ) { ArrayList<AnyValue> values = new ArrayList<>(); for ( Object o : collection ) { values.add( ValueUtils.of( o ) ); } return VirtualValues.fromList( values ); }
public static ListValue asListValue( List<?> collection ) { ArrayList<AnyValue> values = new ArrayList<>( collection.size() ); for ( Object o : collection ) { values.add( ValueUtils.of( o ) ); } return VirtualValues.fromList( values ); }
private static ListValue children( ExecutionPlanDescription plan ) { List<AnyValue> children = new LinkedList<>(); for ( ExecutionPlanDescription child : plan.getChildren() ) { children.add( convert( child ) ); } return VirtualValues.fromList( children ); } }
@Override public AnyValue mapSequence( SequenceValue value ) { List<AnyValue> list = new ArrayList<>( value.length() ); value.forEach( v -> list.add( v.map( this ) ) ); return VirtualValues.fromList( list ); } }
@Override public ListValue split( String separator ) { assert separator != null; String asString = value(); //Cypher has different semantics for the case where the separator //is exactly the value, in cypher we expect two empty arrays //where as java returns an empty array if ( separator.equals( asString ) ) { return EMPTY_SPLIT; } else if ( separator.isEmpty() ) { return VirtualValues.fromArray( Values.charArray( asString.toCharArray() ) ); } List<AnyValue> split = splitNonRegex( asString, separator ); return VirtualValues.fromList( split ); }
return VirtualValues.fromList( (List<AnyValue>) (((List) anyValue).stream() .map( v -> materializeAnyResult( proxySpi, v ) ).collect( Collectors.toList() ) ) ); return VirtualValues.fromList( ((PrimitiveNodeStream) anyValue).longStream() .mapToObj( id -> (AnyValue) ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( id ) ) ) .collect( Collectors.toList() ) ); return VirtualValues.fromList( ((PrimitiveRelationshipStream) anyValue).longStream() .mapToObj( id -> (AnyValue) ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( id ) ) ) .collect( Collectors.toList() ) ); return VirtualValues.fromList( ((IntStream) anyValue).mapToObj( i -> Values.booleanValue( i != 0 ) ).collect( Collectors.toList() ) );
private static AnyValue valueOf( Object obj ) { if ( obj instanceof MappedGraphType ) { return ((MappedGraphType) obj).value; } Value value = Values.unsafeOf( obj, true ); if ( value != null ) { return value; } if ( obj instanceof List<?> ) { return fromList( ((List<?>) obj).stream().map( ValueMapperTest::valueOf ).collect( toList() ) ); } if ( obj instanceof Map<?,?> ) { @SuppressWarnings( "unchecked" ) Map<String,?> map = (Map<String,?>) obj; MapValueBuilder builder = new MapValueBuilder( map.size() ); for ( Map.Entry<String,?> entry : map.entrySet() ) { builder.add( entry.getKey(), valueOf( entry.getValue() ) ); } return builder.build(); } throw new AssertionError( "cannot convert: " + obj + " (a " + obj.getClass().getName() + ")" ); }
public static AnyValue convert( Iterable<Notification> notifications ) { List<AnyValue> out = new ArrayList<>(); for ( Notification notification : notifications ) { InputPosition pos = notification.getPosition(); // position is optional boolean includePosition = !pos.equals( InputPosition.empty ); int size = includePosition ? 5 : 4; MapValueBuilder builder = new MapValueBuilder( size ); builder.add( "code", stringValue( notification.getCode() ) ); builder.add( "title", stringValue( notification.getTitle() ) ); builder.add( "description", stringValue( notification.getDescription() ) ); builder.add( "severity", stringValue( notification.getSeverity().toString() ) ); if ( includePosition ) { // only add the position if it is not empty builder.add( "position", VirtualValues.map( new String[]{"offset", "line", "column"}, new AnyValue[]{ intValue( pos.getOffset() ), intValue( pos.getLine() ), intValue( pos.getColumn() ) } ) ); } out.add( builder.build() ); } return VirtualValues.fromList( out ); } }
public static ListValue asListValue( List<?> collection ) { ArrayList<AnyValue> values = new ArrayList<>( collection.size() ); for ( Object o : collection ) { values.add( ValueUtils.of( o ) ); } return VirtualValues.fromList( values ); }
public static ListValue asListValue( Iterable<?> collection ) { ArrayList<AnyValue> values = new ArrayList<>(); for ( Object o : collection ) { values.add( ValueUtils.of( o ) ); } return VirtualValues.fromList( values ); }
private static ListValue children( ExecutionPlanDescription plan ) { List<AnyValue> children = new LinkedList<>(); for ( ExecutionPlanDescription child : plan.getChildren() ) { children.add( convert( child ) ); } return VirtualValues.fromList( children ); } }
@Override public AnyValue mapSequence( SequenceValue value ) { List<AnyValue> list = new ArrayList<>( value.length() ); value.forEach( v -> list.add( v.map( this ) ) ); return VirtualValues.fromList( list ); } }
@Override public ListValue split( String separator ) { assert separator != null; String asString = value(); //Cypher has different semantics for the case where the separator //is exactly the value, in cypher we expect two empty arrays //where as java returns an empty array if ( separator.equals( asString ) ) { return EMPTY_SPLIT; } else if ( separator.isEmpty() ) { return VirtualValues.fromArray( Values.charArray( asString.toCharArray() ) ); } List<AnyValue> split = splitNonRegex( asString, separator ); return VirtualValues.fromList( split ); }
return VirtualValues.fromList( (List<AnyValue>) (((List) anyValue).stream() .map( v -> materializeAnyResult( proxySpi, v ) ).collect( Collectors.toList() ) ) ); return VirtualValues.fromList( ((PrimitiveNodeStream) anyValue).longStream() .mapToObj( id -> (AnyValue) ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( id ) ) ) .collect( Collectors.toList() ) ); return VirtualValues.fromList( ((PrimitiveRelationshipStream) anyValue).longStream() .mapToObj( id -> (AnyValue) ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( id ) ) ) .collect( Collectors.toList() ) ); return VirtualValues.fromList( ((IntStream) anyValue).mapToObj( i -> Values.booleanValue( i != 0 ) ).collect( Collectors.toList() ) );
public static AnyValue convert( Iterable<Notification> notifications ) { List<AnyValue> out = new ArrayList<>(); for ( Notification notification : notifications ) { InputPosition pos = notification.getPosition(); // position is optional boolean includePosition = !pos.equals( InputPosition.empty ); int size = includePosition ? 5 : 4; MapValueBuilder builder = new MapValueBuilder( size ); builder.add( "code", stringValue( notification.getCode() ) ); builder.add( "title", stringValue( notification.getTitle() ) ); builder.add( "description", stringValue( notification.getDescription() ) ); builder.add( "severity", stringValue( notification.getSeverity().toString() ) ); if ( includePosition ) { // only add the position if it is not empty builder.add( "position", VirtualValues.map( new String[]{"offset", "line", "column"}, new AnyValue[]{ intValue( pos.getOffset() ), intValue( pos.getLine() ), intValue( pos.getColumn() ) } ) ); } out.add( builder.build() ); } return VirtualValues.fromList( out ); } }