/*
Copyright 2012 James Hu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package net.sf.jabb.util.col;

import java.util.List;
import java.util.Map;

/**
 * Get value from Maps according to predefined key list.
 * @author James Hu
 *
 */
public class MapGetter<V> {
	protected Object[] keys;
	
	public MapGetter(Object... keys){
		this.keys = keys;
	}
	
	public MapGetter(List<Object> keyList){
		keys = new Object[keyList.size()];
		for (int i = 0; i < keyList.size(); i ++){
			keys[i] = keyList.get(i);
		}
	}
	
	/**
	 * Get the first matching value in the map.
	 * @param map
	 * @return		null if nothing found
	 */
	public V get(Map<?, V> map){
		for (Object k : keys){
			V v = map.get(k);
			if (v != null){
				return v;
			}
		}
		return null;
	}

}

@@ -11,16 +11,22 @@
 ght 2012
+, 2015
  James H
@@ -619,20 +619,26 @@
 va.util.
-List
+Collection
 ;%0D%0Aimpor
@@ -895,126 +895,54 @@
 ter(
-List%3CObject%3E keyList)%7B%0D%0A%09%09keys = new Object%5BkeyList.size()%5D;%0D%0A%09%09for (int i = 0; i %3C keyList.size(); i ++
+Collection%3C? extends Object%3E keyList
 )%7B%0D%0A
-%09
 %09%09keys
-%5Bi%5D
  = k
@@ -952,20 +952,18 @@
 ist.
-get(i);%0D%0A%09%09%7D
+toArray();
 %0D%0A%09%7D

change List to Collection