Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Eugene Shen
jio
Commits
700ef189
Commit
700ef189
authored
11 years ago
by
Tristan Cavelier
Browse files
Options
Download
Email Patches
Plain Diff
ReferenceArray.js added
parent
4a533092
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
src/jio/core/ReferenceArray.js
src/jio/core/ReferenceArray.js
+87
-0
No files found.
src/jio/core/ReferenceArray.js
0 → 100644
View file @
700ef189
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global */
/**
* An array that contain object (or array) references.
*
* @class ReferenceArray
* @constructor
* @param {array} [array] The array where to work on
*/
function
ReferenceArray
(
array
)
{
if
(
Array
.
isArray
(
array
))
{
this
.
_array
=
array
;
}
else
{
this
.
_array
=
[];
}
}
/**
* Returns the array version of the job queue
*
* @method asArray
* @return {Array} The job queue as array
*/
ReferenceArray
.
prototype
.
asArray
=
function
()
{
return
this
.
_array
;
};
/**
* Returns the index of the object
*
* @method indexOf
* @param {Object} object The object to search
*/
ReferenceArray
.
prototype
.
indexOf
=
function
(
object
)
{
var
i
;
for
(
i
=
0
;
i
<
this
.
_array
.
length
;
i
+=
1
)
{
if
(
this
.
_array
[
i
]
===
object
)
{
return
i
;
}
}
return
-
1
;
};
/**
* Put an object to the list. If an object already exists, do nothing.
*
* @method put
* @param {Object} object The object to add
*/
ReferenceArray
.
prototype
.
put
=
function
(
object
)
{
var
i
;
for
(
i
=
0
;
i
<
this
.
_array
.
length
;
i
+=
1
)
{
if
(
this
.
_array
[
i
]
===
object
)
{
return
false
;
}
}
this
.
_array
[
i
]
=
object
;
return
true
;
};
/**
* Removes an object from the list
*
* @method remove
* @param {Object} object The object to remove
*/
ReferenceArray
.
prototype
.
remove
=
function
(
object
)
{
var
i
;
for
(
i
=
0
;
i
<
this
.
_array
.
length
;
i
+=
1
)
{
if
(
this
.
_array
[
i
]
===
object
)
{
this
.
_array
.
splice
(
i
,
1
);
return
true
;
}
}
return
false
;
};
/**
* Clears the list.
*
* @method clear
*/
ReferenceArray
.
prototype
.
clear
=
function
()
{
this
.
_array
.
length
=
0
;
return
this
;
};
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment