package net.sourceforge.fenixedu.domain.contacts; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.organizationalStructure.Party; import org.apache.commons.lang.StringUtils; import pt.iscte.ci.metadata.ISCTE; public class MobilePhone extends MobilePhone_Base { public static Comparator COMPARATOR_BY_NUMBER = new Comparator() { public int compare(MobilePhone contact, MobilePhone otherContact) { final String number = contact.getNumber(); final String otherNumber = otherContact.getNumber(); int result = 0; if (number != null && otherNumber != null) { result = number.compareTo(otherNumber); } else if (number != null) { result = 1; } else if (otherNumber != null) { result = -1; } return (result == 0) ? COMPARATOR_BY_TYPE.compare(contact, otherContact) : result; } }; protected MobilePhone() { super(); } protected MobilePhone(final Party party, final PartyContactType type, final boolean visible, final boolean defaultContact) { this(); super.init(party, type, visible, defaultContact); } public MobilePhone(final Party party, final PartyContactType type, final Boolean defaultContact, final String number) { this(party, type, true, defaultContact.booleanValue(), number); } public MobilePhone(final Party party, final PartyContactType type, final boolean visible, final boolean defaultContact, final String number) { this(); super.init(party, type, visible, defaultContact); checkParameters(number); super.setNumber(number); } private void checkParameters(final String number) { if (StringUtils.isEmpty(number)) { throw new DomainException("error.contacts.Phone.invalid.number"); } } @Override public boolean isMobile() { return true; } @ISCTE(comment = "Added the checking to null condition", author = "Paulo Zenida") public void edit(final String number) { if (number != null) { super.setNumber(number); invalidate(); } } public void edit(final PartyContactType type, final Boolean defaultContact, final String number) { super.edit(type, true, defaultContact); edit(number); } @ISCTE public static List readMobilePhonesByNumber(final String number) { final List result = new ArrayList(); if (number != null) { for (final PartyContact partyContact : RootDomainObject.getInstance().getPartyContacts()) { if (partyContact instanceof MobilePhone) { MobilePhone mobilePhone = (MobilePhone) partyContact; if (mobilePhone.getNumber() != null && mobilePhone.getNumber().equals(number)) { result.add(mobilePhone); } } } } return result; } }