# util4js

The util4js module contains JavaScript utilities. __util4js__  is free software 
distributed under the terms of the _GNU General Public License version 3_ and 
can be used with __node.js__, __modern web browsers__ and even with __PhantomJS__.

## Installation

    npm install util4js

## API

* Object
* Event
  * Component
* Exception
  * ArgumentException
  * ArgumentNullException
  * IndexOutOfRangeException
* Iterator
* Containers
  * List
  * Dictionary
  * Set
  * Stack
  * Queue

### Object

__Object__ is a root class. Object class containts __getHashCode__ and 
__equals__ methods.

__Example__

    "use strict";
    
    var class4js = require("class4js");
    var util4js = require("util4js.js");
    
    var obj1 = new util4js.Object();
    console.log(obj1.getHashCode());
    
    var obj2 = new util4js.Object();
    console.log(obj2.getHashCode());
    
    console.log(util4js.Object.equals(obj1, obj2));
    console.log(util4js.Object.equals(obj1, obj1));
    console.log(obj1.equals(obj1));

### Exception

__Exception__ class is the base class for all exceptions.

__Example__

    "use strict";
    
    var class4js = require("class4js");
    var util4js = require("util4js.js");
    
    var CustomException = $class({
      __construct__: function () {
        this.name = "CustomException"; 
      }
    }, util4js.Exception);
    
    try {
      throw new CustomException({ message: "Exception was raised" });
    } catch (ex) {
      console.log(ex.toString());
    }

### Iterator

An iterator over a collection.

__Example__

    "use strict";
    
    var class4js = require("class4js");
    var util4js = require("util4js.js");
    
    var iterator = new util4js.Iterator(["1", "2", "3"]);
    console.log(iterator);
    while (iterator.hasNext()) {
      console.log(iterator.next());
    }

### List

__Example__

    var class4js = require("class4js");
    var util4js = require("../../lib/util4js.js");
    
    var list = new util4js.List(["One", "Two", "Three"]);
    
    list.insert(0, "Zero");
    list.add("Four");
    
    for (var i = 0;i < list.count; i++) {
      console.log(list.indexOf(list.get(i)) + " " + list.get(i) + " " + list.contains(list.get(i)));
    }
    
    list.clear();

### PhantomJS

__PhantomJS__ is very similar to the __Node.js__. __util4js__ package dedicated for 
__Node.js__ can be taken and used in __PhantomJS__ without any modifications.

## License

This software is distributed under the terms of the GNU General Public License, 
version 3 (GPL-3.0).
