Skip to content

Commit

Permalink
chore use utils tools to convert to double type
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Apr 29, 2021
1 parent f49bb9d commit 2c18d6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public static class Step {
public Step(HugeGraph g, Directions direction, List<String> labels,
long degree, long skipDegree, int top, int capacity) {
E.checkArgument(top > 0 && top <= MAX_TOP,
"The top of each layer must be in (0, %s]",
MAX_TOP);
"The top of each layer must be in (0, %s], but " +
"got %s", MAX_TOP, top);
E.checkArgument(capacity > 0,
"The capacity of each layer must be > 0, " +
"but got %s", capacity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.baidu.hugegraph.util.CollectionUtil;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.InsertionOrderUtil;
import com.baidu.hugegraph.util.NumericUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

Expand Down Expand Up @@ -122,7 +123,7 @@ public Traverser(Id sourceV, Directions dir, Id label, String weight,
long limit) {
this.source = sourceV;
this.sources = ImmutableSet.of(new NodeWithWeight(
0D, new Node(sourceV, null)));
0D, new Node(sourceV, null)));
this.direction = dir;
this.label = label;
this.weight = weight;
Expand Down Expand Up @@ -155,7 +156,8 @@ public void forward() {

double currentWeight = this.edgeWeight(edge);
double weight = currentWeight + node.weight();
NodeWithWeight nw = new NodeWithWeight(weight, target, node);
NodeWithWeight nw =
new NodeWithWeight(weight, target, node);
NodeWithWeight exist = this.findingNodes.get(target);
if (exist == null || weight < exist.weight()) {
/*
Expand All @@ -170,7 +172,7 @@ public void forward() {
}

Map<Id, NodeWithWeight> sorted = CollectionUtil.sortByValue(
this.findingNodes, true);
this.findingNodes, true);
double minWeight = 0;
Set<NodeWithWeight> newSources = InsertionOrderUtil.newSet();
for (Map.Entry<Id, NodeWithWeight> entry : sorted.entrySet()) {
Expand Down Expand Up @@ -212,19 +214,12 @@ private double edgeWeight(HugeEdge edge) {
!edge.property(this.weight).isPresent()) {
edgeWeight = 1.0;
} else {
edgeWeight = this.toDouble(edge.value(this.weight));
edgeWeight = NumericUtil.convertToNumber(
edge.value(this.weight)).doubleValue();
}
return edgeWeight;
}

private double toDouble(Object obj) {
if (obj instanceof Number) {
return ((Number) obj).doubleValue();
}

return (double) obj;
}

private Iterator<Edge> skipSuperNodeIfNeeded(Iterator<Edge> edges) {
if (this.skipDegree <= 0L) {
return edges;
Expand Down Expand Up @@ -277,7 +272,8 @@ public int compareTo(NodeWithWeight other) {
}
}

public static class WeightedPaths extends LinkedHashMap<Id, NodeWithWeight> {
public static class WeightedPaths extends
LinkedHashMap<Id, NodeWithWeight> {

private static final long serialVersionUID = -313873642177730993L;

Expand Down

0 comments on commit 2c18d6d

Please sign in to comment.