1 28 29 package com.caucho.util; 30 31 public class DoubleArray { 32 double []data; 33 int size; 34 35 public void clear() { 36 size = 0; 37 } 38 39 private void expand(int max) { 40 while (max > data.length) { 41 double []next = new double[data.length * 2]; 42 43 for (int i = 0; i < data.length; i++) 44 next[i] = data[i]; 45 46 data = next; 47 } 48 } 49 50 public int size() { return size; } 51 52 public void append(double i) { 53 expand(size + 1); 54 55 data[size++] = i; 56 } 57 58 public void append(DoubleArray array) { 59 expand(size + array.size); 60 61 for (int i = 0; i < array.size; i++) 62 data[size++] = array.data[i]; 63 } 64 65 public void insert(int i, double value) { 66 expand(size + 1); 67 68 System.arraycopy(data, i, data, i + 1, size - i); 69 data[i] = value; 70 size++; 71 } 72 73 public double pop() { 74 return data[--size]; 75 } 76 77 public void setLength(int size) 78 { 79 expand(size); 80 81 for (int i = this.size; i < size; i++) 82 data[i] = 0; 83 84 this.size = size; 85 } 86 87 public double get(int i) { 88 return data[i]; 89 } 90 91 public double last() { 92 return data[size - 1]; 93 } 94 95 public void set(int i, double value) { 96 if (i + 1 > size) 97 setLength(i + 1); 98 99 data[i] = value; 100 } 101 102 public boolean contains(double test) 103 { 104 for (int i = 0; i < size; i++) 105 if (data[i] == test) 106 return true; 107 108 return false; 109 } 110 111 public boolean isSubset(DoubleArray subset) 112 { 113 for (int i = 0; i < subset.size; i++) 114 if (! contains(subset.data[i])) 115 return false; 116 117 return true; 118 } 119 120 public void union(DoubleArray newArray) 121 { 122 for (int i = 0; i < newArray.size; i++) { 123 if (! contains(newArray.data[i])) 124 append(newArray.data[i]); 125 } 126 } 127 128 public DoubleArray() { 129 data = new double[16]; 130 size = 0; 131 } 132 } 133 | Popular Tags |