GrxTimeSeriesItem.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 /*
00011  *  GrxTimeSeriesItem.java
00012  *
00013  *  Copyright (C) 2007 GeneralRobotix, Inc.
00014  *  All Rights Reserved
00015  *
00016  *  @author Yuichiro Kawasumi (General Robotix, Inc.)
00017  */
00018 package com.generalrobotix.ui;
00019 
00020 import java.util.ArrayList;
00021 import java.util.ListIterator;
00022 
00023 
00027 public abstract class GrxTimeSeriesItem extends GrxBaseItem {
00028         private ArrayList<TValue> log_ = new ArrayList<TValue>();
00029         private int maxLogSize_ = 1000000;
00030         private int currentPos_ = -1;
00031         private boolean bRemoved = false;
00032     protected int overPos_ = 0;
00033     protected int changePos_ = -1;
00034     
00035         public class TValue {
00036                 private Double time;
00037         private Object value;
00038                 TValue(Double t, Object v) {
00039                         time = t;
00040                         value = v;
00041                 }
00042         public Double getTime(){
00043             return time;
00044         }
00045         public Object getValue(){
00046             return value;
00047         }
00048         }
00049 
00055         public GrxTimeSeriesItem(String name, GrxPluginManager manager) {
00056                 super(name, manager);
00057         }
00058         
00063         public int getPosition() {
00064                 return currentPos_;
00065         }
00066         
00067         protected boolean setPosition(int pos){
00068                 if (0 <= pos && pos < log_.size()){
00069                         currentPos_ = pos;
00070                         return true;
00071                 }else
00072                         return false;
00073         }
00074         
00079     public int getChangePosition() {
00080         return changePos_;
00081     }
00086         public int getPositionAt(Double t){
00087                 if (getLogSize() == 0) return -1;
00088                 int pos = 0;
00089                 Double dt = Math.abs(t - getTime(pos));
00090                 for (int i=1; i<getLogSize(); i++){
00091                         Double new_dt = Math.abs(t - getTime(i));
00092                         if (new_dt < dt){
00093                                 dt = new_dt;
00094                                 pos = i;
00095                         }
00096                 }
00097                 return pos;
00098         }
00099         
00105         public void setTimeAt(int pos, Double t) {
00106                 if (0 <= pos && pos < log_.size())
00107                         log_.get(pos).time = t;
00108         }
00109 
00114         public Double getTime() {
00115                 return getTime(currentPos_);
00116         }
00117         
00123         public Double getTime(int pos) {
00124                 if (0 <= pos && pos < log_.size())
00125                         return log_.get(pos).time;
00126                 return null;
00127         }
00128         
00134         public void addValue(Double t, Object val) {
00135                 TValue tv = new TValue(t,val);
00136                 log_.add(tv);
00137                 if (maxLogSize_ > 0 && log_.size() > maxLogSize_){
00138             log_.remove(0);
00139             bRemoved = true;
00140         }
00141         }
00142         
00147         public Object getValue() {
00148                 return getValue(currentPos_);
00149         }
00150         
00157         public Object getValue(int pos) {
00158                 if (0 <= pos && pos < log_.size())
00159                         return log_.get(pos).value;
00160                 return null;
00161         }
00162 
00167         public final void setMaximumLogSize(int maxLogSize) {
00168                 if (maxLogSize > 0) {
00169                         maxLogSize_ = maxLogSize;
00170                 }
00171         }
00172 
00177         public final int getLogSize() {
00178                 return log_.size();
00179         }
00180 
00184         public void clearLog() {
00185                 currentPos_ = -1;
00186         overPos_ = 0;
00187         changePos_ = -1;
00188         bRemoved = false;
00189                 log_.clear();
00190                 System.gc();
00191         }
00192 
00196     protected boolean isRemoved() {
00197         return  bRemoved;
00198     }
00199     
00203     protected TValue getObject(int index) {
00204         return  log_.get(index);
00205     }
00206 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16