Consider this code:
public class DataSt {
DataType time;
DataType memory;
public DataSt(DataType time, DataType memory)
{
this.time=time;
this.memory=memory;
}
private static void saveIt(DataSt p, DataSt p2, String keyval, List<DataSt> comp) {
...
}
private static void saveIt( String keyval, List<DataSt> comp) {
...
}
public static List<DataSt> compO(List<DataSt> curR, List<DataSt> prevR) {
Map<String,DataSt> cur = new HashMap<>();Map<String,DataSt> prev= new HashMap<>();
for(DataSt abc:curR)
{
DataSt v = new DataSt (abc.time,abc.memory);
cur.put(abc.key,v);
}
for(DataSt abc:prevR)
{
DataSt values = new DataSt (abc.time,abc.memory);
prev.put(abc.key,v);
}
List<DataSt> comp = new ArrayList<DataSt>();
for (Entry < String, DataSt > abc: cur.entrySet()) {
if (prev.containsKey(abc.getKey())) {
saveIt(abc.getValue(), prev.get(abc.getKey()), abc.getKey(), comp);
} else {
saveIt(abc.getKey(), comp);
}
}
for (Entry<String, DataSt> abc: prev.entrySet()) {
if (!(cur.containsKey(abc.getKey()))) {
saveIt(abc.getKey(), comp);
}
}
return comp;
}
}
With reference to the link "https://stackoverflow.com/questions/45230104/list-key-comparisons-and-return-value". It would be great if someone could review the code and suggest optimizations.