home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / APCHSSL2.ZIP / OS2HTTPD / jserv / com / kav / xsl / NodeSet.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-05-16  |  2.0 KB  |  191 lines

  1. package com.kav.xsl;
  2.  
  3. import org.w3c.dom.Node;
  4.  
  5. public class NodeSet {
  6.    private int DEFAULT_SIZE = 25;
  7.    private Node[] elements;
  8.    private int initialSize;
  9.    private int elementCount;
  10.  
  11.    public NodeSet() {
  12.       this.initialSize = this.DEFAULT_SIZE;
  13.       this.elements = new Node[this.DEFAULT_SIZE];
  14.    }
  15.  
  16.    public NodeSet(int var1) {
  17.       this.initialSize = this.DEFAULT_SIZE;
  18.       this.initialSize = var1;
  19.       this.elements = new Node[var1];
  20.    }
  21.  
  22.    public boolean add(Node var1) {
  23.       if (!this.contains(var1)) {
  24.          if (this.elementCount == this.elements.length) {
  25.             this.increaseSize();
  26.          }
  27.  
  28.          this.elements[this.elementCount++] = var1;
  29.          return true;
  30.       } else {
  31.          return false;
  32.       }
  33.    }
  34.  
  35.    public boolean add(int var1, Node var2) throws IndexOutOfBoundsException {
  36.       if (var1 >= 0 && var1 <= this.elementCount) {
  37.          if (this.contains(var2)) {
  38.             return false;
  39.          } else {
  40.             if (this.elementCount == this.elements.length) {
  41.                this.increaseSize();
  42.             }
  43.  
  44.             if (var1 == this.elementCount) {
  45.                this.elements[this.elementCount++] = var2;
  46.             } else {
  47.                this.shiftUp(var1);
  48.                this.elements[var1] = var2;
  49.                ++this.elementCount;
  50.             }
  51.  
  52.             return true;
  53.          }
  54.       } else {
  55.          throw new IndexOutOfBoundsException();
  56.       }
  57.    }
  58.  
  59.    public void clear() {
  60.       for(int var1 = 0; var1 < this.elementCount; ++var1) {
  61.          this.elements[var1] = null;
  62.       }
  63.  
  64.       this.elementCount = 0;
  65.    }
  66.  
  67.    public boolean contains(Node var1) {
  68.       return this.indexOf(var1) >= 0;
  69.    }
  70.  
  71.    public boolean equals(Object var1) {
  72.       if (var1 == null) {
  73.          return false;
  74.       } else if (!(var1 instanceof NodeSet)) {
  75.          return false;
  76.       } else {
  77.          NodeSet var2 = (NodeSet)var1;
  78.          if (var2.size() != this.size()) {
  79.             return false;
  80.          } else {
  81.             byte var3 = 0;
  82.             if (var3 >= this.size()) {
  83.                return true;
  84.             } else {
  85.                this.get(var3);
  86.                return !var2.contains(this.get(var3)) ? false : false;
  87.             }
  88.          }
  89.       }
  90.    }
  91.  
  92.    public Node get(int var1) throws IndexOutOfBoundsException {
  93.       if (var1 >= 0 && var1 < this.elementCount) {
  94.          return this.elements[var1];
  95.       } else {
  96.          throw new IndexOutOfBoundsException();
  97.       }
  98.    }
  99.  
  100.    public int hashCode() {
  101.       int var1 = 0;
  102.  
  103.       for(int var2 = 0; var2 < this.elementCount; ++var2) {
  104.          Node var3 = this.elements[var2];
  105.          var1 += var3 == null ? 0 : var3.hashCode();
  106.       }
  107.  
  108.       return var1;
  109.    }
  110.  
  111.    public int indexOf(Node var1) {
  112.       for(int var2 = 0; var2 < this.elementCount; ++var2) {
  113.          if (var1 == this.elements[var2]) {
  114.             return var2;
  115.          }
  116.       }
  117.  
  118.       return -1;
  119.    }
  120.  
  121.    public boolean isEmpty() {
  122.       return this.elementCount == 0;
  123.    }
  124.  
  125.    public Node remove(int var1) {
  126.       if (var1 >= 0 && var1 <= this.elementCount) {
  127.          Node var2 = this.elements[var1];
  128.          this.shiftDown(var1 + 1);
  129.          return var2;
  130.       } else {
  131.          return null;
  132.       }
  133.    }
  134.  
  135.    public boolean remove(Node var1) {
  136.       int var2 = this.indexOf(var1);
  137.       if (var2 > -1) {
  138.          this.remove(var2);
  139.          return true;
  140.       } else {
  141.          return false;
  142.       }
  143.    }
  144.  
  145.    public int size() {
  146.       return this.elementCount;
  147.    }
  148.  
  149.    public Node[] toArray() {
  150.       Node[] var1 = new Node[this.elementCount];
  151.       System.arraycopy(this.elements, 0, var1, 0, this.elementCount);
  152.       return var1;
  153.    }
  154.  
  155.    public Node[] toArray(Node[] var1) {
  156.       Object var2 = null;
  157.       Node[] var3;
  158.       if (var1.length >= this.elementCount) {
  159.          var3 = var1;
  160.       } else {
  161.          var3 = new Node[this.elementCount];
  162.       }
  163.  
  164.       System.arraycopy(this.elements, 0, var3, 0, this.elementCount);
  165.       return var3;
  166.    }
  167.  
  168.    private void increaseSize() {
  169.       Node[] var1 = this.elements;
  170.       this.elements = new Node[var1.length * 2];
  171.       System.arraycopy(var1, 0, this.elements, 0, var1.length);
  172.    }
  173.  
  174.    private void shiftDown(int var1) {
  175.       if (var1 > 0 && var1 < this.elementCount) {
  176.          System.arraycopy(this.elements, var1, this.elements, var1 - 1, this.elementCount - var1);
  177.          this.elements[this.elementCount - 1] = null;
  178.       }
  179.    }
  180.  
  181.    private void shiftUp(int var1) {
  182.       if (var1 != this.elementCount) {
  183.          if (this.elementCount == this.elements.length) {
  184.             this.increaseSize();
  185.          }
  186.  
  187.          System.arraycopy(this.elements, var1, this.elements, var1 + 1, this.elementCount - var1);
  188.       }
  189.    }
  190. }
  191.