public static @NonNull long[] appendLong(
      @Nullable long[] cur, long val, boolean allowDuplicates) {
    if (cur == null) {
      return new long[] {val};
    }
    final int N = cur.length;
    if (!allowDuplicates) {
      for (int i = 0; i < N; i++) {
        if (cur[i] == val) {
          return cur;
        }
      }
    }
    long[] ret = new long[N + 1];
    System.arraycopy(cur, 0, ret, 0, N);
    ret[N] = val;
    return ret;
  }
Adds value to given array if not already present, providing set-like behavior.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/ArrayUtils.java