/* package private */ ShallowTrace(final String name,
                                     final boolean hidden,
                                     final boolean systemHidden,
                                     final ResultType resultType,
                                     final String value,
                                     final Long startNanos,
                                     final Long pendingNanos,
                                     final Long endNanos,
                                     final Map<String, String> attributes)
  {
    assert name != null;
    assert resultType != null;

    _name = name;
    _hidden = hidden;
    _value = value;
    _resultType = resultType;
    _startNanos = startNanos;
    _pendingNanos = pendingNanos;
    _endNanos = endNanos;
    _systemHidden = systemHidden;

    if (!attributes.isEmpty())
    {
      Map<String, String> attributeMap = new HashMap<String, String>(attributes);
      _attributes = Collections.unmodifiableMap(attributeMap);
    }
    else
    {
      _attributes = Collections.emptyMap();
    }

    switch (resultType)
    {
      case EARLY_FINISH:
        if (value != null)
        {
          throw new IllegalArgumentException("value cannot be set if the task is finished early");
        }
        ArgumentUtil.notNull(startNanos, "startNanos");
        ArgumentUtil.notNull(pendingNanos, "pendingNanos");
        ArgumentUtil.notNull(endNanos, "endNanos");
        break;
      case ERROR:
      case SUCCESS:
        ArgumentUtil.notNull(startNanos, "startNanos");
        ArgumentUtil.notNull(pendingNanos, "pendingNanos");
        ArgumentUtil.notNull(endNanos, "endNanos");
        break;
      case UNFINISHED:
        if (value != null)
        {
          throw new IllegalArgumentException("value cannot be set if the task is UNFINISHED");
        }
        break;
      default:
        throw new IllegalArgumentException("Unexpected result type: " + resultType);
    }

    if (startNanos != null && resultType != ResultType.UNFINISHED)
    {
      ArgumentUtil.notNull(pendingNanos, "pendingNanos");
      ArgumentUtil.notNull(endNanos, "endNanos");
    }
  }