├── .gitignore ├── .travis.yml ├── .travis └── maven-settings.xml ├── README.md ├── pom.xml └── src ├── main └── resources │ ├── Vavr.gwt.xml │ └── super │ ├── io │ └── vavr │ │ └── concurrent │ │ ├── CurrentThreadExecutorService.java │ │ ├── CurrentThreadFuture.java │ │ └── FutureImpl.java │ └── java │ ├── lang │ ├── InterruptedException.java │ ├── LinkageError.java │ ├── ThreadDeath.java │ └── VirtualMachineError.java │ └── util │ └── concurrent │ ├── Callable.java │ ├── CancellationException.java │ ├── ExecutionException.java │ ├── Executor.java │ ├── ExecutorService.java │ ├── Executors.java │ ├── ForkJoinPool.java │ ├── Future.java │ ├── TimeUnit.java │ ├── TimeoutException.java │ └── atomic │ ├── AtomicBoolean.java │ ├── AtomicInteger.java │ └── AtomicReference.java └── test └── java ├── TestModule.gwt.xml └── client ├── CollectionsTestGwt.java ├── ConcurrentTest1.java ├── ConcurrentTest2.java └── GwtVavrTestSuite.java /.gitignore: -------------------------------------------------------------------------------- 1 | # -- Maven 2 | target 3 | *.versionsBackup 4 | 5 | # -- Eclipse 6 | .classpath 7 | .project 8 | .settings 9 | bin 10 | 11 | # -- IntelliJ IDEA 12 | .idea 13 | *.iml 14 | 15 | # -- Mac OS 16 | .DS_Store 17 | 18 | # -- Java 19 | hs_err_pid* 20 | 21 | # -- Emacs 22 | .#* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | env: 5 | global: 6 | - secure: FjwU54kfDaAzg1qZilqMhRjr7YJXdj/ZJAHJ8qvmznziV3r5TLPuxe6gJa8qkCpoSTYqtB1gh0irE5RGDtdYrj9aW4OhaFVKHjtlM1bYHRU+pfNcZ3BmcTC9A94H+cGOBo9YNKNBbc16AGz6Juthug7FUE8vrBDB1Qp03KJLannQN57D/hVKY569IzmCvv7eAz1wRxdGaehUYAKdxnQAeXKvOykATNxTGl2gPoZHfjjxZCT9yJMIAfyTAU4i9+h07dwot8B8Ve/rvEaBShZYU3gUjjkHdkBrSAptzEkpRoPIOodeob7ebMzFBgL6ghO5FJwytRsS2bhmYz/IEoq6IWmtvxK7dosLtujOEczcoWZ2cMGsg0zwe5tg9nDgV3Pb+UgURE/W75do2W9gBldt8vX6bskuTWcJFmmbBXl+eP5c3AyMmV/VNbmhTzWNuqi9MfMdKfMHKxev2RkVEe4gE04XZlQsYJQ2ee2ivnyiZwxtd8I5/9/XSlRul2925yOY9UJDbGHChSbV08P+3kBuiH6d9NtMQfzv2S+pflyXpMA/3y2GknV9dEYihGQ+qGKj4LIDzAbec8lIlrYsCb6kbQVISt5lafn0Z0aHLho48R8hdnFaY2yoH6NID35+MWcM8QVVtSTkFbWcmT87yjPbycvvislgoODvug+D7Ygee7c= 7 | - secure: I8GevzVNeNHz4XsdBmLehZ6RdGX5/aGF0kM/sB3ensCUb++1qz43KJkcWk0jEBsKKktN6tGn5L9pv8RU3w+Vb2TpqrXl+uqcm58ngXTaGBiXrZHj3MSJoFMlko6K8+soJfeucUcGV6i5pNsoJE0UH/WbiPdu9J47F4aWywT8vfJsL75FBYXHuPZXW7vUOjc8a3wXiIvTgSy2AVIuIVHLm9kNWdG5CgqHGGQAhHWjrdsgW31Oii1AoUdj36wB2/mpf2YdPoPaz0SMKkah+NoHfaPM4GBts3gQkIMzpO6xuTDnxaNrA7BiuTywNtK5yZHhwFVc6QRcrTRBKWsUlFHFChW3qiCWcNT78dVD+Jxoxbbw3RtkdQwFievzhg28mhdrcShj03X1S90WIQhV/uovgyG2DWrkZUrqZ+CipFAgpJnF7c1Q0HHvrBWwdQR8c0NTp/Te2THKDWjRtKhRajEqj0XGi6vyNgQLbvFHzIMWnzO61cZGs6bDx0hOM/1aiinKWv+a8kjL3TWSa1aKs+KUm5I9QDxpVsKBtmTFbH9yWrGpUGra2mb5IfRSnavKG2kfBiBgRn5h4gR6AECG1S8Co5aD2BJdOTSOxjVEO0b2ktGInfiSrl/mTKwfF90tUI99I2w0A2wtp3+eoSWYBERGXswQz6saotaxbobQlYzlwso= 8 | before_install: 9 | - sudo apt-get update 10 | - sudo apt-get install --only-upgrade -y oracle-java8-installer 11 | - pip install --user codecov 12 | after_success: 13 | - mvn clean deploy -DskipTests --settings .travis/maven-settings.xml 14 | -------------------------------------------------------------------------------- /.travis/maven-settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | sonatype-nexus-snapshots 13 | ${env.SONATYPE_USER} 14 | ${env.SONATYPE_PASS} 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.vavr/vavr-gwt/badge.png)](https://maven-badges.herokuapp.com/maven-central/io.vavr/vavr-gwt) 2 | [![Build Status](https://travis-ci.org/vavr-io/vavr-gwt.png)](https://travis-ci.org/vavr-io/vavr-gwt) 3 | [![Gitter Chat](https://badges.gitter.im/Join%20Chat.png)](https://gitter.im/vavr-io/vavr) 4 | 5 | # GWT support for Vavr 6 | 7 | ### Using Vavr in GWT maven projects 8 | 9 | * Add the following maven dependency to your project: 10 | 11 | ``` 12 | 13 | io.vavr 14 | vavr-gwt 15 | {vavr-current-version} 16 | 17 | ``` 18 | 19 | * Inherit the `Vavr` module in your GWT module's descriptor file: 20 | 21 | ``` 22 | 23 | 24 | 25 | 26 | 27 | ``` 28 | 29 | * Use the Vavr APIs in your code. 30 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 3.0.4 5 | 6 | 7 | org.sonatype.oss 8 | oss-parent 9 | 9 10 | 11 | io.vavr 12 | vavr-gwt 13 | 1.0.0-SNAPSHOT 14 | jar 15 | Vavr GWT 16 | GWT support for Vavr. 17 | http://vavr.io 18 | 19 | 20 | The Apache Software License, Version 2.0 21 | http://www.apache.org/licenses/LICENSE-2.0.txt 22 | repo 23 | 24 | 25 | 26 | scm:git:git@github.com:vavr-io/vavr-gwt.git 27 | scm:git:git@github.com:vavr-io/vavr-gwt.git 28 | git@github.com:vavr-io/vavr-gwt.git 29 | HEAD 30 | 31 | 32 | 33 | ruslansennov 34 | Ruslan Sennov 35 | ruslan.sennov@gmail.com 36 | 37 | 38 | 39 | UTF-8 40 | 3.5.2 41 | 1.0.0 42 | 1.8 43 | 1.0.0-SNAPSHOT 44 | 4.12 45 | 2.8.2 46 | 3.2.0 47 | 2.5.2 48 | 3.5.1 49 | 2.8.2 50 | 1.6 51 | 0.7.8 52 | 3.0.2 53 | 2.10.4 54 | 2.5.3 55 | 2.3 56 | 3.0.1 57 | 58 | 59 | 60 | io.vavr 61 | vavr 62 | ${vavr.version} 63 | 64 | 65 | io.vavr 66 | vavr 67 | ${vavr.version} 68 | sources 69 | 70 | 71 | io.vavr 72 | vavr-match 73 | ${vavr.version} 74 | sources 75 | 76 | 77 | com.google.gwt 78 | gwt-user 79 | ${gwt.version} 80 | provided 81 | 82 | 83 | com.google.gwt 84 | gwt-dev 85 | ${gwt.version} 86 | provided 87 | 88 | 89 | junit 90 | junit 91 | ${junit.version} 92 | test 93 | 94 | 95 | org.assertj 96 | assertj-core 97 | ${assertj.core.version} 98 | test 99 | 100 | 101 | 102 | 103 | 104 | org.apache.felix 105 | maven-bundle-plugin 106 | ${maven.bundle.version} 107 | 108 | 109 | org.codehaus.mojo 110 | versions-maven-plugin 111 | ${maven.versions.version} 112 | 113 | 114 | org.apache.maven.plugins 115 | maven-install-plugin 116 | ${maven.install.version} 117 | 118 | 119 | org.codehaus.mojo 120 | gwt-maven-plugin 121 | ${gwt.version} 122 | 123 | 124 | testing 125 | test 126 | 127 | test 128 | 129 | 130 | 131 | compiling 132 | compile 133 | 134 | compile 135 | 136 | 137 | 138 | 139 | 0 140 | -Xmx1024m 141 | true 142 | 143 | 144 | 145 | 146 | 147 | 148 | org.apache.maven.plugins 149 | maven-source-plugin 150 | ${maven.source.version} 151 | 152 | 153 | attach-sources 154 | generate-resources 155 | 156 | jar-no-fork 157 | test-jar-no-fork 158 | 159 | 160 | 161 | 162 | 163 | org.apache.maven.plugins 164 | maven-release-plugin 165 | ${maven.release.version} 166 | 167 | 168 | v@{project.version} 169 | 170 | forked-path 171 | false 172 | 173 | ${arguments} -Psonatype-oss-release 174 | 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-compiler-plugin 179 | ${maven.compiler.version} 180 | 181 | ${java.version} 182 | ${java.version} 183 | true 184 | true 185 | 186 | -Xlint:all 187 | -Werror 188 | 189 | 190 | 191 | 192 | org.apache.maven.plugins 193 | maven-deploy-plugin 194 | ${maven.deploy.version} 195 | 196 | 197 | org.apache.maven.plugins 198 | maven-jar-plugin 199 | ${maven.jar.version} 200 | 201 | true 202 | 203 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF 204 | 205 | io.vavr.gwt 206 | 207 | 208 | 209 | 210 | 211 | org.apache.maven.plugins 212 | maven-javadoc-plugin 213 | ${maven.javadoc.version} 214 | 215 | 216 | https://docs.oracle.com/javase/8/docs/api/ 217 | 218 | 219 | 220 | 221 | org.apache.felix 222 | maven-bundle-plugin 223 | ${maven.bundle.version} 224 | 225 | 226 | bundle-manifest 227 | process-classes 228 | 229 | manifest 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | ci 241 | 242 | 243 | env.CI 244 | 245 | 246 | 247 | 248 | 249 | org.jacoco 250 | jacoco-maven-plugin 251 | ${maven.jacoco.version} 252 | 253 | 254 | 255 | prepare-agent 256 | 257 | 258 | 259 | report 260 | test 261 | 262 | report 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | release-sign-artifacts 273 | 274 | 275 | 276 | performRelease 277 | true 278 | 279 | 280 | 281 | 282 | 283 | org.apache.maven.plugins 284 | maven-gpg-plugin 285 | ${maven.gpg.version} 286 | 287 | 288 | sign-artifacts 289 | verify 290 | 291 | sign 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | eclipse-m2e 302 | 303 | 304 | m2e.version 305 | 306 | 307 | 308 | 309 | 310 | 311 | org.eclipse.m2e 312 | lifecycle-mapping 313 | ${eclipse.lifecycle.mapping.version} 314 | 315 | 316 | 317 | 319 | 320 | 321 | org.apache.maven.plugins 322 | maven-enforcer-plugin 323 | [0,) 324 | 325 | enforce 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | org.apache.felix 335 | maven-bundle-plugin 336 | [0,) 337 | 338 | manifest 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | org.codehaus.mojo 348 | gwt-maven-plugin 349 | [2.8.0,) 350 | 351 | compile 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | -------------------------------------------------------------------------------- /src/main/resources/Vavr.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/super/io/vavr/concurrent/CurrentThreadExecutorService.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package io.vavr.concurrent; 21 | 22 | import java.util.concurrent.ExecutorService; 23 | import java.util.concurrent.Future; 24 | 25 | /** 26 | * GWT emulated implementation of {@link ExecutorService} which executes all tasks in the current thread. 27 | */ 28 | public class CurrentThreadExecutorService implements ExecutorService { 29 | 30 | @Override public Future submit(Runnable task) { 31 | task.run(); 32 | 33 | return new CurrentThreadFuture<>(null, null); 34 | } 35 | 36 | @Override public void execute(Runnable command) { 37 | command.run(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/resources/super/io/vavr/concurrent/CurrentThreadFuture.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package io.vavr.concurrent; 21 | 22 | import java.util.concurrent.ExecutionException; 23 | import java.util.concurrent.TimeUnit; 24 | import java.util.concurrent.TimeoutException; 25 | 26 | /** 27 | * GWT emulated implementation of {@link java.util.concurrent.Future}. 28 | */ 29 | class CurrentThreadFuture implements java.util.concurrent.Future { 30 | 31 | private T result; 32 | 33 | private Exception exception; 34 | 35 | public CurrentThreadFuture(T result, Exception exception) { 36 | this.result = result; 37 | this.exception = exception; 38 | } 39 | 40 | @Override public boolean cancel(boolean mayInterruptIfRunning) { return false; } 41 | 42 | @Override public boolean isCancelled() { return false; } 43 | 44 | @Override public boolean isDone() { 45 | return true; 46 | } 47 | 48 | @Override public T get() throws InterruptedException, ExecutionException { 49 | if (exception != null) { 50 | throw new ExecutionException(exception); 51 | } 52 | 53 | return result; 54 | } 55 | 56 | @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, 57 | TimeoutException { 58 | return get(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/resources/super/io/vavr/concurrent/FutureImpl.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package io.vavr.concurrent; 21 | 22 | import io.vavr.CheckedConsumer; 23 | import io.vavr.CheckedFunction1; 24 | import io.vavr.collection.Queue; 25 | import io.vavr.control.Option; 26 | import io.vavr.control.Try; 27 | 28 | import java.util.Objects; 29 | import java.util.concurrent.*; 30 | import java.util.function.Consumer; 31 | import java.util.function.Predicate; 32 | 33 | /** 34 | * GWT emulated version of {@link FutureImpl} with removed uses of Object's wait and notify methods. 35 | */ 36 | final class FutureImpl implements Future { 37 | 38 | /** 39 | * Used to start new threads. 40 | */ 41 | private final Executor executor; 42 | 43 | /** 44 | * Used to synchronize state changes. 45 | */ 46 | private final Object lock = new Object(); 47 | 48 | /** 49 | * Indicates if this Future is cancelled 50 | */ 51 | @GuardedBy("lock") 52 | private volatile boolean cancelled; 53 | 54 | /** 55 | * Once the Future is completed, the value is defined. 56 | */ 57 | @GuardedBy("lock") 58 | private volatile Option> value; 59 | 60 | /** 61 | * The queue of actions is filled when calling onComplete() before the Future is completed or cancelled. 62 | * Otherwise actions = null. 63 | */ 64 | @GuardedBy("lock") 65 | private Queue>> actions; 66 | 67 | // single constructor 68 | private FutureImpl(Executor executor, Option> value, Queue>> actions, Computation computation) { 69 | this.executor = executor; 70 | synchronized (lock) { 71 | this.cancelled = false; 72 | this.value = value; 73 | this.actions = actions; 74 | try { 75 | computation.execute(this::tryComplete, this::updateThread); 76 | } catch(Throwable x) { 77 | tryComplete(Try.failure(x)); 78 | } 79 | } 80 | } 81 | 82 | /** 83 | * Creates a {@code FutureImpl} that is immediately completed with the given value. No task will be started. 84 | * 85 | * @param executor An {@link Executor} to run and control the computation and to perform the actions. 86 | * @param value the result of this Future 87 | */ 88 | @SuppressWarnings("unchecked") 89 | static FutureImpl of(Executor executor, Try value) { 90 | return new FutureImpl<>(executor, Option.some(Try.narrow(value)), null, (tryComplete, updateThread) -> {}); 91 | } 92 | 93 | /** 94 | * Creates a {@code FutureImpl} that is eventually completed. 95 | * The given {@code computation} is synchronously executed, no thread is started. 96 | * 97 | * @param executor An {@link Executor} to run and control the computation and to perform the actions. 98 | * @param computation A non-blocking computation 99 | * @param value type of the Future 100 | * @return a new {@code FutureImpl} instance 101 | */ 102 | static FutureImpl sync(Executor executor, CheckedConsumer>> computation) { 103 | return new FutureImpl<>(executor, Option.none(), Queue.empty(), (tryComplete, updateThread) -> { 104 | computation.accept(tryComplete); 105 | }); 106 | } 107 | 108 | /** 109 | * Creates a {@code FutureImpl} that is eventually completed. 110 | * The given {@code computation} is asynchronously executed, a new thread is started. 111 | * 112 | * @param executor An {@link Executor} to run and control the computation and to perform the actions. 113 | * @param computation A (possibly blocking) computation 114 | * @param value type of the Future 115 | * @return a new {@code FutureImpl} instance 116 | */ 117 | static FutureImpl async(Executor executor, CheckedConsumer>> computation) { 118 | return new FutureImpl<>(executor, Option.none(), Queue.empty(), (tryComplete, updateThread) -> executor.execute(() -> { 119 | try { 120 | computation.accept(tryComplete); 121 | } catch (Throwable x) { 122 | tryComplete.test(Try.failure(x)); 123 | } 124 | })); 125 | } 126 | 127 | @Override 128 | public Future await() { 129 | return this; 130 | } 131 | 132 | @Override 133 | public Future await(long timeout, TimeUnit unit) { 134 | return this; 135 | } 136 | 137 | @Override 138 | public Future cancel(boolean mayInterruptIfRunning) { 139 | if (!isCompleted()) { 140 | this.cancelled = tryComplete(Try.failure(new CancellationException())); 141 | } 142 | return this; 143 | } 144 | 145 | private void updateThread() { 146 | } 147 | 148 | @Override 149 | public Executor executor() { 150 | return executor; 151 | } 152 | 153 | @Override 154 | public Option> getValue() { 155 | return value; 156 | } 157 | 158 | @Override 159 | public boolean isCancelled() { 160 | return cancelled; 161 | } 162 | 163 | @Override 164 | public boolean isCompleted() { 165 | return value.isDefined(); 166 | } 167 | 168 | @SuppressWarnings("unchecked") 169 | @Override 170 | public Future onComplete(Consumer> action) { 171 | Objects.requireNonNull(action, "action is null"); 172 | if (isCompleted()) { 173 | perform(action); 174 | } else { 175 | synchronized (lock) { 176 | if (isCompleted()) { 177 | perform(action); 178 | } else { 179 | actions = actions.enqueue((Consumer>) action); 180 | } 181 | } 182 | } 183 | return this; 184 | } 185 | 186 | // This class is MUTABLE and therefore CANNOT CHANGE DEFAULT equals() and hashCode() behavior. 187 | // See http://stackoverflow.com/questions/4718009/mutable-objects-and-hashcode 188 | 189 | @Override 190 | public String toString() { 191 | final Option> value = this.value; 192 | final String s = (value == null || value.isEmpty()) ? "?" : value.get().toString(); 193 | return stringPrefix() + "(" + s + ")"; 194 | } 195 | 196 | /** 197 | * INTERNAL METHOD, SHOULD BE USED BY THE CONSTRUCTOR, ONLY. 198 | *

