All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaregu.database.queries.compiling.expr.Constant Maven / Gradle / Ivy

Go to download

Java based SQL templating project. Store your queries in *.sql files and build queries for execution. Supports simple expressions and conditional clauses and interface proxying for java-sql bridge.

There is a newer version: 1.4.1
Show newest version
package com.jaregu.database.queries.compiling.expr;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public interface Constant extends Operand {

	static final List>> STRING_PARSERS = Arrays.asList(ConstantNull::parse,
			ConstantBoolean::parse, ConstantString::parse, ConstantInteger::parse, ConstantLong::parse,
			ConstantDecimal::parse);
	static final List>> VALUE_PARSERS = Arrays.asList(ConstantNull::of,
			ConstantBoolean::of, ConstantString::of, ConstantInteger::of, ConstantLong::of, ConstantDecimal::of);

	public static Optional parse(String value) {
		for (Function> parser : STRING_PARSERS) {
			Optional result = parser.apply(value);
			if (result.isPresent()) {
				return result;
			}
		}
		return Optional.empty();
	}

	public static Constant of(Object value) {
		for (Function> parser : VALUE_PARSERS) {
			Optional result = parser.apply(value);
			if (result.isPresent()) {
				return result.get();
			}
		}
		return new ConstantObject(value);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy