예제 #1
0
  public synchronized List<Contact> findAll(String stringFilter) {
    ArrayList arrayList = new ArrayList();
    for (Contact contact : contacts.values()) {
      try {
        boolean passesFilter =
            (stringFilter == null || stringFilter.isEmpty())
                || contact.toString().toLowerCase().contains(stringFilter.toLowerCase());
        if (passesFilter) {
          arrayList.add(contact.clone());
        }
      } catch (CloneNotSupportedException ex) {
        Logger.getLogger(ContactService.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    Collections.sort(
        arrayList,
        new Comparator<Contact>() {

          @Override
          public int compare(Contact o1, Contact o2) {
            return (int) (o2.getId() - o1.getId());
          }
        });
    return arrayList;
  }
 @Override
 protected Contact getContactForEnterRangeEvent(Sensor sensor, Mover target) {
   Contact contact = contacts.get(target);
   if (contact == null) {
     contact = new SensorContact((Mover) target);
     contacts.put(target, contact);
   }
   System.out.println(
       "TestMediator providing contact "
           + contact.toString()
           + " for target "
           + target.toString());
   return contact;
 }
  /**
   * Returns a string representation of this group, in the form YahooGroup.GroupName[size]{
   * buddy1.toString(), buddy2.toString(), ...}.
   *
   * @return a String representation of the object.
   */
  @Override
  public String toString() {
    StringBuffer buff = new StringBuffer("VolatileYahooGroup.");
    buff.append(getGroupName());
    buff.append(", childContacts=" + countContacts() + ":[");

    Iterator<Contact> contacts = contacts();

    while (contacts.hasNext()) {
      Contact contact = contacts.next();

      buff.append(contact.toString());
      if (contacts.hasNext()) buff.append(", ");
    }
    return buff.append("]").toString();
  }
예제 #4
0
 public void action() {
   Contact contact = new Contact();
   String name, phone;
   name = JOptionPane.showInputDialog("Ange namn");
   contact.setName(name);
   phone = JOptionPane.showInputDialog("Ange hemtelefon");
   contact.setPhone(phone);
   contact.setMobile(JOptionPane.showInputDialog("Ange mobil"));
   contact.setEmail(JOptionPane.showInputDialog("Ange mail-adress"));
   JOptionPane.showMessageDialog(null, contact.toString());
   JOptionPane.showMessageDialog(
       null,
       contact.getName()
           + "\n"
           + contact.getPhone()
           + "\n"
           + contact.getMobile()
           + "\n"
           + contact.getEmail());
 }
예제 #5
0
  /**
   * Returns a String representation of this group and the contacts it contains (may turn out to be
   * a relatively long string).
   *
   * @return a String representing this group and its child contacts.
   */
  @Override
  public String toString() {
    StringBuffer buff = new StringBuffer(getGroupName());
    buff.append(".subGroups=" + countSubgroups() + ":\n");

    Iterator<ContactGroup> subGroups = subgroups();
    while (subGroups.hasNext()) {
      ContactGroup group = subGroups.next();
      buff.append(group.toString());
      if (subGroups.hasNext()) buff.append("\n");
    }

    buff.append("\nChildContacts=" + countContacts() + ":[");

    Iterator<Contact> contacts = contacts();
    while (contacts.hasNext()) {
      Contact contact = contacts.next();
      buff.append(contact.toString());
      if (contacts.hasNext()) buff.append(", ");
    }
    return buff.append("]").toString();
  }