コード例 #1
0
  @Override
  public void doWork() {
    ApplicationInterface ui = context.getApplication().getUi();
    String input = context.getInput();
    DictionaryManager dm = context.dictionaryManager;

    if (!CmdHelper.isValidOption(input)) {
      return;
    }

    if (input.equals(CmdHelper.CMD_0)) {
      Word addWord = dm.lastQuery().getWord();
      dm.add(addWord);
      ui.showMessage(MessageHelper.t("WORD_ADDED") + addWord);
      context.setState(StateHelper.STATE_SEARCH);
      return;
    }

    if (input.equals(CmdHelper.CMD_1)) {
      List<Word> similarWords = dm.lastResult().getSimilarWords();
      if (similarWords.isEmpty()) {
        ui.showMessage(MessageHelper.t("WORD_NO_SIMILAR"));
        context.setState(StateHelper.STATE_SEARCH);
        return;
      }
      {
        Map<String, String> options = new HashMap<>();
        int optionNumber = 0;
        for (Iterator<Word> iter = similarWords.iterator(); iter.hasNext(); ) {
          options.put(String.valueOf(optionNumber++), iter.next().toString());
        }
        context.setOptions(options);
      }
      context.setState(StateHelper.STATE_CHOSE_SIMILAR);
    }
  }
コード例 #2
0
 @Override
 public String getInvitation() {
   return MessageHelper.t("WORD_NOT_EXISTS");
 }