I am trying to set manufacture price code ,that value is in my map object but when I want to get getName() from map object I am not able to get that particular value. If I use
ipcToMFPNameMap.getClass().getName()
this line of code to get particular value I get "java.util.HashMap" in
my manufacture price code filed for your reference I post my code what I tried to get the particular result
private Item getItemManufacturerPriceCodes(Item item) {
List<ItemPriceCode> itemPriceCodes = item.getItemPriceCodes();
List<String> priceCodeList = new ArrayList<String>();
for (ItemPriceCode ipc : itemPriceCodes) {
//get the string value from the list
priceCodeList.add(ipc.getPriceCode());
}
//pass this string value in query
List<ManufacturerPriceCodes>mpc = manufacturerPriceCodesRepository.
findByManufacturerIDAndPriceCodeInAndRecordDeleted(item.getManufacturerID(),priceCodeList,NOT_DELETED);
//Convert list to map
Map<String, ManufacturerPriceCodes> ipcToMFPNameMap = mpc.stream().collect(
Collectors.toMap(ManufacturerPriceCodes :: getPriceCode,Function.identity()));// Object
for (ItemPriceCode ipcs : itemPriceCodes) {
ipcs.setManufacturerPriceCode(ipcToMFPNameMap.getClass().getName());
}
item.getItemPriceCodes()
.removeIf(ipcs -> DELETED.equals(ipcs.getRecordDeleted()));
return item;
}
I get issue exact at this point
ipcs.setManufacturerPriceCode(ipcToMFPNameMap.getClass().getName());
my manufacture price code is a string type
CodePudding user response:
Your Map contains ManufacturerPriceCodes
objects keyed on their priceCode
which is defined as a String. So you can get the name of an item in the Map as follows (where priceCode
is a String).
String manufacturerPriceCodesName = ipcToMFPNameMap.get(priceCode).getName();
The ManufacturerPricesCodes
appears to capture the price code as a String but Item
has a List<ItemPriceCode>
. You'll have to figure out how to map back and forth.
CodePudding user response:
Give more explanation.
- In JSON file, is values bound to key
priceCode
andmanufacturerPriceCode
always equal? - What is the relationship between classes
ItemPriceCodes
andManufacturerPriceCodes
?