public EdgeId directed(boolean directed) { return new EdgeId(this.ownerVertexId, this.direction, this.edgeLabelId, this.sortValues, this.otherVertexId, directed); }
public EdgeId switchDirection() { Directions direction = this.direction.opposite(); return new EdgeId(this.otherVertexId, direction, this.edgeLabelId, this.sortValues, this.ownerVertexId, this.directed); }
@Test public void testCollectionContainsEdgeIdWithDirection() { EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true); Set<Id> edgeIds = ImmutableSet.of(edgeId1); Assert.assertTrue(edgeIds.contains(edgeId1)); EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true); Assert.assertTrue(edgeIds.contains(edgeId2)); EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko"), true); Assert.assertFalse(edgeIds.contains(edgeId3)); } }
@Test public void testCollectionContainsEdgeId() { EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh")); Set<Id> edgeIds = ImmutableSet.of(edgeId1); Assert.assertTrue(edgeIds.contains(edgeId1)); EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh")); Assert.assertTrue(edgeIds.contains(edgeId2)); EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko")); Assert.assertTrue(edgeIds.contains(edgeId3)); }
public static EdgeId parse(String id) throws NotFoundException { String[] idParts = SplicingIdGenerator.split(id); if (!(idParts.length == 4 || idParts.length == 5)) { throw new NotFoundException("Edge id must be formatted as 4~5 parts" + ", but got '%s'", id); } try { if (idParts.length == 4) { Id ownerVertexId = IdUtil.readString(idParts[0]); Id edgeLabelId = IdGenerator.of(Long.parseLong(idParts[1])); String sortValues = idParts[2]; Id otherVertexId = IdUtil.readString(idParts[3]); return new EdgeId(ownerVertexId, Directions.OUT, edgeLabelId, sortValues, otherVertexId); } else { assert idParts.length == 5; Id ownerVertexId = IdUtil.readString(idParts[0]); HugeType direction = HugeType.fromString(idParts[1]); Id edgeLabelId = IdGenerator.of(Long.parseLong(idParts[2])); String sortValues = idParts[3]; Id otherVertexId = IdUtil.readString(idParts[4]); return new EdgeId(ownerVertexId, Directions.convert(direction), edgeLabelId, sortValues, otherVertexId); } } catch (Exception e) { throw new NotFoundException("Invalid format of edge id '%s'", id); } }
@Test public void testEdgeIdEqual() { EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh")); EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh")); EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko")); Assert.assertTrue(edgeId1.equals(edgeId2)); Assert.assertTrue(edgeId2.equals(edgeId1)); Assert.assertTrue(edgeId1.equals(edgeId3)); Assert.assertTrue(edgeId3.equals(edgeId1)); }
@Test public void testEdgeIdEqualWithDirection() { EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true); EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true); EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko"), true); Assert.assertTrue(edgeId1.equals(edgeId2)); Assert.assertTrue(edgeId2.equals(edgeId1)); Assert.assertFalse(edgeId1.equals(edgeId3)); Assert.assertFalse(edgeId3.equals(edgeId1)); }
@Watched(prefix = "edge") public void assignId() { // Generate an id and assign this.id = new EdgeId(this.ownerVertex(), this.direction(), this.schemaLabel().id(), this.name(), this.otherVertex()); int len = this.id.length(); E.checkArgument(len <= BytesBuffer.BIG_ID_MAX_LEN, "The max length of edge id is %s, but got %s {%s}", BytesBuffer.BIG_ID_MAX_LEN, len, this.id); }
public EdgeId directed(boolean directed) { return new EdgeId(this.ownerVertexId, this.direction, this.edgeLabelId, this.sortValues, this.otherVertexId, directed); }
public EdgeId switchDirection() { Directions direction = this.direction.opposite(); return new EdgeId(this.otherVertexId, direction, this.edgeLabelId, this.sortValues, this.ownerVertexId, this.directed); }
public static EdgeId parse(String id) throws NotFoundException { String[] idParts = SplicingIdGenerator.split(id); if (!(idParts.length == 4 || idParts.length == 5)) { throw new NotFoundException("Edge id must be formatted as 4~5 parts" + ", but got '%s'", id); } try { if (idParts.length == 4) { Id ownerVertexId = IdUtil.readString(idParts[0]); Id edgeLabelId = IdGenerator.of(Long.parseLong(idParts[1])); String sortValues = idParts[2]; Id otherVertexId = IdUtil.readString(idParts[3]); return new EdgeId(ownerVertexId, Directions.OUT, edgeLabelId, sortValues, otherVertexId); } else { assert idParts.length == 5; Id ownerVertexId = IdUtil.readString(idParts[0]); HugeType direction = HugeType.fromString(idParts[1]); Id edgeLabelId = IdGenerator.of(Long.parseLong(idParts[2])); String sortValues = idParts[3]; Id otherVertexId = IdUtil.readString(idParts[4]); return new EdgeId(ownerVertexId, Directions.convert(direction), edgeLabelId, sortValues, otherVertexId); } } catch (Exception e) { throw new NotFoundException("Invalid format of edge id '%s'", id); } }
@Watched(prefix = "edge") public void assignId() { // Generate an id and assign this.id = new EdgeId(this.ownerVertex(), this.direction(), this.schemaLabel().id(), this.name(), this.otherVertex()); int len = this.id.length(); E.checkArgument(len <= BytesBuffer.BIG_ID_MAX_LEN, "The max length of edge id is %s, but got %s {%s}", BytesBuffer.BIG_ID_MAX_LEN, len, this.id); }