Java Reference
In-Depth Information
if
(clientProposal.equals(serverProposal)){ // successful
clientProposal.merge(client.initialProposal());
serverProposal.merge(server.initialProposal());
return true
;
}
else
return false
;
}
}
Class
BasicNegotiator
implements interface
Negotiator
and defines the
maximum number of iterations for the negotiation process. The main
method is
counterProposal()
that formulates a new proposal.
package
Negotiation;
import
java.util.*;
public class
BasicNegotiator
extends
Negotiator {
PreferenceMap preference;
Proposal lastProposal
#
null
;
double
threshold;
private
Proposal finalProposal;
public
BasicNegotiator(Preference preference) {
this
.preference
#
preference;
this
.threshold
#
0.5;
}
public void
intersect(Proposal own, Proposal other) {
own.intersect(other,preference);
}
public
Proposal initialProposal() {
try
{
lastProposal
#
preference.bestProposal();
}
catch
(Exception e){
e.printStackTrace();
}
return
lastProposal;
}
public
Proposal counterProposal(Proposal received) {
if
(lastProposal
##
null
){
return
initialProposal();
}
// the counter-proposal is equal to the last proposal
// but..
Proposal counterProposal
#
new
Proposal(lastProposal);
// only with the allowed values for the common
// attributes and..
counterProposal.intersect(received,preference);
// the values proposed by the counterpart for the
// nonrelevant attributes
counterProposal.merge(received);