UTILS.js 1.67 KB
Newer Older
Thitichaipun Wutthisak committed
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

function StringBuffer() { 
	this.buffer = []; 

	this.append = function(string) {
		this.buffer.push(string);
		return this;
	}
	this.toString = function(delim){
		return this.buffer.join(delim||'');
	}
	this.length = function() {
		return this.buffer.length;
	}
	this.clear = function(){
		this.buffer = [];
		return this;
	}
};

function Stack() { 
	this.array = new Array();

	this.push = function(string) {
		this.array.push(string);
		return this;
	}
	this.pop = function() {
		this.array.pop();
	}
	this.size = function() {
		return this.array.length;
	}
	this.clear = function(){
		this.array = new Array();
		return this;
	}
	this.empty = function(){
		return size() == 0;
	}
};

function ArrayList() {
	this.array = new Array();

	this.add = function(obj) {
		this.array[this.array.length] = obj;
	}
	this.remove = function(obj) {
		if (index >= size) {
			this.array[this.array.length] = obj;
		}else{
			return null;
		}
	}
	
	this.size = function() {
		return this.array.length;
	}
	this.get = function(index) {
		return this.array[index];
	}
	this.toArray = function() {
		return this.array;
	}
	/*
	this.addAll = function(obj) {
		if (obj instanceof Array){
			for (var i=0;i<obj.length;i++) {
				this.add(obj[i]);
		  }
		} else if (obj instanceof ArrayList) {
			for (var i=0;i<obj.length();i++) {
				this.add(obj.get(i));
			}
		}
	}
	this.iterator = function() {
		return new Iterator(this)
	}
	*/
	this.isEmpty = function(){
		return size() == 0;
	}
};

/*
function Iterator (arrayList){
  this.arrayList;
  this.index = 0;

  this.hasNext = function (){
	return this.index < this.arrayList.size();
  }
  this.next = function() {
      return this.arrayList.get(index++);
  }
};
*/