All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avaje.ebeanservice.elastic.update.ConvertToGroups Maven / Gradle / Ivy

package com.avaje.ebeanservice.elastic.update;

import com.avaje.ebean.DocStoreQueueEntry;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Collect and organise elastic updates grouping by queueId.
 */
public class ConvertToGroups {

  /**
   * Entries organised by queueId.
   */
  private final Map byQueue = new LinkedHashMap();

  public static Collection groupByQueueId(List queueEntries) {

    return new ConvertToGroups(queueEntries).groups();
  }

  /**
   * Add all the entries organising them by queueId and type.
   */
  private ConvertToGroups(List queueEntries) {

    for (DocStoreQueueEntry entry : queueEntries) {
      getQueue(entry.getQueueId()).addEntry(entry);
    }
  }

  private UpdateGroup getQueue(String queueId) {
    UpdateGroup queue = byQueue.get(queueId);
    if (queue == null) {
      queue = new UpdateGroup(queueId);
      byQueue.put(queueId, queue);
    }
    return queue;
  }

  private Collection groups() {
    return byQueue.values();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy