Sho SHIMIZU

Refactor: Improve null safety and simplify branch conditioin

Change-Id: I0b8fdf34dcdd1914175ab21f7542d8e85cea7047
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onlab.onos.net.intent.impl; 16 package org.onlab.onos.net.intent.impl;
17 17
18 +import com.google.common.collect.ImmutableList;
18 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
19 import org.apache.felix.scr.annotations.Reference; 20 import org.apache.felix.scr.annotations.Reference;
20 import org.apache.felix.scr.annotations.ReferenceCardinality; 21 import org.apache.felix.scr.annotations.ReferenceCardinality;
...@@ -30,6 +31,7 @@ import org.onlab.onos.net.topology.LinkWeight; ...@@ -30,6 +31,7 @@ import org.onlab.onos.net.topology.LinkWeight;
30 import org.onlab.onos.net.topology.PathService; 31 import org.onlab.onos.net.topology.PathService;
31 import org.onlab.onos.net.topology.TopologyEdge; 32 import org.onlab.onos.net.topology.TopologyEdge;
32 33
34 +import java.util.Collections;
33 import java.util.Iterator; 35 import java.util.Iterator;
34 import java.util.List; 36 import java.util.List;
35 import java.util.Set; 37 import java.util.Set;
...@@ -113,12 +115,16 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> ...@@ -113,12 +115,16 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
113 * @param constraints path constraints 115 * @param constraints path constraints
114 */ 116 */
115 ConstraintBasedLinkWeight(List<Constraint> constraints) { 117 ConstraintBasedLinkWeight(List<Constraint> constraints) {
116 - this.constraints = constraints; 118 + if (constraints == null) {
119 + this.constraints = Collections.emptyList();
120 + } else {
121 + this.constraints = ImmutableList.copyOf(constraints);
122 + }
117 } 123 }
118 124
119 @Override 125 @Override
120 public double weight(TopologyEdge edge) { 126 public double weight(TopologyEdge edge) {
121 - if (constraints == null || !constraints.iterator().hasNext()) { 127 + if (!constraints.iterator().hasNext()) {
122 return 1.0; 128 return 1.0;
123 } 129 }
124 130
......