change roadm app to support EDFA/ROADM/OPS devices, add OPS PowerConfig/LambdaQuery behaviour
Change-Id: Ieb6de727e766fdeb63740c0704f83fd11e44b935
diff --git a/apps/roadm/src/main/java/org/onosproject/roadm/RoadmUtil.java b/apps/roadm/src/main/java/org/onosproject/roadm/RoadmUtil.java
new file mode 100644
index 0000000..d125c77
--- /dev/null
+++ b/apps/roadm/src/main/java/org/onosproject/roadm/RoadmUtil.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016-present 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.roadm;
+
+import org.onlab.util.Frequency;
+import org.onosproject.net.Annotations;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+
+/**
+ * Roadm utilities.
+ */
+public final class RoadmUtil {
+
+ public static final String DEV_ID = "devId";
+ public static final String VALID = "valid";
+ public static final String MESSAGE = "message";
+ public static final String NA = "N/A";
+ public static final String UNKNOWN = "Unknown";
+ public static final String NONE = "(none)";
+ public static final String NO_ROWS_MESSAGE = "No items found";
+
+ public static final long GHZ = 1_000_000_000L;
+ public static final long THZ = 1_000_000_000_000L;
+
+ private RoadmUtil() {
+ }
+
+ /**
+ * Formats Hz to GHz.
+ *
+ * @param value Hz in string format
+ * @return GHz in string format
+ */
+ public static String asGHz(Frequency value) {
+ return value == null ? UNKNOWN : String.valueOf((double) value.asHz() / GHZ);
+ }
+
+ /**
+ * Formats Hz to THz.
+ *
+ * @param value Hz in string format
+ * @return THz in string format
+ */
+ public static String asTHz(Frequency value) {
+ return value == null ? UNKNOWN : String.valueOf((double) value.asHz() / THZ);
+ }
+
+ /**
+ * Gives a default value if the string is null or empty.
+ *
+ * @param value the string value
+ * @param defaultValue default value if null or empty
+ * @return processed string
+ */
+ public static String defaultString(String value, String defaultValue) {
+ return isNullOrEmpty(value) ? defaultValue : value;
+ }
+
+ /**
+ * Gives a default value if the object is null.
+ *
+ * @param object the object
+ * @param defaultValue default value if null
+ * @return processed string
+ */
+ public static String objectToString(Object object, String defaultValue) {
+ return object == null ? defaultValue : String.valueOf(object);
+ }
+
+ /**
+ * Gets value from annotations, if not exists, return default value.
+ *
+ * @param annotations the annotations
+ * @param key key value
+ * @param defaultValue default value
+ * @return value in string format
+ */
+ public static String getAnnotation(Annotations annotations, String key, String defaultValue) {
+ return defaultString(annotations.value(key), defaultValue);
+ }
+
+ /**
+ * Gets value from annotations, default value is NA.
+ *
+ * @param annotations the annotations
+ * @param key key value
+ * @return value in string format
+ */
+ public static String getAnnotation(Annotations annotations, String key) {
+ return getAnnotation(annotations, key, NA);
+ }
+}
\ No newline at end of file