/** * Add a phone to the correct operator responsible by his prefix * * @param phoneNumber The phone object to be added */ public void addPhone(String operatorPrefix, String phoneNumber, AnacomData.PhoneType phoneGen) { Operator operator = this.getOperatorByPrefix(operatorPrefix); String phonePrefix = getPhonePrefixByNumber(phoneNumber); if (!(operator.getPrefix().equals(phonePrefix))) throw new PhoneAndOperatorPrefixDoNotMatchException(operator.getPrefix(), phonePrefix); if (phoneGen == AnacomData.PhoneType.GEN2) { Phone phone = new OldGenPhone(phoneNumber); operator.addPhone(phone); phone.setOperator(operator); } else if (phoneGen == AnacomData.PhoneType.GEN3) { Phone phone = new NewGenPhone(phoneNumber); operator.addPhone(phone); phone.setOperator(operator); } }
public boolean conflicts(Operator operator) { return (operator.getPrefix().equals(this.getPrefix())) && (operator.getName().equals(this.getName())); }
public Operator hasOperatorByPrefix(String prefix) { for (Operator operator : this.getOperator()) if (operator.getPrefix().equals(prefix)) return operator; return null; }
@Override public boolean hasOperator(Operator operator) { for (Operator aux : this.getOperatorSet()) if (operator.conflicts(aux)) return true; return false; }
public void removePhone(String phoneNumber) { Phone phone = this.getPhone(phoneNumber); Operator operator = this.getOperatorByPrefix(getPhonePrefixByNumber(phoneNumber)); operator.removePhone(phone); }
public Phone getPhone(String number) { Operator operator = getOperatorByPrefix(getPhonePrefixByNumber(number)); return operator.getPhoneByNumber(number); }