How to write the content of a Complex Java object to get rid of Cyclic and Redundant info

Discussion in 'Java' started by mullin, Sep 13, 2007.

  1. mullin

    mullin Guest

    For example: (A simple case that Two objects with parent-child
    relationship => 1 order has N order_allocs)

    Orderes
    ========
    orderId (String)
    quantity (BigDecimal)
    tradeDate (Date)

    Order_Allocs
    ============
    allocId (String)
    allocQty (BigDecimal)
    orderId (Set)

    Though I can use ReflectionToStringBuilder.reflectionToString to write
    and get rid of Cyclic issue, when writing the Order_Allocs object, it
    will write back the information on Orders, so duplicate set of
    information will be logged.

    Any ideas to do so? Just want to write the debug messages.

    Thanks!
     
    mullin, Sep 13, 2007
    #1
    1. Advertisements

  2. mullin

    Roedy Green Guest

    On Thu, 13 Sep 2007 04:05:15 -0700, mullin <>
    wrote, quoted or indirectly quoted someone who said :

    >Though I can use ReflectionToStringBuilder.reflectionToString to write
    >and get rid of Cyclic issue, when writing the Order_Allocs object, it
    >will write back the information on Orders, so duplicate set of
    >information will be logged.


    I would just put a boolean in each object initially false.
    Then write a recursive method to chase the ordinary pointers you have
    in your method, turning on the booleans as you start processing an
    object after you finish you go. You add the addresses to an ArrayList
    as you go. You return when or it is already marked an object as
    processed.you have explored all the pointers out of an object. It is
    much like traversing a tree. There is no need for reflection or aux
    objects.

    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Sep 13, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vasanth
    Replies:
    0
    Views:
    783
    Vasanth
    Jun 28, 2004
  2. Laird Nelson

    Cyclic object graph question

    Laird Nelson, Oct 10, 2003, in forum: Java
    Replies:
    2
    Views:
    759
    Roedy Green
    Oct 10, 2003
  3. news.amnet.net.au
    Replies:
    1
    Views:
    838
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  4. hazz
    Replies:
    6
    Views:
    52,128
    SkyUCHC
    Jun 9, 2010
  5. Stanimir Stamenkov
    Replies:
    2
    Views:
    1,031
    Stanimir Stamenkov
    Oct 25, 2005
  6. Robert Mark Bram
    Replies:
    0
    Views:
    865
    Robert Mark Bram
    Feb 4, 2007
  7. ilya

    get CPU info, RAM info

    ilya, Apr 8, 2010, in forum: Java
    Replies:
    43
    Views:
    8,142
    Mike Schilling
    Apr 19, 2010
  8. gga
    Replies:
    0
    Views:
    186
Loading...