From 16930206319bb4f293613431bae6c8094617ddd9 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Tue, 19 Mar 2024 10:21:10 -0300 Subject: [PATCH] Implements addRange, removeRange and set in Collections datatype in Java generator. Issue: 107415 --- .../src/main/java/com/genexus/GXBaseList.java | 84 ++++++++++++------- .../java/com/genexus/GXSimpleCollection.java | 12 +++ 2 files changed, 68 insertions(+), 28 deletions(-) diff --git a/common/src/main/java/com/genexus/GXBaseList.java b/common/src/main/java/com/genexus/GXBaseList.java index 775b84ca4..02ec6de35 100644 --- a/common/src/main/java/com/genexus/GXBaseList.java +++ b/common/src/main/java/com/genexus/GXBaseList.java @@ -5,49 +5,39 @@ import com.genexus.internet.IGxJSONAble; import com.genexus.internet.IGxJSONSerializable; -public abstract class GXBaseList extends Vector implements Serializable, IGxJSONAble, IGxJSONSerializable, IGXAssigned -{ +public abstract class GXBaseList extends Vector implements Serializable, IGxJSONAble, IGxJSONSerializable, IGXAssigned { private boolean IsAssigned; - public GXBaseList() - { + public GXBaseList() { IsAssigned = true; } - public boolean getIsAssigned() - { + public boolean getIsAssigned() { return this.IsAssigned; } - public void setIsAssigned(boolean bAssigned) - { + public void setIsAssigned(boolean bAssigned) { this.IsAssigned = bAssigned; } - public void removeAllItems() - { + public void removeAllItems() { super.clear(); IsAssigned = true; } - public byte removeItem(int index) - { + public byte removeItem(int index) { T item = null; - if(index > 0 && index <= size()) - { + if(index > 0 && index <= size()) { item = super.remove((int)index - 1);//Vector.remove(int) IsAssigned = true; return (byte)1; } return (byte)0; } - public byte removeElement(double index) - { - if(index > 0 && index <= size()) - { + public byte removeElement(double index) { + if(index > 0 && index <= size()) { super.remove((int)index - 1);//Vector.remove(int) IsAssigned = true; return (byte)1; } - else - { + else { return (byte)0; } } @@ -58,24 +48,62 @@ public void addObject(Object obj){ IsAssigned = true; } @SuppressWarnings("unchecked") - public void add(Object item, int index) - { - if(index < 1 || index > size()) - { + public void add(Object item, int index) { + if(index < 1 || index > size()) { add((T)item); //this.add, GXBCLevelCollection.add for example } - else - { + else { super.add(index - 1, (T)item); //Vector insert element IsAssigned = true; } } @SuppressWarnings("unchecked") - public void addBase( Object item) - { + public void addBase( Object item) { super.add((T)item); IsAssigned = true; } + + public boolean addRange( GXBaseList baseList, Number index) { + if (baseList.size() == 0) + return true; + + boolean result; + if (index == null) { + result = addAll(baseList); + } + else { + int nindex = index.intValue(); + if(nindex != 1 && (nindex < 0 || nindex > size() +1)) + return false; + if (nindex == 0) + nindex = 1; + result = addAll(nindex -1, baseList); + } + IsAssigned = true; + return result; + } + + public boolean removeRange( int index, Number count) { + int colSize = size(); + if(index <= 0 || index > colSize || (count != null && index + count.intValue() > colSize)) + return false; + int toIndex; + if (count == null) + toIndex = colSize; + else + toIndex = count.intValue(); + super.removeRange(index -1, toIndex); + IsAssigned = true; + return true; + } + + public boolean setElement( int index, T element) { + if(index < 1 || index > size()) + return false; + super.set(index -1, element); + IsAssigned = true; + return true; + } } diff --git a/common/src/main/java/com/genexus/GXSimpleCollection.java b/common/src/main/java/com/genexus/GXSimpleCollection.java index 8b3b661b3..9a6b34883 100644 --- a/common/src/main/java/com/genexus/GXSimpleCollection.java +++ b/common/src/main/java/com/genexus/GXSimpleCollection.java @@ -1352,5 +1352,17 @@ public boolean update(){ return false; } + public boolean addRange( GXSimpleCollection baseList, Number index) { + return super.addRange(baseList, index); + } + + public boolean removeRange( int index, Number count) { + return super.removeRange(index, count); + } + + public boolean setElement( int index, T element) { + return super.setElement(index, element); + } + }