1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
package com.vaadin.data;
/**
* A exception that indicates that the container is unable to return all of the
* consecutive item ids requested by the caller. This can happen if the
* container size has changed since the input parameters for
* {@link Container.Indexed#getItemIds(int, int)} were computed or if the
* requested range exceeds the containers size due to some other factor.<br>
* <br>
*
* The exception can contain additional parameters for easier debugging. The
* additional parameters are the <code>startIndex</code> and
* <code>numberOfIds</code> which were given to
* {@link Container.Indexed#getItemIds(int, int)} as well as the size of the
* container when the fetch was executed. The container size can be retrieved
* with {@link #getContainerCurrentSize()}. <br>
* <br>
*
* The additional parameters are optional but the party that received the
* exception can check whether or not these were set by calling
* {@link #isAdditionalParametersSet()}.
*
* @since 7.0
*/
public class RangeOutOfContainerBoundsException extends RuntimeException {
private final int startIndex;
private final int numberOfIds;
private final int containerCurrentSize;
private final boolean additionalParametersSet;
// Discourage users to create exceptions without at least some kind of
// message...
private RangeOutOfContainerBoundsException() {
super();
startIndex = -1;
numberOfIds = -1;
containerCurrentSize = -1;
additionalParametersSet = false;
}
public RangeOutOfContainerBoundsException(String message) {
super(message);
startIndex = -1;
numberOfIds = -1;
containerCurrentSize = -1;
additionalParametersSet = false;
}
public RangeOutOfContainerBoundsException(String message,
Throwable throwable) {
super(message, throwable);
startIndex = -1;
numberOfIds = -1;
containerCurrentSize = -1;
additionalParametersSet = false;
}
public RangeOutOfContainerBoundsException(Throwable throwable) {
super(throwable);
startIndex = -1;
numberOfIds = -1;
containerCurrentSize = -1;
additionalParametersSet = false;
}
/**
* Create a new {@link RangeOutOfContainerBoundsException} with the
* additional parameters:
* <ul>
* <li>startIndex - start index for the query</li>
* <li>numberOfIds - the number of consecutive item ids to get</li>
* <li>containerCurrentSize - the size of the container during the execution
* of the query</li>
* </ul>
* given.
*
* @param message
* @param startIndex
* the given startIndex for the query
* @param numberOfIds
* the number of item ids requested
* @param containerCurrentSize
* the current size of the container
*/
public RangeOutOfContainerBoundsException(String message, int startIndex,
int numberOfIds, int containerCurrentSize) {
super(message);
this.startIndex = startIndex;
this.numberOfIds = numberOfIds;
this.containerCurrentSize = containerCurrentSize;
additionalParametersSet = true;
}
/**
* Create a new {@link RangeOutOfContainerBoundsException} with the given
* query parameters set in the exception along with the containers current
* size and a @link {@link Throwable}.
*
* @param message
* @param startIndex
* the given startIndex for the query
* @param numberOfIds
* the number of item ids queried for
* @param containerCurrentSize
* the current size of the container
* @param throwable
*/
public RangeOutOfContainerBoundsException(String message, int startIndex,
int numberOfIds, int containerCurrentSize, Throwable throwable) {
super(message, throwable);
this.startIndex = startIndex;
this.numberOfIds = numberOfIds;
this.containerCurrentSize = containerCurrentSize;
additionalParametersSet = true;
}
/**
* Get the given startIndex for the query. Remember to check if this
* parameter is set by calling {@link #isAdditionalParametersSet()}
*
* @return the startIndex given to the container
*/
public int getStartIndex() {
return startIndex;
}
/**
* Get the number of item ids requested. Remember to check if this parameter
* is set with {@link #isAdditionalParametersSet()}
*
* @return the number of item ids the container was ordered to fetch
*/
public int getNumberOfIds() {
return numberOfIds;
}
/**
* Get the container size when the query was actually executed. Remember to
* check if this parameter is set with {@link #isAdditionalParametersSet()}
*/
public int getContainerCurrentSize() {
return containerCurrentSize;
}
/**
* Check whether or not the additional parameters for the exception were set
* during creation or not.
*
* The additional parameters can be retrieved with: <br>
* <ul>
* <li> {@link #getStartIndex()}</li>
* <li> {@link #getNumberOfIds()}</li>
* <li> {@link #getContainerCurrentSize()}</li>
* </ul>
*
* @return true if parameters are set, false otherwise.
*
* @see #RangeOutOfContainerBoundsException(String, int, int, int)
* RangeOutOfContainerBoundsException(String, int, int, int) for more
* details on the additional parameters
*/
public boolean isAdditionalParametersSet() {
return additionalParametersSet;
}
}
|