-
Notifications
You must be signed in to change notification settings - Fork 2
/
EnumItem.js.html
255 lines (220 loc) · 8.42 KB
/
EnumItem.js.html
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: EnumItem.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: EnumItem.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const ArgumentChecker = require('./internal/ArgumentChecker');
const Errors = require('./Errors');
/**
* Class representing an item of Ignite enum type.
*
* The item is defined by:
* - type Id (mandatory) - Id of the Ignite enum type.
* - ordinal (optional) - ordinal of the item in the Ignite enum type.
* - name (optional) - name of the item (field name in the Ignite enum type).
* - value (optional) - value of the item.
* Usually, at least one from the optional ordinal, name or value must be specified
* in order to use an instance of this class in Ignite operations.
*
* To distinguish one item from another, the Ignite client analyzes the optional fields in the following order:
* ordinal, name, value.
*/
class EnumItem {
/**
* Public constructor.
*
* @param {number} typeId - Id of the Ignite enum type.
*
* @return {EnumItem} - new EnumItem instance
*
* @throws {IgniteClientError} if error.
*/
constructor(typeId) {
this.setTypeId(typeId);
this._ordinal = null;
this._name = null;
this._value = null;
}
/**
* Returns Id of the Ignite enum type.
*
* @return {number} - Id of the enum type.
*/
getTypeId() {
return this._typeId;
}
/**
* Updates Id of the Ignite enum type.
*
* @param {number} typeId - new Id of the Ignite enum type.
*
* @return {EnumItem} - the same instance of EnumItem
*
* @throws {IgniteClientError} if error.
*/
setTypeId(typeId) {
ArgumentChecker.isInteger(typeId, 'typeId');
this._typeId = typeId;
return this;
}
/**
* Returns ordinal of the item in the Ignite enum type
* or null if ordinal is not set.
*
* @return {number} - ordinal of the item in the Ignite enum type.
*/
getOrdinal() {
return this._ordinal;
}
/**
* Sets or updates ordinal of the item in the Ignite enum type.
*
* @param {number} ordinal - ordinal of the item in the Ignite enum type.
*
* @return {EnumItem} - the same instance of EnumItem
*
* @throws {IgniteClientError} if error.
*/
setOrdinal(ordinal) {
ArgumentChecker.isInteger(ordinal, 'ordinal');
this._ordinal = ordinal;
return this;
}
/**
* Returns name of the item
* or null if name is not set.
*
* @return {string} - name of the item.
*/
getName() {
return this._name;
}
/**
* Sets or updates name of the item.
*
* @param {string} name - name of the item.
*
* @return {EnumItem} - the same instance of EnumItem
*
* @throws {IgniteClientError} if error.
*/
setName(name) {
ArgumentChecker.notEmpty(name, 'name');
this._name = name;
return this;
}
/**
* Returns value of the item
* or null if value is not set.
*
* @return {number} - value of the item.
*/
getValue() {
return this._value;
}
/**
* Sets or updates value of the item.
*
* @param {number} value - value of the item.
*
* @return {EnumItem} - the same instance of EnumItem
*
* @throws {IgniteClientError} if error.
*/
setValue(value) {
ArgumentChecker.isInteger(value, 'value');
this._value = value;
return this;
}
/** Private methods */
/**
* @ignore
*/
async _write(buffer) {
buffer.writeInteger(this._typeId);
if (this._ordinal !== null) {
buffer.writeInteger(this._ordinal);
return;
}
else if (this._name !== null || this._value !== null) {
const type = await this._getType(this._typeId);
if (type._isEnum && type._enumValues) {
for (let i = 0; i < type._enumValues.length; i++) {
if (this._name === type._enumValues[i][0] ||
this._value === type._enumValues[i][1]) {
buffer.writeInteger(i);
return;
}
}
}
}
throw Errors.IgniteClientError.illegalArgumentError(
'Proper ordinal, name or value must be specified for EnumItem');
}
/**
* @ignore
*/
async _read(buffer) {
this._typeId = buffer.readInteger();
this._ordinal = buffer.readInteger();
const type = await this._getType(this._typeId);
if (!type._isEnum || !type._enumValues || type._enumValues.length <= this._ordinal) {
throw new Errors.IgniteClientError('EnumItem can not be deserialized: type mismatch');
}
this._name = type._enumValues[this._ordinal][0];
this._value = type._enumValues[this._ordinal][1];
}
/**
* @ignore
*/
async _getType(typeId) {
const BinaryTypeStorage = require('./internal/BinaryTypeStorage');
return await BinaryTypeStorage.getEntity().getType(typeId);
}
}
module.exports = EnumItem;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BinaryObject.html">BinaryObject</a></li><li><a href="CacheClient.html">CacheClient</a></li><li><a href="CacheConfiguration.html">CacheConfiguration</a></li><li><a href="CacheEntry.html">CacheEntry</a></li><li><a href="CacheKeyConfiguration.html">CacheKeyConfiguration</a></li><li><a href="CollectionObjectType.html">CollectionObjectType</a></li><li><a href="ComplexObjectType.html">ComplexObjectType</a></li><li><a href="CompositeType.html">CompositeType</a></li><li><a href="Cursor.html">Cursor</a></li><li><a href="EnumItem.html">EnumItem</a></li><li><a href="IgniteClient.html">IgniteClient</a></li><li><a href="IgniteClientConfiguration.html">IgniteClientConfiguration</a></li><li><a href="IgniteClientError.html">IgniteClientError</a></li><li><a href="IllegalStateError.html">IllegalStateError</a></li><li><a href="LostConnectionError.html">LostConnectionError</a></li><li><a href="MapObjectType.html">MapObjectType</a></li><li><a href="ObjectArrayType.html">ObjectArrayType</a></li><li><a href="ObjectType.html">ObjectType</a></li><li><a href="OperationError.html">OperationError</a></li><li><a href="Query.html">Query</a></li><li><a href="QueryEntity.html">QueryEntity</a></li><li><a href="QueryField.html">QueryField</a></li><li><a href="QueryIndex.html">QueryIndex</a></li><li><a href="ScanQuery.html">ScanQuery</a></li><li><a href="SqlFieldsCursor.html">SqlFieldsCursor</a></li><li><a href="SqlFieldsQuery.html">SqlFieldsQuery</a></li><li><a href="SqlQuery.html">SqlQuery</a></li><li><a href="Timestamp.html">Timestamp</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue May 22 2018 12:08:48 GMT+0300 (Russia TZ 2 Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>