You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Jacques Le Roux <ja...@les7arts.com> on 2014/09/10 09:53:41 UTC

getLast in EntityUtil ?

I want to introduce a getLast in EntityUtil class like we have getFirst
But I wonder if some of you are not doing it otherwise,  because I find strange that it's not already there.

It would be:

--- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
+++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
@@ -86,6 +86,26 @@ public class EntityUtil {
          }
      }

+    public static GenericValue getLast(Collection<GenericValue> values) {
+        if (UtilValidate.isNotEmpty(values)) {
+            Iterator<GenericValue> itr = values.iterator();
+            GenericValue lastElement = itr.next();
+            while(itr.hasNext()) {
+                lastElement=itr.next();
+            }
+            return lastElement;
+        }
+        return null;
+    }
+
+    public static GenericValue getLast(List<GenericValue> values) {
+        if (UtilValidate.isNotEmpty(values)) {
+            return values.get(values.size() - 1);
+        } else {
+            return null;
+        }
+    }
+

Jacques

Re: getLast in EntityUtil ?

Posted by Nicolas Malin <ma...@librenberry.net>.
As LinkedList,

I use a few this code "element = elements.getLast()"

But I use more "element = EntityUtil.getFirst(elements)" instead of 
"element = elements.getFirst()"

So +1 ;)

Nicolas


Le 10/09/2014 11:43, Jacques Le Roux a écrit :
> BTW, I just realise that FastList has getFirst() and getLast() methods 
> (only getLast() is used, twice in OFBiz code)
>
> Jacques
>
> Le 10/09/2014 11:05, Jacques Le Roux a écrit :
>> Actually I thought about it even before sending and I guess it's 
>> because people are using an ASC or DESC sort in function of their 
>> need, so getLast is not needed, agreed?
>>
>> Jacques
>>
>> Le 10/09/2014 09:53, Jacques Le Roux a écrit :
>>> I want to introduce a getLast in EntityUtil class like we have getFirst
>>> But I wonder if some of you are not doing it otherwise, because I 
>>> find strange that it's not already there.
>>>
>>> It would be:
>>>
>>> --- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>>> +++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>>> @@ -86,6 +86,26 @@ public class EntityUtil {
>>>          }
>>>      }
>>>
>>> +    public static GenericValue getLast(Collection<GenericValue> 
>>> values) {
>>> +        if (UtilValidate.isNotEmpty(values)) {
>>> +            Iterator<GenericValue> itr = values.iterator();
>>> +            GenericValue lastElement = itr.next();
>>> +            while(itr.hasNext()) {
>>> +                lastElement=itr.next();
>>> +            }
>>> +            return lastElement;
>>> +        }
>>> +        return null;
>>> +    }
>>> +
>>> +    public static GenericValue getLast(List<GenericValue> values) {
>>> +        if (UtilValidate.isNotEmpty(values)) {
>>> +            return values.get(values.size() - 1);
>>> +        } else {
>>> +            return null;
>>> +        }
>>> +    }
>>> +
>>>
>>> Jacques
>>>
>>


Re: getLast in EntityUtil ?

Posted by Pierre Smits <pi...@gmail.com>.
Ample constructs/solutions to get the result you need.

Pierre Smits

*ORRTIZ.COM <http://www.orrtiz.com>*
Services & Solutions for Cloud-
Based Manufacturing, Professional
Services and Retail & Trade
http://www.orrtiz.com

On Wed, Sep 10, 2014 at 12:00 PM, Adrian Crum <
adrian.crum@sandglass-software.com> wrote:

> So does java.util.LinkedList.
>
> Adrian Crum
> Sandglass Software
> www.sandglass-software.com
>
>
> On 9/10/2014 10:43 AM, Jacques Le Roux wrote:
>
>> BTW, I just realise that FastList has getFirst() and getLast() methods
>> (only getLast() is used, twice in OFBiz code)
>>
>> Jacques
>>
>> Le 10/09/2014 11:05, Jacques Le Roux a écrit :
>>
>>> Actually I thought about it even before sending and I guess it's
>>> because people are using an ASC or DESC sort in function of their
>>> need, so getLast is not needed, agreed?
>>>
>>> Jacques
>>>
>>> Le 10/09/2014 09:53, Jacques Le Roux a écrit :
>>>
>>>> I want to introduce a getLast in EntityUtil class like we have getFirst
>>>> But I wonder if some of you are not doing it otherwise,  because I
>>>> find strange that it's not already there.
>>>>
>>>> It would be:
>>>>
>>>> --- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>>>> +++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>>>> @@ -86,6 +86,26 @@ public class EntityUtil {
>>>>          }
>>>>      }
>>>>
>>>> +    public static GenericValue getLast(Collection<GenericValue>
>>>> values) {
>>>> +        if (UtilValidate.isNotEmpty(values)) {
>>>> +            Iterator<GenericValue> itr = values.iterator();
>>>> +            GenericValue lastElement = itr.next();
>>>> +            while(itr.hasNext()) {
>>>> +                lastElement=itr.next();
>>>> +            }
>>>> +            return lastElement;
>>>> +        }
>>>> +        return null;
>>>> +    }
>>>> +
>>>> +    public static GenericValue getLast(List<GenericValue> values) {
>>>> +        if (UtilValidate.isNotEmpty(values)) {
>>>> +            return values.get(values.size() - 1);
>>>> +        } else {
>>>> +            return null;
>>>> +        }
>>>> +    }
>>>> +
>>>>
>>>> Jacques
>>>>
>>>>
>>>

