Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes | List of all members
com.google.protobuf.util.Durations Class Reference

Static Public Member Functions

static Duration add (Duration d1, Duration d2)
 
static Duration checkNotNegative (Duration duration)
 
static Duration checkPositive (Duration duration)
 
static Duration checkValid (Duration duration)
 
static Duration checkValid (Duration.Builder durationBuilder)
 
static Comparator< Durationcomparator ()
 
static int compare (Duration x, Duration y)
 
static Duration fromDays (long days)
 
static Duration fromHours (long hours)
 
static Duration fromMicros (long microseconds)
 
static Duration fromMillis (long milliseconds)
 
static Duration fromMinutes (long minutes)
 
static Duration fromNanos (long nanoseconds)
 
static Duration fromSeconds (long seconds)
 
static boolean isNegative (Duration duration)
 
static boolean isValid (Duration duration)
 
static boolean isValid (long seconds, int nanos)
 
static Duration parse (String value) throws ParseException
 
static Duration subtract (Duration d1, Duration d2)
 
static long toDays (Duration duration)
 
static long toHours (Duration duration)
 
static long toMicros (Duration duration)
 
static long toMillis (Duration duration)
 
static long toMinutes (Duration duration)
 
static long toNanos (Duration duration)
 
static long toSeconds (Duration duration)
 
static double toSecondsAsDouble (Duration duration)
 
static String toString (Duration duration)
 

Static Public Attributes

static final Duration MAX_VALUE
 
static final Duration MIN_VALUE
 
static final Duration ZERO = Duration.newBuilder().setSeconds(0L).setNanos(0).build()
 

Private Member Functions

 Durations ()
 

Static Private Attributes

static final Comparator< DurationCOMPARATOR
 
static final long SECONDS_PER_DAY = SECONDS_PER_HOUR * 24
 
static final long SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60
 
static final long SECONDS_PER_MINUTE = 60L
 

Detailed Description

Utilities to help create/manipulate

protobuf/duration.proto

. All operations throw an IllegalArgumentException if the input(s) are not {@linkplain isValid(Duration) valid}.

Definition at line 54 of file Durations.java.

Constructor & Destructor Documentation

◆ Durations()

com.google.protobuf.util.Durations.Durations ( )
inlineprivate

Definition at line 73 of file Durations.java.

Member Function Documentation

◆ add()

static Duration com.google.protobuf.util.Durations.add ( Duration  d1,
Duration  d2 
)
inlinestatic

Add two durations.

Definition at line 423 of file Durations.java.

◆ checkNotNegative()

static Duration com.google.protobuf.util.Durations.checkNotNegative ( Duration  duration)
inlinestatic

Ensures that the given Duration is not negative.

Exceptions
IllegalArgumentExceptionif
duration
is negative or invalid
NullPointerExceptionif
duration
is
null

Definition at line 156 of file Durations.java.

◆ checkPositive()

static Duration com.google.protobuf.util.Durations.checkPositive ( Duration  duration)
inlinestatic

Ensures that the given Duration is positive.

Exceptions
IllegalArgumentExceptionif
duration
is negative, , or invalid
NullPointerExceptionif
duration
is
null

Definition at line 169 of file Durations.java.

◆ checkValid() [1/2]

static Duration com.google.protobuf.util.Durations.checkValid ( Duration  duration)
inlinestatic

Throws an IllegalArgumentException if the given Duration is not valid.

Definition at line 180 of file Durations.java.

◆ checkValid() [2/2]

static Duration com.google.protobuf.util.Durations.checkValid ( Duration.Builder  durationBuilder)
inlinestatic

Builds the given builder and throws an IllegalArgumentException if it is not valid. See checkValid(Duration).

Returns
A valid, built Duration.

Definition at line 201 of file Durations.java.

◆ comparator()

static Comparator<Duration> com.google.protobuf.util.Durations.comparator ( )
inlinestatic

Returns a Comparator for Durations which sorts in increasing chronological order. Nulls and invalid Durations are not allowed (see isValid).

Definition at line 90 of file Durations.java.

◆ compare()

static int com.google.protobuf.util.Durations.compare ( Duration  x,
Duration  y 
)
inlinestatic

Compares two durations. The value returned is identical to what would be returned by:

Durations.comparator().compare(x, y)

.

Returns
the value
0
if
x == y
; a value less than
0
if
x < y
; and a value greater than
0
if
x > y

