Ejemplo n.º 1
0
  @Override
  public JSONObject toJSON() {
    JSONObject result = new JSONObject();
    result.put("service", "update");
    result.put("name", name);

    if (!newUser.getName().isEmpty()) {
      result.put("newName", newUser.getName());
    }

    if (!newUser.getNicknames().isEmpty()) {
      result.put("newNicknames", newUser.getNicknames());
    }
    return result;
  }
Ejemplo n.º 2
0
  @Override
  public void initialize(Scanner sc) throws ServiceException {
    System.out.print("Name : ");
    name = sc.nextLine();
    if (name.isEmpty()) {
      throw new ServiceException("You must supply a name");
    }

    System.out.print("New name(optional) : ");
    newUser.setName(sc.nextLine());

    System.out.print("New nicknames (optional spaced by spaces) : ");
    StringTokenizer tokenizer = new StringTokenizer(sc.nextLine());
    while (tokenizer.hasMoreTokens()) {
      newUser.getNicknames().add(tokenizer.nextToken());
    }

    if (newUser.getName().isEmpty() && newUser.getNicknames().size() == 0) {
      throw new ServiceException(
          "You must supply a new name or new nicknames, otherwise it will do nothing");
    }
  }