user1351077
user1351077

Reputation: 117

merging data from different array list classes with different instances

I have two different array list classes with different instances i.e

// Data from the Claims.java arraylist class

    List<Claim> list1 = new ArrayList<Claim>(claims.values());

prints out

{
  "claims": [
    {
      "id": 98879,
      "Names": "Victor xxx"
    },
    {
      "id": 80790,
      "Names": "Mary xxx"
    }
   ]
}

//Data from ServiceTag.java arraylist class

List<ServiceTag> list2 = new ArrayList<ServiceTag>(servicetag.values());

prints out

{
         "serviceTags": [
        {
          "quantity": 1,
          "claimid": 98879,
          "serviceType": pharmacy,
          "cost": 100
        },
        {
          "quantity": 1,
          "claimid": 80790,
          "serviceType": treatment,
          "cost": 400
        }
      ]
}

i would like to merge these two lists and print out an output based on the claimid i.e to get somthing like

{
  "claims": [
    {
      "id": 98879,
      "Names": "Victor xxx",
      "serviceTags": 
        {
          "quantity": 1,
          "claimid": 98879,
          "serviceType": pharmacy,
          "cost": 100
        }
    },
    {
      "id": 80790,
      "Names": "Mary xxx",
      "serviceTags": 
        {
          "quantity": 1,
          "claimid": 80790,
          "serviceType": treatment,
          "cost": 400
        }
    }
   ]
}

Upvotes: 0

Views: 93

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201429

It sounds like you want a List of ServiceTag(s) per Claim. So, modify Claim and add something like,

private List<ServiceTag> serviceTags = new ArrayList<>();
public List<ServiceTag> getServiceTags() {
  return serviceTags;
}
public void addServiceTag(ServiceTag st) {
  serviceTags.add(st);
}
public void addServiceTags(Collection<ServiceTag> sts) {
  serviceTags.addAll(sts);
}

Upvotes: 1

Related Questions