GrxTimeSeriesItem.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxTimeSeriesItem.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  */
18 package com.generalrobotix.ui;
19 
20 import java.util.ArrayList;
21 import java.util.ListIterator;
22 
23 
27 public abstract class GrxTimeSeriesItem extends GrxBaseItem {
28  private ArrayList<TValue> log_ = new ArrayList<TValue>();
29  private int maxLogSize_ = 1000000;
30  private int currentPos_ = -1;
31  private boolean bRemoved = false;
32  protected int overPos_ = 0;
33  protected int changePos_ = -1;
34 
35  public class TValue {
36  private Double time;
37  private Object value;
38  TValue(Double t, Object v) {
39  time = t;
40  value = v;
41  }
42  public Double getTime(){
43  return time;
44  }
45  public Object getValue(){
46  return value;
47  }
48  }
49 
55  public GrxTimeSeriesItem(String name, GrxPluginManager manager) {
56  super(name, manager);
57  }
58 
63  public int getPosition() {
64  return currentPos_;
65  }
66 
67  protected boolean setPosition(int pos){
68  if (0 <= pos && pos < log_.size()){
69  currentPos_ = pos;
70  return true;
71  }else
72  return false;
73  }
74 
79  public int getChangePosition() {
80  return changePos_;
81  }
86  public int getPositionAt(Double t){
87  if (getLogSize() == 0) return -1;
88  int pos = 0;
89  Double dt = Math.abs(t - getTime(pos));
90  for (int i=1; i<getLogSize(); i++){
91  Double new_dt = Math.abs(t - getTime(i));
92  if (new_dt < dt){
93  dt = new_dt;
94  pos = i;
95  }
96  }
97  return pos;
98  }
99 
105  public void setTimeAt(int pos, Double t) {
106  if (0 <= pos && pos < log_.size())
107  log_.get(pos).time = t;
108  }
109 
114  public Double getTime() {
115  return getTime(currentPos_);
116  }
117 
123  public Double getTime(int pos) {
124  if (0 <= pos && pos < log_.size())
125  return log_.get(pos).time;
126  return null;
127  }
128 
134  public void addValue(Double t, Object val) {
135  TValue tv = new TValue(t,val);
136  log_.add(tv);
137  if (maxLogSize_ > 0 && log_.size() > maxLogSize_){
138  log_.remove(0);
139  bRemoved = true;
140  }
141  }
142 
147  public Object getValue() {
148  return getValue(currentPos_);
149  }
150 
157  public Object getValue(int pos) {
158  if (0 <= pos && pos < log_.size())
159  return log_.get(pos).value;
160  return null;
161  }
162 
167  public final void setMaximumLogSize(int maxLogSize) {
168  if (maxLogSize > 0) {
169  maxLogSize_ = maxLogSize;
170  }
171  }
172 
177  public final int getLogSize() {
178  return log_.size();
179  }
180 
184  public void clearLog() {
185  currentPos_ = -1;
186  overPos_ = 0;
187  changePos_ = -1;
188  bRemoved = false;
189  log_.clear();
190  System.gc();
191  }
192 
196  protected boolean isRemoved() {
197  return bRemoved;
198  }
199 
203  protected TValue getObject(int index) {
204  return log_.get(index);
205  }
206 }
GrxTimeSeriesItem(String name, GrxPluginManager manager)
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_infop png_charpp name
Definition: png.h:2382
png_uint_32 i
Definition: png.h:2735
int val
Definition: jpeglib.h:956
final void setMaximumLogSize(int maxLogSize)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03