]> git.basschouten.com Git - openhab-addons.git/blob
4246fb869661f3a21889767c48fa3fb50aeae772
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.neeo.internal.models;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * Represents the meta data information to a directly result. This class is simply used for serialization of the result
22  * back to the brain.
23  *
24  * @author Tim Roberts - Initial Contribution
25  *
26  */
27 @NonNullByDefault
28 public class NeeoDirectoryResultMeta {
29     /** The total items available */
30     private final int totalItems;
31
32     /** The total matching items (if filtered) available */
33     private final int totalMatchingItems;
34
35     /** The current position request (that will be sent back to us) */
36     private final NeeoDirectoryRequest current;
37
38     /** The previous position that will be sent back to us (null if no previous) */
39     @Nullable
40     private final NeeoDirectoryRequest previous;
41
42     /** The next position that will be sent back to us (null if no next) */
43     @Nullable
44     private final NeeoDirectoryRequest next;
45
46     /**
47      * Constructs the meta data from the given items
48      *
49      * @param totalItems the total items available (>= 0)
50      * @param totalMatchingItems the total matching items available (>= 0)
51      * @param current the non-null current position
52      * @param previous the possibly null previous position
53      * @param next the possibly null next position
54      */
55     public NeeoDirectoryResultMeta(int totalItems, int totalMatchingItems, NeeoDirectoryRequest current,
56             @Nullable NeeoDirectoryRequest previous, @Nullable NeeoDirectoryRequest next) {
57         Objects.requireNonNull(current, "current cannot be null");
58         if (totalItems < 0) {
59             throw new IllegalArgumentException("totalItems must be >= 0");
60         }
61         if (totalMatchingItems < 0) {
62             throw new IllegalArgumentException("totalMatchingItems must be >= 0");
63         }
64
65         this.totalItems = totalItems;
66         this.totalMatchingItems = totalMatchingItems;
67         this.current = current;
68         this.previous = previous;
69         this.next = next;
70     }
71
72     /**
73      * Returns the total items available
74      *
75      * @return the total items (>= 0)
76      */
77     public int getTotalItems() {
78         return totalItems;
79     }
80
81     /**
82      * Returns the total matching items available
83      *
84      * @return the total matching items (>= 0)
85      */
86     public int getTotalMatchingItems() {
87         return totalMatchingItems;
88     }
89
90     /**
91      * Returns the current position
92      *
93      * @return a non-null current position
94      */
95     public NeeoDirectoryRequest getCurrent() {
96         return current;
97     }
98
99     /**
100      * Returns the previous position
101      *
102      * @return a possibly null previous position (null if none)
103      */
104     @Nullable
105     public NeeoDirectoryRequest getPrevious() {
106         return previous;
107     }
108
109     /**
110      * Returns the next position
111      *
112      * @return a possibly null next position (null if none)
113      */
114     @Nullable
115     public NeeoDirectoryRequest getNext() {
116         return next;
117     }
118
119     @Override
120     public String toString() {
121         return "NeeoDiscoveryListResultMeta [totalItems=" + totalItems + ", totalMatchingItems=" + totalMatchingItems
122                 + ", current=" + current + ", previous=" + previous + ", next=" + next + "]";
123     }
124 }