目前我在从最低价格到最高价格的排序数组中有这组数据。
Line 1 in the user container need Basic( Special : true) - Ship name: Titanic
The Price is: 10.0 Capacity: 300.0
Line 1 in the user container need Basic( Special : true) - Ship name: Ace
The Price is: 10.0 Capacity: 400.0
Line 1 in the user container need Basic( Special : true) - Ship name: Adda
The Price is: 5.0 Capacity: 130.0
Line 1 in the user container need Basic( Special : true) - Ship name: mutha
The Price is: 6.0 Capacity: 350.0
Line 1 in the user container need Basic( Special : true) - Ship name: spade
The Price is: 10.0 Capacity: 450.0
第一个排序数组的结果**[5.0,6.0,10.0,10.0,10.0]** 每个数据都与船名配对。
我的目标(创建一个新的字符串数组): [Adda,mutha,spade,ace,Titanic] Adda 是最便宜的,其次是 mutha。对于 spade、ace 和 titanic,它们按容量排序,因为它们具有相同的价格 这是我的代码
Map<Ships, Double> sortedMap = sortByComparator(shipsarray);
LinkedHashSet<String> uniqueStrings = new LinkedHashSet<String>();
double tempprice=0,tempcap=0;
String tempship = null;
for (Map.Entry<Ships, Double> entry : sortedMap.entrySet()) {//loop for fill in
if((double)entry.getValue() == tempprice){
if(entry.getKey().getAvailableCapacityForType(user.getContainers().get(i).getClass())>tempcap){
System.out.println(uniqueStrings);
uniqueStrings.remove(tempship);
uniqueStrings.add(entry.getKey().getship().getShipName());
uniqueStrings.add(tempship);
System.out.println(uniqueStrings);
}
else{
System.out.println(uniqueStrings);
uniqueStrings.add(entry.getKey().getship().getShipName());
}
}
else{
uniqueStrings.add(entry.getKey().getship().getShipName());
tempprice = (double)entry.getValue();
tempship = entry.getKey().getship().getShipName();
tempcap = entry.getKey().getAvailableCapacityForType(user.getContainers().get(i).getClass());
}
}
目前的结局是【阿达、穆塔、黑桃、泰坦尼克号】 缺王牌。
感谢您的帮助