Java Reference
In-Depth Information
Collection resources # new Vector();
// the specification, defining the attributes
// (i.e. coordinates)
Specification specification;
public ResourceAllocation(Specification specification) {
this .specification # specification;
}
// define the number of available resources of a given type
// the type is expressed in terms of coordinates
public void setAvailability(Map coordinates, int available){
Resource res # new Resource(coordinates,available);
resources.add(res);
}
// book a resource corresponding to a proposal
// this method MUST be invoked at the end of a successful
// negotiation
public void book(Proposal proposal){
if (proposal ## null ) return ;
Map coordinates # new Hashtable();
Iterator it # proposal.getAttributes().iterator();
while (it.hasNext()){
Attribute attribute # (Attribute)it.next();
coordinates.put(attribute.getName(),
attribute.getValue());
}
book(coordinates);
}
// book a resource with the given coordinates
private void book(Map coordinates){
Iterator it # resources.iterator();
while (it.hasNext()){
Resource resource # (Resource)it.next();
if (resource.match(coordinates)){
resource.book();
return ;
}
}
}
// return the preferences
public PreferenceMap preference(){
PreferenceMap pref # new ResourcePreference
(specification,this);
return preference(pref);
}
// re-calculate the ranks and weights of the preference
public PreferenceMap preference(PreferenceMap pref){
Search WWH ::




Custom Search