本文整理汇总了Java中org.neo4j.helpers.collection.IteratorUtil类的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtil类的具体用法?Java IteratorUtil怎么用?Java IteratorUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IteratorUtil类属于org.neo4j.helpers.collection包,在下文中一共展示了IteratorUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createVertex
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Override
public Vertex createVertex(long id, int weight) {
Vertex v = null;
try {
beginTransaction();
Result result = graphDb.execute("MERGE (a:NODE{INDEX:" + id + "}) RETURN a");
Iterator<Node> n_column = result.columnAs("a");
Node node = null;
for (Node n : IteratorUtil.asIterable(n_column)) {
node = n;
}
node.setProperty(NetworkNeo4jProperties.WEIGHT, weight);
node.setProperty(NetworkNeo4jProperties.LEVEL, (int) 0);
v = new Vertex(id, weight);
} finally {
endTransaction();
}
return v;
}
示例2: edgeExist
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Override
public boolean edgeExist(long id1, long id2) {
boolean res = false;
try {
beginTransaction();
Result result = graphDb.execute("MATCH (a:NODE{INDEX:" + String.valueOf(id1) + "})-[r:LINK]-(b:NODE{INDEX:" + String.valueOf(id2) + "}) RETURN r LIMIT 1");
Relationship rel_result = null;
Iterator<Relationship> n_column = result.columnAs("r");
for (Relationship rel : IteratorUtil.asIterable(n_column)) {
rel_result = rel;
}
if (rel_result != null) {
res = false;
}
} finally {
endTransaction();
}
return res;
}
示例3: getNumVertexWithoutPartition
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Override
public int getNumVertexWithoutPartition() {
int num = 0;
try {
beginTransaction();
Result result = graphDb.execute("MATCH (n:NODE) WHERE n.PARTITION IS NULL RETURN n");
Iterator<Integer> list = result.columnAs("n");
num = IteratorUtil.count(list);
} finally {
endTransaction();
}
return num;//IteratorUtil.count(list);
}
示例4: singleIndexId
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
private int singleIndexId( File luceneRootDirectory )
{
List<Integer> indexIds = new ArrayList<>();
for ( String file : luceneRootDirectory.list() )
{
try
{
indexIds.add( Integer.parseInt( file ) );
}
catch ( NumberFormatException e )
{
// do nothing
}
}
return IteratorUtil.single( indexIds );
}
示例5: matchesSafely
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Override
public boolean matchesSafely( IndexHits<T> indexHits )
{
Collection<T> collection = IteratorUtil.asCollection( indexHits.iterator() );
if ( expectedItems.length != collection.size() )
{
message = "IndexHits with a size of " + expectedItems.length + ", got one with " + collection.size();
message += collection.toString();
return false;
}
for ( T item : expectedItems )
{
if ( !collection.contains( item ) )
{
message = "Item (" + item + ") not found.";
return false;
}
}
return true;
}
示例6: shouldFindAllLabelsForGivenNode
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Test
public void shouldFindAllLabelsForGivenNode() throws Exception
{
// GIVEN
// 16 is the magic number of the page iterator
// 32 is the number of nodes in each lucene document
final long labelId1 = 1, labelId2 = 2, labelId3 = 87;
start();
int nodeId = 42;
write( IteratorUtil.iterator( labelChanges( nodeId, NO_LABELS, new long[]{labelId1, labelId2} ) ) );
write( IteratorUtil.iterator( labelChanges( 41, NO_LABELS, new long[]{labelId3, labelId2} ) ) );
// WHEN
LabelScanReader reader = store.newReader();
// THEN
assertThat( asSet( reader.labelsForNode( nodeId ) ), hasItems(labelId1, labelId2) );
reader.close();
}
示例7: shouldIterateOverAllLuceneDocumentsWhereNoDocumentsHaveBeenDeleted
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Test
public void shouldIterateOverAllLuceneDocumentsWhereNoDocumentsHaveBeenDeleted() throws Exception
{
// given
String[] elements = {"A", "B", "C"};
LuceneAllDocumentsReader reader =
new LuceneAllDocumentsReader(
new SearcherManagerStub( new SearcherStub( new IndexReaderStub( false, elements ), elements )
) );
// when
Iterator<Document> iterator = reader.iterator();
List<Document> actualDocuments = new ArrayList<>( IteratorUtil.asCollection( iterator ) );
// then
for ( int i = 0; i < elements.length; i++ )
{
assertEquals( elements[i], actualDocuments.get( i ).get( "element" ) );
}
}
示例8: shouldFindCorrectNodesUsingIndexedPropertyLookup
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Test
public void shouldFindCorrectNodesUsingIndexedPropertyLookup() throws Exception
{
try ( Transaction tx = db.beginTx() )
{
assertEquals( IteratorUtil.<Integer>asSet(),
externalIds( db.findNodes( label( "Person" ), "age", 0 ) ) );
assertEquals( asSet( 0 ),
externalIds( db.findNodes( label( "Person" ), "age", 1 ) ) );
assertEquals( asSet( 1, 4 ),
externalIds( db.findNodes( label( "Person" ), "age", 2 ) ) );
assertEquals( asSet( 2, 5, 7 ),
externalIds( db.findNodes( label( "Person" ), "age", 3 ) ) );
assertEquals( asSet( 3, 6, 8, 9 ),
externalIds( db.findNodes( label( "Person" ), "age", 4 ) ) );
tx.success();
}
}
示例9: egoMinusEgo
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Test
public void egoMinusEgo() {
try (Transaction tx = db.beginTx()) {
Demon demon = new Demon(db);
Node root = nodes.get(0);
demon.executeEgoMinusEgo(root);
ResourceIterator<Node> demonNodes = demon.getDemonNodes();
Iterator<Relationship> demonRelationships = demon.getDemonRelationships();
int neighCount = 0;
while (demonNodes.hasNext()) {
demonNodes.next();
neighCount++;
}
Assert.assertEquals(5, neighCount);
int relCount = IteratorUtil.asList(demonRelationships).size();
Assert.assertEquals(2, relCount);
demon.clearEgoNetwork(root);
}
}
示例10: getAllFriends
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
public List<String> getAllFriends(String userId){
ExecutionResult result0 = engine
.execute("start node=node:nodes(userId = '" + userId + "') "
+ "match node-[:FRIEND_OF]->deg0 " + "return deg0");
List<String> deg0Nodes = new ArrayList<String>();
Iterator<Node> n_column = result0.columnAs("deg0");
for (Node node : IteratorUtil.asIterable(n_column)) {
String nodeResult = null;
try ( Transaction tx = graphDb.beginTx() ){
nodeResult = node.getProperty(USER_ID).toString();
tx.success();
}
deg0Nodes.add(nodeResult);
}
return deg0Nodes;
}
示例11: getAllFriends
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
public List<String> getAllFriends(String userId) {
ExecutionEngine engine = new ExecutionEngine(graphDb);
ExecutionResult result0 = engine
.execute("start node=node:nodes(message = '" + userId + "') "
+ "match node-[:KNOWS]->deg0 " + "return deg0");
List<String> deg0Nodes = new ArrayList<String>();
Iterator<Node> n_column = result0.columnAs("deg0");
for (Node node : IteratorUtil.asIterable(n_column)) {
String nodeResult = node.getProperty("message").toString();
deg0Nodes.add(nodeResult);
}
return deg0Nodes;
}
示例12: createIdentity
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@POST
@Path("/identity")
public Response createIdentity(@DefaultValue("") @QueryParam("email") String email,
@DefaultValue("") @QueryParam("md5hash") String hash,
@Context GraphDatabaseService db) throws IOException {
hash = Identity.getHash(email, hash);
try ( Transaction tx = db.beginTx() ) {
Node identity = IteratorUtil.singleOrNull(
db.findNodesByLabelAndProperty(Labels.Identity, "hash", hash));
if (identity == null) {
identity = db.createNode(Labels.Identity);
identity.setProperty("hash", hash);
}
tx.success();
} catch (Throwable t) {
// If it is not a duplicate, then something bad happened
if (!(t instanceof ConstraintViolationException)){
throw Exception.identityNotCreated;
}
}
return Response.ok().build();
}
示例13: createPage
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@POST
@Path("/page")
public Response createPage(@DefaultValue("") @QueryParam("url") String url,
@Context GraphDatabaseService db) throws IOException {
url = Page.getPageURL(url);
try ( Transaction tx = db.beginTx() ) {
Node page = IteratorUtil.singleOrNull(
db.findNodesByLabelAndProperty(Labels.Page, "url", url));
if (page == null) {
page = db.createNode(Labels.Page);
page.setProperty("url", url);
}
tx.success();
} catch (Throwable t) {
// If it is not a duplicate, then something bad happened
if (!(t instanceof ConstraintViolationException)){
throw Exception.pageNotCreated;
}
}
return Response.ok().build();
}
示例14: getUserFOFs
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@GET
@Path("/user/{username}/fofs")
public Response getUserFOFs(@PathParam("username") String username, @Context GraphDatabaseService db) throws IOException {
List<Map<String, Object>> results = new ArrayList<>();
HashMap<Node, int[]> fofs = new HashMap<>();
try ( Transaction tx = db.beginTx() )
{
final Node user = IteratorUtil.singleOrNull(db.findNodesByLabelAndProperty(Labels.User, "username", username));
findFofs(fofs, user);
List<Map.Entry<Node, int[]>> fofList = orderFofs(fofs);
returnFofs(results, fofList.subList(0, Math.min(fofList.size(), 10)));
}
return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
示例15: getNodeCount
import org.neo4j.helpers.collection.IteratorUtil; //导入依赖的package包/类
@Override
public int getNodeCount()
{
int nodeCount = 0;
try (final Transaction tx = beginUnforcedTransaction())
{
try
{
nodeCount = IteratorUtil.count(GlobalGraphOperations.at(neo4jGraph).getAllNodes());
tx.success();
}
catch (Exception e)
{
tx.failure();
throw new BenchmarkingException("unable to get node count", e);
}
}
return nodeCount;
}