Creates a new collector using given {@code supplier} as source of rate limiters.

@param supplier the supplier of rate limiters, note that supplier will be called one very {@link #collect()}
765889
public static RateLimiterMetricsCollector ofSupplier(Supplier<? extends Iterable<? extends RateLimiter>> supplier) {
        return new RateLimiterMetricsCollector(MetricNames.ofDefaults(), supplier);
    }
356787
@SuppressWarnings("unchecked")
  static Supplier<CompletableFuture<ExecutionResult>> makeAsync(Supplier<CompletableFuture<ExecutionResult>> supplier,
      Scheduler scheduler, FailsafeFuture<Object> future) {
    return () -> {
      CompletableFuture<ExecutionResult> promise = new CompletableFuture<>();
      Callable<Object> callable = () -> supplier.get().handle((result, error) -> {
        // Propagate result
        if (result != null)
          promise.complete(result);
        else
          promise.completeExceptionally(error);
        return result;
      });

      try {
        future.inject((Future) scheduler.schedule(callable, 0, TimeUnit.NANOSECONDS));
      } catch (Exception e) {
        promise.completeExceptionally(e);
      }
      return promise;
    };
  }
1035612
public <R> R wrapClassLoader(Supplier<R> supplier) {
		try (TemporaryClassLoaderContext tmpCl = new TemporaryClassLoaderContext(classLoader)){
			return supplier.get();
		}
	}
932189
public static <T> Collector<T, ?, List<T>> first(final int n) {
        N.checkArgNotNegative(n, "n");

        final Supplier<List<T>> supplier = new Supplier<List<T>>() {
            @Override
            public List<T> get() {
                return new ArrayList<T>(N.min(256, n));
            }
        };

        final BiConsumer<List<T>, T> accumulator = new BiConsumer<List<T>, T>() {
            @Override
            public void accept(List<T> c, T t) {
                if (c.size() < n) {
                    c.add(t);
                }
            }
        };

        final BinaryOperator<List<T>> combiner = new BinaryOperator<List<T>>() {
            @Override
            public List<T> apply(List<T> a, List<T> b) {
                if (N.notNullOrEmpty(a) && N.notNullOrEmpty(b)) {
                    throw new UnsupportedOperationException("The 'first' and 'last' Collector only can be used in sequential stream");
                }

                return a.size() > 0 ? a : b;
            }
        };

        return new CollectorImpl<>(supplier, accumulator, combiner, CH_ID);
    }
270305
public static DoubleIterator of(final Supplier<? extends DoubleIterator> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

        return new DoubleIterator() {
            private DoubleIterator iter = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iter.hasNext();
            }

            @Override
            public double nextDouble() {
                if (isInitialized == false) {
                    init();
                }

                return iter.nextDouble();
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                }
            }
        };
    }
1221376
@Nonnull
	public static <T> SupplierBuilder<T> supplier(Consumer<Supplier<T>> consumer) {
		return new SupplierBuilder(consumer);
	}
890889
public static DoubleIterator generate(final DoubleSupplier supplier) {
        N.checkArgNotNull(supplier);

        return new DoubleIterator() {
            @Override
            public boolean hasNext() {
                return true;
            }

            @Override
            public double nextDouble() {
                return supplier.getAsDouble();
            }
        };
    }
326659
public static <T> T withDb(DataSource dataSource, Supplier<T> supplier) {
        return new DB(DB.DEFAULT_NAME).withDb(dataSource, supplier);
    }
1203997
public static LongStream of(final Supplier<LongList> supplier) {
        final LongIterator iter = new LongIteratorEx() {
            private LongIterator iterator = null;

            @Override
            public boolean hasNext() {
                if (iterator == null) {
                    init();
                }

                return iterator.hasNext();
            }

            @Override
            public long nextLong() {
                if (iterator == null) {
                    init();
                }

                return iterator.nextLong();
            }

            private void init() {
                final LongList c = supplier.get();

                if (N.isNullOrEmpty(c)) {
                    iterator = LongIterator.empty();
                } else {
                    iterator = c.iterator();
                }
            }
        };

        return of(iter);
    }
858078
public <T> Source<T> from(Supplier<T> supplier) {
		Assert.notNull(supplier, "Supplier must not be null");
		Source<T> source = getSource(supplier);
		if (this.sourceOperator != null) {
			source = this.sourceOperator.apply(source);
		}
		return source;
	}
191903
<T, U> Stage<U> doStreamCollect(
      final Collection<? extends Stage<? extends T>> stages, final Consumer<? super T> consumer,
      final Supplier<? extends U> supplier
  ) {
    final Completable<U> target = completable();

    final StreamCollectHelper<? super T, ? extends U> done =
        new StreamCollectHelper<>(caller, stages.size(), consumer, supplier, target);

    for (final Stage<? extends T> q : stages) {
      q.handle(done);
    }

    bindSignals(target, stages);
    return target;
  }
816364
@NotNull
    public static <T> Exceptional<T> of(@NotNull ThrowableSupplier<T, Throwable> supplier) {
        Objects.requireNonNull(supplier);
        try {
            return new Exceptional<T>(supplier.get(), null);
        } catch (Throwable throwable) {
            return of(throwable);
        }
    }
827067
public static <T> Supplier<T> memoize(final Supplier<T> supplier) {
        return new Supplier<T>() {
            private volatile boolean initialized = false;
            private T instance = null;

            @Override
            public T get() {
                if (initialized == false) {
                    synchronized (this) {
                        if (initialized == false) {
                            instance = supplier.get();
                        }

                    }
                }

                return instance;
            }
        };
    }
1190364
@SuppressWarnings("unchecked")
   public static <T, R> SerializableSupplier<Collector<T, ?, R>> toSerialSupplierCollect(
      SerializableSupplier supplier) {
      return supplier;
   }
957071
public static <T> Supplier<T> newInstance(Class<T> clazz, Object... parameters) {
        return new ClassConstructorNewInstanceSupplier<T>(clazz, parameters);
    }
122985
@Override
  public <R> StreamBuilderImpl<R,U>
  collect(SupplierSync<R> init,
          BiConsumerSync<R,T> accum,
          BiConsumerSync<R,R> combiner)
  {
    return new CollectSync<>(this, init, accum, combiner);
  }
833336
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
        return CompletableFuture
                .supplyAsync(handleSupplierWithException(supplier));
    }