コード例 #1
0
  /** Test for setAddress(). */
  public void testSetAddress() {
    String bareAddress = "*****@*****.**";
    String bracketAddress = "<*****@*****.**>";

    Address address = new Address(bareAddress);
    assertEquals("bare address", "*****@*****.**", address.getAddress());

    address.setAddress(bracketAddress);
    assertEquals("bracket address", "*****@*****.**", address.getAddress());
  }
コード例 #2
0
ファイル: SmtpTransport.java プロジェクト: nulops/k-9
  @Override
  public void sendMessage(Message message) throws MessagingException {
    ArrayList<Address> addresses = new ArrayList<Address>();
    {
      addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO)));
      addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC)));
      addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC)));
    }
    message.setRecipients(RecipientType.BCC, null);

    HashMap<String, ArrayList<String>> charsetAddressesMap =
        new HashMap<String, ArrayList<String>>();
    for (Address address : addresses) {
      String addressString = address.getAddress();
      String charset = MimeUtility.getCharsetFromAddress(addressString);
      ArrayList<String> addressesOfCharset = charsetAddressesMap.get(charset);
      if (addressesOfCharset == null) {
        addressesOfCharset = new ArrayList<String>();
        charsetAddressesMap.put(charset, addressesOfCharset);
      }
      addressesOfCharset.add(addressString);
    }

    for (Map.Entry<String, ArrayList<String>> charsetAddressesMapEntry :
        charsetAddressesMap.entrySet()) {
      String charset = charsetAddressesMapEntry.getKey();
      ArrayList<String> addressesOfCharset = charsetAddressesMapEntry.getValue();
      message.setCharset(charset);
      sendMessageTo(addressesOfCharset, message);
    }
  }
コード例 #3
0
ファイル: ContactsBook.java プロジェクト: cursoagil/proyectos
  public static List<String> getAddressesFromPersonName(String personName)
      throws NotExistsPersonException {
    Person person = getPersonFromIdentifier(personName);
    List<Address> addresses = person.getAddresses();
    List<String> result = new ArrayList<String>();

    for (Address address : addresses) {
      result.add(address.getAddress());
    }
    return result;
  }
コード例 #4
0
  /** Test various combinations of the toHeader (single) method */
  public void testToHeaderSingle() {
    Address noName1 = new Address("*****@*****.**");
    Address noName2 = new Address("<*****@*****.**>", "");
    Address simpleName = new Address("*****@*****.**", "simple name");
    Address dquoteName = new Address("*****@*****.**", "name,4");
    Address quotedName = new Address("*****@*****.**", "big \"G\"");
    Address utf16Name = new Address("<*****@*****.**>", "\"\u65E5\u672C\u8A9E\"");
    Address utf32Name = new Address("<*****@*****.**>", "\uD834\uDF01\uD834\uDF46");
    Address sameName = new Address("*****@*****.**", "*****@*****.**");

    // test for internal states.
    assertEquals("no name 1 address", "*****@*****.**", noName1.getAddress());
    assertNull("no name 1 name", noName1.getPersonal());
    assertEquals("no name 2 address", "*****@*****.**", noName2.getAddress());
    assertNull("no name 2 name", noName2.getPersonal());
    assertEquals("simple name address", "*****@*****.**", simpleName.getAddress());
    assertEquals("simple name name", "simple name", simpleName.getPersonal());
    assertEquals("double quoted name address", "*****@*****.**", dquoteName.getAddress());
    assertEquals("double quoted name name", "name,4", dquoteName.getPersonal());
    assertEquals("quoted name address", "*****@*****.**", quotedName.getAddress());
    assertEquals("quoted name name", "big \"G\"", quotedName.getPersonal());
    assertEquals("utf-16 name address", "*****@*****.**", utf16Name.getAddress());
    assertEquals("utf-16 name name", "\u65E5\u672C\u8A9E", utf16Name.getPersonal());
    assertEquals("utf-32 name address", "*****@*****.**", utf32Name.getAddress());
    assertEquals("utf-32 name name", "\uD834\uDF01\uD834\uDF46", utf32Name.getPersonal());
    assertEquals("name == address address", "*****@*****.**", sameName.getAddress());
    assertEquals("name == address name", "*****@*****.**", sameName.getPersonal());

    // Test for toHeader() results.
    assertEquals("no name 1", "*****@*****.**", noName1.toHeader());
    assertEquals("no name 2", "*****@*****.**", noName2.toHeader());
    assertEquals("simple name", "simple name <*****@*****.**>", simpleName.toHeader());
    assertEquals("double quoted name", "\"name,4\" <*****@*****.**>", dquoteName.toHeader());
    assertEquals("quoted name", "\"big \\\"G\\\"\" <*****@*****.**>", quotedName.toHeader());
    assertEquals("utf-16 name", "=?UTF-8?B?5pel5pys6Kqe?= <*****@*****.**>", utf16Name.toHeader());
    assertEquals("utf-32 name", "=?UTF-8?B?8J2MgfCdjYY=?= <*****@*****.**>", utf32Name.toHeader());
    assertEquals("name == address", "\"[email protected]\" <*****@*****.**>", sameName.toHeader());
  }
