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