Merge "Prevent ConfigPusher from killing its thread"
[controller.git] / opendaylight / forwardingrulesmanager / api / src / main / java / org / opendaylight / controller / forwardingrulesmanager / PortGroupConfig.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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.controller.forwardingrulesmanager;
10
11 import java.io.Serializable;
12 import java.lang.reflect.Field;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.opendaylight.controller.configuration.ConfigurationObject;
17
18 /**
19  * PortGroupConfig class represents the User's Configuration with a Opaque
20  * Regular Expression String that is parsed and handled by PortGroupProvider.
21  *
22  * Typically, the opaque matchString will be a Regular Expression String
23  * supported by a particular PortGroupProvider based on Customer requirements.
24  *
25  *
26  *
27  */
28 public class PortGroupConfig extends ConfigurationObject implements Serializable {
29     private static final long serialVersionUID = 1L;
30     private static final String prettyFields[] = { "Name", "Match Criteria" };
31
32     private String name;
33     private String matchString;
34
35     /**
36      * Default Constructor with regular expression string defaulted to ".*"
37      */
38     public PortGroupConfig() {
39         name = "default";
40         matchString = ".*";
41     }
42
43     /**
44      * Constructor to create a Port Group Configuration using a Group Name and
45      * an Opaque String that is managed by PortGroupProvider.
46      *
47      * @param name
48      *            Group Name representing a Port Group configuration
49      * @param matchString
50      *            An Opaque String managed by PortGroupProvider
51      */
52     public PortGroupConfig(String name, String matchString) {
53         super();
54         this.name = name;
55         this.matchString = matchString;
56     }
57
58     /**
59      * Returns the user configured PortGroup Configuration name.
60      *
61      * @return Configuration Name
62      */
63     public String getName() {
64         return name;
65     }
66
67     /**
68      * Assigns a name to the configuration
69      *
70      * @param name
71      *            configuration name
72      */
73     public void setName(String name) {
74         this.name = name;
75     }
76
77     /**
78      * Returns the Opaque string
79      *
80      * @return
81      */
82     public String getMatchString() {
83         return matchString;
84     }
85
86     /**
87      * Assigns an opaque String to the Configuration.
88      *
89      * @param matchString
90      *            Opaque string handled by PortGroupProvider
91      */
92     public void setMatchString(String matchString) {
93         this.matchString = matchString;
94     }
95
96     /**
97      * Returns the names of all the configurable fields in PortGroupConfig. This
98      * method is typically used by NorthBound apis.
99      *
100      * @return List of Field names that can be configured.
101      */
102     public static List<String> getFieldsNames() {
103         List<String> fieldList = new ArrayList<String>();
104         for (Field fld : PortGroupConfig.class.getDeclaredFields()) {
105             fieldList.add(fld.getName());
106         }
107         // remove static field(s)
108         fieldList.remove(0);
109         fieldList.remove(0);
110
111         return fieldList;
112     }
113
114     /**
115      * Returns the names of all the configurable fields in PortGroupConfig in
116      * human readable format for UI purposes. This method is typically used by
117      * Web/UI apis.
118      *
119      * @return List of Human readable Strings that corresponds to the
120      *         configurable field names.
121      */
122     public static List<String> getPrettyFieldsNames() {
123         List<String> fieldList = new ArrayList<String>();
124         for (String str : prettyFields) {
125             fieldList.add(str);
126         }
127         return fieldList;
128     }
129
130     @Override
131     public int hashCode() {
132         final int prime = 31;
133         int result = 1;
134         result = prime * result + ((matchString == null) ? 0 : matchString.hashCode());
135         result = prime * result + ((name == null) ? 0 : name.hashCode());
136         return result;
137     }
138
139     @Override
140     public boolean equals(Object obj) {
141         if (this == obj) {
142             return true;
143         }
144         if (obj == null) {
145             return false;
146         }
147         if (getClass() != obj.getClass()) {
148             return false;
149         }
150         PortGroupConfig other = (PortGroupConfig) obj;
151         if (matchString == null) {
152             if (other.matchString != null) {
153                 return false;
154             }
155         } else if (!matchString.equals(other.matchString)) {
156             return false;
157         }
158         if (name == null) {
159             if (other.name != null) {
160                 return false;
161             }
162         } else if (!name.equals(other.name)) {
163             return false;
164         }
165         return true;
166     }
167
168     @Override
169     public String toString() {
170         return "PortGroupConfig [name=" + name + ", matchString=" + matchString + "]";
171     }
172 }