/** * Converts values to {@link List} of <tt>T</tt>. * * @param innerMap converter for the values inside the list * @param <T> the type of values inside the list * @return a function that returns {@link Value#asList(Function)} of a {@link Value} */ public static <T> Function<Value,List<T>> ofList( final Function<Value,T> innerMap ) { return value -> value.asList( innerMap ); } }
private static List<Notification> extractNotifications( Map<String,Value> metadata ) { Value notificationsValue = metadata.get( "notifications" ); if ( notificationsValue != null ) { return notificationsValue.asList( InternalNotification.VALUE_TO_NOTIFICATION ); } return Collections.emptyList(); }
private List<Object> get( Value value, List<Object> defaultValue ) { if( value.equals( Values.NULL ) ) { return defaultValue; } else { return value.asList(); } }
@Override public <T> List<T> asList( Function<Value,T> mapFunction, List<T> defaultValue ) { return computeOrDefault( value -> value.asList( mapFunction ), defaultValue ); }
private <T> List<T> get( Value value, List<T> defaultValue, Function<Value, T> mapFunc ) { if( value.equals( Values.NULL ) ) { return defaultValue; } else { return value.asList( mapFunc ); } }
@SuppressWarnings("unchecked") private <T> List<T> asList(Record embeddeds, String alias) { Value value = embeddeds.get( alias ); if ( value.isNull() ) { return Collections.emptyList(); } return (List<T>) value.asList(); }
@Override public Void apply( Value value ) { result.servers( value.get( "role" ).asString() ) .addAll( value.get( "addresses" ).asList( OF_BoltServerAddress ) ); return null; } } );
private void addTargetEmbeddedProperties(Map<String, Object> targetNode, Record row) { if ( !row.get( 1 ).isNull() ) { List<Object> pathToNode = row.get( 1 ).asList(); Map<String, Object> embeddedNodeProperties = (Map<String, Object>) row.get( 3 ).asMap(); String path = concat( pathToNode ); for ( Map.Entry<String, Object> entry : embeddedNodeProperties.entrySet() ) { targetNode.put( path + "." + entry.getKey(), entry.getValue() ); } } }
public static ClusterComposition parse( Record record, long now ) { if ( record == null ) { return null; } final ClusterComposition result = new ClusterComposition( expirationTimestamp( now, record ) ); record.get( "servers" ).asList( new Function<Value,Void>() { @Override public Void apply( Value value ) { result.servers( value.get( "role" ).asString() ) .addAll( value.get( "addresses" ).asList( OF_BoltServerAddress ) ); return null; } } ); return result; }
static Object convert(Value value) { switch (value.type().name()) { case "PATH": return value.asList(BoltCypherExecutor::convert); case "NODE": case "RELATIONSHIP": return value.asMap(); } return value.asObject(); }
Neo4jIndexManagement(Neo4jTransaction transaction, String namespace, Set<String> managedDomains) { currentIndexes = new LinkedHashSet<>(); StatementResult statementResult = transaction.executeCypher(String.format("CALL db.indexes")); while (statementResult.hasNext()) { Record record = statementResult.next(); Value labelValue = record.get("label"); Value properties = record.get("properties"); String label = labelValue.asString(); List<String> propertyList = properties.asList(Value::asString); currentIndexes.add(new Index(label, propertyList, !label.endsWith("_E"))); } wantedIndexes = new LinkedHashSet<>(); for (String managedDomain : managedDomains) { wantedIndexes.add(new Index(managedDomain, List.of("id"), true)); wantedIndexes.add(new Index(managedDomain + "_E", List.of("path", "hashOrValue"), false)); } createMissingIndices(transaction); }
@Override public T apply( Value plan ) { final String operatorType = plan.get( "operatorType" ).asString(); final Value argumentsValue = plan.get( "args" ); final Map<String, Value> arguments = argumentsValue.isNull() ? Collections.<String, Value>emptyMap() : argumentsValue.asMap( Values.ofValue() ); final Value identifiersValue = plan.get( "identifiers" ); final List<String> identifiers = identifiersValue.isNull() ? Collections.<String>emptyList() : identifiersValue.asList( ofString() ); final Value childrenValue = plan.get( "children" ); final List<T> children = childrenValue.isNull() ? Collections.<T>emptyList() : childrenValue.asList( this ); return planCreator.create( operatorType, arguments, identifiers, children, plan ); } }
ret = Boolean.valueOf(val.asBoolean()); else if (typ == ts.LIST()) { List<Object> orgVals = val.asList(); List<Object> vals = new ArrayList<Object>(); int sz = orgVals.size();
ret = Boolean.valueOf(val.asBoolean()); else if (typ == ts.LIST()) { List<Object> orgVals = val.asList(); List<Object> vals = new ArrayList<Object>(); int sz = orgVals.size();
@Test public void prettyPrintList() throws Exception { // given BoltResult result = mock(BoltResult.class); Record record1 = mock(Record.class); Record record2 = mock(Record.class); Value value1 = mock(Value.class); Value value2 = mock(Value.class); when(value1.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.LIST()); when(value2.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.LIST()); when(value1.asList(Matchers.any(Function.class))).thenReturn(asList("val1_1", "val1_2")); when(value2.asList(Matchers.any(Function.class))).thenReturn(asList("val2_1")); when(record1.keys()).thenReturn(asList("col1", "col2")); when(record1.values()).thenReturn(asList(value1, value2)); when(record2.values()).thenReturn(asList(value2)); when(result.getRecords()).thenReturn(asList(record1, record2)); when(result.getSummary()).thenReturn(mock(ResultSummary.class)); // when String actual = plainPrinter.format(result); // then assertThat(actual, is("col1, col2\n[val1_1, val1_2], [val2_1]\n[val2_1]")); }
List<Relationship> embeds = field.value().asList(v -> v.asRelationship()); StringBuilder sb = new StringBuilder("$"); for (Relationship embedRel : embeds) {
switch (key) { case "ColumnsLeft": return "keep columns" + String.join(SEPARATOR, v.asList(Value::asString)); case "LegacyExpression": return removeGeneratedNames(v.asString()); return removeGeneratedNames(v.asString()); case "KeyExpressions": return String.join(SEPARATOR, v.asList(Value::asString));
switch (type.constructor()) { case LIST: return listAsString(value.asList(this::formatValue)); case MAP: return mapAsString(value.asMap(this::formatValue));