| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -235,6 +235,12 @@ if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword') | |||
| 235 | 235 | } | |
| 236 | 236 | } | |
| 237 | 237 | ||
| 238 | + gradle.projectsEvaluated { | ||
| 239 | + tasks.withType(JavaCompile) { | ||
| 240 | + options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | + | ||
| 238 | 244 | // Formatting tasks | |
| 239 | 245 | // ================ | |
| 240 | 246 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + /* | ||
| 2 | + * Copyright 2017, Google Inc. | ||
| 3 | + * All rights reserved. | ||
| 4 | + * | ||
| 5 | + * Redistribution and use in source and binary forms, with or without | ||
| 6 | + * modification, are permitted provided that the following conditions are | ||
| 7 | + * met: | ||
| 8 | + * | ||
| 9 | + * * Redistributions of source code must retain the above copyright | ||
| 10 | + * notice, this list of conditions and the following disclaimer. | ||
| 11 | + * * Redistributions in binary form must reproduce the above | ||
| 12 | + * copyright notice, this list of conditions and the following disclaimer | ||
| 13 | + * in the documentation and/or other materials provided with the | ||
| 14 | + * distribution. | ||
| 15 | + * * Neither the name of Google Inc. nor the names of its | ||
| 16 | + * contributors may be used to endorse or promote products derived from | ||
| 17 | + * this software without specific prior written permission. | ||
| 18 | + * | ||
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 20 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 21 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 22 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 23 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 24 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 25 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 26 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 27 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 28 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 29 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | + */ | ||
| 31 | + package com.google.api.core; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Transforms a value, possibly asynchronously. | ||
| 35 | + * | ||
| 36 | + * <p>It is similar to Guava's {@code AsyncFunction}, redeclared so that Guava can be shaded. | ||
| 37 | + */ | ||
| 38 | + public interface ApiAsyncFunction<I, O> { | ||
| 39 | + /** | ||
| 40 | + * Returns an output Future to use in place of the given input. The output Future need not be | ||
| 41 | + * done, making AsyncFunction suitable for asynchronous derivations. | ||
| 42 | + * | ||
| 43 | + * <p>Throwing an exception from this method is equivalent to returning a failing Future. | ||
| 44 | + */ | ||
| 45 | + ApiFuture<O> apply(I input) throws Exception; | ||
| 46 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ | |||
| 32 | 32 | ||
| 33 | 33 | import com.google.common.base.Function; | |
| 34 | 34 | import com.google.common.collect.Iterables; | |
| 35 | + import com.google.common.util.concurrent.AsyncFunction; | ||
| 35 | 36 | import com.google.common.util.concurrent.FutureCallback; | |
| 36 | 37 | import com.google.common.util.concurrent.Futures; | |
| 37 | 38 | import com.google.common.util.concurrent.ListenableFuture; | |
@@ -99,6 +100,21 @@ public ListenableFuture<V> apply(ApiFuture<V> apiFuture) { | |||
| 99 | 100 | }))); | |
| 100 | 101 | } | |
| 101 | 102 | ||
| 103 | + public static <I, O> ApiFuture<O> transformAsync( | ||
| 104 | + ApiFuture<I> input, final ApiAsyncFunction<I, O> function) { | ||
| 105 | + ListenableFuture<I> listenableInput = listenableFutureForApiFuture(input); | ||
| 106 | + ListenableFuture<O> listenableOutput = | ||
| 107 | + Futures.transformAsync( | ||
| 108 | + listenableInput, | ||
| 109 | + new AsyncFunction<I, O>() { | ||
| 110 | + @Override | ||
| 111 | + public ListenableFuture<O> apply(I input) throws Exception { | ||
| 112 | + return listenableFutureForApiFuture(function.apply(input)); | ||
| 113 | + } | ||
| 114 | + }); | ||
| 115 | + return new ListenableFutureToApiFuture<>(listenableOutput); | ||
| 116 | + } | ||
| 117 | + | ||
| 102 | 118 | private static <V> ListenableFuture<V> listenableFutureForApiFuture(ApiFuture<V> apiFuture) { | |
| 103 | 119 | ListenableFuture<V> listenableFuture; | |
| 104 | 120 | if (apiFuture instanceof AbstractApiFuture) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,4 +102,19 @@ public void testAllAsList() throws Exception { | |||
| 102 | 102 | inputFuture2.set(2); | |
| 103 | 103 | Truth.assertThat(listFuture.get()).containsExactly(1, 2).inOrder(); | |
| 104 | 104 | } | |
| 105 | + | ||
| 106 | + @Test | ||
| 107 | + public void testTransformAsync() throws Exception { | ||
| 108 | + ApiFuture<Integer> inputFuture = ApiFutures.immediateFuture(0); | ||
| 109 | + ApiFuture<Integer> outputFuture = | ||
| 110 | + ApiFutures.transformAsync( | ||
| 111 | + inputFuture, | ||
| 112 | + new ApiAsyncFunction<Integer, Integer>() { | ||
| 113 | + @Override | ||
| 114 | + public ApiFuture<Integer> apply(Integer input) { | ||
| 115 | + return ApiFutures.immediateFuture(input + 1); | ||
| 116 | + } | ||
| 117 | + }); | ||
| 118 | + Truth.assertThat(outputFuture.get()).isEqualTo(1); | ||
| 119 | + } | ||
| 105 | 120 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1 +1 @@ | |||
| 1 | - 1.0.0 | ||
| 1 | + 1.1.0 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments