Skip to content

Commit 984f713

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Expose more Java 8 APIs to Android users.
RELNOTES=Exposed some additional Java 8 APIs to Android users. PiperOrigin-RevId: 689811921
1 parent 309365e commit 984f713

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

android/guava/src/com/google/common/util/concurrent/AbstractScheduledService.java

+44
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
import static com.google.common.base.Preconditions.checkArgument;
1818
import static com.google.common.base.Preconditions.checkNotNull;
1919
import static com.google.common.util.concurrent.Futures.immediateCancelledFuture;
20+
import static com.google.common.util.concurrent.Internal.toNanosSaturated;
2021
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
2122
import static com.google.common.util.concurrent.Platform.restoreInterruptIfIsInterruptedException;
2223
import static java.util.Objects.requireNonNull;
24+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
2325

2426
import com.google.common.annotations.GwtIncompatible;
2527
import com.google.common.annotations.J2ktIncompatible;
2628
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2729
import com.google.errorprone.annotations.concurrent.GuardedBy;
2830
import com.google.j2objc.annotations.WeakOuter;
31+
import java.time.Duration;
2932
import java.util.concurrent.Callable;
3033
import java.util.concurrent.Executor;
3134
import java.util.concurrent.Executors;
@@ -116,6 +119,22 @@ public abstract class AbstractScheduledService implements Service {
116119
* @since 11.0
117120
*/
118121
public abstract static class Scheduler {
122+
/**
123+
* Returns a {@link Scheduler} that schedules the task using the {@link
124+
* ScheduledExecutorService#scheduleWithFixedDelay} method.
125+
*
126+
* @param initialDelay the time to delay first execution
127+
* @param delay the delay between the termination of one execution and the commencement of the
128+
* next
129+
* @since NEXT (but since 28.0 in the JRE flavor)
130+
*/
131+
@SuppressWarnings("Java7ApiChecker")
132+
@IgnoreJRERequirement // Users will use this only if they're already using Duration
133+
public static Scheduler newFixedDelaySchedule(Duration initialDelay, Duration delay) {
134+
return newFixedDelaySchedule(
135+
toNanosSaturated(initialDelay), toNanosSaturated(delay), NANOSECONDS);
136+
}
137+
119138
/**
120139
* Returns a {@link Scheduler} that schedules the task using the {@link
121140
* ScheduledExecutorService#scheduleWithFixedDelay} method.
@@ -140,6 +159,21 @@ public Cancellable schedule(
140159
};
141160
}
142161

162+
/**
163+
* Returns a {@link Scheduler} that schedules the task using the {@link
164+
* ScheduledExecutorService#scheduleAtFixedRate} method.
165+
*
166+
* @param initialDelay the time to delay first execution
167+
* @param period the period between successive executions of the task
168+
* @since NEXT (but since 28.0 in the JRE flavor)
169+
*/
170+
@SuppressWarnings("Java7ApiChecker")
171+
@IgnoreJRERequirement // Users will use this only if they're already using Duration
172+
public static Scheduler newFixedRateSchedule(Duration initialDelay, Duration period) {
173+
return newFixedRateSchedule(
174+
toNanosSaturated(initialDelay), toNanosSaturated(period), NANOSECONDS);
175+
}
176+
143177
/**
144178
* Returns a {@link Scheduler} that schedules the task using the {@link
145179
* ScheduledExecutorService#scheduleAtFixedRate} method.
@@ -685,6 +719,16 @@ public Schedule(long delay, TimeUnit unit) {
685719
this.delay = delay;
686720
this.unit = checkNotNull(unit);
687721
}
722+
723+
/**
724+
* @param delay the time from now to delay execution
725+
* @since NEXT (but since 31.1 in the JRE flavor)
726+
*/
727+
@SuppressWarnings("Java7ApiChecker")
728+
@IgnoreJRERequirement // Users will use this only if they're already using Duration
729+
public Schedule(Duration delay) {
730+
this(toNanosSaturated(delay), NANOSECONDS);
731+
}
688732
}
689733

690734
/**

guava/src/com/google/common/util/concurrent/AbstractScheduledService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public abstract static class Scheduler {
126126
* @param initialDelay the time to delay first execution
127127
* @param delay the delay between the termination of one execution and the commencement of the
128128
* next
129-
* @since 28.0
129+
* @since 28.0 (but only since 33.4.0 in the Android flavor)
130130
*/
131131
public static Scheduler newFixedDelaySchedule(Duration initialDelay, Duration delay) {
132132
return newFixedDelaySchedule(
@@ -163,7 +163,7 @@ public Cancellable schedule(
163163
*
164164
* @param initialDelay the time to delay first execution
165165
* @param period the period between successive executions of the task
166-
* @since 28.0
166+
* @since 28.0 (but only since 33.4.0 in the Android flavor)
167167
*/
168168
public static Scheduler newFixedRateSchedule(Duration initialDelay, Duration period) {
169169
return newFixedRateSchedule(
@@ -730,7 +730,7 @@ public Schedule(long delay, TimeUnit unit) {
730730

731731
/**
732732
* @param delay the time from now to delay execution
733-
* @since 31.1
733+
* @since 31.1 (but only since 33.4.0 in the Android flavor)
734734
*/
735735
public Schedule(Duration delay) {
736736
this(toNanosSaturated(delay), NANOSECONDS);

0 commit comments

Comments
 (0)