/** * 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; }