home *** CD-ROM | disk | FTP | other *** search
- package com.kav.xsl;
-
- import org.w3c.dom.Node;
-
- public class NodeSet {
- private int DEFAULT_SIZE = 25;
- private Node[] elements;
- private int initialSize;
- private int elementCount;
-
- public NodeSet() {
- this.initialSize = this.DEFAULT_SIZE;
- this.elements = new Node[this.DEFAULT_SIZE];
- }
-
- public NodeSet(int var1) {
- this.initialSize = this.DEFAULT_SIZE;
- this.initialSize = var1;
- this.elements = new Node[var1];
- }
-
- public boolean add(Node var1) {
- if (!this.contains(var1)) {
- if (this.elementCount == this.elements.length) {
- this.increaseSize();
- }
-
- this.elements[this.elementCount++] = var1;
- return true;
- } else {
- return false;
- }
- }
-
- public boolean add(int var1, Node var2) throws IndexOutOfBoundsException {
- if (var1 >= 0 && var1 <= this.elementCount) {
- if (this.contains(var2)) {
- return false;
- } else {
- if (this.elementCount == this.elements.length) {
- this.increaseSize();
- }
-
- if (var1 == this.elementCount) {
- this.elements[this.elementCount++] = var2;
- } else {
- this.shiftUp(var1);
- this.elements[var1] = var2;
- ++this.elementCount;
- }
-
- return true;
- }
- } else {
- throw new IndexOutOfBoundsException();
- }
- }
-
- public void clear() {
- for(int var1 = 0; var1 < this.elementCount; ++var1) {
- this.elements[var1] = null;
- }
-
- this.elementCount = 0;
- }
-
- public boolean contains(Node var1) {
- return this.indexOf(var1) >= 0;
- }
-
- public boolean equals(Object var1) {
- if (var1 == null) {
- return false;
- } else if (!(var1 instanceof NodeSet)) {
- return false;
- } else {
- NodeSet var2 = (NodeSet)var1;
- if (var2.size() != this.size()) {
- return false;
- } else {
- byte var3 = 0;
- if (var3 >= this.size()) {
- return true;
- } else {
- this.get(var3);
- return !var2.contains(this.get(var3)) ? false : false;
- }
- }
- }
- }
-
- public Node get(int var1) throws IndexOutOfBoundsException {
- if (var1 >= 0 && var1 < this.elementCount) {
- return this.elements[var1];
- } else {
- throw new IndexOutOfBoundsException();
- }
- }
-
- public int hashCode() {
- int var1 = 0;
-
- for(int var2 = 0; var2 < this.elementCount; ++var2) {
- Node var3 = this.elements[var2];
- var1 += var3 == null ? 0 : var3.hashCode();
- }
-
- return var1;
- }
-
- public int indexOf(Node var1) {
- for(int var2 = 0; var2 < this.elementCount; ++var2) {
- if (var1 == this.elements[var2]) {
- return var2;
- }
- }
-
- return -1;
- }
-
- public boolean isEmpty() {
- return this.elementCount == 0;
- }
-
- public Node remove(int var1) {
- if (var1 >= 0 && var1 <= this.elementCount) {
- Node var2 = this.elements[var1];
- this.shiftDown(var1 + 1);
- return var2;
- } else {
- return null;
- }
- }
-
- public boolean remove(Node var1) {
- int var2 = this.indexOf(var1);
- if (var2 > -1) {
- this.remove(var2);
- return true;
- } else {
- return false;
- }
- }
-
- public int size() {
- return this.elementCount;
- }
-
- public Node[] toArray() {
- Node[] var1 = new Node[this.elementCount];
- System.arraycopy(this.elements, 0, var1, 0, this.elementCount);
- return var1;
- }
-
- public Node[] toArray(Node[] var1) {
- Object var2 = null;
- Node[] var3;
- if (var1.length >= this.elementCount) {
- var3 = var1;
- } else {
- var3 = new Node[this.elementCount];
- }
-
- System.arraycopy(this.elements, 0, var3, 0, this.elementCount);
- return var3;
- }
-
- private void increaseSize() {
- Node[] var1 = this.elements;
- this.elements = new Node[var1.length * 2];
- System.arraycopy(var1, 0, this.elements, 0, var1.length);
- }
-
- private void shiftDown(int var1) {
- if (var1 > 0 && var1 < this.elementCount) {
- System.arraycopy(this.elements, var1, this.elements, var1 - 1, this.elementCount - var1);
- this.elements[this.elementCount - 1] = null;
- }
- }
-
- private void shiftUp(int var1) {
- if (var1 != this.elementCount) {
- if (this.elementCount == this.elements.length) {
- this.increaseSize();
- }
-
- System.arraycopy(this.elements, var1, this.elements, var1 + 1, this.elementCount - var1);
- }
- }
- }
-