OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
Duration.java
Go to the documentation of this file.
1 /* Copyright 2010, Object Management Group, Inc.
2  * Copyright 2010, PrismTech, Inc.
3  * Copyright 2010, Real-Time Innovations, Inc.
4  * All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 package org.omg.dds.core;
20 
21 import java.io.Serializable;
22 import java.util.concurrent.TimeUnit;
23 
25 import org.omg.dds.type.Nested;
26 
27 
33 @Extensibility(Extensibility.Kind.FINAL_EXTENSIBILITY)
34 @Nested
35 public abstract class Duration
36 implements Comparable<Duration>, Serializable, DDSObject
37 {
38  // -----------------------------------------------------------------------
39  // Private Constants
40  // -----------------------------------------------------------------------
41 
42  private static final long serialVersionUID = 6926514364942353575L;
43 
44 
45 
46  // -----------------------------------------------------------------------
47  // Factory Methods
48  // -----------------------------------------------------------------------
49 
62  public static Duration newDuration(
63  long duration,
64  TimeUnit unit,
66  {
67  if (env == null) {
68  throw new IllegalArgumentException(
69  "Invalid ServiceEnvironment (null) provided.");
70  }
71  return env.getSPI().newDuration(duration, unit);
72  }
73 
74 
82  {
83  if (env == null) {
84  throw new IllegalArgumentException(
85  "Invalid ServiceEnvironment (null) provided.");
86  }
87  return env.getSPI().infiniteDuration();
88  }
89 
90 
98  {
99  if (env == null) {
100  throw new IllegalArgumentException(
101  "Invalid ServiceEnvironment (null) provided.");
102  }
103  return env.getSPI().zeroDuration();
104  }
105 
106 
107 
108  // -----------------------------------------------------------------------
109  // Instance Methods
110  // -----------------------------------------------------------------------
111 
112  // --- Data access: ------------------------------------------------------
113 
136  public abstract long getDuration(TimeUnit inThisUnit);
137 
170  public abstract long getRemainder(
171  TimeUnit primaryUnit, TimeUnit remainderUnit);
172 
173 
174  // --- Query: ------------------------------------------------------------
175 
184  public abstract boolean isZero();
185 
196  public abstract boolean isInfinite();
197 
198 
199  // --- Manipulation: -----------------------------------------------------
200 
205  public abstract Duration add(Duration duration);
206 
211  public abstract Duration add(long duration, TimeUnit unit);
212 
217  public abstract Duration subtract(Duration duration);
218 
223  public abstract Duration subtract(long duration, TimeUnit unit);
224 }
abstract Duration subtract(Duration duration)
abstract boolean isInfinite()
Report whether this duration lasts forever.
abstract Duration add(Duration duration)
abstract ServiceProviderInterface getSPI()
This method is not intended for use by applications.
static Duration infiniteDuration(ServiceEnvironment env)
Definition: Duration.java:81
abstract boolean isZero()
Report whether this duration lasts no time at all.
abstract long getRemainder(TimeUnit primaryUnit, TimeUnit remainderUnit)
If getting the magnitude of this duration in the given primaryUnit would cause truncation with respec...
A supertype of all DDS classes and interfaces.
Definition: DDSObject.java:25
abstract long getDuration(TimeUnit inThisUnit)
Truncate this duration to a whole-number quantity of the given time unit.
Duration newDuration(long duration, TimeUnit unit)
Construct a org.omg.dds.core.Duration of the given magnitude.
A span of elapsed time expressed with nanosecond precision.
Definition: Duration.java:35
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
static Duration zeroDuration(ServiceEnvironment env)
Definition: Duration.java:97
static Duration newDuration(long duration, TimeUnit unit, ServiceEnvironment env)
Construct a time duration of the given magnitude.
Definition: Duration.java:62