package io.rouz.task;

import com.google.auto.value.AutoValue;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * {@link AutoValue} implementation of {@link TaskId}
 */
@AutoValue
abstract class TaskIds implements TaskId, Serializable {

  abstract List<Object> args();

  static TaskId create(String name, Object... args) {
    return new AutoValue_TaskIds(name, Objects.hash(args), Arrays.asList(args));
  }

  @Override
  public String toString() {
    return String.format("%s(%s)#%08x", name(), argsString(), hash());
  }

  private String argsString() {
    final StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Object arg : args()) {
      if (!first) {
        sb.append(',');
      }
      sb.append(arg);
      first = false;
    }

    return sb.toString();
  }
}

@@ -412,21 +412,66 @@
 TaskIds(
-name,
+%0A        name,%0A        name.hashCode() * 1000003 %5E
  Objects
@@ -482,16 +482,24 @@
 h(args),
+%0A       
  Arrays.

include name in task id hash