本文整理汇总了Java中org.hypergraphdb.HyperNode类的典型用法代码示例。如果您正苦于以下问题:Java HyperNode类的具体用法?Java HyperNode怎么用?Java HyperNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HyperNode类属于org.hypergraphdb包,在下文中一共展示了HyperNode类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHyperNode
import org.hypergraphdb.HyperNode; //导入依赖的package包/类
@Test
public void testHyperNode() throws Throwable
{
while (peer2.getConnectedPeers().isEmpty())
Thread.sleep(500);
HyperNode node = new PeerHyperNode(peer1, peer2.getIdentity());
HGHandle stringType = graph1.getTypeSystem().getTypeHandle(String.class);
HGHandle beanType = graph1.getTypeSystem().getTypeHandle(ComplexBean.class);
HGHandle intType = graph1.getTypeSystem().getTypeHandle(Integer.class);
HGHandle listType = graph1.getTypeSystem().getTypeHandle(ArrayList.class);
HGHandle x1 = node.add("Hello World", stringType, 0);
HGHandle x2 = graph1.getHandleFactory().makeHandle();
ComplexBean complexBean = new ComplexBean();
complexBean.setStableField("HYPERNODE");
complexBean.setStableNested(new SimpleBean());
node.define(x2, beanType, complexBean, 0);
HGHandle toBeRemoved = node.add(10, intType, 0);
HGHandle toBeReplaced = node.add(Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6 }), listType, 0);
ArrayList<Integer> ints = new ArrayList<Integer>();
for (int i = 0; i < 37; i++)
{
ints.add(i);
node.add(i, intType, 0);
}
node.replace(toBeReplaced, ints, listType);
Assert.assertTrue(node.remove(toBeRemoved));
Assert.assertEquals(node.count(hg.eq(10)), 1);
Assert.assertEquals(node.get(x1), "Hello World");
Assert.assertEquals(node.get(x2), complexBean);
HGSearchResult<HGHandle> rs = node.find(hg.type(intType));
Set<Integer> intSet = new HashSet<Integer>();
intSet.addAll(ints);
ArrayList<HGHandle> intHandles = new ArrayList<HGHandle>();
while (rs.hasNext())
{
Assert.assertTrue(intSet.contains(node.get(rs.next())));
intSet.remove(node.get(rs.current()));
intHandles.add(rs.current());
if (rs.hasPrev())
{
rs.prev();
rs.next();
}
}
rs.close();
Assert.assertTrue(intSet.isEmpty());
Set<HGHandle> expected = new HashSet<HGHandle>();
expected.addAll((List<HGHandle>)(List)node.findAll(hg.type(intType)));
Set<HGHandle> actual = new HashSet<HGHandle>();
actual.addAll(intHandles);
Assert.assertEquals(expected, actual);
Set<Integer> expectedValues = new HashSet<Integer>();
expectedValues.addAll((List<Integer>)(List)node.getAll(hg.type(intType)));
Set<Integer> actualValues = new HashSet<Integer>();
actualValues.addAll(ints);
Assert.assertEquals(expectedValues, actualValues);
Assert.assertEquals(node.get(toBeReplaced), ints);
}
示例2: HGAtomResolver
import org.hypergraphdb.HyperNode; //导入依赖的package包/类
public HGAtomResolver(HyperNode graph)
{
this.node = graph;
}