199 | * Completes this Future with a value and performs all actions. 200 | *

201 | * This method is idempotent. I.e. it does nothing, if this Future is already completed. 202 | * 203 | * @param value A Success containing a result or a Failure containing an Exception. 204 | * @throws IllegalStateException if the Future is already completed or cancelled. 205 | * @throws NullPointerException if the given {@code value} is null. 206 | */ 207 | private boolean tryComplete(Try value) { 208 | Objects.requireNonNull(value, "value is null"); 209 | if (isCompleted()) { 210 | return false; 211 | } else { 212 | final Queue>> actions; 213 | // it is essential to make the completed state public *before* performing the actions 214 | synchronized (lock) { 215 | if (isCompleted()) { 216 | actions = null; 217 | } else { 218 | // the job isn't set to null, see isCancelled() 219 | actions = this.actions; 220 | this.value = Option.some(Try.narrow(value)); 221 | this.actions = null; 222 | } 223 | } 224 | if (actions != null) { 225 | actions.forEach(this::perform); 226 | return true; 227 | } else { 228 | return false; 229 | } 230 | } 231 | } 232 | 233 | private void perform(Consumer> action) { 234 | try { 235 | executor.execute(() -> action.accept(value.get())); 236 | } catch(Throwable x) { 237 | // ignored // TODO: tell UncaughtExceptionHandler? 238 | } 239 | } 240 | 241 | private interface Computation { 242 | void execute(Predicate> tryComplete, Runnable updateThread) throws Throwable; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /src/main/resources/super/java/lang/InterruptedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | package java.lang; 27 | 28 | /** 29 | * Thrown when a thread is waiting, sleeping, or otherwise occupied, 30 | * and the thread is interrupted, either before or during the activity. 31 | * Occasionally a method may wish to test whether the current 32 | * thread has been interrupted, and if so, to immediately throw 33 | * this exception. The following code can be used to achieve 34 | * this effect: 35 | *

36 |  *  if (Thread.interrupted())  // Clears interrupted status!
37 |  *      throw new InterruptedException();
38 |  * 
39 | * 40 | * @author Frank Yellin 41 | * @see java.lang.Object#wait() 42 | * @see java.lang.Object#wait(long) 43 | * @see java.lang.Object#wait(long, int) 44 | * @see java.lang.Thread#sleep(long) 45 | * @see java.lang.Thread#interrupt() 46 | * @see java.lang.Thread#interrupted() 47 | * @since JDK1.0 48 | */ 49 | public 50 | class InterruptedException extends Exception { 51 | private static final long serialVersionUID = 6700697376100628473L; 52 | 53 | /** 54 | * Constructs an InterruptedException with no detail message. 55 | */ 56 | public InterruptedException() { 57 | super(); 58 | } 59 | 60 | /** 61 | * Constructs an InterruptedException with the 62 | * specified detail message. 63 | * 64 | * @param s the detail message. 65 | */ 66 | public InterruptedException(String s) { 67 | super(s); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/resources/super/java/lang/LinkageError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | package java.lang; 27 | 28 | /** 29 | * Subclasses of {@code LinkageError} indicate that a class has 30 | * some dependency on another class; however, the latter class has 31 | * incompatibly changed after the compilation of the former class. 32 | * 33 | * 34 | * @author Frank Yellin 35 | * @since JDK1.0 36 | */ 37 | public 38 | class LinkageError extends Error { 39 | private static final long serialVersionUID = 3579600108157160122L; 40 | 41 | /** 42 | * Constructs a {@code LinkageError} with no detail message. 43 | */ 44 | public LinkageError() { 45 | super(); 46 | } 47 | 48 | /** 49 | * Constructs a {@code LinkageError} with the specified detail 50 | * message. 51 | * 52 | * @param s the detail message. 53 | */ 54 | public LinkageError(String s) { 55 | super(s); 56 | } 57 | 58 | /** 59 | * Constructs a {@code LinkageError} with the specified detail 60 | * message and cause. 61 | * 62 | * @param s the detail message. 63 | * @param cause the cause, may be {@code null} 64 | * @since 1.7 65 | */ 66 | public LinkageError(String s, Throwable cause) { 67 | super(s, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/resources/super/java/lang/ThreadDeath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | package java.lang; 27 | 28 | /** 29 | * An instance of {@code ThreadDeath} is thrown in the victim thread 30 | * when the (deprecated) {@link Thread#stop()} method is invoked. 31 | * 32 | *

An application should catch instances of this class only if it 33 | * must clean up after being terminated asynchronously. If 34 | * {@code ThreadDeath} is caught by a method, it is important that it 35 | * be rethrown so that the thread actually dies. 36 | * 37 | *

The {@linkplain ThreadGroup#uncaughtException top-level error 38 | * handler} does not print out a message if {@code ThreadDeath} is 39 | * never caught. 40 | * 41 | *

The class {@code ThreadDeath} is specifically a subclass of 42 | * {@code Error} rather than {@code Exception}, even though it is a 43 | * "normal occurrence", because many applications catch all 44 | * occurrences of {@code Exception} and then discard the exception. 45 | * 46 | * @since JDK1.0 47 | */ 48 | 49 | public class ThreadDeath extends Error { 50 | private static final long serialVersionUID = -4417128565033088268L; 51 | } 52 | -------------------------------------------------------------------------------- /src/main/resources/super/java/lang/VirtualMachineError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | package java.lang; 27 | 28 | /** 29 | * Thrown to indicate that the Java Virtual Machine is broken or has 30 | * run out of resources necessary for it to continue operating. 31 | * 32 | * 33 | * @author Frank Yellin 34 | * @since JDK1.0 35 | */ 36 | abstract public class VirtualMachineError extends Error { 37 | private static final long serialVersionUID = 4161983926571568670L; 38 | 39 | /** 40 | * Constructs a VirtualMachineError with no detail message. 41 | */ 42 | public VirtualMachineError() { 43 | super(); 44 | } 45 | 46 | /** 47 | * Constructs a VirtualMachineError with the specified 48 | * detail message. 49 | * 50 | * @param message the detail message. 51 | */ 52 | public VirtualMachineError(String message) { 53 | super(message); 54 | } 55 | 56 | /** 57 | * Constructs a {@code VirtualMachineError} with the specified 58 | * detail message and cause.

Note that the detail message 59 | * associated with {@code cause} is not automatically 60 | * incorporated in this error's detail message. 61 | * 62 | * @param message the detail message (which is saved for later retrieval 63 | * by the {@link #getMessage()} method). 64 | * @param cause the cause (which is saved for later retrieval by the 65 | * {@link #getCause()} method). (A {@code null} value is 66 | * permitted, and indicates that the cause is nonexistent or 67 | * unknown.) 68 | * @since 1.8 69 | */ 70 | public VirtualMachineError(String message, Throwable cause) { 71 | super(message, cause); 72 | } 73 | 74 | /** 75 | * Constructs an a {@code VirtualMachineError} with the specified 76 | * cause and a detail message of {@code (cause==null ? null : 77 | * cause.toString())} (which typically contains the class and 78 | * detail message of {@code cause}). 79 | * 80 | * @param cause the cause (which is saved for later retrieval by the 81 | * {@link #getCause()} method). (A {@code null} value is 82 | * permitted, and indicates that the cause is nonexistent or 83 | * unknown.) 84 | * @since 1.8 85 | */ 86 | public VirtualMachineError(Throwable cause) { 87 | super(cause); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/Callable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * A task that returns a result and may throw an exception. 40 | * Implementors define a single method with no arguments called 41 | * {@code call}. 42 | * 43 | *

The {@code Callable} interface is similar to {@link 44 | * java.lang.Runnable}, in that both are designed for classes whose 45 | * instances are potentially executed by another thread. A 46 | * {@code Runnable}, however, does not return a result and cannot 47 | * throw a checked exception. 48 | * 49 | *

The {@link Executors} class contains utility methods to 50 | * convert from other common forms to {@code Callable} classes. 51 | * 52 | * @see Executor 53 | * @since 1.5 54 | * @author Doug Lea 55 | * @param the result type of method {@code call} 56 | */ 57 | @FunctionalInterface 58 | public interface Callable { 59 | /** 60 | * Computes a result, or throws an exception if unable to do so. 61 | * 62 | * @return computed result 63 | * @throws Exception if unable to compute a result 64 | */ 65 | V call() throws Exception; 66 | } 67 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/CancellationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * Exception indicating that the result of a value-producing task, 40 | * such as a {@link FutureTask}, cannot be retrieved because the task 41 | * was cancelled. 42 | * 43 | * @since 1.5 44 | * @author Doug Lea 45 | */ 46 | public class CancellationException extends IllegalStateException { 47 | private static final long serialVersionUID = -9202173006928992231L; 48 | 49 | /** 50 | * Constructs a {@code CancellationException} with no detail message. 51 | */ 52 | public CancellationException() {} 53 | 54 | /** 55 | * Constructs a {@code CancellationException} with the specified detail 56 | * message. 57 | * 58 | * @param message the detail message 59 | */ 60 | public CancellationException(String message) { 61 | super(message); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/ExecutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * Exception thrown when attempting to retrieve the result of a task 40 | * that aborted by throwing an exception. This exception can be 41 | * inspected using the {@link #getCause()} method. 42 | * 43 | * @see Future 44 | * @since 1.5 45 | * @author Doug Lea 46 | */ 47 | public class ExecutionException extends Exception { 48 | private static final long serialVersionUID = 7830266012832686185L; 49 | 50 | /** 51 | * Constructs an {@code ExecutionException} with no detail message. 52 | * The cause is not initialized, and may subsequently be 53 | * initialized by a call to {@link #initCause(Throwable) initCause}. 54 | */ 55 | protected ExecutionException() { } 56 | 57 | /** 58 | * Constructs an {@code ExecutionException} with the specified detail 59 | * message. The cause is not initialized, and may subsequently be 60 | * initialized by a call to {@link #initCause(Throwable) initCause}. 61 | * 62 | * @param message the detail message 63 | */ 64 | protected ExecutionException(String message) { 65 | super(message); 66 | } 67 | 68 | /** 69 | * Constructs an {@code ExecutionException} with the specified detail 70 | * message and cause. 71 | * 72 | * @param message the detail message 73 | * @param cause the cause (which is saved for later retrieval by the 74 | * {@link #getCause()} method) 75 | */ 76 | public ExecutionException(String message, Throwable cause) { 77 | super(message, cause); 78 | } 79 | 80 | /** 81 | * Constructs an {@code ExecutionException} with the specified cause. 82 | * The detail message is set to {@code (cause == null ? null : 83 | * cause.toString())} (which typically contains the class and 84 | * detail message of {@code cause}). 85 | * 86 | * @param cause the cause (which is saved for later retrieval by the 87 | * {@link #getCause()} method) 88 | */ 89 | public ExecutionException(Throwable cause) { 90 | super(cause); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/Executor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * An object that executes submitted {@link Runnable} tasks. This 40 | * interface provides a way of decoupling task submission from the 41 | * mechanics of how each task will be run, including details of thread 42 | * use, scheduling, etc. An {@code Executor} is normally used 43 | * instead of explicitly creating threads. For example, rather than 44 | * invoking {@code new Thread(new(RunnableTask())).start()} for each 45 | * of a set of tasks, you might use: 46 | * 47 | *

 48 |  * Executor executor = anExecutor;
 49 |  * executor.execute(new RunnableTask1());
 50 |  * executor.execute(new RunnableTask2());
 51 |  * ...
 52 |  * 
53 | * 54 | * However, the {@code Executor} interface does not strictly 55 | * require that execution be asynchronous. In the simplest case, an 56 | * executor can run the submitted task immediately in the caller's 57 | * thread: 58 | * 59 | *
 {@code
 60 |  * class DirectExecutor implements Executor {
 61 |  *   public void execute(Runnable r) {
 62 |  *     r.run();
 63 |  *   }
 64 |  * }}
65 | * 66 | * More typically, tasks are executed in some thread other 67 | * than the caller's thread. The executor below spawns a new thread 68 | * for each task. 69 | * 70 | *
 {@code
 71 |  * class ThreadPerTaskExecutor implements Executor {
 72 |  *   public void execute(Runnable r) {
 73 |  *     new Thread(r).start();
 74 |  *   }
 75 |  * }}
76 | * 77 | * Many {@code Executor} implementations impose some sort of 78 | * limitation on how and when tasks are scheduled. The executor below 79 | * serializes the submission of tasks to a second executor, 80 | * illustrating a composite executor. 81 | * 82 | *
 {@code
 83 |  * class SerialExecutor implements Executor {
 84 |  *   final Queue tasks = new ArrayDeque();
 85 |  *   final Executor executor;
 86 |  *   Runnable active;
 87 |  *
 88 |  *   SerialExecutor(Executor executor) {
 89 |  *     this.executor = executor;
 90 |  *   }
 91 |  *
 92 |  *   public synchronized void execute(final Runnable r) {
 93 |  *     tasks.offer(new Runnable() {
 94 |  *       public void run() {
 95 |  *         try {
 96 |  *           r.run();
 97 |  *         } finally {
 98 |  *           scheduleNext();
 99 |  *         }
100 |  *       }
101 |  *     });
102 |  *     if (active == null) {
103 |  *       scheduleNext();
104 |  *     }
105 |  *   }
106 |  *
107 |  *   protected synchronized void scheduleNext() {
108 |  *     if ((active = tasks.poll()) != null) {
109 |  *       executor.execute(active);
110 |  *     }
111 |  *   }
112 |  * }}
113 | * 114 | * The {@code Executor} implementations provided in this package 115 | * implement {@link ExecutorService}, which is a more extensive 116 | * interface. The {@link ThreadPoolExecutor} class provides an 117 | * extensible thread pool implementation. The {@link Executors} class 118 | * provides convenient factory methods for these Executors. 119 | * 120 | *

Memory consistency effects: Actions in a thread prior to 121 | * submitting a {@code Runnable} object to an {@code Executor} 122 | * happen-before 123 | * its execution begins, perhaps in another thread. 124 | * 125 | * @since 1.5 126 | * @author Doug Lea 127 | */ 128 | public interface Executor { 129 | 130 | /** 131 | * Executes the given command at some time in the future. The command 132 | * may execute in a new thread, in a pooled thread, or in the calling 133 | * thread, at the discretion of the {@code Executor} implementation. 134 | * 135 | * @param command the runnable task 136 | * @throws RejectedExecutionException if this task cannot be 137 | * accepted for execution 138 | * @throws NullPointerException if command is null 139 | */ 140 | void execute(Runnable command); 141 | } 142 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/ExecutorService.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package java.util.concurrent; 21 | 22 | /** 23 | * GWT emulated version of the {@link ExecutorService} with a limited set of methods used by Vavr. 24 | */ 25 | public interface ExecutorService extends Executor { 26 | 27 | Future submit(Runnable task); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/Executors.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package java.util.concurrent; 21 | 22 | import io.vavr.concurrent.CurrentThreadExecutorService; 23 | 24 | /** 25 | * GWT emulated implementation of {@link Executors} merged with Guava implementation to address potential 26 | * dependency conflicts. 27 | */ 28 | public class Executors { 29 | 30 | public static Callable callable(Runnable task, T result) { 31 | if (task == null) { 32 | throw new NullPointerException(); 33 | } 34 | return new RunnableAdapter(task, result); 35 | } 36 | 37 | public static Callable callable(Runnable task) { 38 | if (task == null) { 39 | throw new NullPointerException(); 40 | } 41 | return new RunnableAdapter(task, null); 42 | } 43 | 44 | public static ExecutorService newCachedThreadPool() { 45 | return new CurrentThreadExecutorService(); 46 | } 47 | 48 | static final class RunnableAdapter implements Callable { 49 | 50 | final Runnable task; 51 | final T result; 52 | 53 | RunnableAdapter(Runnable task, T result) { 54 | this.task = task; 55 | this.result = result; 56 | } 57 | 58 | public T call() { 59 | task.run(); 60 | return result; 61 | } 62 | } 63 | 64 | private Executors() { 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/ForkJoinPool.java: -------------------------------------------------------------------------------- 1 | package java.util.concurrent; 2 | 3 | import io.vavr.concurrent.CurrentThreadExecutorService; 4 | 5 | public class ForkJoinPool { 6 | public static ExecutorService commonPool() { 7 | return new CurrentThreadExecutorService(); 8 | } 9 | } -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/Future.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * A {@code Future} represents the result of an asynchronous 40 | * computation. Methods are provided to check if the computation is 41 | * complete, to wait for its completion, and to retrieve the result of 42 | * the computation. The result can only be retrieved using method 43 | * {@code get} when the computation has completed, blocking if 44 | * necessary until it is ready. Cancellation is performed by the 45 | * {@code cancel} method. Additional methods are provided to 46 | * determine if the task completed normally or was cancelled. Once a 47 | * computation has completed, the computation cannot be cancelled. 48 | * If you would like to use a {@code Future} for the sake 49 | * of cancellability but not provide a usable result, you can 50 | * declare types of the form {@code Future} and 51 | * return {@code null} as a result of the underlying task. 52 | * 53 | *

54 | * Sample Usage (Note that the following classes are all 55 | * made-up.) 56 | *

 {@code
 57 |  * interface ArchiveSearcher { String search(String target); }
 58 |  * class App {
 59 |  *   ExecutorService executor = ...
 60 |  *   ArchiveSearcher searcher = ...
 61 |  *   void showSearch(final String target)
 62 |  *       throws InterruptedException {
 63 |  *     Future future
 64 |  *       = executor.submit(new Callable() {
 65 |  *         public String call() {
 66 |  *             return searcher.search(target);
 67 |  *         }});
 68 |  *     displayOtherThings(); // do other things while searching
 69 |  *     try {
 70 |  *       displayText(future.get()); // use future
 71 |  *     } catch (ExecutionException ex) { cleanup(); return; }
 72 |  *   }
 73 |  * }}
74 | * 75 | * The {@link FutureTask} class is an implementation of {@code Future} that 76 | * implements {@code Runnable}, and so may be executed by an {@code Executor}. 77 | * For example, the above construction with {@code submit} could be replaced by: 78 | *
 {@code
 79 |  * FutureTask future =
 80 |  *   new FutureTask(new Callable() {
 81 |  *     public String call() {
 82 |  *       return searcher.search(target);
 83 |  *   }});
 84 |  * executor.execute(future);}
85 | * 86 | *

Memory consistency effects: Actions taken by the asynchronous computation 87 | * happen-before 88 | * actions following the corresponding {@code Future.get()} in another thread. 89 | * 90 | * @see FutureTask 91 | * @see Executor 92 | * @since 1.5 93 | * @author Doug Lea 94 | * @param The result type returned by this Future's {@code get} method 95 | */ 96 | public interface Future { 97 | 98 | /** 99 | * Attempts to cancel execution of this task. This attempt will 100 | * fail if the task has already completed, has already been cancelled, 101 | * or could not be cancelled for some other reason. If successful, 102 | * and this task has not started when {@code cancel} is called, 103 | * this task should never run. If the task has already started, 104 | * then the {@code mayInterruptIfRunning} parameter determines 105 | * whether the thread executing this task should be interrupted in 106 | * an attempt to stop the task. 107 | * 108 | *

After this method returns, subsequent calls to {@link #isDone} will 109 | * always return {@code true}. Subsequent calls to {@link #isCancelled} 110 | * will always return {@code true} if this method returned {@code true}. 111 | * 112 | * @param mayInterruptIfRunning {@code true} if the thread executing this 113 | * task should be interrupted; otherwise, in-progress tasks are allowed 114 | * to complete 115 | * @return {@code false} if the task could not be cancelled, 116 | * typically because it has already completed normally; 117 | * {@code true} otherwise 118 | */ 119 | boolean cancel(boolean mayInterruptIfRunning); 120 | 121 | /** 122 | * Returns {@code true} if this task was cancelled before it completed 123 | * normally. 124 | * 125 | * @return {@code true} if this task was cancelled before it completed 126 | */ 127 | boolean isCancelled(); 128 | 129 | /** 130 | * Returns {@code true} if this task completed. 131 | * 132 | * Completion may be due to normal termination, an exception, or 133 | * cancellation -- in all of these cases, this method will return 134 | * {@code true}. 135 | * 136 | * @return {@code true} if this task completed 137 | */ 138 | boolean isDone(); 139 | 140 | /** 141 | * Waits if necessary for the computation to complete, and then 142 | * retrieves its result. 143 | * 144 | * @return the computed result 145 | * @throws CancellationException if the computation was cancelled 146 | * @throws ExecutionException if the computation threw an 147 | * exception 148 | * @throws InterruptedException if the current thread was interrupted 149 | * while waiting 150 | */ 151 | V get() throws InterruptedException, ExecutionException; 152 | 153 | /** 154 | * Waits if necessary for at most the given time for the computation 155 | * to complete, and then retrieves its result, if available. 156 | * 157 | * @param timeout the maximum time to wait 158 | * @param unit the time unit of the timeout argument 159 | * @return the computed result 160 | * @throws CancellationException if the computation was cancelled 161 | * @throws ExecutionException if the computation threw an 162 | * exception 163 | * @throws InterruptedException if the current thread was interrupted 164 | * while waiting 165 | * @throws TimeoutException if the wait timed out 166 | */ 167 | V get(long timeout, TimeUnit unit) 168 | throws InterruptedException, ExecutionException, TimeoutException; 169 | } 170 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/TimeUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * A {@code TimeUnit} represents time durations at a given unit of 40 | * granularity and provides utility methods to convert across units, 41 | * and to perform timing and delay operations in these units. A 42 | * {@code TimeUnit} does not maintain time information, but only 43 | * helps organize and use time representations that may be maintained 44 | * separately across various contexts. A nanosecond is defined as one 45 | * thousandth of a microsecond, a microsecond as one thousandth of a 46 | * millisecond, a millisecond as one thousandth of a second, a minute 47 | * as sixty seconds, an hour as sixty minutes, and a day as twenty four 48 | * hours. 49 | * 50 | *

A {@code TimeUnit} is mainly used to inform time-based methods 51 | * how a given timing parameter should be interpreted. For example, 52 | * the following code will timeout in 50 milliseconds if the {@link 53 | * java.util.concurrent.locks.Lock lock} is not available: 54 | * 55 | *

 {@code
 56 |  * Lock lock = ...;
 57 |  * if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...}
58 | * 59 | * while this code will timeout in 50 seconds: 60 | *
 {@code
 61 |  * Lock lock = ...;
 62 |  * if (lock.tryLock(50L, TimeUnit.SECONDS)) ...}
63 | * 64 | * Note however, that there is no guarantee that a particular timeout 65 | * implementation will be able to notice the passage of time at the 66 | * same granularity as the given {@code TimeUnit}. 67 | * 68 | * @since 1.5 69 | * @author Doug Lea 70 | */ 71 | public enum TimeUnit { 72 | /** 73 | * Time unit representing one thousandth of a microsecond 74 | */ 75 | NANOSECONDS { 76 | public long toNanos(long d) { return d; } 77 | public long toMicros(long d) { return d/(C1/C0); } 78 | public long toMillis(long d) { return d/(C2/C0); } 79 | public long toSeconds(long d) { return d/(C3/C0); } 80 | public long toMinutes(long d) { return d/(C4/C0); } 81 | public long toHours(long d) { return d/(C5/C0); } 82 | public long toDays(long d) { return d/(C6/C0); } 83 | public long convert(long d, TimeUnit u) { return u.toNanos(d); } 84 | int excessNanos(long d, long m) { return (int)(d - (m*C2)); } 85 | }, 86 | 87 | /** 88 | * Time unit representing one thousandth of a millisecond 89 | */ 90 | MICROSECONDS { 91 | public long toNanos(long d) { return x(d, C1/C0, MAX/(C1/C0)); } 92 | public long toMicros(long d) { return d; } 93 | public long toMillis(long d) { return d/(C2/C1); } 94 | public long toSeconds(long d) { return d/(C3/C1); } 95 | public long toMinutes(long d) { return d/(C4/C1); } 96 | public long toHours(long d) { return d/(C5/C1); } 97 | public long toDays(long d) { return d/(C6/C1); } 98 | public long convert(long d, TimeUnit u) { return u.toMicros(d); } 99 | int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); } 100 | }, 101 | 102 | /** 103 | * Time unit representing one thousandth of a second 104 | */ 105 | MILLISECONDS { 106 | public long toNanos(long d) { return x(d, C2/C0, MAX/(C2/C0)); } 107 | public long toMicros(long d) { return x(d, C2/C1, MAX/(C2/C1)); } 108 | public long toMillis(long d) { return d; } 109 | public long toSeconds(long d) { return d/(C3/C2); } 110 | public long toMinutes(long d) { return d/(C4/C2); } 111 | public long toHours(long d) { return d/(C5/C2); } 112 | public long toDays(long d) { return d/(C6/C2); } 113 | public long convert(long d, TimeUnit u) { return u.toMillis(d); } 114 | int excessNanos(long d, long m) { return 0; } 115 | }, 116 | 117 | /** 118 | * Time unit representing one second 119 | */ 120 | SECONDS { 121 | public long toNanos(long d) { return x(d, C3/C0, MAX/(C3/C0)); } 122 | public long toMicros(long d) { return x(d, C3/C1, MAX/(C3/C1)); } 123 | public long toMillis(long d) { return x(d, C3/C2, MAX/(C3/C2)); } 124 | public long toSeconds(long d) { return d; } 125 | public long toMinutes(long d) { return d/(C4/C3); } 126 | public long toHours(long d) { return d/(C5/C3); } 127 | public long toDays(long d) { return d/(C6/C3); } 128 | public long convert(long d, TimeUnit u) { return u.toSeconds(d); } 129 | int excessNanos(long d, long m) { return 0; } 130 | }, 131 | 132 | /** 133 | * Time unit representing sixty seconds 134 | */ 135 | MINUTES { 136 | public long toNanos(long d) { return x(d, C4/C0, MAX/(C4/C0)); } 137 | public long toMicros(long d) { return x(d, C4/C1, MAX/(C4/C1)); } 138 | public long toMillis(long d) { return x(d, C4/C2, MAX/(C4/C2)); } 139 | public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); } 140 | public long toMinutes(long d) { return d; } 141 | public long toHours(long d) { return d/(C5/C4); } 142 | public long toDays(long d) { return d/(C6/C4); } 143 | public long convert(long d, TimeUnit u) { return u.toMinutes(d); } 144 | int excessNanos(long d, long m) { return 0; } 145 | }, 146 | 147 | /** 148 | * Time unit representing sixty minutes 149 | */ 150 | HOURS { 151 | public long toNanos(long d) { return x(d, C5/C0, MAX/(C5/C0)); } 152 | public long toMicros(long d) { return x(d, C5/C1, MAX/(C5/C1)); } 153 | public long toMillis(long d) { return x(d, C5/C2, MAX/(C5/C2)); } 154 | public long toSeconds(long d) { return x(d, C5/C3, MAX/(C5/C3)); } 155 | public long toMinutes(long d) { return x(d, C5/C4, MAX/(C5/C4)); } 156 | public long toHours(long d) { return d; } 157 | public long toDays(long d) { return d/(C6/C5); } 158 | public long convert(long d, TimeUnit u) { return u.toHours(d); } 159 | int excessNanos(long d, long m) { return 0; } 160 | }, 161 | 162 | /** 163 | * Time unit representing twenty four hours 164 | */ 165 | DAYS { 166 | public long toNanos(long d) { return x(d, C6/C0, MAX/(C6/C0)); } 167 | public long toMicros(long d) { return x(d, C6/C1, MAX/(C6/C1)); } 168 | public long toMillis(long d) { return x(d, C6/C2, MAX/(C6/C2)); } 169 | public long toSeconds(long d) { return x(d, C6/C3, MAX/(C6/C3)); } 170 | public long toMinutes(long d) { return x(d, C6/C4, MAX/(C6/C4)); } 171 | public long toHours(long d) { return x(d, C6/C5, MAX/(C6/C5)); } 172 | public long toDays(long d) { return d; } 173 | public long convert(long d, TimeUnit u) { return u.toDays(d); } 174 | int excessNanos(long d, long m) { return 0; } 175 | }; 176 | 177 | // Handy constants for conversion methods 178 | static final long C0 = 1L; 179 | static final long C1 = C0 * 1000L; 180 | static final long C2 = C1 * 1000L; 181 | static final long C3 = C2 * 1000L; 182 | static final long C4 = C3 * 60L; 183 | static final long C5 = C4 * 60L; 184 | static final long C6 = C5 * 24L; 185 | 186 | static final long MAX = Long.MAX_VALUE; 187 | 188 | /** 189 | * Scale d by m, checking for overflow. 190 | * This has a short name to make above code more readable. 191 | */ 192 | static long x(long d, long m, long over) { 193 | if (d > over) return Long.MAX_VALUE; 194 | if (d < -over) return Long.MIN_VALUE; 195 | return d * m; 196 | } 197 | 198 | // To maintain full signature compatibility with 1.5, and to improve the 199 | // clarity of the generated javadoc (see 6287639: Abstract methods in 200 | // enum classes should not be listed as abstract), method convert 201 | // etc. are not declared abstract but otherwise act as abstract methods. 202 | 203 | /** 204 | * Converts the given time duration in the given unit to this unit. 205 | * Conversions from finer to coarser granularities truncate, so 206 | * lose precision. For example, converting {@code 999} milliseconds 207 | * to seconds results in {@code 0}. Conversions from coarser to 208 | * finer granularities with arguments that would numerically 209 | * overflow saturate to {@code Long.MIN_VALUE} if negative or 210 | * {@code Long.MAX_VALUE} if positive. 211 | * 212 | *

For example, to convert 10 minutes to milliseconds, use: 213 | * {@code TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)} 214 | * 215 | * @param sourceDuration the time duration in the given {@code sourceUnit} 216 | * @param sourceUnit the unit of the {@code sourceDuration} argument 217 | * @return the converted duration in this unit, 218 | * or {@code Long.MIN_VALUE} if conversion would negatively 219 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 220 | */ 221 | public long convert(long sourceDuration, TimeUnit sourceUnit) { 222 | throw new Error(); 223 | } 224 | 225 | /** 226 | * Equivalent to 227 | * {@link #convert(long, TimeUnit) NANOSECONDS.convert(duration, this)}. 228 | * @param duration the duration 229 | * @return the converted duration, 230 | * or {@code Long.MIN_VALUE} if conversion would negatively 231 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 232 | */ 233 | public long toNanos(long duration) { 234 | throw new Error(); 235 | } 236 | 237 | /** 238 | * Equivalent to 239 | * {@link #convert(long, TimeUnit) MICROSECONDS.convert(duration, this)}. 240 | * @param duration the duration 241 | * @return the converted duration, 242 | * or {@code Long.MIN_VALUE} if conversion would negatively 243 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 244 | */ 245 | public long toMicros(long duration) { 246 | throw new Error(); 247 | } 248 | 249 | /** 250 | * Equivalent to 251 | * {@link #convert(long, TimeUnit) MILLISECONDS.convert(duration, this)}. 252 | * @param duration the duration 253 | * @return the converted duration, 254 | * or {@code Long.MIN_VALUE} if conversion would negatively 255 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 256 | */ 257 | public long toMillis(long duration) { 258 | throw new Error(); 259 | } 260 | 261 | /** 262 | * Equivalent to 263 | * {@link #convert(long, TimeUnit) SECONDS.convert(duration, this)}. 264 | * @param duration the duration 265 | * @return the converted duration, 266 | * or {@code Long.MIN_VALUE} if conversion would negatively 267 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 268 | */ 269 | public long toSeconds(long duration) { 270 | throw new Error(); 271 | } 272 | 273 | /** 274 | * Equivalent to 275 | * {@link #convert(long, TimeUnit) MINUTES.convert(duration, this)}. 276 | * @param duration the duration 277 | * @return the converted duration, 278 | * or {@code Long.MIN_VALUE} if conversion would negatively 279 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 280 | * @since 1.6 281 | */ 282 | public long toMinutes(long duration) { 283 | throw new Error(); 284 | } 285 | 286 | /** 287 | * Equivalent to 288 | * {@link #convert(long, TimeUnit) HOURS.convert(duration, this)}. 289 | * @param duration the duration 290 | * @return the converted duration, 291 | * or {@code Long.MIN_VALUE} if conversion would negatively 292 | * overflow, or {@code Long.MAX_VALUE} if it would positively overflow. 293 | * @since 1.6 294 | */ 295 | public long toHours(long duration) { 296 | throw new Error(); 297 | } 298 | 299 | /** 300 | * Equivalent to 301 | * {@link #convert(long, TimeUnit) DAYS.convert(duration, this)}. 302 | * @param duration the duration 303 | * @return the converted duration 304 | * @since 1.6 305 | */ 306 | public long toDays(long duration) { 307 | throw new Error(); 308 | } 309 | 310 | /** 311 | * Utility to compute the excess-nanosecond argument to wait, 312 | * sleep, join. 313 | * @param d the duration 314 | * @param m the number of milliseconds 315 | * @return the number of nanoseconds 316 | */ 317 | abstract int excessNanos(long d, long m); 318 | } 319 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/TimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 3 | * 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | */ 24 | 25 | /* 26 | * 27 | * 28 | * 29 | * 30 | * 31 | * Written by Doug Lea with assistance from members of JCP JSR-166 32 | * Expert Group and released to the public domain, as explained at 33 | * http://creativecommons.org/publicdomain/zero/1.0/ 34 | */ 35 | 36 | package java.util.concurrent; 37 | 38 | /** 39 | * Exception thrown when a blocking operation times out. Blocking 40 | * operations for which a timeout is specified need a means to 41 | * indicate that the timeout has occurred. For many such operations it 42 | * is possible to return a value that indicates timeout; when that is 43 | * not possible or desirable then {@code TimeoutException} should be 44 | * declared and thrown. 45 | * 46 | * @since 1.5 47 | * @author Doug Lea 48 | */ 49 | public class TimeoutException extends Exception { 50 | private static final long serialVersionUID = 1900926677490660714L; 51 | 52 | /** 53 | * Constructs a {@code TimeoutException} with no specified detail 54 | * message. 55 | */ 56 | public TimeoutException() {} 57 | 58 | /** 59 | * Constructs a {@code TimeoutException} with the specified detail 60 | * message. 61 | * 62 | * @param message the detail message 63 | */ 64 | public TimeoutException(String message) { 65 | super(message); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/atomic/AtomicBoolean.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package java.util.concurrent.atomic; 21 | 22 | /** 23 | * GWT emulated version of {@link AtomicBoolean} wrapping simple boolean value. 24 | */ 25 | public class AtomicBoolean implements java.io.Serializable { 26 | private static final long serialVersionUID = 4654671469794556979L; 27 | 28 | private boolean value; 29 | 30 | public AtomicBoolean(boolean initialValue) { 31 | value = initialValue; 32 | } 33 | 34 | public AtomicBoolean() { 35 | } 36 | 37 | public final boolean get() { 38 | return value; 39 | } 40 | 41 | public final boolean compareAndSet(boolean expect, boolean update) { 42 | if (value == expect) { 43 | value = update; 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | public boolean weakCompareAndSet(boolean expect, boolean update) { 50 | return compareAndSet(expect, update); 51 | } 52 | 53 | public final void set(boolean newValue) { 54 | value = newValue; 55 | } 56 | 57 | public final void lazySet(boolean newValue) { 58 | set(newValue); 59 | } 60 | 61 | public final boolean getAndSet(boolean newValue) { 62 | boolean prev = get(); 63 | set(newValue); 64 | return prev; 65 | } 66 | 67 | public String toString() { 68 | return Boolean.toString(get()); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/atomic/AtomicInteger.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package java.util.concurrent.atomic; 21 | 22 | import java.util.function.IntUnaryOperator; 23 | import java.util.function.IntBinaryOperator; 24 | import sun.misc.Unsafe; 25 | 26 | /** 27 | * GWT emulated version of {@link AtomicInteger} wrapping simple int value. 28 | */ 29 | public class AtomicInteger extends Number implements java.io.Serializable { 30 | private static final long serialVersionUID = 6214790243416807050L; 31 | 32 | private int value; 33 | 34 | public AtomicInteger(int initialValue) { 35 | value = initialValue; 36 | } 37 | 38 | public AtomicInteger() {} 39 | 40 | public final int get() { return value; } 41 | 42 | public final void set(int newValue) { value = newValue; } 43 | 44 | public final void lazySet(int newValue) { set(newValue); } 45 | 46 | public final int getAndSet(int newValue) { 47 | int old = value; 48 | value = newValue; 49 | 50 | return old; 51 | } 52 | 53 | public final boolean compareAndSet(int expect, int update) { 54 | if (value == expect) { 55 | value = update; 56 | 57 | return true; 58 | } 59 | 60 | return false; 61 | } 62 | 63 | public final boolean weakCompareAndSet(int expect, int update) { 64 | return compareAndSet(expect, update); 65 | } 66 | 67 | public final int getAndIncrement() { 68 | return value++; 69 | } 70 | 71 | public final int getAndDecrement() { 72 | return value--; 73 | } 74 | 75 | public final int getAndAdd(int delta) { 76 | int old = value; 77 | value += delta; 78 | 79 | return old; 80 | } 81 | 82 | public final int incrementAndGet() { 83 | return ++value; 84 | } 85 | 86 | public final int decrementAndGet() { 87 | return --value; 88 | } 89 | 90 | public final int addAndGet(int delta) { 91 | value += delta; 92 | 93 | return value; 94 | } 95 | 96 | public final int getAndUpdate(IntUnaryOperator updateFunction) { 97 | int old = value; 98 | value = updateFunction.applyAsInt(value); 99 | 100 | return old; 101 | } 102 | 103 | public final int updateAndGet(IntUnaryOperator updateFunction) { 104 | value = updateFunction.applyAsInt(value); 105 | 106 | return value; 107 | } 108 | 109 | public final int getAndAccumulate(int x, 110 | IntBinaryOperator accumulatorFunction) { 111 | int old = value; 112 | value = accumulatorFunction.applyAsInt(value, x); 113 | 114 | return old; 115 | } 116 | 117 | public final int accumulateAndGet(int x, 118 | IntBinaryOperator accumulatorFunction) { 119 | value = accumulatorFunction.applyAsInt(value, x); 120 | 121 | return value; 122 | } 123 | 124 | public String toString() { 125 | return Integer.toString(get()); 126 | } 127 | 128 | public int intValue() { 129 | return get(); 130 | } 131 | 132 | public long longValue() { 133 | return (long) get(); 134 | } 135 | 136 | public float floatValue() { 137 | return (float) get(); 138 | } 139 | 140 | public double doubleValue() { 141 | return (double) get(); 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/resources/super/java/util/concurrent/atomic/AtomicReference.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/ 5 | * 6 | * Copyright 2014-2017 Vavr, http://vavr.io 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | package java.util.concurrent.atomic; 21 | 22 | import java.util.function.UnaryOperator; 23 | import java.util.function.BinaryOperator; 24 | 25 | /** 26 | * GWT emulated version of {@link AtomicReference} wrapping reference. 27 | */ 28 | public class AtomicReference implements java.io.Serializable { 29 | private static final long serialVersionUID = -1848883965231344442L; 30 | 31 | private V value; 32 | 33 | public AtomicReference(V initialValue) { 34 | value = initialValue; 35 | } 36 | 37 | public AtomicReference() { 38 | } 39 | 40 | public final V get() { 41 | return value; 42 | } 43 | 44 | public final void set(V newValue) { 45 | value = newValue; 46 | } 47 | 48 | public final void lazySet(V newValue) { 49 | set(newValue); 50 | } 51 | 52 | public final boolean compareAndSet(V expect, V update) { 53 | if (value == expect) { 54 | value = update; 55 | return true; 56 | } 57 | return false; 58 | } 59 | 60 | public final boolean weakCompareAndSet(V expect, V update) { 61 | return compareAndSet(expect, update); 62 | } 63 | 64 | public final V getAndSet(V newValue) { 65 | V prev = get(); 66 | set(newValue); 67 | return prev; 68 | } 69 | 70 | public final V getAndUpdate(UnaryOperator updateFunction) { 71 | V prev = get(); 72 | set(updateFunction.apply(prev)); 73 | return prev; 74 | } 75 | 76 | public final V updateAndGet(UnaryOperator updateFunction) { 77 | V prev = get(); 78 | V next = updateFunction.apply(prev); 79 | set(next); 80 | return next; 81 | } 82 | 83 | public final V getAndAccumulate(V x, BinaryOperator accumulatorFunction) { 84 | V prev = get(); 85 | set(accumulatorFunction.apply(prev, x)); 86 | return prev; 87 | } 88 | 89 | public final V accumulateAndGet(V x, BinaryOperator accumulatorFunction) { 90 | V prev = get(); 91 | V next = accumulatorFunction.apply(prev, x); 92 | set(next); 93 | return next; 94 | } 95 | 96 | public String toString() { 97 | return String.valueOf(get()); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/test/java/TestModule.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/test/java/client/CollectionsTestGwt.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/.ɪᴏ 5 | * ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ 6 | */ 7 | package client; 8 | 9 | import com.google.gwt.junit.client.GWTTestCase; 10 | import io.vavr.Function1; 11 | import io.vavr.Tuple; 12 | import io.vavr.Tuple1; 13 | import io.vavr.collection.*; 14 | 15 | public class CollectionsTestGwt extends GWTTestCase { 16 | 17 | @Override 18 | public String getModuleName() { 19 | return "TestModule"; 20 | } 21 | 22 | public void testTuple() { 23 | Tuple1 t = Tuple.of(1); 24 | assertEquals((int) t._1, 1); 25 | assertEquals((int) t._1(), 1); 26 | } 27 | 28 | private void applyCollection(Function1> factory) { 29 | Traversable traversable = factory.apply(new char[] {'a', 'b', 'c'}); 30 | assertEquals(traversable.count(i -> i != 'b'), 2); 31 | } 32 | 33 | public void testCompileArray() { 34 | applyCollection(chars -> Array.ofAll(Iterator.ofAll(chars))); 35 | } 36 | 37 | public void testCompileBitSet() { 38 | applyCollection(chars -> BitSet.withCharacters().ofAll(Iterator.ofAll(chars))); 39 | } 40 | 41 | public void testCompileCharSeq() { 42 | applyCollection(chars -> CharSeq.ofAll(Iterator.ofAll(chars))); 43 | } 44 | 45 | public void testCompileHashSet() { 46 | applyCollection(chars -> HashSet.ofAll(Iterator.ofAll(chars))); 47 | } 48 | 49 | public void testCompileLinkedHashSet() { 50 | applyCollection(chars -> LinkedHashSet.ofAll(Iterator.ofAll(chars))); 51 | } 52 | 53 | public void testCompileList() { 54 | applyCollection(chars -> List.ofAll(Iterator.ofAll(chars))); 55 | } 56 | 57 | public void testCompilePriorityQueue() { 58 | applyCollection(chars -> PriorityQueue.ofAll(Iterator.ofAll(chars))); 59 | } 60 | 61 | public void testCompileQueue() { 62 | applyCollection(chars -> Queue.ofAll(Iterator.ofAll(chars))); 63 | } 64 | 65 | public void testCompileTreeSet() { 66 | applyCollection(chars -> TreeSet.ofAll(Iterator.ofAll(chars))); 67 | } 68 | 69 | @SuppressWarnings("Convert2MethodRef") 70 | public void testCompileVector() { 71 | applyCollection(chars -> Vector.ofAll(chars)); 72 | } 73 | } -------------------------------------------------------------------------------- /src/test/java/client/ConcurrentTest1.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/.ɪᴏ 5 | * ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ 6 | */ 7 | package client; 8 | 9 | import com.google.gwt.junit.client.GWTTestCase; 10 | import io.vavr.concurrent.Future; 11 | import io.vavr.control.Try; 12 | 13 | import java.util.concurrent.Executors; 14 | import java.util.concurrent.atomic.AtomicBoolean; 15 | import java.util.concurrent.atomic.AtomicReference; 16 | import java.util.function.Predicate; 17 | 18 | import static io.vavr.API.Future; 19 | 20 | //import io.vavr.concurrent.Promise; 21 | 22 | /** 23 | * We should split tests into small parts because of this compiler message 24 | * 25 | * [INFO] Compiling... 26 | * [INFO] [WARN] JDT threw an exception: file:/home/ruslan/proj/javaslang-gwt/src/test/java/client/ConcurrentTestGwt.java: java.lang.ArrayIndexOutOfBoundsException: 1600 27 | */ 28 | public class ConcurrentTest1 extends GWTTestCase { 29 | 30 | @Override public String getModuleName() { 31 | return "TestModule"; 32 | } 33 | 34 | public void testCreateFailFuture() { 35 | final Future failed = Future.failed(new RuntimeException("ooops")); 36 | assertTrue(failed.isFailure()); 37 | Throwable t = failed.getValue().get().getCause(); 38 | assertEquals(t.getClass(), RuntimeException.class); 39 | assertEquals(t.getMessage(), "ooops"); 40 | } 41 | 42 | public void testCreateSuccessFuture() { 43 | final Future success = Future(Executors.newCachedThreadPool(), () -> "hehehe"); 44 | assertTrue(success.isSuccess()); 45 | assertEquals(success.get(), "hehehe"); 46 | } 47 | 48 | public void testFutureSuccess() { 49 | final AtomicBoolean ok = new AtomicBoolean(false); 50 | final AtomicReference>> comp = new AtomicReference<>(); 51 | final Future future = Future.join(comp::set); 52 | future.onComplete(value -> { 53 | ok.set(true); 54 | assertEquals("value", value.get()); 55 | }); 56 | comp.get().test(Try.success("value")); 57 | assertTrue("onComplete handler should have been called", ok.get()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/client/ConcurrentTest2.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/.ɪᴏ 5 | * ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ 6 | */ 7 | package client; 8 | 9 | import com.google.gwt.junit.client.GWTTestCase; 10 | import io.vavr.collection.List; 11 | import io.vavr.concurrent.Future; 12 | import io.vavr.control.Try; 13 | 14 | import java.util.concurrent.atomic.AtomicBoolean; 15 | import java.util.concurrent.atomic.AtomicReference; 16 | import java.util.function.Predicate; 17 | 18 | /** 19 | * We should split tests into small parts because of this compiler message 20 | * 21 | * [INFO] Compiling... 22 | * [INFO] [WARN] JDT threw an exception: file:/home/ruslan/proj/javaslang-gwt/src/test/java/client/ConcurrentTestGwt.java: java.lang.ArrayIndexOutOfBoundsException: 1600 23 | */ 24 | public class ConcurrentTest2 extends GWTTestCase { 25 | 26 | @Override public String getModuleName() { 27 | return "TestModule"; 28 | } 29 | 30 | public void testFutureFailure() { 31 | final AtomicBoolean onFailureCalled = new AtomicBoolean(false); 32 | final AtomicReference>> comp = new AtomicReference<>(); 33 | final Future future = Future.join(comp::set); 34 | future.onFailure(e -> { 35 | onFailureCalled.set(true); 36 | assertEquals("message", e.getMessage()); 37 | }); 38 | comp.get().test(Try.failure(new Exception("message"))); 39 | assertTrue("onFailure handler should have been called", onFailureCalled.get()); 40 | } 41 | 42 | public void testFutureSequence() { 43 | final AtomicBoolean onCompleteCalled = new AtomicBoolean(false); 44 | final AtomicReference>> comp1 = new AtomicReference<>(); 45 | final Future future1 = Future.join(comp1::set); 46 | final AtomicReference>> comp2 = new AtomicReference<>(); 47 | final Future future2 = Future.join(comp2::set); 48 | Future.sequence(List.of(future1, future2)) 49 | .onComplete(results -> { 50 | onCompleteCalled.set(true); 51 | assertEquals(2, results.get().size()); 52 | }); 53 | comp1.get().test(Try.success("success1")); 54 | comp2.get().test(Try.success("success2")); 55 | assertTrue("onComplete handler should have been called", onCompleteCalled.get()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/client/GwtVavrTestSuite.java: -------------------------------------------------------------------------------- 1 | /* __ __ __ __ __ ___ 2 | * \ \ / / \ \ / / __/ 3 | * \ \/ / /\ \ \/ / / 4 | * \____/__/ \__\____/__/.ɪᴏ 5 | * ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ 6 | */ 7 | package client; 8 | 9 | import com.google.gwt.junit.tools.GWTTestSuite; 10 | import junit.framework.Test; 11 | import junit.framework.TestCase; 12 | 13 | public class GwtVavrTestSuite extends TestCase { 14 | 15 | public static Test suite() { 16 | GWTTestSuite suite = new GWTTestSuite("Vavr test suite."); 17 | suite.addTestSuite(CollectionsTestGwt.class); 18 | suite.addTestSuite(ConcurrentTest1.class); 19 | suite.addTestSuite(ConcurrentTest2.class); 20 | return suite; 21 | } 22 | } 23 | --------------------------------------------------------------------------------