import java.util.*; class OntoParamGroup extends OntoParam{ Vector childgroups=new Vector(); Vector parameters=new Vector(); //Integer vector public OntoParamGroup(String ugroupname, double ugroupcoef, OntoParamGroup uparent){ super(ugroupname, ugroupcoef, uparent); } void addParameter(OntoParam param){ if(parameters.contains(param)){ // throw new RuntimeException("Parameter "+param+" allready in group"); System.out.println("Same group"); } addParameter(param, parameters.size()); } void addParameter(OntoParam param, int index){ if(param instanceof OntoParamGroup){ addChildGroup((OntoParamGroup)param); } else { if(param.parent==this){ if(index>parameters.indexOf(param)){ index=index-1; } } param.parent.parameters.remove(param); param.parent=this; if(index>parameters.size()){index=parameters.size();} if(index<0){index=0;} parameters.add(index, param); } } void addChildGroup(OntoParamGroup group){ if(group.parent==null){ return; //root group } if(group.parent!=null){ group.parent.childgroups.remove(group); } group.parent=this; childgroups.add(group); } OntoParam getParameter(int index){ return (OntoParam)parameters.get(index); } boolean isEmpty(){ return parameters.size()==0 && childgroups.size()==0; } }