Menu

Preserving ordering on deep copy?

Help
2007-09-05
2013-04-25
  • rharrington

    rharrington - 2007-09-05

    Hi.  I'm looking for a quick answer to a (hopefully) simple question to determine whether I need to bother you with the details...

    I have a LinkedHashSet<T> Collection (we'll call it 'myOrderedCollection') off of the object that I want deep copied (we'll call it 'myTopLevelObject').  I am using LinkedHashSet to support maintaining the order of the elements in the collection.  I am using something like this to accomplish the copy:

    HibernateBeanReplicator replicator =
       new Hibernate3BeanReplicator().initDetailedBeanPopulatable(myDetailedBeanPopulatableObject)
                                 .initCollectionPropertyNameSet(setProperties)
                                 .initEntityBeanClassSet(setEntityBean);

    replicator.copy(myTopLevelObject);

    What I am seeing is that the order of the elements in the resulting copy's myOrderedCollection is not the same as that passed in.

    Should I expect it to be?

    Using beanlib 3.1.1.

    Thanks in advance.

     
    • Hanson Char

      Hanson Char - 2007-09-05

      Have you tried the latest beanlib 3.3.0beta9 to see if it works for you ?  There has been significant improvement since 3.1.x.

       
      • rharrington

        rharrington - 2007-09-06

        No I haven't tried it.  Was initially just hoping to get a quick answer as to whether preserving order is expected to work or not.

         
        • Hanson Char

          Hanson Char - 2007-09-06

          It is expected to work only if you are uing 3.3.x.

           
          • rharrington

            rharrington - 2007-09-06

            Ok.  I've now tried 3.3.0beta9 with no difference.  Is there anything special I should be doing code-wise to tell the system that I want the order preserved?

             
            • Hanson Char

              Hanson Char - 2007-09-06

              Does the individual element implement Comparable ?  Or are you using a Comparator in the Collection ?  Do you have a small test case to show the problem ?

               
              • rharrington

                rharrington - 2007-09-06

                I am not using any kind of comparator.  I am using an ordered Collection (LinkedHashSet).  The data was originally ordered and entered into the original (source) collection via Hibernate order-by.  I am looking for the deep copy to maintain the order in the original collection, based on the fact that the original collection provides a predictable iteration order.  Maybe that's the key point - it is iteration order I am concerned with.  I am looking to have the iteration order preserved from the source to the copy and expected it would be merely based on the fact that I am using the LinkedHashSet for the source collection.

                I'll work on a test case, though I may not get to it for a while.

                Thanks for your quick responses.  For now, it would be great to know if the behavior I am expecting is expected to be working in the latest code-base based on the latest details I've provided.

                 

Log in to post a comment.