Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.generalrobotix.ui.view.graph;
00011
00018 public class DataSeries {
00019
00020
00021
00022 private int size_;
00023 private double[] data_;
00024 private int headPos_;
00025 private double xOffset_;
00026 private double xStep_;
00027
00028
00029
00037 public DataSeries(
00038 int size,
00039 double xOffset,
00040 double xStep
00041 ) {
00042 size_ = size;
00043 xOffset_ = xOffset;
00044 xStep_ = xStep;
00045 headPos_ = 0;
00046 data_ = new double[size];
00047 for (int i = 0; i < size; i++) {
00048 data_[i] = Double.NaN;
00049 }
00050 }
00051
00052
00053
00059 public void setSize(
00060 int size
00061 ) {
00062 size_ = size;
00063 headPos_ = 0;
00064 data_ = new double[size];
00065 for (int i = 0; i < size; i++) {
00066 data_[i] = Double.NaN;
00067 }
00068 }
00069
00075 public void setXOffset(
00076 double xOffset
00077 ) {
00078 xOffset_ = xOffset;
00079 }
00080
00086 public void setXStep(
00087 double xStep
00088 ) {
00089 xStep_ = xStep;
00090 }
00091
00097 public int getSize() {
00098 return size_;
00099 }
00100
00106 public double getXOffset() {
00107 return xOffset_;
00108 }
00109
00115 public double getXStep() {
00116 return xStep_;
00117 }
00118
00124 public double[] getData() {
00125 return data_;
00126 }
00127
00133 public int getHeadPos() {
00134 return headPos_;
00135 }
00136
00145 public void setHead(
00146 int pos,
00147 double[] data
00148 ) {
00149
00150 int len = data.length;
00151 if (len < 1) {
00152 return;
00153 }
00154
00155
00156 if (pos >= size_) {
00157 return;
00158 }
00159 int ofs = 0;
00160 if (pos < 0) {
00161 if (len <= -pos) {
00162 return;
00163 }
00164 ofs = -pos;
00165 pos = 0;
00166 len -= ofs;
00167 }
00168
00169
00170 if (len > size_ - pos) {
00171 len = size_ - pos;
00172 }
00173
00174
00175 int former = size_ - headPos_;
00176 if (pos < former) {
00177 int remain = former - pos;
00178 if (len <= remain) {
00179 System.arraycopy(
00180 data, ofs,
00181 data_, headPos_ + pos,
00182 len
00183 );
00184 } else {
00185 System.arraycopy(
00186 data, ofs,
00187 data_, headPos_ + pos,
00188 remain
00189 );
00190 System.arraycopy(
00191 data, ofs + remain,
00192 data_, 0,
00193 len - remain
00194 );
00195 }
00196 } else {
00197 System.arraycopy(
00198 data, ofs,
00199 data_, pos - former,
00200 len
00201 );
00202 }
00203 }
00204
00213 public void setTail(
00214 int pos,
00215 double[] data
00216 ) {
00217 setHead(size_ - 1 - pos, data);
00218 }
00219
00232 public void shift(
00233 int count
00234 ) {
00235
00236 if (count == 0) {
00237 return;
00238 }
00239 xOffset_ += xStep_ * count;
00240 if (count >= size_ || count <= -size_) {
00241 for (int i = 0; i < size_; i++) {
00242 data_[i] = Double.NaN;
00243 }
00244 return;
00245 }
00246
00247
00248 int prevHead = headPos_;
00249 int newHead = prevHead + count;
00250 if (count > 0) {
00251 for (int i = prevHead; i < newHead; i++) {
00252 data_[i % size_] = Double.NaN;
00253 }
00254 headPos_ = newHead % size_;
00255 } else {
00256 int ind;
00257 for (int i = newHead; i < prevHead; i++) {
00258 ind = i % size_;
00259 if (ind < 0) {
00260 ind += size_;
00261 }
00262 data_[ind] = Double.NaN;
00263 }
00264
00265 headPos_ = newHead % size_;
00266 if (headPos_ < 0) {
00267 headPos_ += size_;
00268 }
00269 }
00270 }
00271
00279 public void addLast(
00280 double value
00281 ) {
00282 xOffset_ += xStep_;
00283 data_[headPos_] = value;
00284 headPos_ = (headPos_ + 1) % size_;
00285 }
00286
00294 public void set(
00295 int pos,
00296 double value
00297 ) {
00298 int setPos = (headPos_ + pos) % size_;
00299 data_[setPos] = value;
00300 }
00301 }