I checked the following links - Link1 Link2 Link3 but was unable to resolve & hence posting.
Need:
Partial matching of Strings (exact matching not possible in all cases) of 2 string fields & get the info from the matched row. The data is stored in a MySQL db.
The transaction data table contains the description which needs to be compared to the Company name in the Scrip-Info table. I need to get the company code info from Scrip-Info Table, by matching as many words from Transaction Table to Scrip Info Table
Code:
for (List<String> listData : transactionData) {
List<List<String>> code = scripInfo.stream()
.filter(p -> p.get(1).toUpperCase().contains(listData.get(1).toUpperCase()))
.collect(Collectors.toList());
// Output to console to check if its working
code.forEach(p -> System.out.println(p.get(0)));
//Prepare Output List
List<Object> rowData = new ArrayList<>();
rowData.add(code.get(0));
rowData.add(listData.get(2));
rowData.add(listData.get(3));
.........
}
Although I use 'Contains' in the above code it gets the data only if it is an exact match. So from the below example data I have provided only CANARA BANK is found as it is identical in both tables
Note: Data is stored in MySQL db & extracted.
Scrip-Info Table
- [BHARTIARTL, Bharti Airtel Limited]
- [BHEL, Bharat Heavy Electricals Limited]
- [CANBK, Canara Bank]
- [HINDUNILVR, Hindustan Unilever Limited]
- [MARUTI, Maruti Suzuki India Limited]
- [TATAPOWER, Tata Power Company Limited]
- [TATASTEEL, Tata Steel Limited]
- [TECHM, Tech Mahindra Limited]
Transaction Data Table
- [10144, CANARA BANK, B, 100]
- [10278, BHARTI AIRTEL LTD, B, 50]
- [10278, BHARTI AIRTEL LTD, B, 20]
- [10278, HIND.UNILEVER LTD., B, 12]
- [10278, HIND.UNILEVER LTD., B, 32]
- [10278, MARUTI SUZUKI INDIA LTD., S, 26]
- [10278, MARUTI SUZUKI INDIA LTD., S, 26]
- [10278, TECHM FUT 28AUG 14, S, 125]
- [10278, TECHM FUT 28AUG 14, B, 125]
- [11585, TATA STEEL LTD., B, 50]
- [11585, TATA POWER CO. LTD., B, 100]
Required Output:
- [CANBK, B, 100]
- [BHARTIARTL, B, 50]
- [BHARTIARTL, B, 20]
- [BHARTIARTL, B, 80]
- [HINDUNILVR, B, 12]
- [HINDUNILVR, B, 32]
- [HINDUNILVR, B, 52]
- [MARUTI, S, 26]
- [MARUTI, B, 26]
- [TECHM, S, 125]
- [TECHM, B, 125]
- [TATASTEEL, B, 50]
- [TATAPOWER, B, 100]
Output with present Code:
- [CANBK, B, 100]