public static String buildSelectorFromElementAndChildren(String elementName,Collection<String> childrenList,boolean hasChild){
  StringBuilder selector=new StringBuilder();
  boolean isFirstElement=true;
  for (  String child : childrenList) {
    if (!isFirstElement) {
      selector.append(SPACE);
      selector.append(COMMA);
      selector.append(SPACE);
    }
    selector.append(elementName);
    if (!hasChild) {
      selector.append(NOT_PREFIX);
    }
    selector.append(HAS_PREFIX);
    selector.append(child);
    selector.append(CLOSE_PARENTHESE);
    if (!hasChild) {
      selector.append(CLOSE_PARENTHESE);
    }
    isFirstElement=false;
  }
  return selector.toString();
}

public static String buildSelectorFromElementAndChildren ( String elementName , Collection < String > childrenList , boolean hasChild ) { StringBuilder selector = new StringBuilder ( ) ; boolean isFirstElement = true ; for ( String child : childrenList ) { if ( ! isFirstElement ) { selector . append ( SPACE ) ; selector . append ( COMMA ) ; selector . append ( SPACE ) ; } selector . append ( elementName ) ; if ( ! hasChild ) { selector . append ( NOT_PREFIX ) ; } selector . append ( HAS_PREFIX ) ; selector . append ( child ) ; selector . append ( CLOSE_PARENTHESE ) ; if ( ! hasChild ) { selector . append ( CLOSE_PARENTHESE ) ; } isFirstElement = false ; } return selector . toString ( ) ; }
build a jquery selector to retrieve elements that have or not children of a given type . multiple children can be set .
