Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.structure;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.backend.id.EdgeId;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.backend.id.SplicingIdGenerator;
import com.baidu.hugegraph.backend.query.QueryResults;
import com.baidu.hugegraph.backend.serializer.BytesBuffer;
import com.baidu.hugegraph.backend.tx.GraphTransaction;
import com.baidu.hugegraph.perf.PerfUtil.Watched;
import com.baidu.hugegraph.schema.EdgeLabel;
import com.baidu.hugegraph.schema.PropertyKey;
import com.baidu.hugegraph.schema.VertexLabel;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.define.Cardinality;
import com.baidu.hugegraph.type.define.Directions;
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.util.E;
import com.google.common.collect.ImmutableList;
public class HugeEdge extends HugeElement implements Edge, Cloneable {
private Id id;
private EdgeLabel label;
private String name;
private HugeVertex sourceVertex;
private HugeVertex targetVertex;
private boolean isOutEdge;
public HugeEdge(HugeVertex owner, Id id, EdgeLabel label,
HugeVertex other) {
this(owner.graph(), id, label);
this.fresh(true);
this.vertices(owner, other);
}
public HugeEdge(final HugeGraph graph, Id id, EdgeLabel label) {
super(graph);
E.checkArgumentNotNull(label, "Edge label can't be null");
this.label = label;
this.id = id;
this.name = null;
this.sourceVertex = null;
this.targetVertex = null;
this.isOutEdge = true;
}
@Override
public HugeType type() {
// NOTE: we optimize the edge type that let it include direction
return this.isOutEdge ? HugeType.EDGE_OUT : HugeType.EDGE_IN;
}
@Override
public EdgeId id() {
return (EdgeId) this.id;
}
@Override
public EdgeLabel schemaLabel() {
assert this.graph().sameAs(this.label.graph());
return this.label;
}
@Override
public String name() {
if (this.name == null) {
this.name = SplicingIdGenerator.concatValues(sortValues());
}
return this.name;
}
public void name(String name) {
this.name = name;
}
@Override
public String label() {
return this.label.name();
}
public boolean selfLoop() {
return this.sourceVertex != null &&
this.sourceVertex == this.targetVertex;
}
public Directions direction() {
return this.isOutEdge ? Directions.OUT : Directions.IN;
}
public boolean matchDirection(Directions direction) {
if (direction == Directions.BOTH || this.selfLoop()) {
return true;
}
return this.isDirection(direction);
}
public boolean isDirection(Directions direction) {
return this.isOutEdge && direction == Directions.OUT ||
!this.isOutEdge && direction == Directions.IN;
}
@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());
if (this.fresh()) {
int len = this.id.length();
E.checkArgument(len <= BytesBuffer.BIG_ID_LEN_MAX,
"The max length of edge id is %s, but got %s {%s}",
BytesBuffer.BIG_ID_LEN_MAX, len, this.id);
}
}
@Watched(prefix = "edge")
public EdgeId idWithDirection() {
return ((EdgeId) this.id).directed(true);
}
@Watched(prefix = "edge")
public List