コード例 #5
0
  /** Test various combinations of the toHeader (multi) method */
  public void testToHeaderMulti() {
    Address noName1 = new Address("*****@*****.**");
    Address noName2 = new Address("<*****@*****.**>", "");
    Address simpleName = new Address("*****@*****.**", "simple name");
    Address dquoteName = new Address("*****@*****.**", "name,4");
    Address quotedName = new Address("*****@*****.**", "big \"G\"");
    Address utf16Name = new Address("<*****@*****.**>", "\"\u65E5\u672C\u8A9E\"");
    Address utf32Name = new Address("<*****@*****.**>", "\uD834\uDF01\uD834\uDF46");

    // test for internal states.
    assertEquals("no name 1 address", "*****@*****.**", noName1.getAddress());
    assertNull("no name 1 name", noName1.getPersonal());
    assertEquals("no name 2 address", "*****@*****.**", noName2.getAddress());
    assertNull("no name 2 name", noName2.getPersonal());
    assertEquals("simple name address", "*****@*****.**", simpleName.getAddress());
    assertEquals("simple name name", "simple name", simpleName.getPersonal());
    assertEquals("double quoted name address", "*****@*****.**", dquoteName.getAddress());
    assertEquals("double quoted name name", "name,4", dquoteName.getPersonal());
    assertEquals("quoted name address", "*****@*****.**", quotedName.getAddress());
    assertEquals("quoted name name", "big \"G\"", quotedName.getPersonal());
    assertEquals("utf-16 name address", "*****@*****.**", utf16Name.getAddress());
    assertEquals("utf-16 name name", "\u65E5\u672C\u8A9E", utf16Name.getPersonal());
    assertEquals("utf-32 name address", "*****@*****.**", utf32Name.getAddress());
    assertEquals("utf-32 name name", "\uD834\uDF01\uD834\uDF46", utf32Name.getPersonal());

    Address[] addresses =
        new Address[] {
          noName1, noName2, simpleName, dquoteName, quotedName, utf16Name, utf32Name,
        };
    String line = Address.toHeader(addresses);

    assertEquals(
        "toHeader() multi",
        "[email protected], "
            + "[email protected], "
            + "simple name <*****@*****.**>, "
            + "\"name,4\" <*****@*****.**>, "
            + "\"big \\\"G\\\"\" <*****@*****.**>, "
            + "=?UTF-8?B?5pel5pys6Kqe?= <*****@*****.**>, "
            + "=?UTF-8?B?8J2MgfCdjYY=?= <*****@*****.**>",
        line);
  }
  public static void main(String[] args) {

    ArrayList<BankAccount> bankAccounts = new ArrayList<>();
    ArrayList<BankAccount> closedBankAccounts = new ArrayList<>();

    boolean done = false;

    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    Date date = new Date();

    while (!done) {
      int menu =
          GetData.getInt(
              "\tUnited Bank of Java\n"
                  + "\nPlease Choose From the Following"
                  + "\n1. Create New Account"
                  + "\n2. Update Existing Account"
                  + "\n3. Close an Account"
                  + "\n4. View Account Information"
                  + "\n5. Exit");

      switch (menu) {
        case 1: // Create bank account obj and store in database
          String first = JOptionPane.showInputDialog(null, "What is your first name?");
          String last = JOptionPane.showInputDialog(null, "What is your last name?");
          Name customerName = new Name(first, last);
          JOptionPane.showMessageDialog(null, "Customer name is " + customerName.getName());
          String street = JOptionPane.showInputDialog(null, "What's your street address?");
          String city = JOptionPane.showInputDialog(null, "What city do you live in?");
          String state = JOptionPane.showInputDialog(null, "What state do you live in?");
          String zip = JOptionPane.showInputDialog(null, "What is your ZIP code?");
          Address customerAddress = new Address(street, city, state, zip);
          JOptionPane.showMessageDialog(
              null, "Customer's address is: \n" + customerAddress.getAddress());
          String accountNum =
              JOptionPane.showInputDialog(null, "What do you want your account number to be?");
          Customer c = new Customer(customerName, customerAddress, accountNum);
          JOptionPane.showMessageDialog(
              null,
              "Welcome!\nHere's your info.\nName: "
                  + c.getName()
                  + "\nAddress: "
                  + c.getAddress()
                  + "\nAccount #: "
                  + c.getAccountNum());
          String balance = JOptionPane.showInputDialog(null, "What will be your initial balance?");
          double bal = Double.parseDouble(balance);
          BankAccount bankacc = new BankAccount(c, bal);
          JOptionPane.showMessageDialog(null, "Your balance is: \n" + bankacc.getBalance());
          bankAccounts.add(bankacc);
          System.out.print(bankAccounts.indexOf(bankacc) + " " + bankAccounts.size());

          break;

        case 2: // Update Account
          int money =
              GetData.getInt(
                  "What would you like to do?"
                      + "\n1. Make a deposit."
                      + "\n2. Make a withdrawal."
                      + "\n");

          switch (money) {
            case 1: // Make a deposit
              String accNum = JOptionPane.showInputDialog(null, "What is your account number?");
              if (BankAccount.findAccNum(bankAccounts, accNum)) {
                JOptionPane.showMessageDialog(null, "Account found!");
                int i = BankAccount.findIndex(bankAccounts, accNum);
                JOptionPane.showMessageDialog(
                    null, "Account balance is currently: $" + bankAccounts.get(i).getBalance());
                String x = JOptionPane.showInputDialog(null, "How much would you like to deposit?");
                double y = Double.parseDouble(x);
                bankAccounts.get(i).deposit(y);
                JOptionPane.showMessageDialog(
                    null, "Your new balance is: $" + bankAccounts.get(i).getBalance());
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }
              break;

            case 2: // Make a withdrawal
              String accNum1 = JOptionPane.showInputDialog(null, "What is your account number?");
              if (BankAccount.findAccNum(bankAccounts, accNum1)) {
                JOptionPane.showMessageDialog(null, "Account found!");
                int i = BankAccount.findIndex(bankAccounts, accNum1);
                JOptionPane.showMessageDialog(
                    null, "Account balance is currently: $" + bankAccounts.get(i).getBalance());
                String x =
                    JOptionPane.showInputDialog(null, "How much would you like to withdraw?");
                double y = Double.parseDouble(x);

                if (y < bankAccounts.get(i).getBalance()) {
                  bankAccounts.get(i).withdraw(y);
                  JOptionPane.showMessageDialog(
                      null, "Your new balance is: $" + bankAccounts.get(i).getBalance());
                } else {
                  JOptionPane.showMessageDialog(null, "Insufficient funds.");
                }
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }
              break;

            default:
              JOptionPane.showMessageDialog(null, "Invalid option.");
              break;
          }

          break;

        case 3: // close account
          String accNum = JOptionPane.showInputDialog(null, "What is the account number?");
          if (BankAccount.findAccNum(bankAccounts, accNum)) {
            JOptionPane.showMessageDialog(null, "Account found!");
            int i = BankAccount.findIndex(bankAccounts, accNum);
            BankAccount clone = bankAccounts.get(i);
            bankAccounts.get(i).deactivate();
            JOptionPane.showMessageDialog(
                null, "Account is located in the ArrayList at index: " + i);
            closedBankAccounts.add(clone);
            bankAccounts.remove(i);
          } else {
            JOptionPane.showMessageDialog(null, "Account not found!");
          }

          break;

        case 4: // view account info
          int view =
              GetData.getInt(
                  "What information would you like to view?"
                      + "\n1. Single Account"
                      + "\n2. All active accounts"
                      + "\n3. All inactive accounts"
                      + "\n");

          switch (view) {
            case 1: // view single account
              String accNum2 =
                  JOptionPane.showInputDialog(
                      null, "Please enter account number to view information on it.");

              if (BankAccount.findAccNum(bankAccounts, accNum2)) {
                JOptionPane.showMessageDialog(null, "Account found!");

                int i = BankAccount.findIndex(bankAccounts, accNum2);
                JOptionPane.showMessageDialog(
                    null,
                    "Name: "
                        + bankAccounts.get(i).getName()
                        + "\nAccount Number: "
                        + bankAccounts.get(i).getAccountNum()
                        + "\nBalance: $"
                        + bankAccounts.get(i).getBalance());
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }

              break;

            case 2: // view all account

              /*JTextArea textArea = new JTextArea("Date: " + dateFormat.format(date) +
                          BankAccount.printAllCustomers(bankAccounts));
                  JScrollPane scrollPane = new JScrollPane(textArea);
                  textArea.setLineWrap(true);
                  textArea.setWrapStyleWord(true);
                  scrollPane.setPreferredSize( new Dimension( 300, 400 ) );
                  JOptionPane.showMessageDialog(null, scrollPane, "Current Customers",
                         JOptionPane.YES_NO_OPTION);

              */
              break;

            case 3: // view all closed accounts
              break;

            default:
              JOptionPane.showMessageDialog(null, "Invalid Option.");
              break;
          } // end view
          break;

        case 5: // exit
          done = true;
          break;

        default:
          JOptionPane.showMessageDialog(null, "Account not found.");
          break;
      }
    }
  }