Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onlab.onos.net; |
| 17 | |
| 18 | /** |
| 19 | * Collection of keys for annotation. |
| 20 | * Definitions of annotation keys needs to be here to avoid scattering. |
| 21 | */ |
| 22 | public final class AnnotationKeys { |
| 23 | |
| 24 | // Prohibit instantiation |
| 25 | private AnnotationKeys() {} |
| 26 | |
| 27 | /** |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 28 | * Annotation key for durable links. |
| 29 | */ |
| 30 | public static final String DURABLE = "durable"; |
| 31 | |
| 32 | /** |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 33 | * Annotation key for latency. |
| 34 | */ |
| 35 | public static final String LATENCY = "latency"; |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
Toshio Koide | 4b6562b | 2014-11-13 17:20:47 -0800 | [diff] [blame] | 38 | * Annotation key for bandwidth. |
| 39 | */ |
| 40 | public static final String BANDWIDTH = "bandwidth"; |
| 41 | |
| 42 | /** |
| 43 | * Annotation key for the number of optical waves. |
| 44 | */ |
| 45 | public static final String OPTICAL_WAVES = "optical.waves"; |
| 46 | |
| 47 | /** |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 48 | * Returns the value annotated object for the specified annotation key. |
| 49 | * The annotated value is expected to be String that can be parsed as double. |
| 50 | * If parsing fails, the returned value will be 1.0. |
| 51 | * |
| 52 | * @param annotated annotated object whose annotated value is obtained |
| 53 | * @param key key of annotation |
| 54 | * @return double value of annotated object for the specified key |
| 55 | */ |
| 56 | public static double getAnnotatedValue(Annotated annotated, String key) { |
| 57 | double value; |
| 58 | try { |
| 59 | value = Double.parseDouble(annotated.annotations().value(key)); |
| 60 | } catch (NumberFormatException e) { |
| 61 | value = 1.0; |
| 62 | } |
| 63 | return value; |
| 64 | } |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 65 | } |