You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2013/05/13 20:02:17 UTC
svn commit: r1482005 -
/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
Author: doogie
Date: Mon May 13 18:02:16 2013
New Revision: 1482005
URL: http://svn.apache.org/r1482005
Log:
FEATURE: Add getFirst/getOnly variants that take a collection.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java?rev=1482005&r1=1482004&r2=1482005&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java Mon May 13 18:02:16 2013
@@ -69,6 +69,14 @@ public class EntityUtil {
}
+ public static GenericValue getFirst(Collection<GenericValue> values) {
+ if (UtilValidate.isNotEmpty(values)) {
+ return values.iterator().next();
+ } else {
+ return null;
+ }
+ }
+
public static GenericValue getFirst(List<GenericValue> values) {
if (UtilValidate.isNotEmpty(values)) {
return values.get(0);
@@ -77,6 +85,19 @@ public class EntityUtil {
}
}
+ public static GenericValue getOnly(Collection<GenericValue> values) {
+ if (UtilValidate.isNotEmpty(values)) {
+ Iterator<GenericValue> it = values.iterator();
+ GenericValue result = it.next();
+ if (it.hasNext()) {
+ throw new IllegalArgumentException("Passed List had more than one value.");
+ }
+ return result;
+ } else {
+ return null;
+ }
+ }
+
public static GenericValue getOnly(List<GenericValue> values) {
if (UtilValidate.isNotEmpty(values)) {
if (values.size() == 1) {