Search in sources :

Example 1 with Revisioned

use of org.graylog2.contentpacks.model.Revisioned in project graylog2-server by Graylog2.

the class ContentPackPersistenceService method loadAllLatest.

public Set<ContentPack> loadAllLatest() {
    final Set<ContentPack> allContentPacks = loadAll();
    final ImmutableMultimap.Builder<ModelId, ContentPack> byIdBuilder = ImmutableMultimap.builder();
    for (ContentPack contentPack : allContentPacks) {
        byIdBuilder.put(contentPack.id(), contentPack);
    }
    final ImmutableMultimap<ModelId, ContentPack> contentPacksById = byIdBuilder.build();
    final ImmutableSet.Builder<ContentPack> latestContentPacks = ImmutableSet.builderWithExpectedSize(contentPacksById.keySet().size());
    for (ModelId id : contentPacksById.keySet()) {
        final ImmutableCollection<ContentPack> contentPacks = contentPacksById.get(id);
        final ContentPack latestContentPackRevision = Collections.max(contentPacks, Comparator.comparingInt(Revisioned::revision));
        latestContentPacks.add(latestContentPackRevision);
    }
    return latestContentPacks.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ContentPack(org.graylog2.contentpacks.model.ContentPack) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ModelId(org.graylog2.contentpacks.model.ModelId)

Aggregations

ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ContentPack (org.graylog2.contentpacks.model.ContentPack)1 ModelId (org.graylog2.contentpacks.model.ModelId)1