5

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?

Kevdog777
  • 908
  • 7
  • 20
  • 43
shree
  • 73
  • 5
  • @JB. Thanks I was not able to create a tag so added under java – shree Aug 02 '11 at 12:14
  • 1
    How 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 Answers1

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