Package: AbstractStorableListResult
AbstractStorableListResult
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AbstractStorableListResult() |
|
|
|
|
|
||||||||||||||||||||
AbstractStorableListResult(List, Long) |
|
|
|
|
|
||||||||||||||||||||
AbstractStorableListResult(Object) |
|
|
|
|
|
||||||||||||||||||||
AbstractStorableListResult(Object, Long) |
|
|
|
|
|
||||||||||||||||||||
addItem(Storable) |
|
|
|
|
|
||||||||||||||||||||
addItems(Collection) |
|
|
|
|
|
||||||||||||||||||||
clearItems() |
|
|
|
|
|
||||||||||||||||||||
getFirstItem() |
|
|
|
|
|
||||||||||||||||||||
getItem(int) |
|
|
|
|
|
||||||||||||||||||||
getItems() |
|
|
|
|
|
||||||||||||||||||||
getNextKey() |
|
|
|
|
|
||||||||||||||||||||
getSize() |
|
|
|
|
|
||||||||||||||||||||
getTotalCount() |
|
|
|
|
|
||||||||||||||||||||
isEmpty() |
|
|
|
|
|
||||||||||||||||||||
isLimitExceeded() |
|
|
|
|
|
||||||||||||||||||||
setLimitExceeded(boolean) |
|
|
|
|
|
||||||||||||||||||||
setTotalCount(Long) |
|
|
|
|
|
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.storable.model;
14:
15: import java.util.ArrayList;
16: import java.util.Collection;
17: import java.util.List;
18:
19: /**
20: * {@link StorableListResult} {@code abstract} implementation.
21: * <p>
22: * This is the base for all {@link StorableListResult}'s implementations.
23: *
24: * @param <E> The {@link Storable} for which this is a {@link StorableListResult} for.
25: * @since 1.0.0
26: */
27: public class AbstractStorableListResult<E extends Storable> implements StorableListResult<E> {
28:
29: private static final long serialVersionUID = -6792613517586602315L;
30:
31: private boolean limitExceeded;
32: private ArrayList<E> items;
33: private Object nextKey;
34: private Long totalCount;
35:
36: /**
37: * Constructor.
38: *
39: * @since 1.0.0
40: */
41: public AbstractStorableListResult() {
42: }
43:
44: /**
45: * Constructor.
46: *
47: * @param storables The {@link Storable}s to add to the {@link StorableListResult}.
48: * @param totalCount The total count of the {@link Storable}s matched.
49: * @since 1.3.0
50: */
51: public AbstractStorableListResult(List<E> storables, Long totalCount) {
52: this();
53:
54: addItems(storables);
55: setTotalCount(totalCount);
56: }
57:
58: /**
59: * Constructors.
60: *
61: * @param nextKey The {@link StorableListResult#getNextKey()}.
62: * @since 1.0.0
63: * @deprecated Since 1.3.0, this is not used!
64: */
65: @Deprecated
66: public AbstractStorableListResult(Object nextKey) {
67: this();
68: this.nextKey = nextKey;
69: }
70:
71: /**
72: * Constructor.
73: *
74: * @param nextKeyOffset The {@link StorableListResult#getNextKey()}.
75: * @param totalCount The {@link StorableListResult#getTotalCount()}.
76: * @since 1.0.0
77: * @deprecated Since 1.3.0, this is not used!
78: */
79: @Deprecated
80: public AbstractStorableListResult(Object nextKeyOffset, Long totalCount) {
81: this(nextKeyOffset);
82: this.totalCount = totalCount;
83: }
84:
85: @Override
86: public boolean isLimitExceeded() {
87: return limitExceeded;
88: }
89:
90: @Override
91: public void setLimitExceeded(boolean limitExceeded) {
92: this.limitExceeded = limitExceeded;
93: }
94:
95: @Override
96: public E getItem(int index) {
97: return getItems().get(index);
98: }
99:
100: @Override
101: public E getFirstItem() {
102:• return this.isEmpty() ? null : getItem(0);
103: }
104:
105: @Override
106: public int getSize() {
107: return getItems().size();
108: }
109:
110: @Override
111: public boolean isEmpty() {
112: return getItems().isEmpty();
113: }
114:
115: @Override
116: public List<E> getItems() {
117:• if (items == null) {
118: items = new ArrayList<>();
119: }
120:
121: return items;
122: }
123:
124: @Override
125: public void addItems(Collection<? extends E> items) {
126: getItems().addAll(items);
127: }
128:
129: @Override
130: public void addItem(E item) {
131: getItems().add(item);
132: }
133:
134: @Override
135: public void clearItems() {
136: getItems().clear();
137: }
138:
139: @Override
140: public Object getNextKey() {
141: return nextKey;
142: }
143:
144: @Override
145: public Long getTotalCount() {
146: return totalCount;
147: }
148:
149: @Override
150: public void setTotalCount(Long totalCount) {
151: this.totalCount = totalCount;
152: }
153:
154: }