java 实现set_js 实现JAVASET
/**
* Created with IntelliJ IDEA.
* User: chicheng
* Date: 14-11-7
* Time: 下午9:24
* To change this template use File | Settings | File Templates.
*/
function Set() {
this.elements = new Array();
//獲取Set元素個(gè)數(shù)
this.size = function() {
return this.elements.length;
}
//判斷Set是否為空
this.isEmpty = function() {
return (this.elements.length < 1);
}
//清除Set
this.clear = function() {
this.elements = new Array();
}
//增加一個(gè)元素,不重復(fù)
this.add = function(value) {
//alert(this.containsKey(_key));
if(this.containsValue(value)){
this.remove(value);
}
this.elements.push(value);
}
//移除一個(gè)值
this.remove = function(value) {
var bln = false;
try {
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i] == value) {
this.elements.splice(i, 1);
return true;
}
}
} catch (e) {
bln = false;
}
return bln;
}
//移除一個(gè)值,索引
this.kill=function (index){
this.remove(this.get(index));
}
//得到一個(gè)值,索引
this.get = function(_index) {
if (_index < 0 || _index >= this.elements.length) {
return null;
}
return this.elements[_index];
}
//查看是否包含一個(gè)值 ??? this.containsValue = function(value) { ??????? var bln = false; ??????? try { ??????????? for (i = 0; i < this.elements.length; i++) { ??????????????? if (this.elements[i] == value) { ??????????????????? bln = true; ??????????????? } ??????????? } ??????? } catch (e) { ??????????? bln = false; ??????? } ??????? return bln; ??? } }
總結(jié)
以上是生活随笔為你收集整理的java 实现set_js 实现JAVASET的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java单态模式_Java单态模式
- 下一篇: java jeditorpane 自动换