-1

I have below data in arrayList. Every row is an element in arraylist.

How can I get/map for every Service corresponding description Example 1: {Service= Review of Inpatient Hospital Care,Description= When your condition requires you to be an inpatient Description= If payment determination criteria are not met. If we inform you that you do not meet payment determination criteria.}

Example 2: {Service= Ambulatory Surgical Center (ASC),Description= When your condition requires you to be an inpatient Description= Covered, including operating rooms, surgical supplies.}

Service= Review of Inpatient Hospital Care
Description= When your condition requires you to be an inpatient
Description= If payment determination criteria are not met. 
If we inform you that you do not meet payment determination criteria. 
Service= Ambulatory Surgical Center (ASC)
Description= Covered, including operating rooms, surgical supplies.
Service= Hospital Ancillary Services
Description= Covered, including surgical supplies, hospital anesthesia services.
Service= Hospital Room and Board
Description= Covered, including:Semi-Private Rooms.  If you are hospitalized at a participating facility.
Description= Private Rooms.At Participating Hospitals.
Description= At Nonparticipating Hospitals:
Description= Newborn nursery care. Covered for the baby's nursery care after birth.
Description= Please note: Services at nonparticipating and out-of-state post-acute.
Service= Intensive Care Unit/Coronary Care Unit.
Description= Covered.
Service= Intermediate Care Unit
Description= Covered.
Service= Isolation Care Unit
Description= Covered.

1 Answers1

3

I assume you want to create new objects that contain every data for each Service encountered, containing two properties : service and description. Am I right ?

In that case, you can iterate over all the elements and each time you find a line starting with 'Service=', you instanciate a new object with the content of the line after 'Service='. You can do this with regluar expressions. Each instanciated object should be put in another list or map.

Then, the next lines which doesn't start with 'Service=' will be concatenate in the 'Description' property of the current new object.

At the end of the loop, you would have a new list containg objects filled with all your data.

Edit : I would have made a Service classe with two properties : name and description, both as String.

Then, when you loop over the raw data list, each time you get a 'Service' line, you create a new Service with its name, extracted from the current line.

Next lines will be added to your buffer (I recommend the StringBuilder class in a single Thread program without synchronization), as the description value.

Finally, when you find a new Service line, you begin with flushing the buffer into the previous Service instance, filling its description property. And then you can start a new iteration by creating a new Service instance and loop again.

Anthony BONNIER
  • 335
  • 2
  • 8
  • 1
    Thank you.. How do I map Service to its corresponding description with new object. I mean Service will be in list and description will be concatenated in string buffer.. How do I make sure in between two services the description should be concatenated and mapped to first service.. –  Aug 02 '18 at 17:52
  • If the list of the raw data is in the correct order, like your example, and you loop over it in this order without modifing it, it should work. You have to flush the buffer each time you encounter a new 'Service' line. – Anthony BONNIER Aug 03 '18 at 07:54
  • 1
    Do I have to define Service as list and Description as stringbuffer in new class. –  Aug 03 '18 at 08:06
  • Please have a look at my answer, I have to edit it because my comment is too long ! – Anthony BONNIER Aug 03 '18 at 08:49