From 537e6263ea46898ea8798a1508ca2b9cf5ec2fc7 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Thu, 18 Oct 2007 03:41:53 +0000 Subject: [PATCH] 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 --- .../src/org/ofbiz/entity/util/EntityUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java index b7d39f2722..7cb1803f98 100644 --- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java +++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java @@ -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 makeFields(Object... args) { + Map 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 values) { if ((values != null) && (values.size() > 0)) { return values.get(0);