@Override
  public int occurrences(Object element) {
    if (hasLimitIterator) {
      // Asif: If limit iterator then occurrence should be calculated
      // via the limit iterator
      int count = 0;
      boolean encounteredObject = false;
      for (Object v : this) {
        if (element == null ? v == null : element.equals(v)) {
          count++;
          encounteredObject = true;
        } else if (encounteredObject) {
          // Asif: No possibility of its occurrence again
          break;
        }
      }
      return count;
    } else {
      if (element == null) {
        return numNulls;
      }
      return mapGet(element); // returns 0 if not
                              // found
    }
  }
Return an unmodifiable Set view of this bag. Does not require an iteration by using a
lightweight wrapper.
geode-core/src/main/java/org/apache/geode/cache/query/internal/Bag.java