Fix FindBugs violations
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronTrunk.java
1 /*
2  * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.spi;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
17
18 @XmlRootElement(name = "trunk")
19 @XmlAccessorType(XmlAccessType.NONE)
20 public final class NeutronTrunk extends NeutronAdminAttributes<NeutronTrunk> {
21     private static final long serialVersionUID = 1L;
22
23     @XmlElement(name = "port_id")
24     String portId;
25
26     @XmlElement(name = "sub_ports")
27     List<NeutronTrunkSubPort> subPorts;
28
29     public NeutronTrunk() {
30     }
31
32     @Override
33     public void initDefaults() {
34         // In order to override super.initDefaults()
35         // status needs to be checked before calling super.initDefaults()
36         if (status == null) {
37             status = "DOWN";
38         }
39         super.initDefaults();
40         if (subPorts == null) {
41             subPorts = new ArrayList<>();
42         }
43     }
44
45     public String getPortId() {
46         return portId;
47     }
48
49     public void setPortId(String portId) {
50         this.portId = portId;
51     }
52
53     public List<NeutronTrunkSubPort> getSubPorts() {
54         return subPorts;
55     }
56
57     public void setSubPorts(List<NeutronTrunkSubPort> subPorts) {
58         this.subPorts = subPorts;
59     }
60
61     @Override
62     protected boolean extractField(String field, NeutronTrunk ans) {
63         switch (field) {
64             case "port_id":
65                 ans.setPortId(this.getPortId());
66                 break;
67             case "sub_ports":
68                 List<NeutronTrunkSubPort> subPortList = new ArrayList<>();
69                 subPortList.addAll(this.getSubPorts());
70                 ans.setSubPorts(subPortList);
71                 break;
72             default:
73                 return super.extractField(field, ans);
74         }
75         return true;
76     }
77
78     @Override
79     public String toString() {
80         return "NeutronTrunk{" + "trunkUUID='" + uuid + '\'' + ", trunkName='" + name + '\''
81                 + ", tenantID='" + tenantID + '\'' + ", adminStateUp='" + adminStateUp + '\''
82                 + ", status='" + status + '\'' + ", portId='" + portId + '\''
83                 + ", subPorts='" + subPorts + '\'' + '}';
84     }
85 }