Map<Symbol, DoubleList> chans;
Map<TypedSymbol<?>, List<?>> typedChans;
if (size() > 0) {
ImmutableMap.Builder<Symbol, DoubleList> cbld = ImmutableMap.builder();
for (ChannelStorage chan: channels.values()) {
DoubleArrayList built;
if (reuse) {
built = chan.values;
built.trim();
} else {
built = new DoubleArrayList(chan.values);
}
cbld.put(chan.symbol, built);
}
chans = cbld.build();
ImmutableMap.Builder<TypedSymbol<?>, List<?>> tcbld = ImmutableMap.builder();
for (TypedChannelStorage<?> chan: typedChannels.values()) {
List<?> built;
if (reuse) {
chan.values.trimToSize();
built = chan.values;
} else {
built = new ArrayList<Object>(chan.values);
}
tcbld.put(chan.symbol, built);
}
typedChans = tcbld.build();
} else {
chans = Collections.emptyMap();
typedChans = Collections.emptyMap();
}
LongList builtIds;
DoubleList builtScores;
if (reuse) {
ids.trim();
builtIds = ids;
scores.trim();
builtScores = scores;
clear();
} else {
builtIds = new CompactableLongArrayList(ids);
builtScores = new DoubleArrayList(scores);
}
return new PackedScoredIdList(builtIds, builtScores, typedChans, chans);
}