code: private SearchResult searchMap(Map<String, ?> map, String pattern, int limit) {
  
          if (pattern == null) {
              throw new IllegalArgumentException("pattern is null");
          }
          if (pattern.isEmpty()) {
              throw new IllegalArgumentException("pattern is an empty String");
          }
  
          String regexPattern = convertToRegex(pattern);
  
          if (limit < 0) {
              return new SearchResult();
          }
          if (map.size() == 0) {
              return new SearchResult();
          }
          int count = 0;
          // Set the stopping point 1 past our limit. If we reach
          // this point, then we know there are more entries than
          // limit which match pattern, so we can say hasMore is
          // true. We have to keep trying to match 1 past the limit
          // because if we stop at limit, we can't be sure the
          // other entries will match pattern.
          int stoppingPoint = (limit == 0) ? 0 : limit + 1;
          boolean hasMore = false;
          List<String> matched = new ArrayList<String>();
          Set<String> userNames = map.keySet();
          Iterator<String> itr = userNames.iterator();
          while (itr.hasNext()) {
              String name = itr.next();
              if (name.matches(regexPattern)) {
                  matched.add(name);
                  count++;
                  if (count == stoppingPoint) {
                      matched.remove(name);
                      hasMore = true;
                      break;
                  }
              }
          }
  
          if (count > 0) {
              return new SearchResult(matched, hasMore);
          } else {
              return new SearchResult();
          }
      }
docs: Finds key entries in the specified Map<String,?> which match the specified pattern.
  
  @see #getUsers(String, int)
  @see #getGroups(String, int)
  @param pattern pattern to match
  @param limit limit of entries to return
  @return a SearchResult object