private Ports getPortBindings ( String portSpecs , ExposedPort [ ] exposedPorts , TestContext context ) { String [ ] ports = StringUtils . commaDelimitedListToStringArray ( portSpecs ) ; Ports portsBindings = new Ports ( ) ; for ( String portSpec : ports ) { String [ ] binding = context . replaceDynamicContentInString ( portSpec ) . split ( ":" ) ; if ( binding . length == 2 ) { Integer hostPort = Integer . valueOf ( binding [ 0 ] ) ; Integer port = Integer . valueOf ( binding [ 1 ] ) ; portsBindings . bind ( Stream . of ( exposedPorts ) . filter ( exposed -> port . equals ( exposed . getPort ( ) ) ) . findAny ( ) . orElse ( ExposedPort . tcp ( port ) ) , Ports . Binding . bindPort ( hostPort ) ) ; } } Stream . of ( exposedPorts ) . filter ( exposed -> ! portsBindings . getBindings ( ) . keySet ( ) . contains ( exposed ) ) . forEach ( exposed -> portsBindings . bind ( exposed , Ports . Binding . empty ( ) ) ) ; return portsBindings ; }
Construct set of port bindings from comma delimited list of ports .