use of org.knime.core.data.DataValue in project knime-core by knime.
the class AscendingNumericTickPolicyStrategy method makeTicks.
private Double[] makeTicks(final double min, final double max, final int count) {
double minimum = Math.min(min, max);
minimum = (minimum <= Double.NEGATIVE_INFINITY ? -Double.MAX_VALUE : minimum);
double maximum = Math.max(min, max);
maximum = (maximum >= Double.POSITIVE_INFINITY ? Double.MAX_VALUE : maximum);
if (count == 1) {
return new Double[] { (minimum + maximum) / 2 };
}
// so step is <= Double.MAX_VALUE
double step = Math.log10((maximum - minimum) / count);
double base = Math.floor(step);
double frac = step - base;
if (minimum == maximum || Double.isInfinite(step) || Double.isNaN(step) || Double.isInfinite(base) || Double.isNaN(base) || Double.isInfinite(frac) || Double.isNaN(frac)) {
return new Double[] { (minimum + maximum) / 2 };
}
ArrayList<Double> result = new ArrayList<Double>();
if (frac < 0.1) {
frac = 1;
} else if (frac < 0.4) {
frac = 2;
} else if (frac < 0.6) {
frac = 2.5;
} else if (frac < 0.8) {
frac = 5;
} else {
frac = 1;
base += frac;
}
step = frac * Math.pow(10, base);
double value = minimum;
while (value + 0.55 * step < maximum) {
if (result.size() == 0 || result.get(result.size() - 1) + EPSILON * step < value) {
boolean add = true;
for (DataValue v : getValues()) {
if (v instanceof DoubleValue) {
double desVal = ((DoubleValue) v).getDoubleValue();
if (value + EPSILON * step > desVal && value < desVal) {
add = false;
} else if (value - EPSILON * step < desVal && value > desVal) {
add = false;
}
}
}
if (add) {
result.add(value);
}
}
int m = 1;
while (value + m * step == value) {
m++;
}
value += m * step;
}
if (result.get(result.size() - 1) < maximum) {
// enough space?
if (result.get(result.size() - 1) + EPSILON * step > maximum) {
result.remove(result.size() - 1);
}
result.add(maximum);
}
for (DataValue v : getValues()) {
if (v instanceof DoubleValue) {
double val = ((DoubleValue) v).getDoubleValue();
if (!result.contains(val) && val > minimum && val < maximum) {
result.add(val);
}
}
}
Collections.sort(result);
return result.toArray(new Double[0]);
}
use of org.knime.core.data.DataValue in project knime-core by knime.
the class Axis method createToolTip.
private String createToolTip(final CoordinateMapping coordMapping) {
String tooltip = "";
for (DataValue v : coordMapping.getValues()) {
if (v == null) {
continue;
}
if (v instanceof DoubleValue) {
double value = ((DoubleValue) v).getDoubleValue();
if (Double.isNaN(value) || Double.isInfinite(value)) {
continue;
}
tooltip += new BigDecimal(value, new MathContext(25)) + " ";
} else {
tooltip += v.toString() + " ";
}
}
return tooltip.trim();
}
use of org.knime.core.data.DataValue in project knime-core by knime.
the class AccuracyScorerNodeModel method sort.
/**
* @param order The cells to sort.
*/
private void sort(final DataCell[] order) {
if (order.length == 0) {
return;
}
DataType type = order[0].getType();
for (DataCell dataCell : order) {
type = DataType.getCommonSuperType(type, dataCell.getType());
}
final Comparator<DataCell> comparator;
switch(m_sortingStrategy) {
case InsertionOrder:
if (m_sortingReversed) {
reverse(order);
}
return;
case Unsorted:
return;
case Lexical:
if (StringCell.TYPE.isASuperTypeOf(type)) {
Comparator<String> stringComparator;
Collator instance = Collator.getInstance();
// do not try to combine characters
instance.setDecomposition(Collator.NO_DECOMPOSITION);
// case and accents matter.
instance.setStrength(Collator.IDENTICAL);
@SuppressWarnings("unchecked") Comparator<String> collator = (Comparator<String>) (Comparator<?>) instance;
stringComparator = collator;
comparator = new StringValueComparator(stringComparator);
} else if (DoubleCell.TYPE.isASuperTypeOf(type)) {
comparator = new DataValueComparator() {
@Override
protected int compareDataValues(final DataValue v1, final DataValue v2) {
String s1 = v1.toString();
String s2 = v2.toString();
return s1.compareTo(s2);
}
};
} else {
throw new IllegalStateException("Lexical sorting strategy is not supported.");
}
break;
case Numeric:
if (DoubleCell.TYPE.isASuperTypeOf(type)) {
comparator = type.getComparator();
} else {
throw new IllegalStateException("Numerical sorting strategy is not supported.");
}
break;
default:
throw new IllegalStateException("Unrecognized sorting strategy: " + m_sortingStrategy);
}
Arrays.sort(order, comparator);
if (m_sortingReversed) {
reverse(order);
}
}
use of org.knime.core.data.DataValue in project knime-core by knime.
the class NominalValue method getNominalValues.
/**
* @param colIndex
* @return nominal values of the column
* @since 3.5
*/
public Map<DataValue, Integer> getNominalValues(final int colIndex) {
Iterator it = m_nominalValues[colIndex].entrySet().iterator();
Map<DataValue, Integer> output = new HashMap<DataValue, Integer>(m_nominalValues[colIndex].size());
while (it.hasNext()) {
@SuppressWarnings("unchecked") Map.Entry<DataCell, MutableInteger> pair = (Map.Entry<DataCell, MutableInteger>) it.next();
// if (!pair.getKey().isMissing()) {
output.put(pair.getKey(), pair.getValue().intValue());
// } //else {
// output.put(((MissingCell)pair.getKey()).toString(), pair.getValue().intValue());
// }
// System.out.println( + " = " + );
// avoids a ConcurrentModificationException
it.remove();
}
return output;
}
use of org.knime.core.data.DataValue in project knime-core by knime.
the class AggregationMethods method getCompatibleMethodGroupList.
/**
* @param type the {@link DataType} to check
* @return the aggregation methods that are compatible
* with the given {@link DataType} grouped by the supported data type
* @since 2.6
*/
public static List<Entry<String, List<AggregationMethod>>> getCompatibleMethodGroupList(final DataType type) {
final Map<Class<? extends DataValue>, List<AggregationMethod>> methodGroups = AggregationMethods.getCompatibleMethodGroups(type);
final Set<Entry<Class<? extends DataValue>, List<AggregationMethod>>> methodSet = methodGroups.entrySet();
final List<String> labels = new ArrayList<>(methodSet.size());
final Map<String, List<AggregationMethod>> labelSet = new HashMap<>(methodSet.size());
for (final Entry<Class<? extends DataValue>, List<AggregationMethod>> entry : methodSet) {
final String label = getUserTypeLabel(entry.getKey());
labels.add(label);
labelSet.put(label, entry.getValue());
}
Collections.sort(labels);
final List<Entry<String, List<AggregationMethod>>> list = new ArrayList<>(methodSet.size());
for (final String label : labels) {
final List<AggregationMethod> methods = labelSet.get(label);
final Entry<String, List<AggregationMethod>> entry = new Map.Entry<String, List<AggregationMethod>>() {
@Override
public String getKey() {
return label;
}
@Override
public List<AggregationMethod> getValue() {
return methods;
}
@Override
public List<AggregationMethod> setValue(final List<AggregationMethod> value) {
return methods;
}
};
list.add(entry);
}
return list;
}
Aggregations