public synchronized int getAvailablePort() {
    int result = IntStream.generate(supplier)
        .filter(port -> !usedPorts.contains(port))
        .findFirst()
        .getAsInt();

    usedPorts.add(result);
    return result;
  }
Supplies unique ports that have not already been supplied by this instance of PortSupplier
geode-junit/src/main/java/org/apache/geode/internal/UniquePortSupplier.java