on 04-13-2010 10:08 AM
Hi,
What is the best way to remove duplicate values in a webdynpro context.
Thanks in advance.
Jyothi.
Hi,
Well its very simple hash may takes unique value only so all duplicate value will be eliminated
Regards ,
Piyas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Traverse your node and get the value like the below
HashSet set = new HashSet();
for ( int i = 0 ; i < wdContext.node<>.size(); i++)
{
String attrib = wdContext.node< Your Node> ().get<Your Node>ElementAt(i).get<Attribute>();
set.add(attrib);
}
HashSet will remove the duplicates and again you can traverse the HashSet and put back the valid set to the contextnode.
Regards,
Saravanan K
Due to some problem the message came 2 -3 times.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use the follwing pice of code for removing Duplicate elements.
Here i am using two node's Node Info for storing All values (with duplicate values) and node Info_copy for storing values without duplicate.
ArrayList al=new ArrayList();
al.add("Trilochan");
al.add("Trilochan");
al.add("Trilochan");
al.add("Pramod");
al.add("Pramod");
al.add("Lokesh");
int size=al.size();
//==============Store all values==============
for(int i=0;i<size;i++){
IPrivateRemoveappView.IInfoElement ele=wdContext.nodeInfo().createInfoElement();
Object obj=al.get(i);
ele.setName(obj.toString());
wdContext.nodeInfo().addElement(ele);
}
LinkedHashSet hSet=new LinkedHashSet(al);
//==================Store values (No duplicate)==============
Iterator iterator = hSet.iterator();
while(iterator.hasNext())
{
IPrivateRemoveappView.IInfo_copyElement ele=wdContext.nodeInfo_copy().createInfo_copyElement();
ele.setName(iterator.next().toString());
wdContext.nodeInfo_copy().addElement(ele);
}
Regards
Trilochan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
--
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
---
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
this is the code you whew looking for
HashSet hashSet = new HashSet();
ITestNodeElement element = null ;
for (int i = 0 ; i < wdContext.nodeTestNode().size() ; i++){
element = wdContext.nodeTestNode().getTestNodeElementAt(i);
hashSet.add(element.getTestAtt());
}
wdContext.nodeTestNode().invalidate();
Iterator iterator = hashSet.iterator();
while(iterator.hasNext())
{
element = wdContext.createAndAddTestNodeElement();
element.setTestAtt(iterator.next().toString());
}
Regards
Piyas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Sorry for the delay in reply was busy with work
but hear is the code you wanted
public void wdDoModifyView(com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
HashMap hashMap = new HashMap ();
ITestNodeElement element = null ;
ArrayList<String> test = new ArrayList<String>();
for (int i = 0 ; i < wdContext.nodeTestNode().size() ; i++){
element = wdContext.nodeTestNode().getTestNodeElementAt(i);
if (hashMap.put(element.getTestAtt(), i) == null ){
test.add(element.getTestAtt());
}
}
wdContext.nodeTestNode().invalidate();
for (int i = 0 ; i < hashMap.size() ; i++ ){
element = wdContext.createAndAddTestNodeElement();
element.setTestAtt(test.get(i));
}
//@@end
}
regards ,
Piyas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Write a function which iterates the node and puts the value in a hash map,then invalidate the node and then iterate the hash map to put the values back into the node
Regards ,
Piyas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you explain your problem in more detail so that a proper solution can be given
Regards
Piyas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.