Utility.java :  » Web-Mail » claros-intouch2-2.2-beta » org » claros » intouch » contacts » utility » Java Open Source

Java Open Source » Web Mail » claros intouch2 2.2 beta 
claros intouch2 2.2 beta » org » claros » intouch » contacts » utility » Utility.java
package org.claros.intouch.contacts.utility;

import java.util.Collections;
import java.util.List;

import org.claros.intouch.contacts.models.Contact;

/**
 * @author Umut Gokbayrak
 */
public class Utility {

  /* (non-Javadoc)
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  public static List sortContacts(List contacts, boolean nameFirst) {
    if (contacts != null) {
      Collections.sort(contacts, new ContactsComparator(nameFirst));
    }
    return contacts;
  }

  public static String getFullName(Contact contact, boolean nameFirst) {
    String firstName = contact.getFirstName();
    String middleName = contact.getMiddleName();
    String lastName = contact.getLastName();
    
    String fullName = "";  
    if (lastName == null || lastName.trim().equals("")) {
      fullName = firstName;
    } else {
      if (nameFirst) {
        fullName = firstName + " " + lastName;
        if (middleName != null && !middleName.trim().equals("")) {
          fullName = firstName + " " + middleName + " " + lastName;
        }
      } else {
        fullName = lastName + ", " + firstName;
        if (middleName != null && !middleName.trim().equals("")) {
          fullName = lastName + ", " + firstName + " " + middleName;
        }
      }
    }
    return fullName.trim();
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.