io.quarkus.panache.common.Parameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-panache-common Show documentation
Show all versions of quarkus-panache-common Show documentation
An opinionated approach to make Hibernate as easy as possible
package io.quarkus.panache.common;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
*
* Utility class to build populated `Map` instances. Page instances are mutable (builder-like).
*
*
*
* Usage:
*
*
*
* Map<String, Object> params = Parameters.with("foo", foo)
* .and("bar", bar)
* .and("gee", gee)
* .map();
*
*
* @author Stéphane Épardaud
*/
public class Parameters {
private final Map values = new HashMap<>();
/**
* Add a parameter to this {@link Parameters}.
*
* @param name name of the parameter to add
* @param value value of the parameter to add
* @return this instance, modified.
* @see {@link Parameters#map()}
*/
public Parameters and(String name, Object value) {
values.put(name, value);
return this;
}
/**
* Constructs an unmodifiable {@link Map} with the current parameters.
*
* @return an unmodifiable {@link Map} with the current parameters.
*/
public Map map() {
return Collections.unmodifiableMap(values);
}
/**
* Build a {@link Parameters} with a single parameter.
*
* @param name name of the first parameter
* @param value value of the first parameter
* @return a {@link Parameters} with a single parameter.
* @see {@link Parameters#and(String, Object)}
* @see {@link Parameters#map()}
*/
public static Parameters with(String name, Object value) {
return new Parameters().and(name, value);
}
}