private Collection<Insanity> checkSubreaders(MapOfSets<Integer,CacheEntry> valIdToItems,MapOfSets<ReaderField,Integer> readerFieldToValIds){
  final List<Insanity> insanity=new ArrayList<>(23);
  Map<ReaderField,Set<ReaderField>> badChildren=new HashMap<>(17);
  MapOfSets<ReaderField,ReaderField> badKids=new MapOfSets<>(badChildren);
  Map<Integer,Set<CacheEntry>> viToItemSets=valIdToItems.getMap();
  Map<ReaderField,Set<Integer>> rfToValIdSets=readerFieldToValIds.getMap();
  Set<ReaderField> seen=new HashSet<>(17);
  Set<ReaderField> readerFields=rfToValIdSets.keySet();
  for (  final ReaderField rf : readerFields) {
    if (seen.contains(rf))     continue;
    List<Object> kids=getAllDescendantReaderKeys(rf.readerKey);
    for (    Object kidKey : kids) {
      ReaderField kid=new ReaderField(kidKey,rf.fieldName);
      if (badChildren.containsKey(kid)) {
        badKids.put(rf,kid);
        badKids.putAll(rf,badChildren.get(kid));
        badChildren.remove(kid);
      }
 else       if (rfToValIdSets.containsKey(kid)) {
        badKids.put(rf,kid);
      }
      seen.add(kid);
    }
    seen.add(rf);
  }
  for (  final ReaderField parent : badChildren.keySet()) {
    Set<ReaderField> kids=badChildren.get(parent);
    List<CacheEntry> badEntries=new ArrayList<>(kids.size() * 2);
{
      for (      final Integer value : rfToValIdSets.get(parent)) {
        badEntries.addAll(viToItemSets.get(value));
      }
    }
    for (    final ReaderField kid : kids) {
      for (      final Integer value : rfToValIdSets.get(kid)) {
        badEntries.addAll(viToItemSets.get(value));
      }
    }
    CacheEntry[] badness=new CacheEntry[badEntries.size()];
    badness=badEntries.toArray(badness);
    insanity.add(new Insanity(InsanityType.SUBREADER,"Found caches for descendants of " + parent.toString(),badness));
  }
  return insanity;
}

private Collection < Insanity > checkSubreaders ( MapOfSets < Integer , CacheEntry > valIdToItems , MapOfSets < ReaderField , Integer > readerFieldToValIds ) { final List < Insanity > insanity = new ArrayList < > ( 23 ) ; Map < ReaderField , Set < ReaderField > > badChildren = new HashMap < > ( 17 ) ; MapOfSets < ReaderField , ReaderField > badKids = new MapOfSets < > ( badChildren ) ; Map < Integer , Set < CacheEntry > > viToItemSets = valIdToItems . getMap ( ) ; Map < ReaderField , Set < Integer > > rfToValIdSets = readerFieldToValIds . getMap ( ) ; Set < ReaderField > seen = new HashSet < > ( 17 ) ; Set < ReaderField > readerFields = rfToValIdSets . keySet ( ) ; for ( final ReaderField rf : readerFields ) { if ( seen . contains ( rf ) ) continue ; List < Object > kids = getAllDescendantReaderKeys ( rf . readerKey ) ; for ( Object kidKey : kids ) { ReaderField kid = new ReaderField ( kidKey , rf . fieldName ) ; if ( badChildren . containsKey ( kid ) ) { badKids . put ( rf , kid ) ; badKids . putAll ( rf , badChildren . get ( kid ) ) ; badChildren . remove ( kid ) ; } else if ( rfToValIdSets . containsKey ( kid ) ) { badKids . put ( rf , kid ) ; } seen . add ( kid ) ; } seen . add ( rf ) ; } for ( final ReaderField parent : badChildren . keySet ( ) ) { Set < ReaderField > kids = badChildren . get ( parent ) ; List < CacheEntry > badEntries = new ArrayList < > ( kids . size ( ) * 2 ) ; { for ( final Integer value : rfToValIdSets . get ( parent ) ) { badEntries . addAll ( viToItemSets . get ( value ) ) ; } } for ( final ReaderField kid : kids ) { for ( final Integer value : rfToValIdSets . get ( kid ) ) { badEntries . addAll ( viToItemSets . get ( value ) ) ; } } CacheEntry [ ] badness = new CacheEntry [ badEntries . size ( ) ] ; badness = badEntries . toArray ( badness ) ; insanity . add ( new Insanity ( InsanityType . SUBREADER , "Found caches for descendants of " + parent . toString ( ) , badness ) ) ; } return insanity ; }
internal helper method used by check that iterates over the keys of readerfieldtovalids and generates a collection of insanity instances whenever two ( or more ) readerfield instances are found that have an ancestry relationships .
