CLICK HERE TO EARN MONEY FREE

Sunday, July 21, 2019

Arraylist and Forlop

package com.anand.model; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import org.json.JSONException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; public class Test { public static void main(String[] args) throws JsonProcessingException, JSONException { ArrayList dataList = buildData(); ArrayList uniqueList = getUniqueList(dataList); ArrayList> response = buildResponse(uniqueList); response = buildCompleteResponse(dataList, uniqueList, response); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(response); System.out.println(json); } private static ArrayList> buildCompleteResponse(ArrayList dataList, ArrayList uniqueList, ArrayList> response) { for (int i = 0; i < dataList.size(); i++) { int poistion = i; int mtd = dataList.get(i).getMTD() > 0 ? response.get(poistion).get(0).getMTD() + 1 : response.get(poistion).get(0).getMTD() + 0; response.get(poistion).get(0).setMTD(mtd); int ytd = dataList.get(i).getYTD() > 0 ? response.get(poistion).get(0).getYTD() + 1 : response.get(poistion).get(0).getYTD() + 0; response.get(poistion).get(0).setYTD(ytd); int inflight = dataList.get(i).getIN_FLIGHT() > 0 ? response.get(poistion).get(0).getIN_FLIGHT() + 1 : response.get(poistion).get(0).getIN_FLIGHT() + 0; response.get(poistion).get(0).setIN_FLIGHT(inflight); response.get(poistion).get(0).setName(dataList.get(i).getName()); response.get(poistion).get(0).getNFIDArray().add(dataList.get(i).getNFID()); } return response; } public static ArrayList getUniqueList(ArrayList dataList) { ArrayList uniqueList = new ArrayList<>(); for (int i = 0; i < dataList.size(); i++) { uniqueList.add(dataList.get(i).getName()); } Set uniqueSet = new HashSet(uniqueList); ArrayList mainList = new ArrayList(); mainList.addAll(uniqueSet); return mainList; } public static ArrayList> buildResponse(ArrayList uniqueList) { ArrayList> response = new ArrayList<>(); for (int i = 0; i < uniqueList.size(); i++) { Values values = new Values(); ArrayList valueList = new ArrayList(); ArrayList nfidLsit = new ArrayList(); values.setNFIDArray(nfidLsit); valueList.add(values); response.add(valueList); } return response; } public static ArrayList buildData() { ArrayList dataList = new ArrayList<>(); for (int i = 0; i <10000; i++) { dataList.add(new Data("SA", "Design"+i, "2000"+i, 1, 0, 1, 1, 0, 1)); } return dataList; } }

0 comments:

Post a Comment

 

TEKONOLOGY Copyright © 2011 -- Template created by TEKONOLOGY -- Powered by Blogger