@Override public Path findSinglePath( Node start, Node end ) { return Iterables.firstOrNull( findAllPaths( start, end ) ); }
@Deprecated public Map<String, String> asMap() { Map<String,String> result = new HashMap<>(); for ( Map.Entry<String,List<Option<String>>> entry : map.entrySet() ) { Option<String> value = Iterables.firstOrNull( entry.getValue() ); result.put( entry.getKey(), value != null ? value.value() : null ); } return result; }
@Override public WeightedPath findSinglePath( Node start, Node end ) { return Iterables.firstOrNull( findPaths( start, end, false ) ); }
public static QueryExecutionEngine initialize( Dependencies deps, GraphDatabaseAPI graphAPI, Iterable<QueryEngineProvider> providers ) { List<QueryEngineProvider> engineProviders = asList( providers ); engineProviders.sort( Comparator.comparingInt( QueryEngineProvider::enginePriority ) ); QueryEngineProvider provider = Iterables.firstOrNull( engineProviders ); if ( provider == null ) { return noEngine(); } QueryExecutionEngine engine = provider.createEngine( deps, graphAPI ); return deps.satisfyDependency( engine ); }
@Test void testFirstElement() { Object object = new Object(); Object object2 = new Object(); // first Iterable assertEquals( object, Iterables.first( asList( object, object2 ) ) ); assertEquals( object, Iterables.first( asList( object ) ) ); assertThrows( NoSuchElementException.class, () -> Iterables.first( asList() ) ); // first Iterator assertEquals( object, Iterators.first( asList( object, object2 ).iterator() ) ); assertEquals( object, Iterators.first( asList( object ).iterator() ) ); assertThrows( NoSuchElementException.class, () -> Iterators.first( asList().iterator() ) ); // firstOrNull Iterable assertEquals( object, Iterables.firstOrNull( asList( object, object2 ) ) ); assertEquals( object, Iterables.firstOrNull( asList( object ) ) ); assertNull( Iterables.firstOrNull( asList() ) ); // firstOrNull Iterator assertEquals( object, Iterators.firstOrNull( asList( object, object2 ).iterator() ) ); assertEquals( object, Iterators.firstOrNull( asList( object ).iterator() ) ); assertNull( Iterators.firstOrNull( asList().iterator() ) ); }
private boolean indexExists( Label label ) { try ( Transaction transaction = db.beginTx() ) { Iterable<IndexDefinition> indexes = db.schema().getIndexes( label ); IndexDefinition index = Iterables.firstOrNull( indexes ); boolean exists = index != null; transaction.success(); return exists; } } }
@Test public void shouldCreateSchemaIndex() { // GIVEN String labelName = "person"; String propertyKey = "name"; // WHEN actions.createSchemaIndex( labelName, Arrays.asList( propertyKey ) ); // THEN try ( Transaction transaction = graph.beginTx() ) { Iterable<IndexDefinition> defs = graphdbHelper.getSchemaIndexes( labelName ); assertEquals( 1, Iterables.count( defs ) ); assertEquals( propertyKey, firstOrNull( firstOrNull( defs ).getPropertyKeys() ) ); } }
private Object toPropertyValue(Object value) { if (value instanceof Iterable) { Iterable it = (Iterable) value; Object first = Iterables.firstOrNull(it); if (first==null) return EMPTY_ARRAY; return Iterables.asArray(first.getClass(), it); } return value; }
@Test public void convertConstraintToIndex() { try ( Transaction tx = graphDb.beginTx() ) { graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create(); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { ConstraintDefinition constraint = firstOrNull( graphDb.schema().getConstraints( LABEL ) ); constraint.drop(); graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create(); tx.success(); } // assert no exception is thrown }
@Test public void convertIndexToConstraint() { try ( Transaction tx = graphDb.beginTx() ) { graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create(); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { IndexDefinition index = firstOrNull( graphDb.schema().getIndexes( LABEL ) ); index.drop(); graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create(); tx.success(); } // assert no exception is thrown }
@Test public void convertIndexToConstraintWithExistingData() { try ( Transaction tx = graphDb.beginTx() ) { for ( int i = 0; i < 2000; i++ ) { Node node = graphDb.createNode( LABEL ); node.setProperty( PROPERTY_KEY, i ); } tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create(); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { IndexDefinition index = firstOrNull( graphDb.schema().getIndexes( LABEL ) ); index.drop(); graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create(); tx.success(); } // assert no exception is thrown }
@Test public void shouldGenerateWattsStrogatz3() { db.execute("CALL apoc.generate.ws(null,null,null,'TestLabel','TEST_REL')"); try (Transaction tx = db.beginTx()) { assertEquals(1000, count(db.getAllNodes())); assertEquals(2000, count(db.getAllRelationships())); assertEquals("TestLabel", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("TEST_REL", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("uuid")); tx.success(); } }
@Test public void shouldGenerateSimple1() { db.execute("CALL apoc.generate.simple([2,2,2,2],'TestLabel','TEST_REL')"); try (Transaction tx = db.beginTx()) { assertEquals(4, count(db.getAllNodes())); assertEquals(4, count(db.getAllRelationships())); assertEquals("TestLabel", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("TEST_REL", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("uuid")); tx.success(); } }
@Test public void shouldGenerateErdosRenyi2() { db.execute("CALL apoc.generate.er(null,null,null,null)"); try (Transaction tx = db.beginTx()) { assertEquals(1000, count(db.getAllNodes())); assertEquals(10000, count(db.getAllRelationships())); assertEquals("Person", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("FRIEND_OF", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("name")); tx.success(); } }
@Test public void shouldGenerateComplete1() { db.execute("CALL apoc.generate.complete(10,'TestLabel','TEST_REL')"); try (Transaction tx = db.beginTx()) { assertEquals(10, count(db.getAllNodes())); assertEquals(45, count(db.getAllRelationships())); assertEquals("TestLabel", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("TEST_REL", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("uuid")); tx.success(); } }
@Test public void shouldGenerateBarabasiAlbert1() { db.execute("CALL apoc.generate.ba(100,3,null,null)"); try (Transaction tx = db.beginTx()) { assertEquals(100, count(db.getAllNodes())); assertEquals(294, count(db.getAllRelationships())); assertEquals("Person", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("FRIEND_OF", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("name")); tx.success(); } }
@Test public void shouldGenerateComplete2() { db.execute("CALL apoc.generate.complete(10,null,null)"); try (Transaction tx = db.beginTx()) { assertEquals(10, count(db.getAllNodes())); assertEquals(45, count(db.getAllRelationships())); assertEquals("Person", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("FRIEND_OF", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("name")); tx.success(); } }
@Test public void shouldGenerateBarabasiAlbert3() { db.execute("CALL apoc.generate.ba(null,null,'TestLabel','TEST_REL')"); try (Transaction tx = db.beginTx()) { assertEquals(1000, count(db.getAllNodes())); assertEquals(1997, count(db.getAllRelationships())); assertEquals("TestLabel", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("TEST_REL", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("uuid")); tx.success(); } }
@Test public void shouldGenerateWattsStrogatz1() { db.execute("CALL apoc.generate.ws(100,10,0.5,null,null)"); try (Transaction tx = db.beginTx()) { assertEquals(100, count(db.getAllNodes())); assertEquals(500, count(db.getAllRelationships())); assertEquals("Person", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("FRIEND_OF", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("name")); tx.success(); } }
@Test public void shouldGenerateErdosRenyi3() { db.execute("CALL apoc.generate.er(20,100,'TestLabel','TEST_REL')"); try (Transaction tx = db.beginTx()) { assertEquals(20, count(db.getAllNodes())); assertEquals(100, count(db.getAllRelationships())); assertEquals("TestLabel", firstOrNull(firstOrNull(db.getAllNodes()).getLabels()).name()); assertEquals("TEST_REL", firstOrNull(db.getAllRelationships()).getType().name()); assertTrue(firstOrNull(db.getAllNodes()).hasProperty("uuid")); tx.success(); } }