Skip to Content

In this post, I have tried to write the node functions which will help in understanding the node functions, as well as how User Defined Function works. I have written the standard node functions code as UDF .

 

USE ONE AS MANY:

 

A field that only occurs once is replicated as often as another field in second queue occurs and the context is adjusted as it is in the third queue in result queue.

 

PIC1.png

Here C1 is repeated twice and C2 also twice and context changes adjusted as it is in third queue.

PIC2.png

 

PIC3.png

The code is given below:

 

int countarr1=0;int countarr2=0;int countarr3 = 0;

int i,j,k,start;

i=j=k=0;

for(i = 0;i<arr1.length;i++)

{

  if( arr1[i].equals(ResultList.CC))

countarr1++;

}// countarr1 counts value in first queue

 

for(j = 0;j<arr2.length;j++)

{

  if( arr2[j].equals(ResultList.CC))

countarr2++;

}}// countarr2 counts value in second queue

 

for(k = 0;k<arr3.length;k++)

{

  if( arr3[k].equals(ResultList.CC))

countarr3++;

}// countarr3 counts value in second queue

start = 0;

ArrayList<String> arrresult = new ArrayList<String>();

/*checking number of context in first and second queue are same or not

And wheteher the number of values in second and third queue are same or not*/

if(countarr1==countarr2 && (arr2.length-countarr2)==(arr3.length-countarr3) )

{

   for(i = 0;i<arr1.length;i += 2)

  {

     // taking the value from first queue,

     String temp = arr1[i];

    for(j=start;j<arr2.length;j++)

    {

      //repeating the value based on second queue

       if(arr2[j].equals(ResultList.CC))

       break;

else

       arrresult.add(temp);

     }

      start = j+1;

   }

j = 0;

// here we are adjusting the result queue based on third queue,

  for(k = 0;k<arr3.length && j<arrresult.size();k++)

  {

     if(arr3[k].equals(ResultList.CC))

       result2.addValue(ResultList.CC);

     else

     {

       result2.addValue(arrresult.get(j));

       j++;

    }

}

}

 

REMOVE CONTEXT:

We use removeContext() to remove all the context for an element. This deletes all top hierarchy levels, so that all elements of the target queue are assigned to a root element of the source queue.

 

PIC4.png

 

PIC5.png

The code is given below:

 

int i=0;

for(i = 0;i<arr1.length;i++)

{

      if( !arr1[i].equals(ResultList.CC))// checking if context change is there or not

 

      result2.addValue(arr1[i]);

}

 

SPLIT BY EACH VALUE:

 

SplitByValue() inserts a context change in the source value queue. You can insert a context change in the queue after each value, after each value change, or after each tag without a value.

 

PIC6.png

 

PIC7.png

The code is given below:

int i=0;

for(i = 0;i<arr1.length;i++)

{

      if(arr1[i].equals(ResultList.CC))

      break;

      result2.addValue(arr1[i]);  

      result2.addValue(ResultList.CC);

 

 

}

FORMAT BY EXAMPLE:

We use this function if you need to adjust two queues of equal length with context change from 1st queue. The mapping runtime takes the values from the first queue, and the context change from the second queue. If the two inbound queues do not have the same number of values, the mapping runtime will generate an exception. Here the first and second queue has same number of values.

PIC8.png

PIC9.png

 

The code is given below:

 

int countarr1=0;int countarr2=0;

int i,j,k,start;

i=j=k=0;

for(i = 0;i<arr1.length;i++)

{

  if( arr1[i].equals(ResultList.CC))

countarr1++; // countarr1 counts value in first queue

}

 

for(j = 0;j<arr2.length;j++)

{

  if( arr2[j].equals(ResultList.CC))

countarr2++; // countarr2 counts value in second queue

}

}

j=0;

if((arr1.length-countarr1)==(arr2.length-countarr2) ) //Checking whether number of values are same or not

{

   for(i = 0;i<arr1.length;i++)

  {

      if(!arr1[i].equals(ResultList.CC))

      {

        while(arr2[j].equals(ResultList.CC))

        j++;

        result2.addValue(arr2[j]);

        j++;

       }

       else

       result2.addValue(ResultList.CC);

  }

}

 

COLLAPSE CONTEXT:

collapseContexts()copies the first value from all context to one context.

 

PIC10.png

 

PIC11.png

The code is given below:

 

   for(int i = 0;i<arr1.length;i++)

  {

        if(i==0)

        {

          result2.addValue(arr1[0]);

          result2.addValue(ResultList.CC);

        }

        if(arr1[i].equals(ResultList.CC))

        {

          result2.addValue(arr1[++i]);

          result2.addValue(ResultList.CC);

        }

 

}

 

SORT:

 

It sorts all value in a queue

PIC12.png

PIC13.png

The code is given below:

 

ArrayList a1 = new ArrayList(Arrays.asList(var1));

 

  1. Collections.sort(a1);

for(int i=0;i<a1.size();i++)

  1. result.addValue(a1.get(i));

 

SORTBYKEY:

Sorts value in second queue based on first queue

Here Key is Float

PIC14.png

Here Key is string

PIC15.png

Here Key is Integer

PIC16.png

PIC17.png

 

The code is given below,

 

boolean flagint,flagstring,flagfloat;

flagint=flagfloat=flagstring= true;

String temp = key[0];

try{

// checking it is a character or not

if(temp.matches(“^.*[a-zA-Z].*$”))

{

flagint = false;

flagfloat = false;

}

else{

throw new Exception() ;

}

}catch(Exception e){

flagstring = false;

}

if(flagstring==false){

try{

                                Integer.parseInt(temp);

                                }catch(NumberFormatException e)                  {

       flagint = false;

                                }

                                try{

                                                if(!temp.matches(“^([+-]?(\\d+\\.)?\\d+)$”))// checking whether it is a floating point number or not

                                                                throw new NumberFormatException();

 

                                }catch(NumberFormatException e)

                                {

                                                flagfloat = false;

                                }

}

if(flagint==true){

HashMap<Integer, String> hash = new HashMap<Integer, String>();// here key will be integer and value will be string

for(int i=0;i<key.length;i++)

{

  int t = Integer.parseInt(key[i]);

  hash.put(t,value[i]);

}

Set<Integer> set = hash.keySet();

ArrayList<Integer> list = new ArrayList<Integer>();

  1. list.addAll(set);
  2. Collections.sort(list);

for (Integer key1 : list)

  1. result.addValue(hash.get(key1));

}

else

if(flagfloat==true){

HashMap<Float, String> hash1 = new HashMap<Float, String>(); here key will be float and value will be string

for(int j=0;j<key.length;j++)

{

float t = Float.parseFloat(key[j]);

  hash1.put(t,value[j]);

}

Set<Float> set = hash1.keySet();

ArrayList<Float> list = new ArrayList<Float>();

  1. list.addAll(set);
  2. Collections.sort(list);

for (Float key1 : list)

  1. result.addValue(hash1.get(key1));

}

else

if(flagstring==true){

HashMap<String, String> hash2 = new HashMap<String, String>(); here key will be string and value will also be string

for(int k=0;k<key.length;k++)

{

  hash2.put(key[k],value[k]);

}

Set<String> set = hash2.keySet();

ArrayList<String> list = new ArrayList<String>();

  1. list.addAll(set);
  2. Collections.sort(list);// sorting the value based on key

for (String key1 : list)

  1. result.addValue(hash2.get(key1));// adding the sorted value based on key in result

}

;

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply