我正忙着为我的最后一年项目制定计划。以下方法需要返回组合列表,组合是LoadCases列表(variableLoad和permanentLoad是LoadCase的子类):
public ArrayList<ArrayList<LoadCase>> strUfCombinations()
{
ArrayList<ArrayList<LoadCase>> combinationslist = new ArrayList<ArrayList<LoadCase>>();
int i = 0;
for(int x = 0; x < allvariableLoads.size(); x++)
{
combinationslist.add(new ArrayList<LoadCase>());
}
ListIterator<ArrayList<LoadCase>> cListItr = combinationslist.listIterator();
while(cListItr.hasNext())
{
cListItr.next();
ArrayList<LoadCase> combination = new ArrayList<LoadCase>();
for(int j = 0; j < allvariableLoads.size(); j++)
{
allvariableLoads.get(j).setIsLeading(false);
}
allvariableLoads.get(i).setIsLeading(true);
Iterator<VariableLoad> vLoadIterator = allvariableLoads.iterator();
while(vLoadIterator.hasNext())
{
VariableLoad vload = vLoadIterator.next();
if(vload.getIsLeading()==true)
{
vload.finalfactor = vload.partialFactor.strUf;
}
if(vload.getIsLeading()== false)
{
vload.finalfactor = vload.combinationFactor * vload.partialFactor.strUf;
}
combination.add(vload);
}
Iterator<PermanentLoad> pLoadIterator = permanentLoads.iterator();
while(pLoadIterator.hasNext())
{
PermanentLoad pload = pLoadIterator.next();
pload.finalfactor = pload.partialFactor.strUf;
combination.add(pload);
}
Iterator<LoadCase> combItr = combination.iterator();
while(combItr.hasNext())
{
LoadCase test = combItr.next();
System.out.print(test.finalfactor+test.name+" ");
}
System.out.println();
cListItr.set(combination);
i++;
}
System.out.println("\n");
return combinationslist;
}
我正在使用测试类来运行它:
public static void main(String[] args)
{
PermanentLoad testload = new PermanentLoad("DL1", "self");
PermanentLoad testload2 = new PermanentLoad("DL2", "geofac");
PermanentLoad testload3 = new PermanentLoad("DL3", "fluid");
PermanentLoad testload4 = new PermanentLoad("DL4", "geounf");
VariableLoad vload1 = new VariableLoad("VL1", "imposed", "A");
VariableLoad vload2 = new VariableLoad("VL2", "wind", "normal");
VariableLoad vload3 = new VariableLoad("VL3", "imposed", "E2");
VariableLoad vload4 = new VariableLoad("VL4", "thermal", "normal");
CasesManager manager = new CasesManager();
manager.addCase("DL1", "self", "null");
manager.addCase("DL2", "geofac", "null");
manager.addCase("DL3", "fluid", "null");
manager.addCase("DL4", "geounf", "null");
manager.addCase("VL1", "imposed", "A");
manager.addCase("VL2", "wind", "normal");
manager.addCase("VL3", "imposed", "E2");
manager.addCase("VL4", "thermal", "normal");
manager.addCase("VL5", "cranes", "normal");
System.out.println("\n");
CombinationCalculator calc = new CombinationCalculator(manager);
ArrayList<ArrayList<LoadCase>> combinations = calc.strUfCombinations();
Iterator<ArrayList<LoadCase>> cListItr = combinations.iterator();
while(cListItr.hasNext())
{
Iterator<LoadCase> combItr = cListItr.next().iterator();
while(combItr.hasNext())
{
LoadCase test = combItr.next();
System.out.print(test.finalfactor+test.name+" ");
}
System.out.println();
}
运行测试类时的输出是:
1.6VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 1.6VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 1.6VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 1.3VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
0.48VL1 0.96VL3 0.48VL4 0.0VL2 1.6VL5 1.2DL1 0.0DL2 1.2DL3 1.2DL4
矩阵从strUfCombinations()内打印,第二个矩阵通过迭代最终组合列表从测试类打印。第一个矩阵是正确的输出。在我看来,strUfCombinations()方法是使用最后添加的组合填充组合列表。
有人可以帮忙吗?也许我只是错过了一些简单的东西。
此致 雅克
答案 0 :(得分:0)
问题是我使用的LoadCases
被回收,即arraylist中的每个元素都指向一个LoadCase
,这就是为什么所有元素都具有最终数组的值。
我通过在类 LoadCase 中编写static clone()
方法来解决问题,该方法创建 LoadCase 的副本。然后创建克隆并将其组合而不是来自allvariableloads
和permanentloads
的原始LoadCase。