@Override public List<String> getColumns() { List<String> columns = new ArrayList<String>(); if (this.records.size() > 0) { Record rec = this.records.get(0); columns.addAll(rec.keys()); } return columns; }
@Override public List<String> getColumns() { List<String> columns = new ArrayList<String>(); if (this.records.size() > 0) { Record rec = this.records.get(0); columns.addAll(rec.keys()); } return columns; }
@Override @Nonnull public String format(@Nonnull final BoltResult result) { StringBuilder sb = new StringBuilder(); List<Record> records = result.getRecords(); if (!records.isEmpty()) { sb.append(records.get(0).keys().stream().collect(Collectors.joining(COMMA_SEPARATOR))); sb.append("\n"); sb.append(records.stream().map(this::formatRecord).collect(Collectors.joining("\n"))); } return sb.toString(); }
@Override public List<String> keys() { return peek().keys(); }
public static <V> List<Pair<String, V>> fields( final Record map, final Function<Value, V> mapFunction ) { int size = map.keys().size(); switch ( size ) { case 0: return emptyList(); case 1: { String key = map.keys().iterator().next(); Value value = map.get( key ); return singletonList( InternalPair.of( key, mapFunction.apply( value ) ) ); } default: { List<Pair<String, V>> list = new ArrayList<>( size ); List<String> keys = map.keys(); for ( int i = 0; i < size; i++ ) { String key = keys.get( i ); Value value = map.get( i ); list.add( InternalPair.of( key, mapFunction.apply( value ) ) ); } return unmodifiableList( list ); } } }
public static <T> Map<String, T> map( Record record, Function<Value, T> mapFunction ) { int size = record.size(); switch ( size ) { case 0: return emptyMap(); case 1: return singletonMap( record.keys().get( 0 ), mapFunction.apply( record.get( 0 ) ) ); default: Map<String,T> map = Iterables.newLinkedHashMapWithSize( size ); List<String> keys = record.keys(); for ( int i = 0; i < size; i++ ) { map.put( keys.get( i ), mapFunction.apply( record.get( i ) ) ); } return unmodifiableMap( map ); } }
@Override public List<String> keys() { return records.stream().map(r -> r.keys().get(0)).collect(Collectors.toList()); }
private void checkMapForPrettyPrint(Map<String, String> map, String expectedResult) { // given BoltResult result = mock(BoltResult.class); Record record = mock(Record.class); Value value = mock(Value.class); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.MAP()); when(value.asMap((Function<Value, String>) anyObject())).thenReturn(map); when(record.keys()).thenReturn(asList("map")); when(record.values()).thenReturn(asList(value)); when(result.getRecords()).thenReturn(asList(record)); when(result.getSummary()).thenReturn(mock(ResultSummary.class)); // when String actual = plainPrinter.format(result); // then assertThat(actual, is(expectedResult)); }
@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]")); }
@Test public void prettyPrintRelationships() throws Exception { // given BoltResult result = mock(BoltResult.class); Record record = mock(Record.class); Value value = mock(Value.class); Relationship relationship = mock(Relationship.class); HashMap<String, Object> propertiesAsMap = new HashMap<>(); propertiesAsMap.put("prop1", "prop1_value"); propertiesAsMap.put("prop2", "prop2_value"); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP()); when(value.asRelationship()).thenReturn(relationship); when(relationship.type()).thenReturn("RELATIONSHIP_TYPE"); when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap)); when(record.keys()).thenReturn(asList("rel")); when(record.values()).thenReturn(asList(value)); when(result.getRecords()).thenReturn(asList(record)); when(result.getSummary()).thenReturn(mock(ResultSummary.class)); // when String actual = plainPrinter.format(result); // then assertThat(actual, is("rel\n[:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}]")); }
if ( ! keys.equals( otherRecord.keys() ) )
@Test public void prettyPrintNode() throws Exception { // given BoltResult result = mock(BoltResult.class); Record record = mock(Record.class); Value value = mock(Value.class); Node node = mock(Node.class); HashMap<String, Object> propertiesAsMap = new HashMap<>(); propertiesAsMap.put("prop1", "prop1_value"); propertiesAsMap.put("prop2", "prop2_value"); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.NODE()); when(value.asNode()).thenReturn(node); when(node.labels()).thenReturn(asList("label1", "label2")); when(node.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap)); when(record.keys()).thenReturn(asList("col1", "col2")); when(record.values()).thenReturn(asList(value)); when(result.getRecords()).thenReturn(asList(record)); when(result.getSummary()).thenReturn(mock(ResultSummary.class)); // when String actual = plainPrinter.format(result); // then assertThat(actual, is("col1, col2\n" + "(:label1:label2 {prop2: prop2_value, prop1: prop1_value})")); }
when(path.iterator()).thenReturn(asList(segment1).iterator()); when(record.keys()).thenReturn(asList("path")); when(record.values()).thenReturn(asList(value));
when(record.keys()).thenReturn(asList("rel", "node")); when(record.values()).thenReturn(asList(relVal, nodeVal));
when(end.asMap(anyObject())).thenReturn(unmodifiableMap(endProperties)); when(record.keys()).thenReturn(asList("path")); when(record.values()).thenReturn(asList(value));
when(path.iterator()).thenReturn(asList(segment1, segment2, segment3).iterator()); when(record.keys()).thenReturn(asList("path")); when(record.values()).thenReturn(asList(value));
recordMap.put("node", nodeVal); List<String> keys = asList("rel", "node"); when(record.keys()).thenReturn(keys); when(record.get(eq("rel"))).thenReturn(relVal); when(record.get(eq("node"))).thenReturn(nodeVal);