Add missing license headers in alto-commons
[alto.git] / alto-commons / src / main / java / org / opendaylight / alto / commons / types / converter / RFC2ModelCostMapConverter.java
1 /*
2  * Copyright (c) 2015 Yale University and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.alto.commons.types.converter;
10
11 import java.util.LinkedList;
12
13 import org.opendaylight.alto.commons.helper.Converter;
14 import org.opendaylight.alto.commons.types.model150404.ModelCostMap;
15 import org.opendaylight.alto.commons.types.model150404.ModelCostMapData;
16 import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
17
18 public class RFC2ModelCostMapConverter
19     extends Converter<RFC7285CostMap, ModelCostMap>{
20
21   protected RFC2ModelCostMapMetaConverter metaConv = new RFC2ModelCostMapMetaConverter();
22   protected RFC2ModelCostMapDataConverter dataConv = new RFC2ModelCostMapDataConverter();
23
24   public RFC2ModelCostMapConverter() {
25   }
26
27   public RFC2ModelCostMapConverter(RFC7285CostMap _in) {
28       super(_in);
29   }
30
31   @Override
32   protected Object _convert() {
33     ModelCostMap out = new ModelCostMap();
34     out.rid = getCostMapResourceId(in());
35     //TODO: replace the dummy one in the future
36     out.tag = "da65eca2eb7a10ce8b059740b0b2e3f8eb1d4786";
37
38     out.meta = metaConv.convert(in().meta);
39     out.map = new LinkedList<ModelCostMapData>();
40     for (String src : in().map.keySet()) {
41       ModelCostMapData data = new ModelCostMapData();
42       data.src = src;
43       data.dstCosts = dataConv.convert(in().map.get(src));
44       out.map.add(data);
45     }
46     return out;
47   }
48
49   private String getCostMapResourceId(RFC7285CostMap costMap) {
50     String networkMapRID = costMap.meta.netmap_tags.get(0).rid;
51     String costMetric = costMap.meta.costType.metric;
52     String costMode = costMap.meta.costType.mode;
53     return networkMapRID + "-" + costMetric + "-" + costMode;
54   }
55 }