Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: how to merge java objects with effective dates

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to merge java objects with effective dates

    Hi,
    I created Customer.java with two fields effective start date and effective end date.
    Now i have a List<Customer>, i need to merge the all the customer objects into one object with following information:
    a. min(effective start date)
    b. max (effective end date)

    Please help me to arrive logic.

    Thanks in advance,
    esl


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: how to merge java objects with effective dates

    How are the dates stored? Date, String, int, long?

    Merging all objects into one doens't make sense Why not just have a min and max variable to hold the data.
    Date minDate = findMinDate();
    Date maxDate = findMaxDate();
    Then those 2 methods would iterate over the Collection of Customer objects and find the approriate dates with a little logic.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to merge java objects with effective dates

    Dates are java.util.Date

    Customer also has other attributes and so i need to combine into one.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: how to merge java objects with effective dates

    Sounds like you just need a loop that finds the min and max Dates, in the Object that holds the List of Customers.

    Or you could just create a List of Dates from the Customer List, sort the List, then look at the first and last items in the List.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: how to merge java objects with effective dates

    Another approach could be to use the Collections sort() method with you own Comparator class to set the order that you want.

Similar Threads

  1. Replies: 1
    Last Post: February 10th, 2011, 08:57 AM
  2. Replies: 4
    Last Post: November 14th, 2010, 11:44 AM
  3. Java/Excel integration, Reading in Dates
    By aussiemcgr in forum JDBC and Database Tutorials
    Replies: 0
    Last Post: July 16th, 2010, 08:38 AM
  4. how to merge my OO with GUI
    By zyspt in forum AWT / Java Swing
    Replies: 1
    Last Post: May 18th, 2010, 03:28 PM
  5. UTC Dates
    By PedroCosta in forum Java Theory & Questions
    Replies: 4
    Last Post: April 1st, 2010, 11:39 AM