Add makeFields() method to verify keys/values of entity maps.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@585834 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adam Heath
2007-10-18 03:41:53 +00:00
parent fc82438bfa
commit 537e6263ea
@@ -19,6 +19,7 @@
package org.ofbiz.entity.util;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Collections;
@@ -53,6 +54,23 @@ public class EntityUtil {
public static final String module = EntityUtil.class.getName();
public static Map<String, Object> makeFields(Object... args) {
Map<String, Object> fields = FastMap.newInstance();
if (args != null) {
for (int i = 0; i < args.length;) {
if (!(args[i] instanceof String)) throw new IllegalArgumentException("Key(" + i + "), with value(" + args[i] + ") is not a String.");
String key = (String) args[i];
i++;
if (!(args[i] instanceof Comparable)) throw new IllegalArgumentException("Value(" + i + "), with value(" + args[i] + ") does not implement Comparable.");
if (!(args[i] instanceof Serializable)) throw new IllegalArgumentException("Value(" + i + "), with value(" + args[i] + ") does not implement Serializable.");
fields.put(key, args[i]);
i++;
}
}
return fields;
}
public static GenericValue getFirst(List<GenericValue> values) {
if ((values != null) && (values.size() > 0)) {
return values.get(0);