Merge "Aggregate definition of annotation key for latency into a single file"
diff --git a/core/api/src/main/java/org/onlab/onos/net/AnnotationKeys.java b/core/api/src/main/java/org/onlab/onos/net/AnnotationKeys.java
new file mode 100644
index 0000000..eace91c
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/AnnotationKeys.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed 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 org.onlab.onos.net;
+
+/**
+ * Collection of keys for annotation.
+ * Definitions of annotation keys needs to be here to avoid scattering.
+ */
+public final class AnnotationKeys {
+
+    // Prohibit instantiation
+    private AnnotationKeys() {}
+
+    /**
+     * Annotation key for latency.
+     */
+    public static final String LATENCY = "latency";
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/constraint/LatencyConstraint.java b/core/api/src/main/java/org/onlab/onos/net/intent/constraint/LatencyConstraint.java
index fcdf330..45151ef 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/constraint/LatencyConstraint.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/constraint/LatencyConstraint.java
@@ -25,14 +25,13 @@
 import java.time.temporal.ChronoUnit;
 import java.util.Objects;
 
+import static org.onlab.onos.net.AnnotationKeys.LATENCY;
+
 /**
  * Constraint that evaluates the latency through a path.
  */
 public class LatencyConstraint implements Constraint {
 
-    // TODO: formalize the key for latency all over the codes.
-    private static final String LATENCY_KEY = "latency";
-
     private final Duration latency;
 
     /**
@@ -49,7 +48,7 @@
 
     @Override
     public double cost(Link link, LinkResourceService resourceService) {
-        String value = link.annotations().value(LATENCY_KEY);
+        String value = link.annotations().value(LATENCY);
 
         double latencyInMicroSec;
         try {
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/constraint/LatencyConstraintTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/constraint/LatencyConstraintTest.java
index b9fa3ee..d1a280c 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/constraint/LatencyConstraintTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/constraint/LatencyConstraintTest.java
@@ -37,6 +37,7 @@
 import static org.hamcrest.Matchers.closeTo;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
+import static org.onlab.onos.net.AnnotationKeys.LATENCY;
 import static org.onlab.onos.net.DefaultLinkTest.cp;
 import static org.onlab.onos.net.DeviceId.deviceId;
 import static org.onlab.onos.net.Link.Type.DIRECT;
@@ -51,7 +52,6 @@
     private static final PortNumber PN3 = PortNumber.portNumber(3);
     private static final PortNumber PN4 = PortNumber.portNumber(4);
     private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
-    private static final String LATENCY_KEY = "latency";
     private static final String LATENCY1 = "3.0";
     private static final String LATENCY2 = "4.0";
 
@@ -66,8 +66,8 @@
     public void setUp() {
         linkResourceService = createMock(LinkResourceService.class);
 
-        Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY_KEY, LATENCY1).build();
-        Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY_KEY, LATENCY2).build();
+        Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
+        Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
 
         link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1);
         link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2);