fi.evolver.ai.spring.prompt.Prompt Maven / Gradle / Ivy
package fi.evolver.ai.spring.prompt;
import java.util.Map;
import java.util.Optional;
/**
*
*/
public interface Prompt {
Map parameters();
default Object getParameter(String key) {
return parameters().get(key);
}
default Optional getStringProperty(String name) {
return Optional.ofNullable(parameters().get(name)).map(Object::toString);
}
default Optional getBooleanProperty(String name) {
Object value = parameters().get(name);
if (value instanceof Boolean)
return Optional.of((Boolean) value);
if (value instanceof String)
return Optional.of((String) value).map("true"::equalsIgnoreCase);
return Optional.empty();
}
default Optional getIntProperty(String name) {
Object value = parameters().get(name);
if (value instanceof Integer)
return Optional.of((Integer) value);
if (value instanceof Long)
return Optional.of((int) (long) (Long) value);
if (value instanceof Float)
return Optional.of(Math.round((Float) value));
if (value instanceof Double)
return Optional.of((int) Math.round((Double) value));
if (value instanceof String)
return Optional.of(Integer.parseInt((String) value));
return Optional.empty();
}
default Optional getLongProperty(String name) {
Object value = parameters().get(name);
if (value instanceof Integer)
return Optional.of((long) (Integer) value);
if (value instanceof Long)
return Optional.of((Long) value);
if (value instanceof Float)
return Optional.of((long) Math.round((Float) value));
if (value instanceof Double)
return Optional.of(Math.round((Double) value));
if (value instanceof String)
return Optional.of(Long.parseLong((String) value));
return Optional.empty();
}
default Optional getDoubleProperty(String name) {
Object value = parameters().get(name);
if (value instanceof Integer)
return Optional.of((double) (Integer) value);
if (value instanceof Long)
return Optional.of((double) (Long) value);
if (value instanceof Float)
return Optional.of((double) (Float) value);
if (value instanceof Double)
return Optional.of((Double) value);
if (value instanceof String)
return Optional.of(Double.parseDouble((String) value));
return Optional.empty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy