void addNode( long id, Node data ) { nodes.put( id, data ); labels.addAll( Iterables.asCollection( data.getLabels() ) ); }
public static <T> void assertContainsInOrder( Iterable<T> collection, T... expectedItems ) { assertContainsInOrder( Iterables.asCollection( collection ), expectedItems ); }
public Collection<T> collection() { try ( Transaction ignore = db.beginTx() ) { return Iterables.asCollection( manifest() ); } }
@Mapping( "metadata" ) public MapRepresentation metadata() { if ( isDeleted() ) { return new MapRepresentation( map( "id", node.getId(), "deleted", Boolean.TRUE ) ); } else { Collection<String> labels = Iterables.asCollection( new IterableWrapper<String,Label>( node.getLabels() ) { @Override protected String underlyingObjectToObject( Label label ) { return label.name(); } } ); return new MapRepresentation( map( "id", node.getId(), "labels", labels ) ); } }
private void changeRandomNode( GraphDatabaseService db, int nodeCount, RandomValues random ) { try ( Transaction tx = db.beginTx() ) { long nodeId = random.nextInt( nodeCount ); Node node = db.getNodeById( nodeId ); Object[] keys = Iterables.asCollection( node.getPropertyKeys() ).toArray(); String key = (String) random.among( keys ); if ( random.nextFloat() < 0.1 ) { // REMOVE node.removeProperty( key ); } else { // CHANGE node.setProperty( key, random.nextValue().asObject() ); } tx.success(); } catch ( NotFoundException e ) { // It's OK, it happens if some other thread deleted that property in between us reading it and // removing or setting it } }
private static Collection asCollection(Object value) { if (value instanceof Collection) return (Collection) value; if (value instanceof Iterable) return Iterables.asCollection((Iterable) value); if (value instanceof Iterator) return Iterators.asCollection((Iterator) value); return Collections.singleton(value); }
@Test public void oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving() { // GIVEN NodeRecord node = nodeRecordWithDynamicLabels( nodeStore, oneByteLongs( 5 ) ); Collection<DynamicRecord> initialRecords = node.getDynamicLabelRecords(); NodeLabels nodeLabels = NodeLabelsField.parseLabelsField( node ); // WHEN Collection<DynamicRecord> changedDynamicRecords = Iterables.asCollection( nodeLabels.remove( 255, nodeStore ) ); // THEN assertEquals( initialRecords, changedDynamicRecords ); assertFalse( Iterables.single( changedDynamicRecords ).inUse() ); assertEquals( inlinedLabelsLongRepresentation( 251, 252, 253, 254 ), node.getLabelField() ); }
@Test public void shouldCreateDeferredSchemaIndexesInEmptyDatabase() throws Exception { // GIVEN BatchInserter inserter = newBatchInserter(); // WHEN IndexDefinition definition = inserter.createDeferredSchemaIndex( label( "Hacker" ) ).on( "handle" ).create(); // THEN assertEquals( "Hacker", single( definition.getLabels() ).name() ); assertEquals( asCollection( iterator( "handle" ) ), Iterables.asCollection( definition.getPropertyKeys() ) ); inserter.shutdown(); }
assertEquals( nodes, Iterables.asCollection( getGraphDb().traversalDescription().evaluator( excludeStartPosition() ) .sort( endNodeProperty( "name" ) ).traverse( getNodeWithName( me ) ).nodes() ) ); tx.success();
assertEquals( highMark, relAboveTheLine.getId() ); assertEquals( asSet( asList( relBelowTheLine, relAboveTheLine ) ), asSet( Iterables.asCollection( db.getNodeById( idBelow ).getRelationships() ) ) ); transaction.success();
void addNode( long id, Node data ) { nodes.put( id, data ); labels.addAll( Iterables.asCollection( data.getLabels() ) ); }
private static Label[] labelsArray(BatchInserter db, long node, Set<String> ignoreLabels) { Collection<Label> labels = Iterables.asCollection(db.getNodeLabels(node)); if (labels.isEmpty()) return NO_LABELS; if (!ignoreLabels.isEmpty()) { labels.removeIf(label -> ignoreLabels.contains(label.name())); } return labels.toArray(new Label[labels.size()]); }
public void outputResults(List<String> columns, Iterable<Map<String, Object>> result, long time, QueryStatistics queryStatistics, PrintWriter out) { Collection<Map<String, Object>> rows = (result instanceof Collection) ? (Collection<Map<String, Object>>) result : Iterables.asCollection(result); Map<String, Integer> columnSizes = calculateColumnSizes(columns, rows); int totalWidth = totalWith(columnSizes.values()); final boolean hasData = !columns.isEmpty(); if (hasData) { String _________ = "+" + repeat('-', totalWidth) + "+"; out.println(_________); out.println(row(columns, columnSizes)); out.println(_________); for (Map<String, Object> row : rows) { out.println(row(columns, columnSizes, row)); } out.println(_________); } out.println(rowsTime(time, rows.size())); final String stats = info(queryStatistics, hasData); if (!stats.isEmpty()) { out.println(stats); } }
@Mapping( "metadata" ) public MapRepresentation metadata() { if ( isDeleted() ) { return new MapRepresentation( map( "id", node.getId(), "deleted", Boolean.TRUE ) ); } else { Collection<String> labels = Iterables.asCollection( new IterableWrapper<String,Label>( node.getLabels() ) { @Override protected String underlyingObjectToObject( Label label ) { return label.name(); } } ); return new MapRepresentation( map( "id", node.getId(), "labels", labels ) ); } }