Java Code Examples for java.util.HashMap.replace()

The following are Jave code examples for showing how to use replace() of the java.util.HashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PatProject   File: Test3Hashmap.java   View Source Code Vote up 7 votes
public static void main(String[] args) {
    Scanner scanner=new Scanner(System.in);
    HashMap<String, Integer> map = new HashMap<String, Integer>(16);
    map.put("he",98);
    map.put("he1",99);
    map.put("he",100);
    map.replace("he",1000);
    System.out.println(map.entrySet());
    System.out.println(map.get("he"));
}
 
Example 2
Project: munche_prog   File: dataBaseFunctions.java   View Source Code Vote up 5 votes
/**
 * delete double mac from database
 * @param database
 */
public static void deleteDoubleMacFromDataBase(Vector<sameScanWifi> dataBase){
	HashMap< String,sameScanWifi> hmap = new HashMap< String,sameScanWifi>();
	for (Iterator<sameScanWifi> sameScanWifiIterator = dataBase.iterator(); sameScanWifiIterator.hasNext(); ) {
		sameScanWifi currentSameScanWifi=sameScanWifiIterator.next();
		for(Iterator<wifi> iter = currentSameScanWifi.iterator(); iter.hasNext(); ) {
			wifi currentWifi=iter.next();
			if(hmap.get(currentWifi.getMAC())==null){
				hmap.put(currentWifi.getMAC(), currentSameScanWifi);
			}
			else{
				for(wifi sameMac:hmap.get(currentWifi.getMAC())){
					if(sameMac.getMAC().equals(currentWifi.getMAC())){
						if(sameMac.getRSSI()>currentWifi.getRSSI()){
							iter.remove();
							break;
						}
						else{
							hmap.get(currentWifi.getMAC()).remove(sameMac);
							hmap.replace(currentWifi.getMAC(),  currentSameScanWifi);
						}
					}
				}
			}
		}
	}
	for (Iterator<sameScanWifi> sameScanWifiIterator = dataBase.iterator(); sameScanWifiIterator.hasNext(); ) {
		if(sameScanWifiIterator.next().size()==0){
			sameScanWifiIterator.remove();
		}
	}

}
 
Example 3
Project: Himalaya-JavaFX   File: Board.java   View Source Code Vote up 5 votes
private Player determineWinner3Players(Player winner) {
    Player playerECO = winnerEconnomicScore();
    Player playerREL = winnerReligiousScore();
    Player playerPOL = winnerPoliticalScore();
    HashMap<Player, Integer> nbVictory = new HashMap<>();
    players.forEach((p) -> {
        nbVictory.put(p, 0);
    });
    if (playerECO != null) {
        nbVictory.replace(playerECO, nbVictory.get(playerECO) + 1);
    }
    if (playerPOL != null) {
        nbVictory.replace(playerPOL, nbVictory.get(playerPOL) + 1);
    }
    if (playerREL != null) {
        nbVictory.replace(playerREL, nbVictory.get(playerREL) + 1);
    }
    Map.Entry<Player, Integer> maxVictoryPlayer = Collections.max(nbVictory.entrySet(), Map.Entry.comparingByValue());
    if (maxVictoryPlayer.getValue() >= 2) {
        winner = maxVictoryPlayer.getKey();
    } else if (playerECO != null) {
        winner = playerECO;
    } else if (playerPOL != null) {
        winner = playerPOL;
    } else if (playerREL != null) {
        winner = playerREL;
    }
    return winner;
}
 
Example 4
Project: OOPIter2   File: MessageGenerator.java   View Source Code Vote up 4 votes
private void interpretKeystrokes(HashMap<String, Boolean> keystrokes) {
    if (keystrokes.get("ENTER")) {
        currentState.setCmd(assetIterator.getCommand());
        dispatchCommandForConfig(assetIterator.getCommand());
        keystrokes.replace("ENTER", false);
    }

    /* Keypress combinations with CONTROL+[some key] cycle MODE or TYPE */

    /* CONTROL+{UP/DOWN}: Cycle MODE */
    else if (keystrokes.get("CONTROL") && keystrokes.get("UP")) {
        assetIterator.prev();           //CONTROL+UP: Previous Mode
    } else if (keystrokes.get("CONTROL") && keystrokes.get("DOWN")) {
        assetIterator.next();           //CONTROL+DOWN: Next Mode
    }

    /* CONTROL+{LEFT/RIGHT}: Cycle TYPE */

    else if (keystrokes.get("CONTROL") && keystrokes.get("LEFT")) {        //CONTROL+LEFT: Previous Type
        assetIterator.prevType();
    } else if (keystrokes.get("CONTROL") && keystrokes.get("RIGHT")) {     //CONTROL+RIGHT: Next Type
        assetIterator.nextType();
    }

    /* Keypresses without control cycle TYPE INSTANCES and COMMANDS */

    //LEFT/RIGHT: Cycle Type Instances
    else if (!(keystrokes.get("CONTROL")) && keystrokes.get("LEFT")) {
        assetIterator.prevInstance();
    } else if (!(keystrokes.get("CONTROL")) && keystrokes.get("RIGHT")) {
        assetIterator.nextInstance();
    }

    /* UP/DOWN: Cycle Commands */
    else if (!(keystrokes.get("CONTROL")) && keystrokes.get("UP")) {               /* Previous command */
        assetIterator.prevCommand();
    } else if (!(keystrokes.get("CONTROL")) && keystrokes.get("DOWN")) {      /* Next command */
        assetIterator.nextCommand();
    }
    else{
        return;
    }
    updateView(assetIterator);
}