static SamplingFlags toSamplingFlags(int flags) {
    switch (flags) {
      case 0:
        return EMPTY;
      case FLAG_SAMPLED_SET:
        return NOT_SAMPLED;
      case FLAG_SAMPLED_SET | FLAG_SAMPLED:
        return SAMPLED;
      case FLAG_SAMPLED_SET | FLAG_SAMPLED | FLAG_DEBUG:
        return DEBUG;
      case FLAG_SAMPLED_LOCAL:
        return EMPTY_SAMPLED_LOCAL;
      case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET:
        return NOT_SAMPLED_SAMPLED_LOCAL;
      case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET | FLAG_SAMPLED:
        return SAMPLED_SAMPLED_LOCAL;
      case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET | FLAG_SAMPLED | FLAG_DEBUG:
        return DEBUG_SAMPLED_LOCAL;
      default:
        assert false; // programming error, but build anyway
        return new SamplingFlags(flags);
    }
  }
@Test void toSamplingFlags_returnsConstantsAndHasNiceToString() {
    assertThat(toSamplingFlags(SamplingFlags.EMPTY.flags))
      .isSameAs(SamplingFlags.EMPTY)
      .hasToString("");
    assertThat(toSamplingFlags(SamplingFlags.NOT_SAMPLED.flags))
      .isSameAs(SamplingFlags.NOT_SAMPLED)
      .hasToString("NOT_SAMPLED_REMOTE");
    assertThat(toSamplingFlags(SamplingFlags.SAMPLED.flags))
      .isSameAs(SamplingFlags.SAMPLED)
      .hasToString("SAMPLED_REMOTE");
    assertThat(toSamplingFlags(SamplingFlags.DEBUG.flags))
      .isSameAs(SamplingFlags.DEBUG)
      .hasToString("DEBUG");
    assertThat(toSamplingFlags(SamplingFlags.EMPTY.flags | FLAG_SAMPLED_LOCAL))
      .isSameAs(SamplingFlags.EMPTY_SAMPLED_LOCAL)
      .hasToString("SAMPLED_LOCAL");
    assertThat(toSamplingFlags(SamplingFlags.NOT_SAMPLED.flags | FLAG_SAMPLED_LOCAL))
      .isSameAs(SamplingFlags.NOT_SAMPLED_SAMPLED_LOCAL)
      .hasToString("NOT_SAMPLED_REMOTE|SAMPLED_LOCAL");
    assertThat(toSamplingFlags(SamplingFlags.SAMPLED.flags | FLAG_SAMPLED_LOCAL))
      .isSameAs(SamplingFlags.SAMPLED_SAMPLED_LOCAL)
      .hasToString("SAMPLED_REMOTE|SAMPLED_LOCAL");
    assertThat(toSamplingFlags(SamplingFlags.DEBUG.flags | FLAG_SAMPLED_LOCAL))
      .isSameAs(SamplingFlags.DEBUG_SAMPLED_LOCAL)
      .hasToString("DEBUG|SAMPLED_LOCAL");
  }