for( Duct duct : ducts )
{
if( !( duct instanceof ElementDuct ) )
continue;
ElementDuct elementDuct = (ElementDuct) duct;
FlowElement flowElement = elementDuct.getFlowElement();
Set<String> branchNames = new TreeSet<String>();
if( flowElement instanceof Pipe )
branchNames.add( ( (Pipe) flowElement ).getName() );
else if( flowElement instanceof Tap )
branchNames.addAll( getTapBranchNamesFor( duct ) );
else
throw new IllegalStateException( "unexpected duct type" + duct.getClass().getCanonicalName() );
elementDuct.setBranchNames( branchNames );
for( String branchName : branchNames )
{
Tap trap = node.getTrap( branchName );
if( trap != null )
{
elementDuct.setTrapHandler( new TrapHandler( flowProcess, trap, branchName ) );
break;
}
}
if( !elementDuct.hasTrapHandler() )
elementDuct.setTrapHandler( new TrapHandler( flowProcess ) );
}
}