I'm a beginner in smooks. I'm facing an issue. This is java-java transformation. I have a list and within that I have an inner list with 2 objects. How can I achieve list.list to list copy in smooks?
Asked
Active
Viewed 663 times
5
-
@JB. Thanks I was not able to create a tag so added under java – shree Aug 02 '11 at 12:14
-
1How about adding an example of what you have tried, and why you are trying to do it, then those trying to answer have somewhere to start – nuzz Oct 26 '11 at 21:39
1 Answers
0
From what I can tell smooks
does not have a method that provides this. You can, however, achieve this by iterating over the lists and extracting the contents out into a new list.
You can define a function to do this, for example:
public List<Object> extractEmbeddedList(List<List<Object>> embeddedList)
{
List<Object> extractedList = new ArrayList<Object>();
for (List<Object> l : embeddedList) {
for (Object o : l) {
extractedList.add(o);
}
}
return extractedList;
}
Here is an example of it being used:
List<List<Object>> embeddedList = new ArrayList<List<Object>>();
List<Object> someEmbeddedObjects = new ArrayList<Object>();
List<Object> moreEmbeddedObjects = new ArrayList<Object>();
List<Object> normalList = new ArrayList<Object>();
someEmbeddedObjects.add("I'm a String!");
someEmbeddedObjects.add("I'm another String!");
moreEmbeddedObjects.add(5);
moreEmbeddedObjects.add(6);
embeddedList.add(someEmbeddedObjects);
embeddedList.add(moreEmbeddedObjects);
normalList = extractEmbeddedList(embeddedList);
System.out.println(normalList.toString());
//Output is: [I'm a String!, I'm another String!, 5, 6]

Deco
- 3,261
- 17
- 25
-
Using google's guava library, this is merely Lists.newArrayList(Iterables.concat(embeddedList)) – Michael Deardeuff Nov 13 '11 at 21:50
-
Or that works too :) If you don't use Google's guava library than the code achieves the same result – Deco Nov 13 '11 at 22:51