code: private void clear(IntSet segments, boolean keepSegments) {
        for (Iterator<K> keyIterator = entries.keySet().iterator(); keyIterator.hasNext(); ) {
           K key = keyIterator.next();
           int keySegment = getSegmentForKey(key);
           if (keepSegments != segments.contains(keySegment)) {
              keyIterator.remove();
           }
        }
     }
docs: Clears entries out of caffeine map by invoking remove on iterator. This can either keep all keys that match the
  provided segments when keepSegments is <code>true</code> or it will remove only the provided segments when
  keepSegments is <code>false</code>.
  @param segments the segments to either remove or keep
  @param keepSegments whether segments are kept or removed