FieldInfoCache { public FieldInfos dedupFieldInfos(FieldInfo[] infos) { FieldInfosKey key = new FieldInfosKey(infos); return this.infosCache.computeIfAbsent(key, (FieldInfosKey k) -> new FieldInfos(k.infos)); } FieldInfoCache(); static int hashCode(FieldInfo fi); static boolean equals(FieldInfo a, FieldInfo b); FieldInfos dedupFieldInfos(FieldInfo[] infos); FieldInfo dedupFieldInfo(String name, int fieldNumber, boolean storeTermVector, boolean omitNorms,
            boolean storePayloads, IndexOptions indexOptions, DocValuesType docValuesType, long dvGen,
            Map<String, String> attributes, int pointDimensionCount, int pointNumBytes); void handleMaintenance();  }
@Test public void testDense() throws NoSuchFieldException, IllegalAccessException { FieldInfo[] infosArray = makeInfosArray(100); FieldInfos orig = new FieldInfos(infosArray); Collection<Object> values = extractValues(orig); assertSame(Collections.unmodifiableCollection(new TreeMap<String, Object>().values()).getClass(), values.getClass()); FieldInfoCache cache = new FieldInfoCache(); FieldInfos fixedFieldInfo = cache.dedupFieldInfos(infosArray); values = extractValues(fixedFieldInfo); assertSame(Collections.unmodifiableCollection(Collections.emptyList()).getClass(), values.getClass()); }
@Test public void testSparse() throws NoSuchFieldException, IllegalAccessException { FieldInfo[] infosArray = new FieldInfo[3]; infosArray[0] = makeFieldInfo(1); infosArray[1] = makeFieldInfo(1000); infosArray[2] = makeFieldInfo(5000); FieldInfos orig = new FieldInfos(infosArray); Collection<Object> values = extractValues(orig); assertSame(Collections.unmodifiableCollection(new TreeMap<String, Object>().values()).getClass(), values.getClass()); FieldInfoCache cache = new FieldInfoCache(); FieldInfos fixedFieldInfo = cache.dedupFieldInfos(infosArray); values = extractValues(fixedFieldInfo); assertSame(Collections.unmodifiableCollection(new TreeMap<String, Object>().values()).getClass(), values.getClass()); }