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