summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/certsrv/common
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-02-27 09:36:14 -0600
committerEndi Sukma Dewata <edewata@redhat.com>2012-03-12 12:45:05 -0500
commit0bc851bff69ef174b11cf147aeb1289c43de0666 (patch)
tree08daf5662ba4fc31d04947e887e7929b87e185c4 /pki/base/common/src/com/netscape/certsrv/common
parentc0b210a15ef43873b52c1c9fbec73eba48155b4b (diff)
downloadpki-0bc851bff69ef174b11cf147aeb1289c43de0666.tar.gz
pki-0bc851bff69ef174b11cf147aeb1289c43de0666.tar.xz
pki-0bc851bff69ef174b11cf147aeb1289c43de0666.zip
Refactored NameValuePairs.
The NameValuePairs class has been modified to extend the Linked- HashMap which preserves the order of elements as in the original code. Some methods are renamed to match Java Map interface. The NameValuePair class is no longer needed and has been removed. Ticket #78
Diffstat (limited to 'pki/base/common/src/com/netscape/certsrv/common')
-rw-r--r--pki/base/common/src/com/netscape/certsrv/common/NameValuePair.java68
-rw-r--r--pki/base/common/src/com/netscape/certsrv/common/NameValuePairs.java121
2 files changed, 8 insertions, 181 deletions
diff --git a/pki/base/common/src/com/netscape/certsrv/common/NameValuePair.java b/pki/base/common/src/com/netscape/certsrv/common/NameValuePair.java
deleted file mode 100644
index ed1d06149..000000000
--- a/pki/base/common/src/com/netscape/certsrv/common/NameValuePair.java
+++ /dev/null
@@ -1,68 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2007 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.common;
-
-/**
- * A class represents a name value pair. A name value
- * pair consists of a name and a value.
- *
- * @version $Revision$, $Date$
- */
-public class NameValuePair {
-
- private String mName = null;
- private String mValue = null;
-
- /**
- * Constructs value pair object.
- *
- * @param name name
- * @param value value
- */
- public NameValuePair(String name, String value) {
- mName = name;
- mValue = value;
- }
-
- /**
- * Retrieves the name.
- *
- * @return name
- */
- public String getName() {
- return mName;
- }
-
- /**
- * Retrieves the value.
- *
- * @return value
- */
- public String getValue() {
- return mValue;
- }
-
- /**
- * Sets the value
- *
- * @param value value
- */
- public void setValue(String value) {
- mValue = value;
- }
-}
diff --git a/pki/base/common/src/com/netscape/certsrv/common/NameValuePairs.java b/pki/base/common/src/com/netscape/certsrv/common/NameValuePairs.java
index 61d3cad62..0999db7bc 100644
--- a/pki/base/common/src/com/netscape/certsrv/common/NameValuePairs.java
+++ b/pki/base/common/src/com/netscape/certsrv/common/NameValuePairs.java
@@ -17,10 +17,8 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.common;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.LinkedHashMap;
import java.util.StringTokenizer;
-import java.util.Vector;
/**
* A class represents an ordered list of name
@@ -28,13 +26,9 @@ import java.util.Vector;
*
* @version $Revision$, $Date$
*/
-public class NameValuePairs {
+public class NameValuePairs extends LinkedHashMap<String, String> {
- private Vector<NameValuePair> mPairs = new Vector<NameValuePair>();
-
- // an index to speed up searching
- // The key is the name. The element is the NameValuePair.
- private Hashtable<String, NameValuePair> index = new Hashtable<String, NameValuePair>();
+ private static final long serialVersionUID = 1494507857048437440L;
/**
* Constructs name value pairs.
@@ -43,97 +37,6 @@ public class NameValuePairs {
}
/**
- * Adds a name value pair into this set.
- * if the name already exist, the value will
- * be replaced.
- *
- * @param name name
- * @param value value
- */
- public void add(String name, String value) {
- NameValuePair pair = getPair(name);
-
- if (pair == null) {
- pair = new NameValuePair(name, value);
- mPairs.addElement(pair);
- index.put(name, pair);
- } else {
- pair.setValue(value);
- }
- }
-
- /**
- * Retrieves name value pair from this set.
- *
- * @param name name
- * @return name value pair
- */
- public NameValuePair getPair(String name) {
- return (NameValuePair) index.get(name);
- }
-
- /**
- * Returns number of pairs in this set.
- *
- * @return size
- */
- public int size() {
- return mPairs.size();
- }
-
- /**
- * Retrieves name value pairs in specific position.
- *
- * @param pos position of the value
- * @return name value pair
- */
- public NameValuePair elementAt(int pos) {
- return (NameValuePair) mPairs.elementAt(pos);
- }
-
- /**
- * Removes all name value pairs in this set.
- */
- public void removeAllPairs() {
- mPairs.removeAllElements();
- index.clear();
- }
-
- /**
- * Retrieves value of the name value pairs that matches
- * the given name.
- *
- * @param name name
- * @return value
- */
- public String getValue(String name) {
- NameValuePair p = getPair(name);
-
- if (p != null) {
- return p.getValue();
- }
- return null;
- }
-
- /**
- * Retrieves a list of names.
- *
- * @return a list of names
- */
- public Enumeration<String> getNames() {
- Vector<String> v = new Vector<String>();
- int size = mPairs.size();
-
- for (int i = 0; i < size; i++) {
- NameValuePair p = (NameValuePair) mPairs.elementAt(i);
-
- v.addElement(p.getName());
- }
- //System.out.println("getNames: "+v.size());
- return v.elements();
- }
-
- /**
* Show the content of this name value container as
* string representation.
*
@@ -142,12 +45,13 @@ public class NameValuePairs {
public String toString() {
StringBuffer buf = new StringBuffer();
- for (int i = 0; i < mPairs.size(); i++) {
- NameValuePair p = (NameValuePair) mPairs.elementAt(i);
+ for (String name : keySet()) {
+ String value = get(name);
- buf.append(p.getName() + "=" + p.getValue());
+ buf.append(name + "=" + value);
buf.append("\n");
}
+
return buf.toString();
}
@@ -171,17 +75,8 @@ public class NameValuePairs {
String n = t.substring(0, i);
String v = t.substring(i + 1);
- nvp.add(n, v);
+ nvp.put(n, v);
}
return true;
}
-
- /**
- * Returns a list of name value pair object.
- *
- * @return name value objects
- */
- public Enumeration<NameValuePair> elements() {
- return mPairs.elements();
- }
}