@Override public MapEntityCollection build() { Preconditions.checkState(store != null, "build() already called"); ImmutableMap.Builder<String,EntityIndex> indexes = ImmutableMap.builder(); for (Map.Entry<String,EntityIndexBuilder> e: indexBuilders.entrySet()) { indexes.put(e.getKey(), e.getValue().build()); } KeyedObjectMap<Entity> map = store.build(); ImmutableMap<String, EntityIndex> idxMap = indexes.build(); logger.debug("built collection of {} entities with type {} and {} indexes", map.size(), type, idxMap.size()); store = null; indexBuilders = null; return new MapEntityCollection(type, map, idxMap, hasher.hash()); } }
@Override public <T> EntityCollectionBuilder addIndex(TypedName<T> attribute) { Preconditions.checkState(indexBuilders != null, "build() already called"); if (indexBuilders.containsKey(attribute.getName())) { // already have that index return this; } EntityIndexBuilder ib = EntityIndexBuilder.create(attribute); indexBuilders.put(attribute.getName(), ib); for (Entity e: store.build()) { ib.add(e); } return this; }
static KeyedObjectMap<String> createMap(String... strings) { return KeyedObjectMap.newBuilder(StringEx.INSTANCE) .add(strings) .build(); }
@Override public EntityIndex build() { Preconditions.checkState(entityLists != null, "build() already called"); // arrange compact storage of the index KeyedObjectMapBuilder<IdBox<ImmutableList<Entity>>> bld = KeyedObjectMap.newBuilder(); for (Long2ObjectMap.Entry<ImmutableList.Builder<Entity>> entry: entityLists.long2ObjectEntrySet()) { long value = entry.getLongKey(); bld.add(IdBox.create(value, entry.getValue().build())); entry.setValue(null); } entityLists = null; return new LongEntityIndex(bld.build()); } }
return builder.build();
@Override public MapEntityCollection build() { Preconditions.checkState(store != null, "build() already called"); ImmutableMap.Builder<String,EntityIndex> indexes = ImmutableMap.builder(); for (Map.Entry<String,EntityIndexBuilder> e: indexBuilders.entrySet()) { indexes.put(e.getKey(), e.getValue().build()); } KeyedObjectMap<Entity> map = store.build(); ImmutableMap<String, EntityIndex> idxMap = indexes.build(); logger.debug("built collection of {} entities with type {} and {} indexes", map.size(), type, idxMap.size()); store = null; indexBuilders = null; return new MapEntityCollection(type, map, idxMap, hasher.hash()); } }
@Override public <T> EntityCollectionBuilder addIndex(TypedName<T> attribute) { Preconditions.checkState(indexBuilders != null, "build() already called"); if (indexBuilders.containsKey(attribute.getName())) { // already have that index return this; } EntityIndexBuilder ib = EntityIndexBuilder.create(attribute); indexBuilders.put(attribute.getName(), ib); for (Entity e: store.build()) { ib.add(e); } return this; }
@Override public EntityIndex build() { Preconditions.checkState(entityLists != null, "build() already called"); // arrange compact storage of the index KeyedObjectMapBuilder<IdBox<ImmutableList<Entity>>> bld = KeyedObjectMap.newBuilder(); for (Long2ObjectMap.Entry<ImmutableList.Builder<Entity>> entry: entityLists.long2ObjectEntrySet()) { long value = entry.getLongKey(); bld.add(IdBox.create(value, entry.getValue().build())); entry.setValue(null); } entityLists = null; return new LongEntityIndex(bld.build()); } }