Implementation of lambda query behaviour for LINC and Calient drivers.

ONOS-3431

Change-Id: I03b7e7c9d2b0ba7e55d09745cfc6ceb57cc6eb5e
diff --git a/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java b/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java
new file mode 100644
index 0000000..e605dcf
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 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.onosproject.net;
+
+import java.util.Comparator;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Comparator implementation for OchSignal. Assumes identical grid type and channel spacing.
+ */
+public class DefaultOchSignalComparator implements Comparator<OchSignal> {
+    @Override
+    public int compare(OchSignal o1, OchSignal o2) {
+        checkNotNull(o1.gridType());
+        checkNotNull(o1.channelSpacing());
+
+        checkArgument(o1.gridType().equals(o2.gridType()));
+        checkArgument(o1.channelSpacing().equals(o2.channelSpacing()));
+
+        return o1.spacingMultiplier() * o1.slotGranularity() - o2.spacingMultiplier() * o2.slotGranularity();
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/OchSignal.java b/core/api/src/main/java/org/onosproject/net/OchSignal.java
index 5a5af34..3adc908 100644
--- a/core/api/src/main/java/org/onosproject/net/OchSignal.java
+++ b/core/api/src/main/java/org/onosproject/net/OchSignal.java
@@ -17,6 +17,7 @@
 
 import com.google.common.base.MoreObjects;
 import org.onlab.util.Frequency;
+import org.onlab.util.Spectrum;
 
 import java.util.Objects;
 
@@ -32,7 +33,6 @@
  */
 public class OchSignal implements Lambda {
 
-    public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1);
     public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
     private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM;
     private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ;
@@ -78,7 +78,7 @@
 
         this.gridType = DEFAULT_OCH_GRIDTYPE;
         this.channelSpacing = DEFAULT_CHANNEL_SPACING;
-        this.spacingMultiplier = (int) (centerFrequency.subtract(OchSignal.CENTER_FREQUENCY).asHz() / grid.asHz());
+        this.spacingMultiplier = (int) (centerFrequency.subtract(Spectrum.CENTER_FREQUENCY).asHz() / grid.asHz());
         this.slotGranularity = (int) Math.round((double) grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz());
     }
 
@@ -86,7 +86,7 @@
         this.gridType = DEFAULT_OCH_GRIDTYPE;
         this.channelSpacing = channelSpacing;
         this.spacingMultiplier = (int) Math.round((double) centerFrequency.
-                subtract(OchSignal.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz());
+                subtract(Spectrum.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz());
         this.slotGranularity = slotGranularity;
     }
 
@@ -132,7 +132,7 @@
      * @return frequency in MHz
      */
     public Frequency centralFrequency() {
-        return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
+        return Spectrum.CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
     }
 
     /**