Commit c8d85421 authored by Nico Mack's avatar Nico Mack
Browse files

Added GraduationHelper class

Minor API change to VectorBasedCallback class
parent ed5fb542
...@@ -38,7 +38,7 @@ import java.util.Map; ...@@ -38,7 +38,7 @@ import java.util.Map;
*/ */
// *************************************************************************** // ***************************************************************************
// * Class Definition and Members * // * Class Definition and Members
// *************************************************************************** // ***************************************************************************
public class VectorBasedCallback implements BootstrapCallback { public class VectorBasedCallback implements BootstrapCallback {
...@@ -50,14 +50,14 @@ public class VectorBasedCallback implements BootstrapCallback { ...@@ -50,14 +50,14 @@ public class VectorBasedCallback implements BootstrapCallback {
private Integer size; private Integer size;
// *************************************************************************** // ***************************************************************************
// * Constants * // * Constants
// *************************************************************************** // ***************************************************************************
private static final Logger LOGGER = LoggerFactory.getLogger(VectorBasedCallback.class.getName()); private static final Logger LOGGER = LoggerFactory.getLogger(VectorBasedCallback.class.getName());
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Constructor(s) * // * Constructor(s)
// *************************************************************************** // ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -79,7 +79,7 @@ public class VectorBasedCallback implements BootstrapCallback { ...@@ -79,7 +79,7 @@ public class VectorBasedCallback implements BootstrapCallback {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Class Body * // * Class Body
// *************************************************************************** // ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -87,10 +87,6 @@ public class VectorBasedCallback implements BootstrapCallback { ...@@ -87,10 +87,6 @@ public class VectorBasedCallback implements BootstrapCallback {
List<BaseWidget> widgets = null; List<BaseWidget> widgets = null;
Map<String, Variable<?>> systemVariables = new HashMap<>(); Map<String, Variable<?>> systemVariables = new HashMap<>();
/*
* index = 0; context.setProperty(Templating.HANDLE_ID_PROPERTY, widgetId);
* context.setProperty(Templating.SIZE_OF_VECTORS_PROPERTY, size);
*/
this.initialize(null, context); this.initialize(null, context);
for (Variable<?> systemVariable : variables) { for (Variable<?> systemVariable : variables) {
...@@ -102,7 +98,6 @@ public class VectorBasedCallback implements BootstrapCallback { ...@@ -102,7 +98,6 @@ public class VectorBasedCallback implements BootstrapCallback {
for (BaseWidget widget : widgets) { for (BaseWidget widget : widgets) {
List<Variable<?>> connected; List<Variable<?>> connected;
// if (widget.getClass().isAssignableFrom(VariableBased.class)) {
if (widget instanceof VariableBased) { if (widget instanceof VariableBased) {
VariableBased display = (VariableBased) widget; VariableBased display = (VariableBased) widget;
connected = display.connectWithSystemVariables(systemVariables); connected = display.connectWithSystemVariables(systemVariables);
...@@ -180,4 +175,16 @@ public class VectorBasedCallback implements BootstrapCallback { ...@@ -180,4 +175,16 @@ public class VectorBasedCallback implements BootstrapCallback {
return reset(context); return reset(context);
} }
// ---------------------------------------------------------------------------
public int getSize() {
return this.size;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class
// ***************************************************************************
// ---------------------------------------------------------------------------
} }
/**
* Copyright Luxembourg Institute of Science and Technology, 2020. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.utility.graduation;
/**
* @author nico.mack@list.lu
* @since 2.9
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class GraduationHelper {
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final int[] DIVISIONS = {3, 4, 5, 10};
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
private GraduationHelper() {
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private static int getPower(double value) {
int decimals = (int) Math.floor(Math.log10(value));
int powerOfTen = (int) Math.pow(10, decimals);
return powerOfTen;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public static int getGraduationLevels(double value) {
int powerOfTen = getPower(value) / 10;
double normalized = value / powerOfTen;
int numberOfLevels = -1;
for (int range = 0; range < DIVISIONS.length; range++) {
if (normalized % DIVISIONS[range] == 0) {
numberOfLevels = DIVISIONS[range];
break;
}
}
return numberOfLevels;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
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