Time.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  */
17 package com.generalrobotix.ui.view.graph;
18 
19 import java.text.DecimalFormat;
20 
21 public class Time {
22  int msec_;
23  int usec_;
24  DecimalFormat format_ = new DecimalFormat("000");
25 
29  public Time() {
30  msec_ = 0;
31  usec_ = 0;
32  }
33 
39  public Time(int m, int u) {
40  msec_ = m;
41  usec_ = u;
42  }
43 
48  public Time(double time) {
49  set(time);
50  }
51 
52  public Time(float time) {
53  set(time);
54  }
55 
56  public Time(Time time) {
57  set(time);
58  }
59 
64  public Time(long time) {
65  setUtime(time);
66  }
67 
72  public void set(Time time) {
73  msec_ = time.msec_;
74  usec_ = time.usec_;
75  }
76 
81  public void set(double time) {
82  long utime = (long)Math.round(time * 1000000.0);
83  usec_ = (int)(utime % 1000);
84  msec_ = (int)(utime / 1000);
85  }
86 
87  public void set(float time) {
88  long utime = (long)Math.round((double)time * 1000000.0);
89  usec_ = (int)(utime % 1000);
90  msec_ = (int)(utime / 1000);
91  }
92 
98  public void set(int m, int u) {
99  msec_ = m;
100  usec_ = u;
101  }
102 
107  public void add(Time time) {
108  msec_ += time.msec_;
109  usec_ += time.usec_;
110  if (usec_ >= 1000) {
111  msec_ += usec_ / 1000;
112  usec_ = usec_ % 1000;
113  }
114  }
119  public void sub(Time time) {
120  msec_ -= time.msec_;
121  usec_ -= time.usec_;
122  if (usec_ < 0) {
123  msec_ += usec_ / 1000 - 1 ;
124  usec_ = usec_ % 1000;
125  }
126  }
127 
128  public void addUtime(int utime) {
129  usec_ += utime;
130  if (usec_ >= 1000) {
131  msec_ += usec_ / 1000;
132  usec_ = usec_ % 1000;
133  }
134  }
135 
140  public double getDouble() {
141  return (double)msec_ * 0.001 + (double)usec_ * 0.000001;
142  }
143 
147  public float getFloat() {
148  return (float)msec_ * 0.001f + (float)usec_ * 0.000001f;
149  }
150 
151  public boolean compare(Time time) {
152  if ((msec_ == time.msec_) && (usec_ == time.usec_)) return true;
153  else return false;
154  }
155 
156  public long getUtime() {
157  return (long)msec_ * 1000L + (long)usec_;
158  }
159 
160  public void setUtime(long utime) {
161  msec_ = (int)(utime / 1000);
162  usec_ = (int)utime % 1000;
163  }
164 
165  public String toString() {
166  StringBuffer buf = new StringBuffer();
167  buf.append(String.valueOf(msec_ / 1000));
168  buf.append('.');
169  buf.append(format_.format(msec_ % 1000));
170  buf.append(format_.format(usec_ % 1000));
171  return buf.toString();
172  }
173 }
png_bytep buf
Definition: png.h:2729
typedef int
Definition: png.h:1113


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:25