2 * Copyright (c) 2010-2022 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.surepetcare.internal.dto;
15 import java.util.ArrayList;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.surepetcare.internal.SurePetcareConstants;
21 * The {@link SurePetcareDeviceCurfewList} class is used to serialize a list of curfew parameters.
23 * @author Rene Scherer - Initial contribution
26 public class SurePetcareDeviceCurfewList extends ArrayList<SurePetcareDeviceCurfew> {
28 private static final long serialVersionUID = -6947992959305282143L;
31 * Return the list element with the given index. If the list if too short, it will grow automatically to the given
34 * @return element with given index
37 public SurePetcareDeviceCurfew get(int index) {
38 while (size() <= index) {
39 // grow list to required size
40 add(new SurePetcareDeviceCurfew());
42 return super.get(index);
46 public String toString() {
47 StringBuilder builder = new StringBuilder("[");
48 for (SurePetcareDeviceCurfew c : this) {
49 builder.append("(").append(c).append(")");
52 return builder.toString();
56 * Creates a list of curfews with enabled ones at the front of the list and disabled ones at the back.
58 * @return new ordered list.
60 public SurePetcareDeviceCurfewList order() {
61 SurePetcareDeviceCurfewList orderedList = new SurePetcareDeviceCurfewList();
62 // remove any disabled curfews from the list
63 for (SurePetcareDeviceCurfew curfew : this) {
65 orderedList.add(curfew);
68 // now fill up the list with empty disabled slots.
69 for (int i = orderedList.size(); i < SurePetcareConstants.FLAP_MAX_NUMBER_OF_CURFEWS; i++) {
70 orderedList.add(new SurePetcareDeviceCurfew());
76 * Trims the list of curfews and removes any disabled ones.
78 * @return the new compact list of curfews.
80 public SurePetcareDeviceCurfewList compact() {
81 SurePetcareDeviceCurfewList compactList = new SurePetcareDeviceCurfewList();
82 // remove any disabled curfews from the list
83 for (SurePetcareDeviceCurfew curfew : this) {
85 compactList.add(curfew);