Using LOOP in fetchxml
Hi, I deeply need your help. I've try to use an array in a condition part, but it doesn't work. Here is my code:
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='new_pledge'>" +
"<attribute name='new_name' />" +
"<attribute name='new_pledgeid' />" +
"<attribute name='new_marketvalue' />" +
"<order attribute='new_name' descending='false' />" +
"<filter type='or'>" +
"<condition attribute='new_pledgeid' operator='eq' value='"
for (var i = 0; i < gravid.length; i++) {
+ gravid[i] + "' />" ;
+
"</filter>" +
"</entity>" +
"</fetch>";
var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='new_pledgeid'>" +
"<cell name='new_name' width='300' />" +
Try below code
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='new_pledge'>" +
"<attribute name='new_name' />" +
"<attribute name='new_pledgeid' />" +
"<attribute name='new_marketvalue' />" +
"<order attribute='new_name' descending='false' />" +
"<filter type='or'>" +
"<condition attribute='new_pledgeid' operator='in' >";
for (var i = 0; i < gravid.length; i++)
fetchXml += "<value>{" + gravid[i] + "}</value>";// if you having {} with guid in gravid, then please remove the hardcoded "{}" from for loop
fetchXml += " </condition>" +
"</filter>" +
"</entity>" +
"</fetch>";
Similar Messages
-
Hi,
I would like to use LOOP functionality in BPM until all the records are processed.
Any Help would be appreciated.
Regards,
Ganesh Karicharlahi,
what does it mean all records
by payload loop, time loop?
this page presents all sorts of loops jut check it:
http://help.sap.com/saphelp_nw04/helpdata/en/08/16163ff8519a06e10000000a114084/content.htm
Regards,
michal
<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a> -
Hi All How to TypeCast in vector<>... typedef struct ... to class...
//how to cast the vector to vector cast with out using loop
// is there any way?
//================ This is Type Definition for the class of ClsMytype=====================
typedef struct tagClsMytype
CString m_Name;
int m_Index;
double m_Value;
} xClsMytype;
//================ End of Type Definition for the class of ClsMytype=====================
class ClsMytype : public CObject
public:
ClsMytype(); // Constructor
virtual ~ClsMytype(); // Distructor
ClsMytype(const ClsMytype &e);//Copy Constructor
// =========================================
DECLARE_SERIAL(ClsMytype)
virtual void Serialize(CArchive& ar); /// Serialize
ClsMytype& operator=( const ClsMytype &e); //= operator for class
xClsMytype GetType(); // return the typedef struct of an object
ClsMytype& operator=( const xClsMytype &e);// = operator to use typedef struct
ClsMytype* operator->() { return this;};
operator ClsMytype*() { return this; };
//public veriable decleare
public:
CString m_Name;
int m_Index;
double m_Value;
typedef struct tagClsMyTypeCollection
vector <xClsMytype> m_t_Col;
} xClsMyTypeCollection;
class ClsMyTypeCollection : public CObject
public:
ClsMyTypeCollection(); // Constructor
virtual ~ClsMyTypeCollection(); // Distructor
ClsMyTypeCollection(const ClsMyTypeCollection &e);//Copy Constructor
DECLARE_SERIAL(ClsMyTypeCollection)
virtual void Serialize(CArchive& ar);
xClsMyTypeCollection GetType();
ClsMyTypeCollection& operator=( const xClsMyTypeCollection &e);
ClsMyTypeCollection& operator=( const ClsMyTypeCollection &e); //= operator for class
void Init(); // init all object
CString ToString(); // to convert value to string for the display or message proposed
ClsMyTypeCollection* operator->() { return this;}; // operator pointer to ->
operator ClsMyTypeCollection*() {return this;};
public:
vector <ClsMytype> m_t_Col;
//private veriable decleare
private:
//===================================================
ClsMytype& ClsMytype::operator=( const xClsMytype &e )
this->m_Name= e.m_Name;
this->m_Index= e.m_Index;
this->m_Value= e.m_Value;
return (*this);
//==========================Problem for the vector to vector cast
ClsMyTypeCollection& ClsMyTypeCollection::operator=( const xClsMyTypeCollection &e )
this->m_t_Col= (vector<ClsMytype>)e.m_t_Col; // how to cast
return (*this);
Thanks in AdvanceHi Smirt
You could do:
ClsMyTypeCollection* operator->() {
returnthis;};
// operator pointer to ->
operatorClsMyTypeCollection*()
{returnthis;};
public:
vector<ClsMytype>
m_t_Col;//??
The last line with "vector<xClsMytype>
m_t_Col;". It compiles but I doubt that is what you want.
Regards
Chong -
It is possible to print any name 200 times without using loops?
How to print any name 200 times without using loops and recurssive function and that to in java?
String name = "incognito10";
System.out.println(name.replaceAll("\\w+",
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n"+
"$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0\n$0"
); -
Using loop in dbms_advisor Package
Dears,,
I used dbms_advisor package as following below
dbms_advisor.create_object
task_name => name,
object_type => 'TABLE',
attr1 => 'HR',
attr2 => 'Employees',
attr3 => NULL,
attr4 => NULL,
attr5 => NULL,
object_id => obj_id
what i need is to use loop to retrieve all tables at once then use them one by one in the script above without inserting table name myself.
In another meaning (See the following):
* loop to retrieve all tables
* dbms_advisor.create_object
task_name => name,
object_type => 'TABLE',
attr1 => 'HR',
attr2 => 'TAB', Which TAB retrieved from loop one by one by itself
attr3 => NULL,
attr4 => NULL,
attr5 => NULL,
object_id => obj_id
* end loop;
How can i make this please?
Thanks & Regards,,
Edited by: . . Oracle DBA . . on Apr 10, 2011 5:56 AM. . Oracle DBA . . wrote:
How can i make this please?
begin
for v_rec in (select owner,table_name from dba_tables) loop
dbms_advisor.create_object(
task_name => v_rec.owner || '_' || v_rec.table_name,
object_type => 'TABLE',
attr1 => v_rec.owner,
attr2 => v_rec.table_name,
attr3 => NULL,
attr4 => NULL,
attr5 => NULL,
object_id => obj_id
end loop;
end;
/SY. -
How to use loop in VBAK table using BDC RFC connection through excel vba ?
Hello,
I am trying to extract data from VBAK table using rfc connection with Excel VBA. where i can able to pull data first time, when i tried to use the same set of code using loops, it throws an error like BAD INDEX.
Any help appreciated.Hello,
I am trying to extract data from VBAK table using rfc connection with Excel VBA. where i can able to pull data first time, when i tried to use the same set of code using loops, it throws an error like BAD INDEX.
Any help appreciated. -
How to use LOOP(Until) step in a Workflow
Hi,
How to use LOOP(Until) step in a Workflow?
What are the steps involved in using the step LOOP(Until).Hmmm... using it is just like using a LOOP UNTIL statement in any programming language. You get at least one loop iteration, as opposed to a WHILE loop which may give you zero iterations.
You simply insert a node of this type in the workflow, and magically there will be a loop inside which you can insert the steps you want to execute in the loop, and by double-clicking at the end node of the loop you can enter the condition for exiting.
What exactly is it you are having trouble understanding about the use of it? -
How to use loop in BPEL Process
Hi friends
I have done a bpel process which picks up XMl file using File Adapter and imports the data from the XMl file to oracle db table using DB adapter....
But here the XMl file which have only one row ..if i want insert the XML file which have two or more rows i want to use loop in my BPEL process how to use the loop in my bpel process ?
In my BPEL process i have used receive ,transform , and invoke activity where can i use loop in my BPEL process
Advance Thanks
ATHi Friend thanks
Hi Oracler how to make use of transform activity and use a for each in it.?
iam not getting i try can u please explain some more in brief
Thanks
AT -
How to use loop in smartforms???
hi experts,
I have an internal table with three values .i am passing it into new itab inside smartforms .while displaying it is displaying only the third data .i think i must use loop condition .but i dont know where to use it .pls help me.if i select only one data it is coming .if i select multiple data using select statement .only the final thing is coming .On your smartform, you should have a table set up. Go to transaction SMARTFORMS, enter your form name, and display it. Now navigate to the table on your form and double-click it. Go to the Data tab. Under "LOOP", make sure that you have checked "Internal table". Next to that should be the name of your internal table, then "Into", then a work area. The work area needs to be defined under "Global Definitions" (under Global Settings, check the tree for your form). Your work area should be defined as TYPE, with the associated type being your internal table. Your internal table should actually be defined as a structure where each component is one item that you want to include in your row. I hope this helps.
- April King -
How to use loop in premiere elements 8?
Hi,
Using pre elements 8 and I don`t know how to set or use loop option in premiere elements 8
Please help
VinayFor an authored DVD, there is no capability to Loop that DVD, created in PrE. There are other authoring programs, like Sony's DVD Architect, and Adobe Encore (available only with PrPro), that allow this to be done easily.
The way to do similar in PrE is to do an AutoPlay DVD and then this use the Repeat button on the DVD player.
Good luck,
Hunt -
Hi
I have one control block in form of Grid and now I want clear my grid when button pressed for new selection.
So any one let me know how can I use loop for these field
:ADVANCES_SCHEME.TXT_MONTH := '';
:ADVANCES_SCHEME.MONTH_VERIFIED := '';
:ADVANCES_SCHEME.CK_VERIFIED := 'N';
Thanks in advance...
RegardsThanks every one. I have solve my problem, just put this statement in begin clause
Clear_Block(No_Validate);
this statement clear my grid.
Regards -
Problem in fetching data by using loop.
Hello Friends,
i have to create one report based upon item wise.
Based upon item wise i have displayed Total stock qty and
then item wise GRPO details with Qty data.
I have created Stored procedure for this.
Now i have kept one column RestQty which is basically used to
display rest quantity based upon the data of Total Stock Qty and GRPO quantity.
To Implement this logic i have used loop condition but its not returning correct
qty on Rest Qty column.
Rest Qty should work like this:-
Item aaaaa
If Total Quantity = 28
GRPO Quantity = 40(First GRPO Qty),
7(second last GRPO Qty), &
3 (Last GRPO Quantity)
Now Total quantity always first check with Last GRPo Qty,
it means 28 > 3 then 3 comes to Rest Qty col.
then Total quantity check with second Last GRPo Qty,
it means 28 > 7 + 3(Last GRPo Qty) then 7 comes to Rest qty col.
then Total quantity first check with first GRPo Qty,
it means 28 > 40(first grpo qty) + 7 + 3, its not satisfied,
hence it should display 28 - (7+3) = 18 in rest qty col.
if we sum Rest qty column for Item aaaa then it should equal to Total Qty for particular item.
so its should work for Item aaaa, based upon this other items should work like this.
so i only need to correct the data of Rest Qty col, other are ok.
Please help me to correct this query.
Regards,SELECT OITM.ItemCode,OITM.ItemName,sum(OITW.onhand) as onhand,abc.basenum as GRPONo, abc.docdate as GRPODate,
(select top 1 docrate from opdn where docentry = abc.baseentry and docnum = abc.basenum) as GRPORate,
(select sum(quantity) from pdn1 where docentry = abc.baseentry and abc.itemcode = itemcode) As GRPOQty,null,
(select top 1 price from pdn1 where docentry = abc.baseentry and abc.itemcode = itemcode) As GRPOUnitPrice,
(select distinct top 1 opch.docnum from opch inner join pch1 on opch.docentry = pch1.docentry
where pch1.baseentry = abc.baseentry) as APInvNo,
(select distinct top 1 opch.docdate from opch inner join pch1 on opch.docentry = pch1.docentry
where pch1.baseentry = abc.baseentry) as APInvDt,
(select distinct top 1 opch.u_dodamt from opch inner join pch1 on opch.docentry = pch1.docentry
where pch1.baseentry = abc.baseentry) as APInvDocRate
FROM OITW
INNER JOIN OITM ON OITW.ItemCode = OITM.ItemCode
INNER JOIN OITB ON OITM.ItmsGrpCod = OITB.ItmsGrpCod
left join sri1 as abc on OITW.ItemCode = abc.ItemCode
WHERE(OITW.OnHand <> 0 Or oitw.iscommited <> 0 Or oitw.onorder <> 0 Or oitw.minstock <> 0)
AND (OITW.ItemCode IN (SELECT pdn1.ItemCode FROM Opdn
inner join pdn1 on opdn.docentry = pdn1.docentry
where opdn.series = 314 or opdn.series = 94 or opdn.series = 663))and (abc.Direction = 0)
AND (abc.LineNum =(SELECT MAX(LineNum) AS Expr1 FROM SRI1
WHERE (ItemCode = abc.ItemCode) AND (SysSerial = abc.SysSerial))) AND basetype = 20
and abc.docdate >= (@FromDate) and abc.docdate <= (@ToDate)
group by OITM.ItemCode,OITM.ItemName, oitm.suppcatnum,
abc.basenum, abc.sysserial, abc.baseentry, abc.basenum, abc.docdate,
oitm.ItmsGrpcod, oitb.ItmsGrpNam, abc.baseentry, abc.SysSerial, abc.ItemCode,oitw.itemcode
order by OITM.ItemName,abc.basenum -
Hello
How to make labview program to get average value of 200 reading from multimeter (I using using loop) to read voltage from mulmeter but I like to get average value of all of 200 reding how can I do that?
Thanks
Wee
Solved!
Go to Solution.Another idea with less programming - take advantage of the "free" array that comes with a Chart - i.e. the History Data.
1) Wire your DMM data to a Chart. (You can set the chart to invisible if you don't plan on using it in the GUI).
2) Set the Chart History Length to 200 (right click on the chart, click on Chart History Length...)
3) On the block diagram, use the History Data Property Node, wire it to Mean.vi, and you're done.
Easiest running average ever.
Message Edited by Broken Arrow on 04-07-2010 11:36 AM
Richard
Attachments:
EasyAvg.jpg 8 KB -
A suggestion : use "loop array list" instead of ArrayList / LinkedList
ArrayList is good at:
get / set by index : O(1)
appending : O(log(n))
remove last : O(1)
and very bad at:
add middle : O(n)
remove from middle : O(n)
LinkedList is good at:
fast remove from middle, if your iteraror already goes there : O(1)
convenient methods : addFirst, addLast, removeFirst, removeLast : O(1)
and very bad at :
get / set by index : O(n)
here I want to make a suggestion : use "loop array list" instead of the ArrayList and LinkedList.
a "loop array list" is based on array, just like ArrayList. But it has 2 member-variables : the start position, and the real size. the start position can be anywhere within array.length. an element of index "i" is stored in array[ start + i ], and when (start + i > array.length), loop to the beginning of the array; when (start + i < 0), loop to the end of the array.
this "loop array list" has all the good sides:
get / set by index : O(1)
add first / last : O(log(n))
remove first / last : O(log(n))
add / remove from middle : O(n)
(note : because we shrink the backup-array when the real size is too small, add / remove operation take O(log(n)) now.)
the only problem is : add / remove from middle. let's take a look at it.
1. the LinkedList does NOT really add/remove from middle in O(1), you has to locate the element, which is O(n).
2. O(n) is acceptable, O(n^2) is not acceptable. try this : keep removing first element from an very big ArrayList ( size>10^6 ) until it's empty.
the fact is, any list can perform batch-remove / batch-add operation in O(n) instead of O(n^2). it's easy : allocate a new list, iterate the original list, copy the element into the new list if condition is satisfied.
so, instead of "remove from middle", what we need is a new methods : removeAllByCondition( Condition condition ), and now the batch-remove operation can be done in O(n)
here is an implementation of mine. I've tested it on my computer( 512mem + 2G cpu, win2k + jdk1.5 ), it's amazing, just a little slower then ArrayList when add last, and a liitle slower then LinkedList when batch-remove. in all other cases, it's far more better then those 2 kinds of List.
// source code : List2
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
public final class List2<T> extends AbstractList<T> {
private static int initialArrayLength = 4;
private T[] array;
private int start;
private int size;
private void init( T[] newArray, int start_a, int size_a ) {
array = newArray;
start = start_a;
size = size_a;
@SuppressWarnings("unchecked")
private void init() {
init( (T[]) new Object[ initialArrayLength ], 0, 0 );
public List2() {
init();
@SuppressWarnings("unchecked")
public List2( Collection<? extends T> collection ) {
init(
collection.toArray( (T[]) new Object[ collection.size() * 11 / 10 + 1 ] ),
0,
collection.size()
private List2( T[] array_a, int start_a, int size_a ) {
init( array_a, start_a, size_a );
@SuppressWarnings("unchecked")
public static <TT> List2<TT> createV( TT... elements ) {
TT[] array = (TT[]) new Object[ elements.length * 11 / 10 + 1 ];
System.arraycopy( elements, 0, array, 0, elements.length );
return new List2<TT>( array, 0, elements.length );
public static List2<Double> create( double... elements ) {
Double[] array = new Double[ elements.length * 11 / 10 + 1 ];
for( int i=0; i < elements.length; i++ )
array[i] = elements;
return new List2<Double>( array, 0, elements.length );
public static List2<Integer> create( int... elements ) {
Integer[] array2 = new Integer[ elements.length * 11 / 10 + 1 ];
for( int i=0; i < elements.length; i++ )
array2[i] = elements[i];
return new List2<Integer>( array2, 0, elements.length );
public static List2<Character> create( char... elements ) {
Character[] array2 = new Character[ elements.length * 11 / 10 + 1 ];
for( int i=0; i < elements.length; i++ )
array2[i] = elements[i];
return new List2<Character>( array2, 0, elements.length );
public static List2<Character> create( String s ) {
return create( s.toCharArray() );
public List2<T> clone() {
return new List2<T>( this );
// basic
public int size() {
return size;
private int index( int index ) {
int i = start + index;
if( i >= array.length )
i -= array.length;
return i;
public T get( int d ) {
if( d < 0 || d >= size )
throw new IndexOutOfBoundsException();
if( size == 0 )
throw new NoSuchElementException();
return array[ index( d ) ];
public T set( int index, T element ) {
if( index < 0 || index >= size )
throw new IndexOutOfBoundsException();
int i = index( index );
T oldElement = array[i];
array[i] = element;
return oldElement;
@SuppressWarnings("unchecked")
private void copyAndSetToNewArray( int newArrayLength ) {
T[] newArray = (T[]) new Object[ newArrayLength ];
for( int i=0; i<size; i++ )
newArray[i] = array[ index( i ) ];
init( newArray, 0, size );
public void addFirst( T element ) {
if( size == array.length )
copyAndSetToNewArray( size * 3 / 2 + 1 );
int i = index( array.length - 1 );
array[ i ] = element;
start = i;
size++;
public void addLast( T element ) {
if( size == array.length )
copyAndSetToNewArray( size * 3 / 2 + 1 );
array[ index( size ) ] = element;
size++;
public T removeFirst() {
if( size == 0 )
throw new NoSuchElementException();
T oldElement = array[ start ];
array[ start ] = null;
start = index( 1 );
size--;
if( array.length > size * 2 + 1 )
copyAndSetToNewArray( size * 11 / 10 + 1 );
return oldElement;
public T removeLast() {
if( size == 0 )
throw new NoSuchElementException();
int i = index( size - 1 );
T oldElement = array[i];
array[i] = null;
size--;
if( array.length > size * 2 + 1 )
copyAndSetToNewArray( size * 11 / 10 + 1 );
return oldElement;
@SuppressWarnings("unchecked")
public int removeAll( ListCondition<T> condition ) {
T[] newArray = (T[]) new Object[ array.length ];
int iNew = 0;
for( int i=0; i < size; i++ ) {
T element = get( i );
if( ! condition.isConditionSatisfied( this, i, element ) )
newArray[ iNew++ ] = element;
int oldSize = size;
init( newArray, 0, iNew );
if( array.length > size * 2 + 1 )
copyAndSetToNewArray( size * 11 / 10 + 1 );
return size - oldSize;
// aux
public boolean equals(Object obj) {
if( obj == this )
return true;
if( obj instanceof List2 ) {
List2 that = (List2) obj;
if( this.size != that.size )
return false;
for( int i=0; i < size; i++ )
if( ! Tools.equals( this.array[ this.index(i) ], that.array[ that.index(i) ] ) )
return false;
return true;
if( obj instanceof List ) {
List that = (List) obj;
if( this.size != that.size() )
return false;
Iterator thatIter = that.iterator();
for( int i=0; i < size; i++ )
if( ! Tools.equals( this.array[ this.index(i) ], thatIter.next() ) )
return false;
return true;
return true;
public int hashCode() {
int hashCode = 1;
for( int i=0; i < size; i++ ) {
T element = array[ index( i ) ];
hashCode = 31*hashCode + ( element==null ? 0 : element.hashCode() );
return hashCode;
public boolean isEmpty() {
return size == 0;
public T getFirst() {
return get( 0 );
public T getLast() {
return get( size() - 1 );
public T getRandom() {
return get( (int) (Math.random() * size) );
public int indexOf( Object element ) {
for( int i=0; i < size; i++ )
if( Tools.equals( array[ index( i ) ], element ) )
return i;
return -1;
public int lastIndexOf( Object element ) {
for( int i=size-1; i >= 0; i-- )
if( Tools.equals( array[ index( i ) ], element ) )
return i;
return -1;
public boolean contains( Object element ) {
return indexOf( element ) != -1;
public boolean add( T element ) {
addLast( element );
return true;
@Deprecated
public void add( int index, T element ) {
throw new UnsupportedOperationException();
public T remove() {
return removeFirst();
@Deprecated
public boolean remove( Object element ) {
throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
@Deprecated
public T remove( int index ) {
throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
public void clear() {
init();
public Object[] toArray() {
Object[] result = new Object[ size ];
for( int i=0; i < size; i++ )
result[i] = array[ index( i ) ];
return result;
@SuppressWarnings("unchecked")
public <TT> TT[] toArray( TT[] a ) {
if( a.length < size )
a = (TT[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size );
for( int i=0; i < size; i++ )
a[i] = (TT) array[ index( i ) ];
if( a.length > size )
a[size] = null;
return a;
@SuppressWarnings("unchecked")
public void sort() {
Object[] a = toArray();
Arrays.sort( a );
for( int i=0; i < size; i++ )
array[ i ] = (T) a[ i ];
start = 0;
@SuppressWarnings("unchecked")
public void sortDesc() {
Object[] a = toArray();
Arrays.sort( a );
for( int i=0, j=size-1; i < size; i++, j-- )
array[ i ] = (T) a[ j ];
start = 0;
@SuppressWarnings("unchecked")
public void sort( Comparator<T> comparator ) {
T[] a = (T[]) toArray();
Arrays.sort( a, comparator );
for( int i=0; i < size; i++ )
array[ i ] = a[ i ];
start = 0;
@SuppressWarnings("unchecked")
public void sortDesc( Comparator<T> comparator ) {
T[] a = (T[]) toArray();
Arrays.sort( a, comparator );
for( int i=0, j=size-1; i < size; i++, j-- )
array[ i ] = a[ j ];
start = 0;
public String toString( String delimiter ) {
return toString( "", delimiter, "", size() );
public String toString( String prefix, String delimiter, String suffix, int max ) {
StringBuffer stringBuffer = new StringBuffer( prefix );
int dest = Math.min( max, size );
for( int i=0; i < dest; i++ ) {
stringBuffer.append( get(i) );
if( i < dest - 1 )
stringBuffer.append( delimiter );
if( size > max )
stringBuffer.append( "...(" ).append( size() - max ).append( " more)" );
stringBuffer.append( suffix );
return stringBuffer.toString();
// batch operation
public boolean containsAll( Collection<?> that ) {
Set<Object> thisSet = new HashSet<Object>( this );
for( Object element : that )
if( ! thisSet.contains( element ) )
return false;
return true;
@SuppressWarnings("unchecked")
public List2<T> subList( int fromIndex, int toIndex ) {
if( fromIndex < 0 || toIndex > size || toIndex < fromIndex )
throw new IndexOutOfBoundsException();
int newSize = toIndex - fromIndex;
T[] newArray = (T[]) new Object[ newSize * 11 / 10 + 1 ];
for( int i=fromIndex, iNew=0; i < toIndex; i++, iNew++ )
newArray[ iNew ] = array[ index( i ) ];
return new List2<T>( newArray, 0, newSize );
public void addV( T... that ) {
for( T element : that )
addLast( element );
public boolean addAll( Collection<? extends T> that ) {
for( T element : that )
addLast( element );
return ! that.isEmpty();
@Deprecated
public boolean addAll( int index, Collection<? extends T> c ) {
throw new UnsupportedOperationException();
public void removeRest( T element ) {
int position = lastIndexOf( element );
if( position == -1 )
return;
while( ! Tools.equals( element, removeLast() ) );
public void removeAllEquals( final T element ) {
removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T currentElement) {
return currentElement.equals( element );
public void removeAllBetween( final T from, final T to ) {
removeAll( new ListCondition<T>() {
@SuppressWarnings("unchecked")
public boolean isConditionSatisfied(List2 list, int index, T element) {
if( from != null && ((Comparable) from).compareTo( element ) > 0 )
return false;
if( to != null && ((Comparable) to).compareTo( element ) <= 0 )
return false;
return true;
public boolean retainAll( Collection<?> that ) {
final Set<Object> thatSet = new HashSet<Object>( that );
int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
return ! thatSet.contains( element );
return removeCount > 0;
public boolean removeAll( Collection<?> that ) {
final Set<Object> thatSet = new HashSet<Object>( that );
int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
return thatSet.contains( element );
return removeCount > 0;
// unit test
private static int maxTestCount = 1000 * 1000;
public static void unitTest() throws Exception {
// thest thoese methods for one time
Tools.ensureEquals( new List2(), new ArrayList() );
Tools.ensureNotEquals( List2.create( "abcde" ), new ArrayList() );
Tools.ensureNotEquals( List2.create( "abcde" ), List2.create( "abcdef" ) );
final List<Double> list1 = new ArrayList<Double>();
final List2<Double> list2 = new List2<Double>();
Runnable[] tasks = new Runnable[] {
// test those methods that do NOT change the list
new Runnable() { public void run() {
Tools.ensureEquals( new List2<Double>( list1 ), list1 );
Tools.ensureEquals( List2.createV( list1.toArray() ), list1 );
Tools.ensureEquals( List2.createV( list1.toArray( new Double[0] ) ), list1 );
double[] doubles = new double[ list1.size() ];
int i = 0;
for( double d : list1 )
doubles[i++] = d;
Tools.ensureEquals( List2.create( doubles ), list1 );
Tools.ensure( list1.isEmpty() == list2.isEmpty() );
Arrays.equals( list1.toArray(), list2.toArray() );
Tools.ensureEquals( list1, list2.clone() );
Double notExistElement = -2.0;
Tools.ensure( list1.indexOf( notExistElement ) == -1 );
Tools.ensure( list1.lastIndexOf( notExistElement ) == -1 );
Tools.ensure( list1.contains( notExistElement ) == false );
Tools.ensureEquals( list1.toString(), list2.toString() );
Tools.ensureEquals( list1.toString(), list2.toString() );
Tools.ensureEquals( list1.hashCode(), list2.hashCode() );
if( list1.isEmpty() )
return;
Tools.ensure( list1.get(0).equals( list2.getFirst() ) );
Tools.ensure( list1.get(list1.size()-1).equals( list2.getLast() ) );
Double existRandomElement = list2.getRandom();
Tools.ensure( list1.contains( existRandomElement ) );
Tools.ensure( list2.contains( existRandomElement ) );
Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
int from = (int) (Math.random() * list1.size());
int to = (int) (Math.random() * (list1.size()+1));
if( from > to ) {
int t = from;
from = to;
to = t;
Tools.ensureEquals( list1.subList( from, to ), list2.subList( from, to ) );
// test those methods that change the list
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int i = (int) (Math.random() * list1.size());
double d = Math.random();
list1.set( i, d );
list2.set( i, d );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int i = (int) (Math.random() * list1.size());
Tools.ensure( list1.get( i ).equals( list2.get( i ) ) );
new Runnable() { public void run() {
double d = Math.random();
list1.add( 0, d );
list2.addFirst( d );
new Runnable() { public void run() {
double d = Math.random();
list1.add( d );
list2.addLast( d );
new Runnable() { public void run() {
double d = Math.random();
list1.add( d );
list2.addLast( d );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
Tools.ensure( list1.remove( 0 ).equals( list2.removeFirst() ) );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
Tools.ensure( list1.remove( list1.size() - 1 ).equals( list2.removeLast() ) );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int i = 0;
for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); i++ ) {
iter.next();
if( i % 3 == 0 )
iter.remove();
list2.removeAll( new ListCondition<Double>() { public boolean isConditionSatisfied(List2 list, int index, Double element) {
return index % 3 == 0;
new Runnable() { public void run() {
double d = Math.random();
list1.add( d );
list2.add( d );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
Tools.ensure( list1.remove(0).equals( list2.remove() ) );
new Runnable() { public void run() {
if( list1.isEmpty() )
return;
int r = (int) (Math.random() * list1.size());
Double element = list1.get( r );
int index = list1.lastIndexOf( element );
for( int i=list1.size()-1; i>=index; i-- )
list1.remove( i );
list2.removeRest( element );
new Runnable() { public void run() {
list2.removeRest( Math.random() - 2 );
new Runnable() { public void run() {
list1.clear();
list2.clear();
new Runnable() { public void run() {
Collections.sort( list1 );
list2.sort();
new Runnable() { public void run() {
Collections.sort( list1 );
Collections.reverse( list1 );
list2.sortDesc();
new Runnable() { public void run() {
Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
Collections.sort( list1, comparator );
list2.sort( comparator );
new Runnable() { public void run() {
Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
Collections.sort( list1, comparator );
Collections.reverse( list1 );
list2.sortDesc( comparator );
new Runnable() { public void run() {
Double notExistElement = -2.0;
list2.removeAllEquals( notExistElement );
Tools.ensureEquals( list1, list2 );
list2.removeAllBetween( 0.5, 0.6 );
for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); ) {
double d = iter.next();
if( d >= 0.5 && d < 0.6 )
iter.remove();
Tools.ensureEquals( list1, list2 );
System.out.print( "test List2 " );
for( int i=0; i < maxTestCount; i++ ) {
tasks[ (int) (Math.random() * tasks.length) ].run();
Tools.ensureEquals( list1, list2 );
if( i % (maxTestCount/10) == 0 )
System.out.print( "." );
System.out.println( " ok" );
// source code : ListCondition
public interface ListCondition<T> {
boolean isConditionSatisfied( List2 list, int index, T element );Hi,
I have the following statement:
private List list = new ArrayList();
why not use private ArrayList list = new
ArrayList()?
I know ArrayList implements List, so list has a wide
scope, right? What's the benefit?
Thanks,
JieBy using the interface you are not tied to a specific implementation.
Later, you may determine that using a LinkedList is more efficient to your specific code and then all you need to do is change the statement to:
private List list = new LinkedList();As long as you are not casting the list reference to ArrayList (or something along those lines) you would not need to change anything else. -
Hi All,
Can any one help me how to use loop in workflow.
Initially i will send workitem to agents.
if the loop condition fails i need to send the workitem again to the agents.
Thank you,
HarshaHi,
Just try it. Open the workflow builder, create a new workflow and enter a loop into it. It is really straightforward. You just need to enter the condition into the loop. Basically you need to check some value in the container. Let's say you have a container element APPROVED. If it has value X, the loop will end, etc.
Regards,
Karri
Maybe you are looking for
-
Can you set up an apple ID without a payment method?
do you have to put in a card number?? or is there an option for none like there used to be?
-
I've been an aperture user since 1.0 and was always impressed with the potential of the book tool to create easily albums of photos. The great thing about it of course is that you can fiddle with the RAW images directly in the layout without having t
-
Multpile Email issue in Oracle Alert
Hi, I need to do a customization where email needs to be sent when the quote gets Approved. I used Oracle Alerts for that. I have defined the alert on aso_quote_headers_all by checking 'After Update' option. Whenever we approve the quote, there are m
-
Can I store photos from ipad while travelling for later download to my mac desktop
can I store photos from ipad while travelling for later download to my mac desktop
-
I cant connect to my wifi!!!!!!
i have the iphone 5 on ios 6 and i try to connect and the spinning icon keeps going and i cant find a solution PLease help me i tried so many solutions and they dont work!!!!!!!!