static SQLTemplates toSQLTemplates(final String type) { return when(type) .<SQLTemplates>is("db2", DB2Templates::new) .is("mysql", MySQLTemplates::new) .is("mariadb", MySQLTemplates::new) .is("h2", H2Templates::new) .is("hsqldb", HSQLDBTemplates::new) .is("pgsql", PostgreSQLTemplates::new) .is("postgresql", PostgreSQLTemplates::new) .is("sqlite", SQLiteTemplates::new) .is("oracle", OracleTemplates::new) .is("firebirdsql", FirebirdTemplates::new) .is("sqlserver", SQLServer2012Templates::new) .orElseThrow(() -> new IllegalStateException("Unsupported database: " + type)); } }
static Class loadType(final ClassLoader loader, final String name) { return when(name) .<Class>is("boolean", boolean.class) .is("char", char.class) .is("byte", byte.class) .is("short", short.class) .is("int", int.class) .is("long", long.class) .is("float", float.class) .is("double", double.class) .orElseGet(() -> loader.loadClass(name.replace("/", "."))); }
static SQLTemplates toSQLTemplates(final String type) { return when(type) .<SQLTemplates>is("db2", DB2Templates::new) .is("mysql", MySQLTemplates::new) .is("mariadb", MySQLTemplates::new) .is("h2", H2Templates::new) .is("hsqldb", HSQLDBTemplates::new) .is("pgsql", PostgreSQLTemplates::new) .is("postgresql", PostgreSQLTemplates::new) .is("sqlite", SQLiteTemplates::new) .is("oracle", OracleTemplates::new) .is("firebirdsql", FirebirdTemplates::new) .is("sqlserver", SQLServer2012Templates::new) .orElseThrow(() -> new IllegalStateException("Unsupported database: " + type)); } }
public Value<V, R> is(V value, R result) { return is(source -> Objects.equals(source, value), v -> result); }
public R orElseGet(Throwing.Supplier<R> value) { return toOptional().orElseGet(value); }
public R get() { return toOptional().orElseThrow(NoSuchElementException::new); }
public R orElse(R value) { return toOptional().orElse(value); }
public Value<V, R> is(V value, Throwing.Supplier<R> result) { return is(source -> Objects.equals(source, value), v -> result.get()); }
public <T extends V> Value<V, R> is(Class<T> predicate, R result) { return is(predicate::isInstance, v -> result); }
public <T extends V> Value<V, R> is(Class<T> predicate, Throwing.Function<T, R> result) { return is(predicate::isInstance, result); }
public R orElseThrow(Throwing.Supplier<Throwable> exception) { return toOptional().orElseThrow(() -> Throwing.sneakyThrow(exception.get())); }
public <T extends V> Value<V, R> is(Throwing.Predicate<T> predicate, Throwing.Supplier<R> result) { return is(predicate, v -> result.get()); }
private static ReadConcern readConcern(final String value) { return when(value.toUpperCase()) .is("DEFAULT", ReadConcern.DEFAULT) .is("LOCAL", ReadConcern.LOCAL) .is("MAJORITY", ReadConcern.MAJORITY) .orElseThrow(() -> new IllegalArgumentException("readConcern: " + value)); }
static Class loadType(final ClassLoader loader, final String name) { return when(name) .<Class>is("boolean", boolean.class) .is("char", char.class) .is("byte", byte.class) .is("short", short.class) .is("int", int.class) .is("long", long.class) .is("float", float.class) .is("double", double.class) .orElseGet(() -> loader.loadClass(name.replace("/", "."))); }
private static WriteConcern writeConcern(final String value) { return when(value.toUpperCase()) .is("W1", WriteConcern.W1) .is("W2", WriteConcern.W2) .is("W3", WriteConcern.W3) .is("ACKNOWLEDGED", WriteConcern.ACKNOWLEDGED) .is("MAJORITY", WriteConcern.MAJORITY) .orElseThrow(() -> new IllegalArgumentException("writeConcern: " + value)); }