Pulling out duplicates

C

C.Thomson

I have an application in which I have a list of business objects that
hold repeating coupon data about mortgage information. Each record
contains the following fields:
BeginDate,EndDate,Rate,Cap,Floor,DayCount

There can be any number of records for each trade. For instance, here
is a trade with 3 coupons:

11/05/04 - 07/04/05 Rate:prime minus 0.5
Cap:8.0%
Floor:0.0%
DayCount:30/360
07/05/05 - 09/04/06 Rate:3.0%
Cap:
Floor:0.0%
DayCount:30/360
09/05/06 - 11/04/08 Rate:4.0%
Cap:
Floor:0.0%
DayCount:30/360

I have a coupon object with getters/setters for each field listed. I
have an ArrayList that stores that coupon data. What I am trying to
do is add a new entry that holds the repeating data that does not
change over the life of the trade. From the example above, the added
object would hold:
11/05/04 - 11/04/08 Floor:0.0%
DayCount:30/360

I have a method of doing this by iterating over the list and comparing
each field and saving duplicates to a new object. I am just wondering
if there is an easier/more sophisticated way of doing this.

Thanks.
 
A

Ann

C.Thomson said:
I have an application in which I have a list of business objects that
hold repeating coupon data about mortgage information. Each record
contains the following fields:
BeginDate,EndDate,Rate,Cap,Floor,DayCount

There can be any number of records for each trade. For instance, here
is a trade with 3 coupons:

11/05/04 - 07/04/05 Rate:prime minus 0.5
Cap:8.0%
Floor:0.0%
DayCount:30/360
07/05/05 - 09/04/06 Rate:3.0%
Cap:
Floor:0.0%
DayCount:30/360
09/05/06 - 11/04/08 Rate:4.0%
Cap:
Floor:0.0%
DayCount:30/360

I have a coupon object with getters/setters for each field listed. I
have an ArrayList that stores that coupon data. What I am trying to
do is add a new entry that holds the repeating data that does not
change over the life of the trade. From the example above, the added
object would hold:
11/05/04 - 11/04/08 Floor:0.0%
DayCount:30/360

I have a method of doing this by iterating over the list and comparing
each field and saving duplicates to a new object. I am just wondering
if there is an easier/more sophisticated way of doing this.

Thanks.

Ah, the business equivalent of homework.
You should implement as you state above, then you
can get more credit (ass kissing points) later for REFACTORing it !!!
 
X

xarax

C.Thomson said:
I have an application in which I have a list of business objects that
hold repeating coupon data about mortgage information. Each record
contains the following fields:
BeginDate,EndDate,Rate,Cap,Floor,DayCount

There can be any number of records for each trade. For instance, here
is a trade with 3 coupons:

11/05/04 - 07/04/05 Rate:prime minus 0.5
Cap:8.0%
Floor:0.0%
DayCount:30/360
07/05/05 - 09/04/06 Rate:3.0%
Cap:
Floor:0.0%
DayCount:30/360
09/05/06 - 11/04/08 Rate:4.0%
Cap:
Floor:0.0%
DayCount:30/360

I have a coupon object with getters/setters for each field listed. I
have an ArrayList that stores that coupon data. What I am trying to
do is add a new entry that holds the repeating data that does not
change over the life of the trade.

Is the new entry a different class? Hmm...probably, since it
represents a summary of the activity...
From the example above, the added
object would hold:
11/05/04 - 11/04/08 Floor:0.0%
DayCount:30/360

I have a method of doing this by iterating over the list and comparing
each field and saving duplicates to a new object. I am just wondering
if there is an easier/more sophisticated way of doing this.

You could also try extracting the instances into an array
using the toArray method. Then use a Comparator object to
sort the array (by calling Arrays.sort(Object[],Comparator)).
Duplicate entries will be adjacent in the array. Define
multiple comparators to sort on the various fields as needed.


--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top