Creates a new OptionalFunction that will throw the exception supplied by the given
supplier for null values.

@param exceptionSupplier the supplier to use when this function is called with a null value
@return a new OptionalFunction
967960
public OptionalFunction<T, R> orElseThrow(Supplier<? extends RuntimeException> exceptionSupplier) {
    return new OptionalFunction<>(this.function, () -> {
      throw exceptionSupplier.get();
    });
  }
530002
@Override
	public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
			throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
		throw new UnsupportedOperationException();
	}
746557
public static <T> OptionalJsonSerializer<T> newInstance( JsonSerializer<T> serializer ) {
        return new OptionalJsonSerializer<T>( serializer );
    }
758709
public static <R, E extends Exception> Nullable<R> ifOrEmpty(final boolean b, final Try.Supplier<R, E> supplier) throws E {
        if (b) {
            return Nullable.of(supplier.get());
        } else {
            return Nullable.empty();
        }
    }
827577
@SuppressWarnings("unchecked")
    public static <T> Optional<Class<T>> optional(String dependency) {
        try {
            return Optional.of((Class<T>) Class.forName(dependency));
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
            return Optional.empty();
        }
    }
215018
public static <E, T, X extends RuntimeException> List<E> parallelConvertIfNullThrow(List<T> source,
            Class<E> targetClass, Supplier<X> exceptionSupplier) {
        return BeansConvertStrategy.parallelConvertBeans(source, targetClass, exceptionSupplier, false);
    }
1217676
public static LongIteratorEx of(final Supplier<? extends LongIterator> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

        return new LongIteratorEx() {
            private LongIterator iter = null;
            private LongIteratorEx iterEx = null;
            private boolean isInitialized = false;

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

                return iter.hasNext();
            }

            @Override
            public long nextLong() {
                if (isInitialized == false) {
                    init();
                }

                return iter.nextLong();
            }

            @Override
            public void skip(long n) {
                N.checkArgNotNegative(n, "n");

                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    iterEx.skip(n);
                } else {
                    super.skip(n);
                }
            }

            @Override
            public long count() {
                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    return iterEx.count();
                } else {
                    return super.count();
                }
            }

            @Override
            public void close() {
                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    iterEx.close();
                }
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                    iterEx = iter instanceof LongIteratorEx ? (LongIteratorEx) iter : null;
                }
            }
        };
    }
882138
public static <T> Supplier<Constructor<T>> constructor(Class<T> clazz, Class<?>... parameterTypes) {
        return new ConstructorSupplier<T>(clazz, parameterTypes);
    }
919602
private static BiFunction<AnnotatedValueResolver, ResolverContext, Object>
    resolver(Function<ResolverContext, List<String>> getter, Supplier<String> failureMessageSupplier) {
        return (resolver, ctx) -> {
            final List<String> values = getter.apply(ctx);
            if (!resolver.hasContainer()) {
                if (values != null && !values.isEmpty()) {
                    return resolver.convert(values.get(0));
                }
                return resolver.defaultOrException();
            }

            try {
                assert resolver.containerType() != null;
                @SuppressWarnings("unchecked")
                final Collection<Object> resolvedValues =
                        (Collection<Object>) resolver.containerType().getDeclaredConstructor().newInstance();

                // Do not convert value here because the element type is String.
                if (values != null && !values.isEmpty()) {
                    values.stream().map(resolver::convert).forEach(resolvedValues::add);
                } else {
                    final Object defaultValue = resolver.defaultOrException();
                    if (defaultValue != null) {
                        resolvedValues.add(defaultValue);
                    }
                }
                return resolvedValues;
            } catch (Throwable cause) {
                throw new IllegalArgumentException(failureMessageSupplier.get(), cause);
            }
        };
    }
521965
public static IntIterator of(final Supplier<? extends IntIterator> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

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

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

                return iter.hasNext();
            }

            @Override
            public int nextInt() {
                if (isInitialized == false) {
                    init();
                }

                return iter.nextInt();
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                }
            }
        };
    }
1154655
public static <T, E extends Exception> Supplier<T> sneaked(SneakySupplier<T, E> supplier) {
    return () -> {
      @SuppressWarnings("unchecked")
      SneakySupplier<T, RuntimeException> castedSupplier =
          (SneakySupplier<T, RuntimeException>) supplier;
      return castedSupplier.get();
    };
  }
119986
public static <T, R, E extends Exception> Nullable<R> tryOrEmpty(final T init, final Try.Function<? super T, R, E> func) {
        try {
            return Nullable.of(func.apply(init));
        } catch (Exception e) {
            return Nullable.<R> empty();
        }
    }
1354774
public static <T, V> ChannelSupplier<V> remap(ChannelSupplier<T> supplier, Function<? super T, ? extends Iterator<? extends V>> fn) {
		return new AbstractChannelSupplier<V>(supplier) {
			Iterator<? extends V> iterator = CollectionUtils.emptyIterator();
			boolean endOfStream;

			@Override
			protected Promise<V> doGet() {
				if (iterator.hasNext()) return Promise.of(iterator.next());
				return Promise.ofCallback(this::next);
			}

			private void next(SettableCallback<V> cb) {
				if (!endOfStream) {
					supplier.get()
							.whenComplete((item, e) -> {
								if (e == null) {
									if (item == null) endOfStream = true;
									iterator = fn.apply(item);
									if (iterator.hasNext()) {
										cb.set(iterator.next());
									} else {
										next(cb);
									}
								} else {
									cb.setException(e);
								}
							});
				} else {
					cb.set(null);
				}
			}
		};
	}
1161662
private Optional tryCreate(Constructor<?> constructor) {
    Object[] args = new Object[constructor.getParameterCount()];
    Object arg;
    Optional<Object> resolved;
    int i = 0;
    for (Parameter parameter : constructor.getParameters()) {
      resolved = context.resolve(parameter);
      if (!resolved.isPresent()) {
        return Optional.empty();
      }
      arg = resolved.value();
      args[i++] = arg;
    }
    return Optional.of(createFunction.apply(constructor, args));
  }
1284144
public static <T> Supplier<T> synchronizedSupplier(Supplier<T> delegate) {
		return new ThreadSafeSupplier<>(Objects.requireNonNull(delegate));
	}
1084770
public static <T, U, X extends RuntimeException> U convertBean(T source, Class<U> targetClass,
            Supplier<X> exceptionSupplier) {
        Objects.requireNonNull(targetClass,"TargetClass can not be null");
        if (Objects.isNull(source)) {
            return SupplierUtil.ifNonNullThrowOrElse(exceptionSupplier, () -> null);
        }
        Handler handler = ConverterContext.getActionHandler(source.getClass(), targetClass);
        log.info("Call method \"{}\"", handler.getMethod());
        try {
            return targetClass.cast(handler.getMethod().invoke(handler.getHandler(), source));
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw ConvertException.of("Call method \"" + handler.getMethod() + "\" failed", e);
        }
    }
581375
public <T extends Exception> Javalin exception(@NotNull Class<T> exceptionClass, @NotNull ExceptionHandler<? super T> exceptionHandler) {
        servlet.getExceptionMapper().getHandlers().put(exceptionClass, (ExceptionHandler<Exception>) exceptionHandler);
        return this;
    }