HI Could yu please tell me how to get previous values from current iteration

 in the below example : public void parseDtoCollection(Collection dtos) contains list of dtos 
 in private AssetClassVersion createNewAssetClassVersion(AssetDTO dto) method i am iterating but i want to get 
to get  previous itearation values in current iteration if the dto.assetClassId is same then i want to append like previous matchedstring value + current matchedstring value


 public void parseDtoCollection(Collection dtos) {


        for (Iterator i = dtos.iterator(); i.hasNext();) {

            AssetDTO dto = (AssetDTO) i.next();          

            AssetClass assetClass = findAssetClass(dto.assetClassId);            

            AssetClassVersion assetClassVersion = createNewAssetClassVersion(dto);

            assetClass.addVersion(assetClassVersion);


            if (dto.id > 0) {

                InformationAsset infoAsset =
                        findInformationAsset(dto.id, assetClass);
                InformationAssetVersion infoAssetVersion =
                        createInfoAssetVersion(dto);
                infoAsset.setBusinessArea(createBusinessArea(dto));
                infoAsset.addVersion(infoAssetVersion);
                infoAsset.setAssetClass(assetClass);




            }
        }
    }


    private AssetClass findAssetClass(int id) { 
        Integer oid = new Integer(id);


        AssetClass assetClass = (AssetClass) assetClassMap.get(oid);


        if (null == assetClass) {
            assetClass = getOJBFactory().getAssetClass(); 
            assetClass.setOid(oid);

            assetClassMap.put(oid, assetClass);

            AssetClassAssets aca = getOJBFactory().getAssetClassAssets();
            aca.setAssetClass(assetClass);
            assetHolder.put(oid,  aca);

        }

        return assetClass;      
    }

       private AssetClassVersion createNewAssetClassVersion(AssetDTO dto) {     



        AssetClassVersion ac = new AssetClassVersion();     

        ac.setVersion(new Integer(dto.assetClassVersion)); 

        ac.setName(dto.assetClassName);

        ac.setDescription(dto.assetClassDescription);
        ac.setStatus(Status.findById(dto.assetClassStatusId));
        ac.setModifyDate(dto.assetClassModifyDate);
        ac.setEffectiveDate(dto.assetClassEffectiveDate);
        ac.setSeriesCode(dto.seriesCode);     

        ac.setMatchedString(dto.matchedString);     


        return ac;        
    }   


    private InformationAsset findInformationAsset(int id, AssetClass assetClass) {
        Integer oid = new Integer(id);
        InformationAsset infoAsset = (InformationAsset)infoAssetMap.get(oid);
        if (null == infoAsset) {
            infoAsset = getOJBFactory().getInformationAsset();
            infoAsset.setOid(oid);
            infoAsset.setAssetClass(assetClass); 
            infoAssetMap.put(oid, infoAsset);
        }

        return infoAsset;       
    }

I'm not sure how you are using the word "previous" here, but if that's the opposite of "next" in the Iterator then...
If you have your dtos in a List (rather than just a Collection) then that implies a sequence for the members, and you can get a ListIterator rather than a simple Iterator. ListIterators allow both forward and backward traversal of the List.

There are 2 things that comes to mind..
1. Did you code this yourself
2. If so , then why didnt you use a supported object like ListIterator of ArrayList which will be easy to manipulate?

Also with the int and interger examples...

line 40 and 85 is nt necessary as you could simply do

public static void foo(int bar, Dim dim){
   // int does not really need interger object as it safe casted.
   int faa = bar; // there was no need for new interger. 
   dim = new Dim;

   /// bla bla bla

}

on line 47 and 88..

if(foo.equals("null"){ // then do this or that}
Always use this if you are checking for null datas
Its very accurate.
Also mind you that null and zero are not the same.
zero is a value but null means empty. So be very careful what you are checking for.

Hope it helps :-)

@ritchieking: looks like you were distracted or something when you wrote that one!

The original code creates an Integer (nb spelling!) from the int parameter because its used as a key value in the Map, and Map keys can't be primitives. Modern Java versions will auto box/unbox to convert implicitly between int and Integer, but it cases like that it's helpful to keep it explicit.

dim = new Dim; Starting a method by overwriting a parameter's value is never going to be a good idea.

if(foo.equals("null")) this is in no possible way a substitute for if (foo == null) What were you thinking?

HI All
my requiurement is:
I am getting list, list consists of follwing

id version name assstatusid seriescode matchedstring
10 1 ab 3 34 match1
11 2 some 3 67 mat
12 3 name 3 678 matchstring
12 3 name 3 678 matchstringone
12 3 name 3 678 matchstri
12 3 name 3 678 sonemat

in the above code i want to display in such way that
here id 12 is repeating but matchedstring column having different values i want to display in
o/p:
12 3 name 3 678 matchstring, matchstringone, matchstri, sonemat

can you please let me know how to solve this based on above code iam using JDK 14 and Tomcat 4

Regards
ravi

---------------------------------------------------------------------------------------------------------

You really must update your Java.

Pseudo-code:

String previous = "";
loop through values {
    if (value.equals(previous)) print on same line;
    else  start a new line;
    previous = value;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.