From 13a6b1a0bca8703b495b436b1d853fcf1e21b604 Mon Sep 17 00:00:00 2001 From: Mouna Tayahi Date: Fri, 13 Sep 2024 21:28:20 +0200 Subject: [PATCH] fix cloud cover agg --- .../com/datastax/oss/cass_stac/entity/Item.java | 16 ++++++++-------- .../oss/cass_stac/model/AggregateRequest.java | 11 ++++------- .../oss/cass_stac/util/AggregationUtil.java | 6 ++---- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/datastax/oss/cass_stac/entity/Item.java b/src/main/java/com/datastax/oss/cass_stac/entity/Item.java index 5096683..a3dc9f4 100644 --- a/src/main/java/com/datastax/oss/cass_stac/entity/Item.java +++ b/src/main/java/com/datastax/oss/cass_stac/entity/Item.java @@ -36,14 +36,14 @@ public Double getCloudCover() throws JsonProcessingException { Map map = objectMapper.readValue(properties, new TypeReference<>() { }); - Object value = map.get("eo:cloud_cover"); - if (value != null) { - try { - return Double.parseDouble(value.toString()); - } catch (NumberFormatException e) { - return Double.longBitsToDouble(Long.getLong(value.toString())); - } + if (properties == null) { + return -1.0; + } + Object value = map.getOrDefault("eo:cloud_cover", -1.0); + try { + return Double.parseDouble(value.toString()); + } catch (NumberFormatException e) { + return Double.longBitsToDouble(Long.getLong(value.toString())); } - return null; } } diff --git a/src/main/java/com/datastax/oss/cass_stac/model/AggregateRequest.java b/src/main/java/com/datastax/oss/cass_stac/model/AggregateRequest.java index f75c9ad..1dfbaef 100644 --- a/src/main/java/com/datastax/oss/cass_stac/model/AggregateRequest.java +++ b/src/main/java/com/datastax/oss/cass_stac/model/AggregateRequest.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; -import java.util.Optional; @Data @Builder @@ -41,18 +40,16 @@ public class AggregateRequest { @NoArgsConstructor @AllArgsConstructor public static class Range { - private Optional from = Optional.of(Double.MIN_VALUE); - private Optional to = Optional.of(Double.MAX_VALUE); + private Double from = 0.0; + private Double to = 100.0; public boolean contains(double value) { - return value >= from.orElse(Double.MIN_VALUE) && value < to.orElse(Double.MAX_VALUE); + return value >= from && value <= to; } public String toString() { - String _from = from.isPresent() ? from.get() == Double.MIN_VALUE ? "*" : from.get().toString() : "*"; - String _to = to.isPresent() ? to.get() == Double.MAX_VALUE ? "*" : to.get().toString() : "*"; - return _from + "-" + _to; + return from + "-" + to; } } } diff --git a/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java b/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java index f3ef280..0bd5a94 100644 --- a/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java +++ b/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java @@ -82,10 +82,8 @@ public Aggregation apply(List items, List ranges) bucket.setKey(entry.getKey().get().toString()); bucket.setFrequency(Math.toIntExact(entry.getValue())); bucket.setData_type("numeric"); - if (entry.getKey().get().getFrom().isPresent()) - bucket.setFrom(entry.getKey().get().getFrom().orElse(null)); - if (entry.getKey().get().getTo().isPresent()) - bucket.setTo(entry.getKey().get().getTo().orElse(null)); + bucket.setFrom(entry.getKey().get().getFrom()); + bucket.setTo(entry.getKey().get().getTo()); } return bucket; })