package com.continuuity.internal.app.runtime.flow;

import com.continuuity.app.program.Program;
import com.continuuity.app.queue.QueueSpecification;
import com.continuuity.common.queue.QueueName;
import com.google.common.hash.Hashing;

/**
 * Set of static helper methods used by flow system.
 */
public final class FlowUtils {

  /**
   * Gets the number of consumer groups of a given queue based on the queue specifications.
   * @param queueSpecs Queue specifications to search for usage of given queue.
   * @param queueName Name of the queue.
   * @return Number of consumer groups of the given queue.
   */
  public static int getQueueConsumerGroups(Iterable<QueueSpecification> queueSpecs, QueueName queueName) {
    int numGroups = 0;
    for (QueueSpecification queueSpec : queueSpecs) {
      if (queueName.equals(queueSpec.getQueueName())) {
        numGroups++;
      }
    }
    return numGroups;
  }


  /**
   * Generates a queue consumer groupId for the given flowlet in the given program.
   */
  public static long generateConsumerGroupId(Program program, String flowletId) {
    return Hashing.md5().newHasher()
                  .putString(program.getAccountId())
                  .putString(program.getApplicationId())
                  .putString(program.getProgramName())
                  .putString(flowletId).hash().asLong();
  }


  private FlowUtils() {
  }
}

@@ -93,108 +93,8 @@
 am;%0A
-import com.continuuity.app.queue.QueueSpecification;%0Aimport com.continuuity.common.queue.QueueName;%0A
 impo
@@ -226,595 +226,8 @@
  %7B%0A%0A
-  /**%0A   * Gets the number of consumer groups of a given queue based on the queue specifications.%0A   * @param queueSpecs Queue specifications to search for usage of given queue.%0A   * @param queueName Name of the queue.%0A   * @return Number of consumer groups of the given queue.%0A   */%0A  public static int getQueueConsumerGroups(Iterable%3CQueueSpecification%3E queueSpecs, QueueName queueName) %7B%0A    int numGroups = 0;%0A    for (QueueSpecification queueSpec : queueSpecs) %7B%0A      if (queueName.equals(queueSpec.getQueueName())) %7B%0A        numGroups++;%0A      %7D%0A    %7D%0A    return numGroups;%0A  %7D%0A%0A%0A
   /*

Remove unused method