public void addServiceIfNotPresent(WiFiP2pService service) {
        WfdLog.d(TAG, "addServiceIfNotPresent BEGIN, with size = " + serviceList.size());

        if (service == null) {
            WfdLog.e(TAG, "Service is null, returning...");
            return;
        }

        boolean add = true;
        for (WiFiP2pService element : serviceList) {
            if (element != null
                    && element.getDevice().equals(service.getDevice())
                    && element.getInstanceName().equals(service.getInstanceName())) {
                add = false; //already in the list
            }
        }

        if (add) {
            serviceList.add(service);
        }

        WfdLog.d(TAG, "addServiceIfNotPresent END, with size = " + serviceList.size());
    }
public void addServiceIfNotPresent(WiFiP2pService service) {
        WfdLog.d(TAG, "addServiceIfNotPresent BEGIN, with size = " + serviceList.size());

        if (service == null) {
            WfdLog.e(TAG, "Service is null, returning...");
            return;
        }

        boolean add = true;
        for (WiFiP2pService element : serviceList) {
            if (element != null
                    && element.getDevice().equals(service.getDevice())
                    && element.getInstanceName().equals(service.getInstanceName())) {
                add = false; 
            }
        }

        if (add) {
            serviceList.add(service);
        }

        WfdLog.d(TAG, "addServiceIfNotPresent END, with size = " + serviceList.size());
    }
public void addServiceIfNotPresent ( WiFiP2pService service ) { WfdLog . d ( TAG , "addServiceIfNotPresent BEGIN, with size = " + serviceList . size ( ) ) ; if ( service == null ) { WfdLog . e ( TAG , "Service is null, returning..." ) ; return ; } boolean add = true ; for ( WiFiP2pService element : serviceList ) { if ( element != null && element . getDevice ( ) . equals ( service . getDevice ( ) ) && element . getInstanceName ( ) . equals ( service . getInstanceName ( ) ) ) { add = false ; //already in the list } } if ( add ) { serviceList . add ( service ) ; } WfdLog . d ( TAG , "addServiceIfNotPresent END, with size = " + serviceList . size ( ) ) ; }
Method to add a service inside the list in a secure way.
The service is added only if isn't already inside the list.

@param service {@link WiFiP2pService} to add.
Method to add a service inside the list in a secure way . The service is added only if isn t already inside the list .