Dúvidas EP5

Dúvidas EP5

por Artur Santos -
Número de respostas: 3

Olá, professor e monitores,

Estava terminando o EP5 e sugiram algumas dúvidas:

1) "Nesta tarefa vocês deverão acrescentar um método keysWithPrefixByValue()"

É pedido para implementarmos o método keysWithPrefixByValue(), mas mais adiante no texto: "Na segunda vez as chaves são exibidas em ordem decrescente de valores. É nessa segunda vez que seu método prefixMatchByValue()" Qual deve ser o nome do nosso método?

2) Tentei rodar o Autocomplete, mas surgiram os seguintes erros:

$ javac-algs4 AutocompleteGUI.java
AutocompleteGUI.java:198: warning: [rawtypes] found raw type: JList
        private JList suggestions;                // a list of autocomplete matches (Java 6)
                ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:302: warning: [rawtypes] found raw type: JList
            suggestions = new JList(results);
                              ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:302: warning: [unchecked] unchecked call to JList(E[]) as a member of the raw type JList
            suggestions = new JList(results);
                          ^
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:311: warning: [unchecked] unchecked call to setPrototypeCellValue(E) as a member of the raw type JList
            suggestions.setPrototypeCellValue(suggListLen);   
                                             ^
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:424: warning: [rawtypes] found raw type: JList
                            JList theList = (JList) mouseEvent.getSource();
                            ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:441: warning: [rawtypes] found raw type: JList
                            JList theList = (JList) mouseEvent.getSource();
                            ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:460: warning: [rawtypes] found raw type: JList
                            JList theList = (JList) mouseEvent.getSource();
                            ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:476: warning: [rawtypes] found raw type: JList
                            JList theList = (JList) mouseEvent.getSource();
                            ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:485: warning: [rawtypes] found raw type: JList
                            JList theList = (JList) mouseEvent.getSource();
                            ^
  missing type arguments for generic class JList<E>
  where E is a type-variable:
    E extends Object declared in class JList
AutocompleteGUI.java:584: warning: [unchecked] unchecked call to setListData(E[]) as a member of the raw type JList
                suggestions.setListData(new String[0]);
                                       ^
  where E is a type-variable:
    E extends Object declared in class JList
Note: AutocompleteGUI.java has additional unchecked or unsafe operations.
10 warnings

E na hora de execução:

$ java-algs4 AutocompleteGUI
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at AutocompleteGUI.main(AutocompleteGUI.java:747)

Alguma sugestão para corrigir esses erros?

 

Obrigado!

Em resposta à Artur Santos

Re: Dúvidas EP5

por José Coelho de Pina -

Oi Artur,

É pedido para implementarmos o método keysWithPrefixByValue(), mas mais adiante no texto:... Qual deve ser o nome do nosso método?

Muito obrigado por avisar!
O métodos é o do esqueleto, KeysWithPrefixByValue().
Corrigi o enunciado.

Em resposta à Artur Santos

Re: Dúvidas EP5

por José Coelho de Pina -

Continuando.

2) Tentei rodar o Autocomplete, mas surgiram os seguintes erros:

Para mim aparecem os mesmos avisos. O AutoCompleteGUI vem com eles:

% javac AutocompleteGUI.java 
Note: AutocompleteGUI.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Não acho isso legal, mas não sei arrumar. triste
Da mesma forma que não sei arrumar os avisos com vetores genêricos.
Não acho isso legal... morto

Em resposta à Artur Santos

Re: Dúvidas EP5

por José Coelho de Pina -

Continuando a continuação

E na hora de execução:

$ java-algs4 AutocompleteGUI

A chamada deve ser, por exemplo:

% java AutocompleteGUI wiktionary.txt 10

Esse programa recebe através da linha de comando o nome de um arquivo no formato descrito anteriormente e um inteiro k

Desculpem...
Eu deveria ter colocado no AutocompleteGUI um método help():

    private static void help(){
        String msg = "Uso:\n" +
            "   % java AutocompleteGUI input.txt k\n" +
            "     input.txt = com os pares chave-valor.\n" +
            "     k = inteiro que indica o tamanho da lista exibida.";
        System.out.println(msg);
    }

    public static void main(String[] args) {
        if (args.length != 2) {
            help();
            return ;
        }    
        [...]
    }        

Hmm. Eu deveria sempre colocar isso...