2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.awattar.internal;
15 import static org.openhab.binding.awattar.internal.AwattarUtil.*;
17 import java.time.Instant;
18 import java.time.ZoneId;
19 import java.util.ArrayList;
20 import java.util.Comparator;
21 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
26 * Stores a non consecutive bestprice result
28 * @author Wolfgang Klimt - initial contribution
31 public class AwattarNonConsecutiveBestPriceResult extends AwattarBestPriceResult {
33 private List<AwattarPrice> members;
34 private ZoneId zoneId;
35 private boolean sorted = true;
37 public AwattarNonConsecutiveBestPriceResult(int size, ZoneId zoneId) {
40 members = new ArrayList<AwattarPrice>();
43 public void addMember(AwattarPrice member) {
46 updateStart(member.getStartTimestamp());
47 updateEnd(member.getEndTimestamp());
51 public boolean isActive() {
52 return members.stream().anyMatch(x -> x.contains(Instant.now().toEpochMilli()));
55 public String toString() {
56 return String.format("NonConsecutiveBestpriceResult with %s", members.toString());
61 members.sort(new Comparator<AwattarPrice>() {
63 public int compare(AwattarPrice o1, AwattarPrice o2) {
64 return Long.compare(o1.getStartTimestamp(), o2.getStartTimestamp());
70 public String getHours() {
71 boolean second = false;
73 StringBuilder res = new StringBuilder();
74 for (AwattarPrice price : members) {
78 res.append(getHourFrom(price.getStartTimestamp(), zoneId));
81 return res.toString();