code: private static String getBowerBestMatchFromMainArray(ArrayList<String> items, String name) {
          if(items.size() == 1) // not really much choice here
              return items.get(0);
  
          ArrayList<String> filteredList = new ArrayList<>();
  
          // first idea: only look at .js files
  
          for(String item : items) {
              if(item.toLowerCase().endsWith(".js")) {
                  filteredList.add(item);
              }
          }
  
          // ... if there are any
          if(filteredList.size() == 0)
              filteredList = items;
  
          final HashMap<String, Integer> distanceMap = new HashMap<>();
          final String nameForComparisons = name.toLowerCase();
  
          // second idea: most scripts are named after the project's name
          // sort all script files by their Levenshtein-distance
          // and return the one which is most similar to the project's name
  
          Collections.sort(filteredList, new Comparator<String>() {
  
              Integer getDistance(String value) {
                  int distance;
                  value = value.toLowerCase();
                  if (distanceMap.containsKey(value)) {
                      distance = distanceMap.get(value);
                  } else {
                      distance = StringUtils.getLevenshteinDistance(nameForComparisons, value);
                      distanceMap.put(value, distance);
                  }
                  return distance;
              }
  
              @Override
              public int compare(String o1, String o2) {
                  return getDistance(o1).compareTo(getDistance(o2));
              }
          });
  
          return filteredList.get(0);
      }
docs: /*
  Heuristic approach to find the 'best' candidate which most likely is the main script of a package.