remove unnecessary cast
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronLoadBalancerInterface.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, Inc. 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.neutron.transcriber;
10
11 import java.util.List;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.neutron.spi.INeutronLoadBalancerCRUD;
14 import org.opendaylight.neutron.spi.NeutronLoadBalancer;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.Loadbalancers;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.loadbalancers.Loadbalancer;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.loadbalancers.LoadbalancerBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.loadbalancers.LoadbalancerKey;
20
21 public final class NeutronLoadBalancerInterface
22         extends AbstractNeutronInterface<Loadbalancer, Loadbalancers, LoadbalancerKey, NeutronLoadBalancer>
23         implements INeutronLoadBalancerCRUD {
24     NeutronLoadBalancerInterface(DataBroker db) {
25         super(LoadbalancerBuilder.class, db);
26     }
27
28     @Override
29     protected List<Loadbalancer> getDataObjectList(Loadbalancers lbs) {
30         return lbs.getLoadbalancer();
31     }
32
33     @Override
34     protected NeutronLoadBalancer fromMd(Loadbalancer loadBalancer) {
35         final NeutronLoadBalancer answer = new NeutronLoadBalancer();
36         fromMdAdminAttributes(loadBalancer, answer);
37         if (loadBalancer.getVipAddress() != null) {
38             answer.setLoadBalancerVipAddress(String.valueOf(loadBalancer.getVipAddress().getValue()));
39         }
40         if (loadBalancer.getVipSubnetId() != null) {
41             answer.setLoadBalancerVipSubnetID(loadBalancer.getVipSubnetId().getValue());
42         }
43         return answer;
44     }
45
46     @Override
47     protected Loadbalancer toMd(NeutronLoadBalancer loadBalancer) {
48         final LoadbalancerBuilder loadBalancerBuilder = new LoadbalancerBuilder();
49         toMdAdminAttributes(loadBalancer, loadBalancerBuilder);
50         if (loadBalancer.getLoadBalancerVipAddress() != null) {
51             loadBalancerBuilder.setVipAddress(new IpAddress(loadBalancer.getLoadBalancerVipAddress().toCharArray()));
52         }
53         if (loadBalancer.getLoadBalancerVipSubnetID() != null) {
54             loadBalancerBuilder.setVipSubnetId(toUuid(loadBalancer.getLoadBalancerVipSubnetID()));
55         }
56         return loadBalancerBuilder.build();
57     }
58 }