static <T extends Comparable<? super T>> List<T> sortedList(@Nullable List<T> in) {
    if (in == null || in.isEmpty()) return Collections.emptyList();
    if (in.size() == 1) return Collections.singletonList(in.get(0));
    Object[] array = in.toArray();
    Arrays.sort(array);

    // dedupe
    int j = 0, i = 1;
    while (i < array.length) {
      if (!array[i].equals(array[j])) {
        array[++j] = array[i];
      }
      i++;
    }

    List result = Arrays.asList(i == j + 1 ? array : Arrays.copyOf(array, j + 1));
    return Collections.unmodifiableList(result);
  }
Inspired by {@code okio.Buffer.writeLong}
zipkin/src/main/java/zipkin2/Span.java