我有一個目的插入值的數組列表,並刪除任何重複
Table[] tables = new Table[10];
此列表存儲信息約10球員和他們的位置從頂1,其爲表[推移的數組列表0]和前10名等於表[9]
然而,有時我需要在數組之間放置一個值,並且讓我們說我輸入的球員名稱必須是前5名,也就是說,top 5進入前4,從前4到3 ..和3到2 ..等等,但我也需要檢查這些值是否包含我剛剛添加的球員名稱,所以在這種情況下,我必須將其刪除,並將所有列表備份,很多添加1,有沒有人有最好的方式來做到這一點,我想這樣做的方式可能不是最好的。
這裏是我做了那麼遠,但它不是完整的..
private void addToBoard(Player damaged, Player killer) {
if(damaged.getName().equalsIgnoreCase(killer.getName())){
return;
}
for(Table table : tables){
if(table != null){
if(table.currentPlayer.equalsIgnoreCase("No One")){
table.currentPlayer = killer.getName();
break;
}else if(table.currentPlayer.equalsIgnoreCase(damaged.getName()) || table.currentPlayer.equalsIgnoreCase("Searching...")){
if(table.currentPlayer.equalsIgnoreCase(killer.getName())){
return;
}
if(table.currentPlayer.equalsIgnoreCase(killer.getName())){
return;
//update the list, and remove duplications
}
if(!table.currentPlayer.equalsIgnoreCase("Searching...")){
killer.chat("I killed "+damaged.getName()+" and now I am Top: "+table.topID+" gf :)");
}
table.currentPlayer = killer.getName();
if(table.topID != 10){
//make a list on a hashmap with the key from 1 to 10
HashMap<Integer, Table> addAll = new HashMap<Integer, Table>();
//add the top
for(int i = 0; i < tables.length; i++){
addAll.put(tables[i].topID, tables[i]);
}
HashMap<Integer, Table> updated = new HashMap<Integer, Table>();
String oldPlayer;
for(Entry<Integer, Table> top : addAll.entrySet()){
if(top.getValue().currentPlayer.equalsIgnoreCase(damaged.getName())){
//dont add
oldPlayer = top.getValue().currentPlayer;
top.getValue().currentPlayer = killer.getName();
Table next = updated.get((top.getValue().topID+1));
next.currentPlayer = oldPlayer;
updated.put(next.topID, next);
}else{
if(updated.containsKey(top.getValue().topID)){
updated.put((top.getValue().topID+1), top.getValue());
}else{
updated.put(top.getValue().topID, top.getValue());
}
}
}
for(int i = 0; i < tables.length; i++){
if(updated.get(i) != null){
tables[i] = updated.get(i);
}
}
}
break;
}
}
}
}
的感謝!
我正在使用java。 – Stefan15ist
顯示你試圖解決你的問題的一個例子 – UnknownOctopus
呃..我試圖做到這一點,但後來我迷失了哈哈..這裏是:http://hastebin.com/vofiqisore.avrasm – Stefan15ist