Definition at line 101 of file Durations.java.

◆ fromDays()

static Duration com.google.protobuf.util.Durations.fromDays ( long  days)
inlinestatic

Create a Duration from the number of days.

Definition at line 278 of file Durations.java.

◆ fromHours()

static Duration com.google.protobuf.util.Durations.fromHours ( long  hours)
inlinestatic

Create a Duration from the number of hours.

Definition at line 287 of file Durations.java.

◆ fromMicros()

static Duration com.google.protobuf.util.Durations.fromMicros ( long  microseconds)
inlinestatic

Create a Duration from the number of microseconds.

Definition at line 319 of file Durations.java.

◆ fromMillis()

static Duration com.google.protobuf.util.Durations.fromMillis ( long  milliseconds)
inlinestatic

Create a Duration from the number of milliseconds.

Definition at line 311 of file Durations.java.

◆ fromMinutes()

static Duration com.google.protobuf.util.Durations.fromMinutes ( long  minutes)
inlinestatic

Create a Duration from the number of minutes.

Definition at line 296 of file Durations.java.

◆ fromNanos()

static Duration com.google.protobuf.util.Durations.fromNanos ( long  nanoseconds)
inlinestatic

Create a Duration from the number of nanoseconds.

Definition at line 327 of file Durations.java.

◆ fromSeconds()

static Duration com.google.protobuf.util.Durations.fromSeconds ( long  seconds)
inlinestatic

Create a Duration from the number of seconds.

Definition at line 305 of file Durations.java.

◆ isNegative()

static boolean com.google.protobuf.util.Durations.isNegative ( Duration  duration)
inlinestatic

Returns whether the given Duration is negative or not.

Definition at line 144 of file Durations.java.

◆ isValid() [1/2]

static boolean com.google.protobuf.util.Durations.isValid ( Duration  duration)
inlinestatic

Returns true if the given Duration is valid. The

seconds

value must be in the range [-315,576,000,000, +315,576,000,000]. The

nanos

value must be in the range [-999,999,999, +999,999,999].

Note: Durations less than one second are represented with a 0

seconds

field and a positive or negative

nanos

field. For durations of one second or more, a non-zero value for the

nanos

field must be of the same sign as the

seconds

field.

Definition at line 114 of file Durations.java.

◆ isValid() [2/2]

static boolean com.google.protobuf.util.Durations.isValid ( long  seconds,
int  nanos 
)
inlinestatic

Returns true if the given number of seconds and nanos is a valid Duration. The

seconds

value must be in the range [-315,576,000,000, +315,576,000,000]. The

nanos

value must be in the range [-999,999,999, +999,999,999].

Note: Durations less than one second are represented with a 0

seconds

field and a positive or negative

nanos

field. For durations of one second or more, a non-zero value for the

nanos

field must be of the same sign as the

seconds

field.

Definition at line 128 of file Durations.java.

◆ parse()

static Duration com.google.protobuf.util.Durations.parse ( String  value) throws ParseException
inlinestatic

Parse from a string to produce a duration.

Returns
A Duration parsed from the string.
Exceptions
ParseExceptionif parsing fails.

Definition at line 241 of file Durations.java.

◆ subtract()

static Duration com.google.protobuf.util.Durations.subtract ( Duration  d1,
Duration  d2 
)
inlinestatic

Subtract a duration from another.

Definition at line 431 of file Durations.java.

◆ toDays()

static long com.google.protobuf.util.Durations.toDays ( Duration  duration)
inlinestatic

Convert a Duration to the number of days. The result will be rounded towards 0 to the nearest day.

Definition at line 339 of file Durations.java.

◆ toHours()

static long com.google.protobuf.util.Durations.toHours ( Duration  duration)
inlinestatic

Convert a Duration to the number of hours. The result will be rounded towards 0 to the nearest hour.

Definition at line 348 of file Durations.java.

◆ toMicros()

static long com.google.protobuf.util.Durations.toMicros ( Duration  duration)
inlinestatic

Convert a Duration to the number of microseconds. The result will be rounded towards 0 to the nearest microseconds. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Definition at line 405 of file Durations.java.

◆ toMillis()

static long com.google.protobuf.util.Durations.toMillis ( Duration  duration)
inlinestatic

Convert a Duration to the number of milliseconds. The result will be rounded towards 0 to the nearest millisecond. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Definition at line 393 of file Durations.java.

