org.packagesettings.Field Maven / Gradle / Ivy
package org.packagesettings;
import org.lambda.functions.Function0;
import java.util.Map;
public class Field
{
public final String Name;
public final Class Class;
public Field(String name, Class clazz)
{
this.Name = name;
this.Class = clazz;
}
public boolean isPresent(Map settings)
{
Settings value = settings.get(Name);
return value != null && this.Class.isInstance(value.getValue());
}
public T getValue(Map settings, Function0 defaultValue)
{
return isPresent(settings) ? (T) settings.get(Name).getValue() : defaultValue.call();
}
public String getFieldName()
{
return Name;
}
public Class getFieldClass()
{
return Class;
}
}