I have a list of objects as follows.
List<Map<String, CustomObject>> xList = getData();
xList's structure as follows.
[
{
ask: {
description: {
pricing: "200",
// other key / values
}
},
// other key / values
},
{
description: {
pricing: "500",
// other key / values
}
// other key / values
},
more objects
]
I am looking to change the value for the pricing key.
This key is meant to be used for sorting via another service and looking to hide actual value.
Thus for example if the pricing value for Object1 is 200 and Object2 is 500, I wish to modify the object / or create a copy as follows where the pricing value is ordered from the lowest:
[
{
ask: {
description: {
pricing: "1", // order 1 cos 200 is lower than 500
// other key / values
}
},
// other key / values
},
{
ask: {
description: {
pricing: "2", // order 2 cos 500 is higher than 200
// other key / values
}
},
// other key / values
},
more objects
]
But for me to know the order value correctly, I am gonna need to know
all the pricing values first before modifying anything.
Unable to see how I could know all the pricing values and modify the values via a stream. Could I get some advice please.
Was attempting something like the following but as said I can't be doing this without knowing all the pricing values first.
List<Map<String, CustomObject>> xList = getData();
xList.stream().map(AllData::getAsk)
.map(map -> map.get("description"))
.map(stringObjectMap -> stringObjectMap.get("pricing"))
or
for (CustomObject data : xList) {
Map<String, Object> map = data.getAsk().get("description");
int pricing = Integer.parseInt((String) map.get("pricing"));
}