code: private UnicodeSet applyFilter(Filter filter, int src) {
          // Logically, walk through all Unicode characters, noting the start
          // and end of each range for which filter.contain(c) is
          // true.  Add each range to a set.
          //
          // To improve performance, use an inclusions set which
          // encodes information about character ranges that are known
          // to have identical properties.
          // getInclusions(src) contains exactly the first characters of
          // same-value ranges for the given properties "source".
  
          clear();
  
          int startHasProperty = -1;
          UnicodeSet inclusions = getInclusions(src);
          int limitRange = inclusions.getRangeCount();
  
          for (int j=0; j<limitRange; ++j) {
              // get current range
              int start = inclusions.getRangeStart(j);
              int end = inclusions.getRangeEnd(j);
  
              // for all the code points in the range, process
              for (int ch = start; ch <= end; ++ch) {
                  // only add to the unicodeset on inflection points --
                  // where the hasProperty value changes to false
                  if (filter.contains(ch)) {
                      if (startHasProperty < 0) {
                          startHasProperty = ch;
                      }
                  } else if (startHasProperty >= 0) {
                      add_unchecked(startHasProperty, ch-1);
                      startHasProperty = -1;
                  }
              }
          }
          if (startHasProperty >= 0) {
              add_unchecked(startHasProperty, 0x10FFFF);
          }
  
          return this;
      }
docs: Generic filter-based scanning code for UCD property UnicodeSets.