◆ toMinutes()

static long com.google.protobuf.util.Durations.toMinutes ( Duration  duration)
inlinestatic

Convert a Duration to the number of minutes. The result will be rounded towards 0 to the nearest minute.

Definition at line 357 of file Durations.java.

◆ toNanos()

static long com.google.protobuf.util.Durations.toNanos ( Duration  duration)
inlinestatic

Convert a Duration to the number of nanoseconds.

Definition at line 414 of file Durations.java.

◆ toSeconds()

static long com.google.protobuf.util.Durations.toSeconds ( Duration  duration)
inlinestatic

Convert a Duration to the number of seconds. The result will be rounded towards 0 to the nearest second. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Definition at line 366 of file Durations.java.

◆ toSecondsAsDouble()

static double com.google.protobuf.util.Durations.toSecondsAsDouble ( Duration  duration)
inlinestatic

Returns the number of seconds of the given duration as a

double

. This method should be used to accommodate APIs that only accept durations as

double

values.

This conversion may lose precision.

If you need the number of seconds in this duration as a

long

(not a

double

), simply use

duration.getSeconds()

or toSeconds (which includes validation).

Definition at line 383 of file Durations.java.

◆ toString()

static String com.google.protobuf.util.Durations.toString ( Duration  duration)
inlinestatic

Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits depending on the precision required to represent the exact Duration value. For example: "1s", "1.010s", "1.000000100s", "-3.100s" The range that can be represented by Duration is from -315,576,000,000 to +315,576,000,000 inclusive (in seconds).

Returns
The string representation of the given duration.
Exceptions
IllegalArgumentExceptionif the given duration is not in the valid range.

Definition at line 214 of file Durations.java.

Member Data Documentation

◆ COMPARATOR

final Comparator<Duration> com.google.protobuf.util.Durations.COMPARATOR
staticprivate
Initial value:
=
new Comparator<Duration>() {
@Override
public int compare(Duration d1, Duration d2) {
int secDiff = Long.compare(d1.getSeconds(), d2.getSeconds());
return (secDiff != 0) ? secDiff : Integer.compare(d1.getNanos(), d2.getNanos());
}
}

Definition at line 75 of file Durations.java.

◆ MAX_VALUE

final Duration com.google.protobuf.util.Durations.MAX_VALUE
static
Initial value:
=
Duration.newBuilder().setSeconds(DURATION_SECONDS_MAX).setNanos(999999999).build()

A constant holding the maximum valid Duration, approximately

+10,000

years.

Definition at line 67 of file Durations.java.

◆ MIN_VALUE

final Duration com.google.protobuf.util.Durations.MIN_VALUE
static
Initial value:
=
Duration.newBuilder().setSeconds(DURATION_SECONDS_MIN).setNanos(-999999999).build()

A constant holding the minimum valid Duration, approximately

-10,000

years.

Definition at line 63 of file Durations.java.

◆ SECONDS_PER_DAY

final long com.google.protobuf.util.Durations.SECONDS_PER_DAY = SECONDS_PER_HOUR * 24
staticprivate

Definition at line 60 of file Durations.java.

◆ SECONDS_PER_HOUR

final long com.google.protobuf.util.Durations.SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60
staticprivate

Definition at line 59 of file Durations.java.

◆ SECONDS_PER_MINUTE

final long com.google.protobuf.util.Durations.SECONDS_PER_MINUTE = 60L
staticprivate

Definition at line 58 of file Durations.java.

◆ ZERO

final Duration com.google.protobuf.util.Durations.ZERO = Duration.newBuilder().setSeconds(0L).setNanos(0).build()
static

A constant holding the duration of zero.

Definition at line 71 of file Durations.java.


The documentation for this class was generated from the following file:
y
GLint y
Definition: glcorearb.h:2768
x
GLint GLenum GLint x
Definition: glcorearb.h:2834
com.google.protobuf.util.Durations.Durations
Durations()
Definition: Durations.java:73
com.google.protobuf.util.Durations.checkValid
static Duration checkValid(Duration duration)
Definition: Durations.java:180
com.google.protobuf.util.Durations.compare
static int compare(Duration x, Duration y)
Definition: Durations.java:101
com.google.protobuf.util.Durations.ZERO
static final Duration ZERO
Definition: Durations.java:71
Duration
Definition: duration.pb.h:69


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:08