예제 #1
0
  protected static void printUserList(Collection<UserID> users) {

    Iterator<UserID> it = users.iterator();

    while (it.hasNext()) {
      UserID user = it.next();
      System.out.println(
          "Username: "******"Name: " + user.getName() + " " + user.getAttributes());
    }

    if (users.isEmpty()) System.out.println("No results");
  }
예제 #2
0
  protected static void removeContact(UserID user, Scanner scan) {
    System.out.println("Please enter username of the user you want to remove: ");
    String username = scan.next();

    if (user.removeContact(username)) {
      System.out.println("Remove was successful.");
    } else {
      System.out.println("Cannot remove contact, check make sure username is correct");
    }
  }
예제 #3
0
 protected static void addContact(UserID user, Scanner scan) {
   assert (user != null);
   System.out.println("Please enter username of the user you want to add: ");
   String username = scan.next();
   UserID userAboutToAdd = registeredUsers.get(username);
   if (userAboutToAdd != null) {
     user.addContact(username);
     System.out.println("Contact added.");
   } else System.out.println("Contact cannot be added, check make sure username is correct");
 }
예제 #4
0
  protected static void searchBasedOnCriteria(UserID user, Scanner scan) {

    assert (user != null && scan != null);

    SearchCriteria criteria = user.getUserCriteria();
    if (criteria != null) { //
      System.out.println("Current search criteria:\n" + criteria);
      System.out.println(
          "Press 1 if you would like to set up new search criteria or "
              + "anything else if you want to use current one");
      String input = scan.next();
      if (input.length() == 1 && input.charAt(0) == '1') user.setUpSearch(scan);
    } else {
      user.setUpSearch(scan);
    }

    Search search = new Search(user);
    printUserList(search.findUsersBasedOnSearchCriteria());
  }
예제 #5
0
  /*
   * UserID uid should not be null
   */
  private static boolean checkPassword(String password, boolean newPassword, UserID uid) {

    if (password == null || password.length() < 8) {
      System.out.println("Password must be length of 8 or more.");
      return false;
    }

    assert (uid != null);
    if (!newPassword && !uid.getPassword().equals(password)) {

      System.out.println("Password does not match with the username");
      return false;
    }
    return true;
  }