[jboss-svn-commits] JBL Code SVN: r6230 - labs/jbossesb/workspace/tfennelly/product/core/common/src/org/jboss/soa/esb/helpers

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 14 11:22:27 EDT 2006


Author: tfennelly
Date: 2006-09-14 11:22:25 -0400 (Thu, 14 Sep 2006)
New Revision: 6230

Modified:
   labs/jbossesb/workspace/tfennelly/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java
Log:
Support for key value lookup from a list of KVPs

Modified: labs/jbossesb/workspace/tfennelly/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java	2006-09-14 15:21:47 UTC (rev 6229)
+++ labs/jbossesb/workspace/tfennelly/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java	2006-09-14 15:22:25 UTC (rev 6230)
@@ -23,6 +23,7 @@
 package org.jboss.soa.esb.helpers;
 
 import java.io.Serializable;
+import java.util.List;
 
 public class KeyValuePair implements Serializable {
 	private static final long serialVersionUID = 1L;
@@ -53,4 +54,29 @@
 	public String dump() {
 		return "KVpair[" + mKey + "=" + mVal + "]";
 	}
+    
+    /**
+     * Get the value associated with the specified key from the supplied list of Key Value Pairs.
+     * <p/>
+     * Returns the value from the first matching key.
+     * @param key The key to search for.
+     * @param list The list of KeyValuePairs to search.
+     * @return The value associated with the supplied key, or null if key not found.
+     */
+    public static String getValue(String key, List<KeyValuePair> list) {
+        if(key == null) {
+            throw new IllegalArgumentException("null 'key' arg in call.");
+        }
+        if(list == null) {
+            throw new IllegalArgumentException("null 'list' arg in call.");
+        }
+        
+        for(KeyValuePair kvp : list) {
+            if(kvp.mKey.equals(key)) {
+                return kvp.mVal;
+            }
+        }
+        
+        return null;
+    }
 } // ____________________________________________________________________________




More information about the jboss-svn-commits mailing list