Element RoleDp: RoleDps) {
if (!RoleHostsMap.containsKey(RoleDp.attribute ("Target").getText ())) {
ArrayList<String> tmp=new ArrayList<String>();tmp.addAll(HostsList);
RoleHostsMap.put (RoleDp.attribute ("Dependent,,).getText (),tmp);
RoleHostsMap.put(RoleDp.attribute(〃Target〃).getText(),tmp);
}else {
ArrayList<String> tmp=RoleHostsMap.get(RoleDp.attribute(〃Target〃).getText());
RoleHostsMap.put (RoleDp.attribute ("Dependent,,).getText (),tmp);
}
}
//System, out.println("After deal RoleDependencies,the RoleHostsMap
is
//System, out.println(RoleHostsMap);
}
publicvoid DealExclusives(){
InitialRemainingRoles();
String RoleA, RoleB;
int AMin,AMax, BMin,BMax, AHave, BHave, ABHave;
for (Element Exclu: (List〈Element>) ExclusEle.elements 0){
ArrayList<String> AHostList=new ArrayList〈String>(),BHostList=new ArrayList<String> (),ABHostList=new ArrayList<String> (),TmpHostList=newArrayList<String>();
int gapA=0,gapB = 0,addToA=0,addToB=0;
RoleA =Exclu.attributeValue(〃RoleA〃);
RoleB =Exclu.attributeValue(〃RoleB〃);
//System, out.println(〃RoleA is 〃+RoleA);
//System, out.println(〃RoleB is 〃+RoleB);
AMin= (int) new Calculator ().calculate(this.NumberOfRolesEle.element(RoleA).attributeValue(〃MinNumber〃).replaceAll (〃AllHostsNum〃,〃〃+this.AllHostNum));
AMax= (int) new Calculator ().calculate(this.NumberOfRolesEle.element(RoleA).attributeValue(〃MaxNumber〃).replaceAll(〃AllHostsNum〃,〃〃+this.AllHostNum));
BMin= (int) new Calculator ().calculate(this.NumberOfRolesEle.element(RoleB).attributeValue(〃MinNumber〃).replaceAll (〃AllHostsNum〃,〃〃+this.AllHostNum));
BMax= (int) new Calculator ().calculate(this.NumberOfRolesEle.element(RoleB).attributeValue(〃MaxNumber〃).replaceAll (〃AllHostsNum〃,〃〃+this.AllHostNum));
AHostList=RoleHostsMap.get(RoleA);
BHostList=RoleHostsMap.get(RoleB);
ABHostList.addAll(AHostList);
ABHostList.retainAll(BHostList);
ABHave = ABHostList.size ();
AHave = AHostList.size ();
BHave = BHostList.size ();
System, out.println (RoleA);
System, out.println (RoleB);
System, out.println (〃A: 〃+AHostList);
System, out.println (〃B: 〃+BHostList);
System, out.println (AHave);
System, out.println (BHave);
System, out.println (ABHave);
//把roleA和roleB各分成3种情况,“①《min《=②《=max《③”,即除去交集部分,已经拥有的节点数量在①、②、③的哪个位置,通过组合可以得到如下的几种情况(共3*3=9种,其中5种可以合并为第一种情况)
if(AHave-ABHave-AMax>0 | | BHave-ABHave-BMax>0) { if (! (AHave-ABHave-AMax>0)){
BHostList.removeAll(ABHostList);
}elseif (! (BHave-ABHave-BMax>0)) {
AHostList.removeAll(ABHostList);
}else {
AHostList.removeAll(ABHostList);
BHostList.removeAll(ABHostList);
}
}elseif(AHave-ABHave-AMin<0 && BHave-ABHave-BMin<0){ if ((AHave+BHave-AMin-BMin-ABHave)〈0) { try {
thrownew Except1n (^Error, the number of hosts is notenough.\n The error is found when deal Exclusive-Relat1n between 〃+RoleA+〃 and"+RoleB);
} catch (Except1n e) {
// TODO Auto-generated catch blocke.printStackTrace ();
System, exii(0);
}
}
gapA=AMax-(AHave-ABHave);gapB=BMax-(BHave-ABHave);
addToA=(AHave+BHave-AMin-BMin-ABHave)*(AMax-AMin)/((AMax-AMin) + (BMax-BMin)) + (AMin-(AHave-ABHave));
addT oB=ABHave-addT oA;
}elseif(!(AHave-ABHave-AMin<0) && BHave-ABHave-BMin<0){ if ((BHave-BMin)<0) { try {
thrownew Except1n (^Error, the number of hosts is notenough.\n The error is found when deal Exclusive-Relat1n between 〃+RoleA+〃 and"+RoleB);
} catch (Except1n e) {
// TODO Auto-generated catch block e.printStackTrace ();
System, exii(0);
}
}
gapA=AMax-(AHave-ABHave);gapB=BMax-(BHave-ABHave);addToA=(BHave_BMin)*gapA/(gapA+(BMax-BMin));addT oB=ABHave-addT oA;
}elseif (AHave-ABHave_AMin〈0 && !(BHave-ABHave-BMin<0)){ if ((AHave-AMin)〈0){ try {
thrownew Except1n (^Error, the number of hosts is notenough.\n The error is found when deal Exclusive-Relat1n between 〃+RoleA+〃 and"+RoleB);
} catch (Except1n e) {
// TODO Auto-generated catch block e.printStackTrace ();
System, exii(0);
}
}
gapA=AMax-(AHave-ABHave);gapB=BMax-(BHave-ABHave); System, out.println ((gapB+ (AMax-AMin)));
System, out.println (AMin- (AHave-ABHave));
addToA=(AHave-AMin) *(AMax-AMin)/(gapB+ (AMax-AMin)) + (AMin- (A
Have-ABHave));
addT oB=ABHave-addT oA;
}else {
gapA=AMax-(AHave-ABHave);gapB=BMax-(BHave-ABHave);addToA = ABHave*gapA/(gapA+gapB);addT oB=ABHave-addT oA;
}
if(!(AHave-ABHave-AMax>0 || BHave-ABHave-BMax>0)){
TmpHostList.addAll(ABHostList);
AHostList.removeAll(ABHostList);
BHostList.removeAll(ABHostList); for (int i=0;i〈addToA&&i〈gapA;i++){
AHostList.add (ABHostList.get (i));
Tmp