public void addClientIfNotPresent ( DeviceGuiElement device ) { boolean add = true ; for ( DeviceGuiElement element : clients ) { if ( element != null && element . getName ( ) . equals ( device . getName ( ) ) && element . getAddress ( ) . equals ( device . getAddress ( ) ) ) { add = false ; //already in the list } } if ( add ) { clients . add ( device ) ; } }
Method to add a client inside the list in a secure way . The client is added only if isn t already inside the list .