EP05 - erratas

EP05 - erratas

por Guilherme Thomaz -
Número de respostas: 1

Acredito ter um erro no codigo fornecido para o EP05:

/**
* Inserts the key-value pair into the symbol table, overwriting the old value
* with the new value if the key is already in the symbol table.
* If the value is {@code null}, this effectively deletes the key from the symbol table.
* @param key the key
* @param val the value
* @throws IllegalArgumentException if {@code key} is {@code null}
*/
public void put(String key, Value val) {
    if (key == null) {
    delete(key); // MAC0323
    // throw new IllegalArgumentException("calls put() with null key"); MAC0323
    }
    if (!contains(key)) n++;
    root = put(root, key, val, 0);
}

 

no if, acredito que deveria ser val == null para entrar no delete?

 

Alem do erro apontado na outra postagem pelo Arthur sobre nomes diferentes da funcao que devemos implementar.

 

Meu programa passou nos testes delete 1 e 3, mas nao no 2, existe alguma dica do que e testado nesse teste especifico? =)

 

Em resposta à Guilherme Thomaz

Re: EP05 - erratas

por José Coelho de Pina -

Oi Guilherme,

no if, acredito que deveria ser val == null para entrar no delete?

Você tem razão. olho roxo
Muito obrigado por avisar.
O código de put deveria ser:

    /**
     * Inserts the key-value pair into the symbol table, overwriting the old value
     * with the new value if the key is already in the symbol table.
     * If the value is {@code null}, this effectively deletes the key from the symbol table.
     * @param key the key
     * @param val the value
     * @throws IllegalArgumentException if {@code key} is {@code null}
     */
    public void put(String key, Value val) {
        if (key == null) {
            throw new IllegalArgumentException("calls put() with null key"); 
        }
        if (val == null) { // MAC0323
            delete(key);
        }    
        if (!contains(key)) n++;
        root = put(root, key, val, 0);
    }