Commit 8af4ee59 authored by Nico Mack's avatar Nico Mack

Minor API changes and improvements

parent adc0e622
......@@ -51,12 +51,14 @@ public class VariableBootstrapper {
double scale = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.SCALE_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 1.0, context);
double numericValue = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.INITIAL_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 0.0, context);
int decimals = BootstrappingUtils.getContentAsInteger(variableNode, EquationSystemBundle.DECIMALS_ATTRIBUTE, BootstrappingUtils.OPTIONAL, -1, context);
double epsilon = BootstrappingUtils.getContentAsDouble(variableNode, EquationSystemBundle.EPSILON_ATTRIBUTE, BootstrappingUtils.OPTIONAL, 1e-6, context);
NumericalVariable numerical = new NumericalVariable(name, unit, numericValue);
numerical.setMinValue(minValue);
numerical.setMaxValue(maxValue);
numerical.setInitialValue(initialValue);
numerical.setScale(scale);
numerical.setEpsilon(epsilon);
if (decimals >= 0) {
numerical.setNumberOfDecimals(decimals);
}
......
......@@ -502,6 +502,18 @@ public class NumericalVariable extends Variable<Double> {
return this.normalizeValue(rawValue);
}
// ---------------------------------------------------------------------------
/**
*
* @param rawValue
* @return
*/
// ---------------------------------------------------------------------------
public double getRoundedToPrecision(double rawValue) {
return this.roundToPrecision(rawValue);
}
// ---------------------------------------------------------------------------
/**
*
......
......@@ -123,6 +123,12 @@ public class ValueRange<T extends Comparable<T>> implements Comparable<T>, Clone
// ---------------------------------------------------------------------------
public boolean valueInRange(T candidate) {
return (this.lowerValue.compareTo(candidate) <= 0) && (this.upperValue.compareTo(candidate) > 0);
}
// ---------------------------------------------------------------------------
@Override
public ValueRange<T> clone() {
return new ValueRange<T>(this);
......
......@@ -11,7 +11,7 @@ import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.CpsSignature;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ValueRange;
import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder;
import lu.list.itis.dkd.tui.widget.builder.BaseSelectorWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
import lu.list.itis.dkd.tui.widget.state.StateManager;
import lu.list.itis.dkd.tui.widget.state.StateManager.Direction;
......@@ -87,7 +87,7 @@ public class SelectorWidget extends ValueWidget {
*/
// ---------------------------------------------------------------------------
public SelectorWidget(SelectorWidgetBuilder<?> builder) {
public SelectorWidget(BaseSelectorWidgetBuilder<?> builder) {
super(builder);
selectableCoronas = getCoronas(SelectableCorona.class);
......
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.feature.selection.SelectionGroup;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.SelectorWidget;
import org.jdom2.Element;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author nmack
* @date 13 Jan 2016
*
* <br>
* $Log: LayerWidgetBuilder.java,v $
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class BaseSelectorWidgetBuilder<B extends BaseSelectorWidgetBuilder<B>> extends BaseValueWidgetBuilder<B> {
public Integer numberOfPositions;
public Integer preselect;
public Map<String, SelectionGroup> selectionGroups;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple no-arg constructor initializing all fields.
*/
// ---------------------------------------------------------------------------
public BaseSelectorWidgetBuilder() {
super();
preselect = SelectorWidget.NONE;
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public BaseSelectorWidgetBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public BaseSelectorWidgetBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
numberOfPositions = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.POSITIONS_NODE, BootstrappingUtils.OPTIONAL, SelectorWidget.NONE, context);
preselect = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.PRESELECT_NODE, BootstrappingUtils.OPTIONAL, SelectorWidget.NONE, context);
selectionGroups = new HashMap<>();
Element selectionGroupsElement = rootElement.getChild(Externalization.SELECTION_GROUPS_NODE);
if (selectionGroupsElement != null) {
List<Element> selectionGroupElements = selectionGroupsElement.getChildren(Externalization.SELECTION_GROUP_NODE);
for (Element selectionGroupElement : selectionGroupElements) {
SelectionGroup group = new SelectionGroup(selectionGroupElement);
selectionGroups.put(group.getName(), group);
}
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withPreselect(Integer index) {
this.preselect = index;
return (B) this;
}
// ---------------------------------------------------------------------------
@Override
public SelectorWidget build() {
return new SelectorWidget(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.feature.selection.SelectionGroup;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.SelectorWidget;
import lu.list.itis.dkd.tui.widget.ValueWidget;
import org.jdom2.Element;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author nmack
* @date 13 Jan 2016
*
* <br>
* $Log: LayerWidgetBuilder.java,v $
* The concrete builder that will build a new instance of {@link ValueWidget} with each call to
* {@link #build()}.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.3
* @version 1.3.0
*/
public class SelectorWidgetBuilder extends BaseSelectorWidgetBuilder<SelectorWidgetBuilder> {
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class SelectorWidgetBuilder<B extends SelectorWidgetBuilder<B>> extends BaseValueWidgetBuilder<B> {
public Integer numberOfPositions;
public Integer preselect;
public Map<String, SelectionGroup> selectionGroups;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple no-arg constructor initializing all fields.
*/
// ---------------------------------------------------------------------------
public SelectorWidgetBuilder() {
super();
preselect = SelectorWidget.NONE;
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public SelectorWidgetBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public SelectorWidgetBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
numberOfPositions = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.POSITIONS_NODE, BootstrappingUtils.OPTIONAL, SelectorWidget.NONE, context);
preselect = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.PRESELECT_NODE, BootstrappingUtils.OPTIONAL, SelectorWidget.NONE, context);
selectionGroups = new HashMap<>();
Element selectionGroupsElement = rootElement.getChild(Externalization.SELECTION_GROUPS_NODE);
if (selectionGroupsElement != null) {
List<Element> selectionGroupElements = selectionGroupsElement.getChildren(Externalization.SELECTION_GROUP_NODE);
for (Element selectionGroupElement : selectionGroupElements) {
SelectionGroup group = new SelectionGroup(selectionGroupElement);
selectionGroups.put(group.getName(), group);
}
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withPreselect(Integer index) {
this.preselect = index;
return (B) this;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public SelectorWidget build() {
return new SelectorWidget(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment