Debian Codegraph @

rhino/examples/enum.js

raw symbols SCIP
1 /* -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 /*
8 Implementing the interface java.util.Enumeration passing the object
9 with JavaScript implementation directly to the constructor.
10 This is a shorthand for JavaAdapter constructor:
11
12 elements = new JavaAdapter(java.util.Enumeration, {
13 index: 0,
14 elements: array,
15 hasMoreElements: function ...
16 nextElement: function ...
17 });
18 */
19
20 // an array to enumerate.
21 var array = [0, 1, 2];
22
23 // create an array enumeration.
24 var elements = new java.util.Enumeration({
25 index: 0,
26 elements: array,
27 hasMoreElements: function() {
28 return (this.index < this.elements.length);
29 },
30 nextElement: function() {
31 return this.elements[this.index++];
32 }
33 });
34
35 // now print out the array by enumerating through the Enumeration
36 while (elements.hasMoreElements())
37 print(elements.nextElement());