Re: getLast in EntityUtil ?

Posted by Adrian Crum <ad...@sandglass-software.com>.
So does java.util.LinkedList.

Adrian Crum
Sandglass Software
www.sandglass-software.com

On 9/10/2014 10:43 AM, Jacques Le Roux wrote:
> BTW, I just realise that FastList has getFirst() and getLast() methods
> (only getLast() is used, twice in OFBiz code)
>
> Jacques
>
> Le 10/09/2014 11:05, Jacques Le Roux a écrit :
>> Actually I thought about it even before sending and I guess it's
>> because people are using an ASC or DESC sort in function of their
>> need, so getLast is not needed, agreed?
>>
>> Jacques
>>
>> Le 10/09/2014 09:53, Jacques Le Roux a écrit :
>>> I want to introduce a getLast in EntityUtil class like we have getFirst
>>> But I wonder if some of you are not doing it otherwise,  because I
>>> find strange that it's not already there.
>>>
>>> It would be:
>>>
>>> --- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>>> +++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>>> @@ -86,6 +86,26 @@ public class EntityUtil {
>>>          }
>>>      }
>>>
>>> +    public static GenericValue getLast(Collection<GenericValue>
>>> values) {
>>> +        if (UtilValidate.isNotEmpty(values)) {
>>> +            Iterator<GenericValue> itr = values.iterator();
>>> +            GenericValue lastElement = itr.next();
>>> +            while(itr.hasNext()) {
>>> +                lastElement=itr.next();
>>> +            }
>>> +            return lastElement;
>>> +        }
>>> +        return null;
>>> +    }
>>> +
>>> +    public static GenericValue getLast(List<GenericValue> values) {
>>> +        if (UtilValidate.isNotEmpty(values)) {
>>> +            return values.get(values.size() - 1);
>>> +        } else {
>>> +            return null;
>>> +        }
>>> +    }
>>> +
>>>
>>> Jacques
>>>
>>

Re: getLast in EntityUtil ?

Posted by Jacques Le Roux <ja...@les7arts.com>.
BTW, I just realise that FastList has getFirst() and getLast() methods (only getLast() is used, twice in OFBiz code)

Jacques

Le 10/09/2014 11:05, Jacques Le Roux a écrit :
> Actually I thought about it even before sending and I guess it's because people are using an ASC or DESC sort in function of their need, so getLast 
> is not needed, agreed?
>
> Jacques
>
> Le 10/09/2014 09:53, Jacques Le Roux a écrit :
>> I want to introduce a getLast in EntityUtil class like we have getFirst
>> But I wonder if some of you are not doing it otherwise,  because I find strange that it's not already there.
>>
>> It would be:
>>
>> --- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>> +++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
>> @@ -86,6 +86,26 @@ public class EntityUtil {
>>          }
>>      }
>>
>> +    public static GenericValue getLast(Collection<GenericValue> values) {
>> +        if (UtilValidate.isNotEmpty(values)) {
>> +            Iterator<GenericValue> itr = values.iterator();
>> +            GenericValue lastElement = itr.next();
>> +            while(itr.hasNext()) {
>> +                lastElement=itr.next();
>> +            }
>> +            return lastElement;
>> +        }
>> +        return null;
>> +    }
>> +
>> +    public static GenericValue getLast(List<GenericValue> values) {
>> +        if (UtilValidate.isNotEmpty(values)) {
>> +            return values.get(values.size() - 1);
>> +        } else {
>> +            return null;
>> +        }
>> +    }
>> +
>>
>> Jacques
>>
>

Re: getLast in EntityUtil ?

Posted by Jacques Le Roux <ja...@les7arts.com>.
Actually I thought about it even before sending and I guess it's because people are using an ASC or DESC sort in function of their need, so getLast is 
not needed, agreed?

Jacques

Le 10/09/2014 09:53, Jacques Le Roux a écrit :
> I want to introduce a getLast in EntityUtil class like we have getFirst
> But I wonder if some of you are not doing it otherwise,  because I find strange that it's not already there.
>
> It would be:
>
> --- a/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
> +++ b/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
> @@ -86,6 +86,26 @@ public class EntityUtil {
>          }
>      }
>
> +    public static GenericValue getLast(Collection<GenericValue> values) {
> +        if (UtilValidate.isNotEmpty(values)) {
> +            Iterator<GenericValue> itr = values.iterator();
> +            GenericValue lastElement = itr.next();
> +            while(itr.hasNext()) {
> +                lastElement=itr.next();
> +            }
> +            return lastElement;
> +        }
> +        return null;
> +    }
> +
> +    public static GenericValue getLast(List<GenericValue> values) {
> +        if (UtilValidate.isNotEmpty(values)) {
> +            return values.get(values.size() - 1);
> +        } else {
> +            return null;
> +        }
> +    }
> +
>
> Jacques
>