Skip to content
Permalink
Browse files
add createId methods in GraphFactory (#45)
  • Loading branch information
houzhizhen committed May 8, 2021
1 parent c9e5ef4 commit b666ff2807499f5f7f0d3163a04257bba9bacca5
Showing 4 changed files with 89 additions and 0 deletions.
@@ -21,6 +21,7 @@

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.baidu.hugegraph.computer.core.graph.edge.Edge;
import com.baidu.hugegraph.computer.core.graph.edge.Edges;
@@ -31,6 +32,12 @@

public interface GraphFactory {

Id createId(long id);

Id createId(String id);

Id createId(UUID id);

Vertex createVertex();

<V extends Value<?>> Vertex createVertex(Id id, V value);
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.config.Config;
@@ -31,6 +32,9 @@
import com.baidu.hugegraph.computer.core.graph.edge.Edge;
import com.baidu.hugegraph.computer.core.graph.edge.Edges;
import com.baidu.hugegraph.computer.core.graph.id.Id;
import com.baidu.hugegraph.computer.core.graph.id.LongId;
import com.baidu.hugegraph.computer.core.graph.id.Utf8Id;
import com.baidu.hugegraph.computer.core.graph.id.UuidId;
import com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties;
import com.baidu.hugegraph.computer.core.graph.properties.Properties;
import com.baidu.hugegraph.computer.core.graph.value.Value;
@@ -45,6 +49,21 @@ public BuiltinGraphFactory(Config config) {
this.config = config;
}

@Override
public Id createId(long id) {
return new LongId(id);
}

@Override
public Id createId(String id) {
return new Utf8Id(id);
}

@Override
public Id createId(UUID id) {
return new UuidId(id);
}

@Override
public Vertex createVertex() {
return new DefaultVertex(this);
@@ -0,0 +1,62 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.computer.core.graph;

import java.util.UUID;

import org.junit.Assert;
import org.junit.Test;

import com.baidu.hugegraph.computer.core.UnitTestBase;
import com.baidu.hugegraph.computer.core.graph.id.Id;
import com.baidu.hugegraph.computer.core.graph.id.IdType;
import com.baidu.hugegraph.computer.core.graph.id.LongId;
import com.baidu.hugegraph.computer.core.graph.id.Utf8Id;
import com.baidu.hugegraph.computer.core.graph.id.UuidId;

public class BuiltinGraphFactoryTest extends UnitTestBase {

@Test
public void testCreateLongId() {
long value = 1L;
GraphFactory graphFactory = graphFactory();
Id id = graphFactory.createId(value);
Assert.assertEquals(IdType.LONG, id.type());
Assert.assertEquals(new LongId(value), id);
}

@Test
public void testCreateUtf8Id() {
String value = "John";
GraphFactory graphFactory = graphFactory();
Id id = graphFactory.createId(value);
Assert.assertEquals(IdType.UTF8, id.type());
Assert.assertEquals(new Utf8Id(value), id);
}

@Test
public void testCreateUuidId() {
UUID uuid = UUID.randomUUID();
GraphFactory graphFactory = graphFactory();
Id id = graphFactory.createId(uuid);
Assert.assertEquals(IdType.UUID, id.type());
Assert.assertEquals(new UuidId(uuid), id);
}
}
@@ -63,6 +63,7 @@
ListValueTest.class,
ValueTypeTest.class,
BuiltinValueFactoryTest.class,
BuiltinGraphFactoryTest.class,
ContainerInfoTest.class,
PartitionStatTest.class,
HashPartitionerTest.class,

0 comments on commit b666ff2

Please sign in to comment.