package net.sourceforge.fenixedu.domain.contacts; import java.util.Comparator; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.organizationalStructure.Party; import org.apache.commons.lang.StringUtils; public class InternalPhone extends InternalPhone_Base { public static Comparator COMPARATOR_BY_NUMBER = new Comparator() { public int compare(Phone contact, Phone 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 InternalPhone() { super(); } protected InternalPhone(final Party party, final PartyContactType type, final boolean visible, final boolean defaultContact) { this(); super.init(party, type, visible, defaultContact); } public InternalPhone(final Party party, final PartyContactType type, final Boolean defaultContact, final String number) { this(party, type, true, defaultContact, number); } public InternalPhone(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 isInternalPhone() { return true; } public void edit(final PartyContactType type, final Boolean defaultContact, final String number) { super.edit(type, true, defaultContact); setNumber(number); } @Override protected void checkRulesToDelete() { if (getParty().getPartyContacts(getClass()).size() == 1) { throw new DomainException("error.domain.contacts.Phone.cannot.remove.last.phone"); } } }