// element occurrences in list
static int countOccurrences(Iterable c, A x) {
int n = 0;
if (c != null) for (O o : c)
if (eq(x, o))
++n;
ret n;
}
static int countOccurrences(A x, Iterable c) {
ret countOccurrences(c, x);
}
// string occurrences in string (not counting overlapping)
static int countOccurrences(S s, S x) {
int i = 0, nx = l(x), count = 0;
if (nx == 0) ret 0;
while ((i = indexOf(s, x, i)) >= 0) {
++count;
i += nx;
}
ret count;
}