SEBSERV-57 fixed

This commit is contained in:
anhefti 2022-05-30 09:41:34 +02:00
parent a0ca72e3ea
commit 64b496e4ac
3 changed files with 24 additions and 12 deletions

View file

@ -15,6 +15,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -247,14 +248,20 @@ public class POSTMapper {
.map(ts -> { .map(ts -> {
try { try {
final String[] split = StringUtils.split(ts, Constants.EMBEDDED_LIST_SEPARATOR); final String[] split = StringUtils.split(ts, Constants.EMBEDDED_LIST_SEPARATOR);
return new Threshold(Double.parseDouble( Double val = null;
split[0]), try {
(split.length > 1) ? split[1] : null, val = Double.parseDouble(split[0]);
(split.length > 2) ? split[2] : null); } catch (final Exception e) {
}
return new Threshold(
val,
(split.length > 1) ? Utils.parseColorString(Utils.parseRGB(split[1])) : null,
(split.length > 2 && "null".equals(split[2])) ? split[2] : null);
} catch (final Exception e) { } catch (final Exception e) {
return null; return null;
} }
}) })
.filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View file

@ -578,6 +578,9 @@ public final class Utils {
* @param rgb foreground or text color * @param rgb foreground or text color
* @return true of the background color for given foreground color shall be dark or false if it shall be light */ * @return true of the background color for given foreground color shall be dark or false if it shall be light */
public static boolean darkColorContrast(final RGB rgb) { public static boolean darkColorContrast(final RGB rgb) {
if (rgb == null) {
return true;
}
return rgb.red + rgb.green + rgb.blue > DARK_COLOR_THRESHOLD; return rgb.red + rgb.green + rgb.blue > DARK_COLOR_THRESHOLD;
} }
@ -592,15 +595,16 @@ public final class Utils {
} }
public static RGB parseRGB(final String colorString) { public static RGB parseRGB(final String colorString) {
if (StringUtils.isBlank(colorString)) { try {
final int r = Integer.parseInt(colorString.substring(0, 2), 16);
final int g = Integer.parseInt(colorString.substring(2, 4), 16);
final int b = Integer.parseInt(colorString.substring(4, 6), 16);
return new RGB(r, g, b);
} catch (final Exception e) {
return null; return null;
} }
final int r = Integer.parseInt(colorString.substring(0, 2), 16);
final int g = Integer.parseInt(colorString.substring(2, 4), 16);
final int b = Integer.parseInt(colorString.substring(4, 6), 16);
return new RGB(r, g, b);
} }
public static String toColorFractionString(final int fraction) { public static String toColorFractionString(final int fraction) {

View file

@ -121,11 +121,12 @@ public final class ThresholdList extends Composite {
public Collection<Threshold> getThresholds() { public Collection<Threshold> getThresholds() {
removeInvalidListEntries(); removeInvalidListEntries();
return this.thresholds final List<Threshold> collect = this.thresholds
.stream() .stream()
.map(entry -> new Threshold(entry.getValue(), entry.getColor(), .map(entry -> new Threshold(entry.getValue(), entry.getColor(),
null /* TODO add icon selection here */)) null /* TODO add icon selection here */))
.collect(Collectors.toList()); .collect(Collectors.toList());
return collect;
} }
private void removeInvalidListEntries() { private void removeInvalidListEntries() {