/// <summary> /// Compare this Delegation with other according to the ordering, based first /// on the preference number, then on the delegation name. /// </summary> /// /// <param name="other">The other Delegation to compare with.</param> /// <returns>0 If they compare equal, -1 if this Delegation comes before other /// in the ordering, or 1 if this Delegation comes after.</returns> public int compare(DelegationSet.Delegation other) { if (preference_ < other.preference_) { return(-1); } if (preference_ > other.preference_) { return(1); } return(name_.compare(other.name_)); }
/// <summary> /// Add a new DelegationSet.Delegation to the list of delegations, sorted by /// preference number then by name. If there is already a delegation with the /// same name, update its preference, and remove any extra delegations with the /// same name. /// </summary> /// /// <param name="preference">The preference number.</param> /// <param name="name">The delegation name. This makes a copy of the name.</param> public void add(int preference, Name name) { remove(name); DelegationSet.Delegation newDelegation = new DelegationSet.Delegation (preference, name); // Find the index of the first entry where it is not less than newDelegation. int i = 0; while (i < delegations_.Count) { if (delegations_[i].compare(newDelegation) >= 0) break; ++i; } delegations_.Insert(i, newDelegation); }
/// <summary> /// Add a new DelegationSet.Delegation to the list of delegations, sorted by /// preference number then by name. If there is already a delegation with the /// same name, update its preference, and remove any extra delegations with the /// same name. /// </summary> /// /// <param name="preference">The preference number.</param> /// <param name="name">The delegation name. This makes a copy of the name.</param> public void add(int preference, Name name) { remove(name); DelegationSet.Delegation newDelegation = new DelegationSet.Delegation(preference, name); // Find the index of the first entry where it is not less than newDelegation. int i = 0; while (i < delegations_.Count) { if (delegations_[i].compare(newDelegation) >= 0) { break; } ++i; } delegations_.Insert(i, newDelegation); }