Minor improvements around Scalar weight.
- ScalarWeight should be immutable
- Added constant for default weights
- Added factory method
Change-Id: I700e89abe968838a5049a441c37a92ffdb63f1bc
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java
index 43923b5..74e94b1 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java
@@ -193,7 +193,7 @@
Iterator<Constraint> it = constraints.iterator();
if (!it.hasNext()) {
- return new ScalarWeight(HOP_WEIGHT_VALUE);
+ return DEFAULT_HOP_WEIGHT;
}
double cost = it.next().cost(edge.link(), resourceService::isAvailable);
diff --git a/utils/misc/src/main/java/org/onlab/graph/DefaultEdgeWeigher.java b/utils/misc/src/main/java/org/onlab/graph/DefaultEdgeWeigher.java
index e280391..b723e0e 100644
--- a/utils/misc/src/main/java/org/onlab/graph/DefaultEdgeWeigher.java
+++ b/utils/misc/src/main/java/org/onlab/graph/DefaultEdgeWeigher.java
@@ -36,14 +36,28 @@
*/
protected static final double NULL_WEIGHT_VALUE = 0;
+ /**
+ * Default weight based on hop count.
+ * {@value #HOP_WEIGHT_VALUE}
+ */
+ public static final ScalarWeight DEFAULT_HOP_WEIGHT =
+ new ScalarWeight(HOP_WEIGHT_VALUE);
+
+ /**
+ * Default initial weight.
+ * {@value #NULL_WEIGHT_VALUE}
+ */
+ public static final ScalarWeight DEFAULT_INITIAL_WEIGHT =
+ new ScalarWeight(NULL_WEIGHT_VALUE);
+
@Override
public Weight weight(E edge) {
- return new ScalarWeight(HOP_WEIGHT_VALUE);
+ return DEFAULT_HOP_WEIGHT;
}
@Override
public Weight getInitialWeight() {
- return new ScalarWeight(NULL_WEIGHT_VALUE);
+ return DEFAULT_INITIAL_WEIGHT;
}
@Override
diff --git a/utils/misc/src/main/java/org/onlab/graph/ScalarWeight.java b/utils/misc/src/main/java/org/onlab/graph/ScalarWeight.java
index f82bb3a..5c08b7b 100644
--- a/utils/misc/src/main/java/org/onlab/graph/ScalarWeight.java
+++ b/utils/misc/src/main/java/org/onlab/graph/ScalarWeight.java
@@ -36,7 +36,16 @@
private static double samenessThreshold = Double.MIN_VALUE;
- private double value;
+ private final double value;
+
+ /**
+ * Creates a new scalar weight with the given double value.
+ * @param value double value
+ * @return scalar weight instance
+ */
+ public static ScalarWeight toWeight(double value) {
+ return new ScalarWeight(value);
+ }
/**
* Creates a new scalar weight with the given double value.