diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..def5ba5d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "gradle" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/compute-entropy.py b/.github/workflows/compute-entropy.py new file mode 100644 index 00000000..44a11770 --- /dev/null +++ b/.github/workflows/compute-entropy.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +import os +import sys +import math +import json +import subprocess +from collections import Counter +from pathlib import Path + +def shannon_entropy(text: str) -> float: + if not text or len(text) < 10: + return 0.0 + freq = Counter(text) + probs = [count / len(text) for count in freq.values()] + return -sum(p * math.log2(p) for p in probs if p > 0) + +# Determine changed files based on event type +changed_files = [] +event_name = os.environ.get("EVENT_NAME", "") +base_sha = os.environ.get("BASE_SHA", "").strip() +head_sha = os.environ.get("HEAD_SHA", "").strip() or "HEAD" + +try: + if event_name == "pull_request_target" and base_sha: + # PR case: we checked out the PR head and fetched the base commit + changed_files = subprocess.check_output( + ["git", "diff", "--name-only", base_sha, head_sha], + text=True + ).splitlines() + else: + # push / release: diff against previous commit + changed_files = subprocess.check_output( + ["git", "diff", "--name-only", "HEAD~1", "HEAD"], + text=True + ).splitlines() +except subprocess.CalledProcessError: + # Fallbacks + try: + changed_files = subprocess.check_output( + ["git", "diff", "--name-only", "HEAD~1", "HEAD"], + text=True + ).splitlines() + except subprocess.CalledProcessError: + changed_files = subprocess.check_output( + ["git", "ls-files"], text=True + ).splitlines() + +results = [] +total_ent = 0.0 +count = 0 + +for f in changed_files: + path = Path(f.strip()) + if not path.exists() or path.suffix in {'.png', '.jpg', '.gif', '.bin', '.lock', '.exe', '.dll', '.so'}: + continue + try: + content = path.read_text(encoding="utf-8", errors="ignore") + ent = shannon_entropy(content) + results.append(f"{f}: {ent:.3f}") + total_ent += ent + count += 1 + except Exception: + pass + +avg = round(total_ent / count, 3) if count > 0 else 0.0 + +verdict = ( + "✅ Mid-4 beauty detected (thoughtful human code!)" if 4.3 <= avg <= 4.7 else + "⚠️ Consider review — entropy outside sweet spot" if avg > 0 else + "No source files changed" +) + +with open("/tmp/beauty.json", "w") as f: + json.dump({ + "average_entropy": avg, + "verdict": verdict, + "files": results[:20] + }, f, indent=2) + +print(f"Average entropy: {avg}") +print(verdict) \ No newline at end of file diff --git a/.github/workflows/entropy-beauty-scan.yml b/.github/workflows/entropy-beauty-scan.yml new file mode 100644 index 00000000..980ab63d --- /dev/null +++ b/.github/workflows/entropy-beauty-scan.yml @@ -0,0 +1,151 @@ +name: Entropy Beauty + TruffleHog Scan + +on: [push, release, pull_request_target] + +permissions: + contents: read + pull-requests: write + issues: write # must be at workflow level for push/merge events + +jobs: + scan: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }} + fetch-depth: ${{ github.event_name == 'pull_request_target' && 1 || 2 }} + allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} + + - name: Fetch PR base commit (needed for accurate diff) + if: github.event_name == 'pull_request_target' + run: git fetch origin ${{ github.event.pull_request.base.sha }} --depth=1 + + - name: Cache pip manually + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-entropy-${{ hashFiles('.github/workflows/compute-entropy.py') }} + restore-keys: | + ${{ runner.os }}-pip-entropy- + + - name: Setup Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: '3.12' + + - name: Install Python dependencies (only when needed) + run: | + python -m pip install --upgrade pip + # No extra packages needed — compute-entropy.py uses only stdlib + + - name: Run TruffleHog + uses: trufflesecurity/trufflehog@e76dff8a7e57d6df0c60ad8cbf5d5cba505a8fc9 # v3.99.2 + with: + path: . + extra_args: --results=verified,unknown --filter-entropy=3.5 --json + + - name: Compute mid-4 beauty entropy + env: + EVENT_NAME: ${{ github.event_name }} + BASE_SHA: ${{ github.event.pull_request.base.sha || '' }} + HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + run: python .github/workflows/compute-entropy.py + + - name: Post summary comment (PR only) + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + uses: actions/github-script@v9 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + + // Read TruffleHog output — it prints one JSON object per line (NDJSON) + let findings = []; + if (fs.existsSync('trufflehog.json')) { + try { + const lines = fs.readFileSync('trufflehog.json', 'utf8').trim().split('\n'); + findings = lines.map(line => { + try { return JSON.parse(line); } catch(e) { return null; } + }).filter(Boolean); + } catch(e) {} + } else { + console.log("No trufflehog.json found, using empty findings"); + } + + const beauty = JSON.parse(fs.readFileSync('/tmp/beauty.json', 'utf8')); + + let body = `## 🐷 TruffleHog + Entropy Beauty Scan\n\n`; + body += `**Average entropy of changed code:** ${beauty.average_entropy} bits/char\n`; + body += `**Verdict:** ${beauty.verdict}\n\n`; + + if (beauty.files && beauty.files.length) { + body += `**Changed files entropy:**\n\`\`\`\n${beauty.files.join('\n')}\n\`\`\`\n\n`; + } + + if (findings.length > 0) { + body += `⚠️ **TruffleHog found ${findings.length} potential issue(s)**\n`; + } else { + body += `✅ No secrets or suspicious high-entropy strings found.\n`; + } + + body += `\n*Mid-4 beauty heuristic in action — powered by our entropy chats! 😊*`; + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: body + }); + + # ── Create issue on push ONLY if suspicious (entropy outside 4.3–5.1) ── + - name: Create issue on suspicious push + if: github.event_name == 'push' || github.event_name == 'release' + uses: actions/github-script@v9 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const beauty = JSON.parse(fs.readFileSync('/tmp/beauty.json', 'utf8')); + + // Only create issue if it's NOT beautiful mid-4 + if (beauty.average_entropy >= 4.3 && beauty.average_entropy <= 5.1) { + console.log("✅ Mid-4 beauty — no issue created"); + return; + } + + let findings = []; + if (fs.existsSync('trufflehog.json')) { + try { + const lines = fs.readFileSync('trufflehog.json', 'utf8').trim().split('\n'); + findings = lines.map(line => { + try { return JSON.parse(line); } catch(e) { return null; } + }).filter(Boolean); + } catch(e) {} + } + + let body = `**Average entropy:** ${beauty.average_entropy} bits/char\n\n`; + body += `**Verdict:** ${beauty.verdict}\n\n`; + + if (beauty.files && beauty.files.length) { + body += `**Changed files:**\n\`\`\`\n${beauty.files.join('\n')}\n\`\`\`\n\n`; + } + + if (findings.length > 0) { + body += `**TruffleHog found ${findings.length} potential issue(s)**\n`; + } else { + body += `✅ No secrets or suspicious high-entropy strings found.\n`; + } + + body += `\n*Triggered by push to \`${context.sha}\` — mid-4 beauty heuristic*`; + + await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: `🚨 Suspicious entropy detected in recent push (${beauty.average_entropy})`, + body: body, + labels: ['entropy', 'security', 'review-needed'] + }); + + console.log("⚠️ Created issue because entropy was outside mid-4 range"); diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml new file mode 100644 index 00000000..227188ef --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -0,0 +1,13 @@ +name: "Validate Gradle Wrapper" +on: [push, pull_request] + +permissions: + contents: read + +jobs: + validation: + name: "Validation" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: gradle/actions/wrapper-validation@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6 diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 00000000..b544c74e --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,44 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ 4.x ] + pull_request: + branches: [ 4.x ] + +jobs: + build: + + runs-on: ubuntu-latest + env: + CI_PULL_REQUEST: ${{ github.event.number }} + JAVADOCS_TOKEN: ${{ secrets.JAVADOCS_TOKEN }} + CI_BUILD_NUMBER: ${{ github.run_number }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Set up JDK 26 + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 + with: + distribution: 'zulu' + java-version: '26' + - name: Cache Gradle packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Grant execute permission for push + run: chmod +x push.sh + - name: Build with Gradle + run: ./gradlew build javadoc --stacktrace + - name: Upload to Codecov + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + - name: Push Javadocs + run: ./push.sh diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml new file mode 100644 index 00000000..ff0568ec --- /dev/null +++ b/.github/workflows/scorecard.yml @@ -0,0 +1,60 @@ +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '43 12 * * 4' + push: + branches: [ "4.x" ] + workflow_dispatch: + +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + + steps: + - name: "Checkout code" + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@fa7117db83c52d787ae5a89f350999701505d78e # v2.5.0 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if + # you want to enable the Branch-Protection check on a *public* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-fine-grained-pat-optional. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0 + with: + sarif_file: results.sarif diff --git a/README.md b/README.md index 037098de..348bc628 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # RxJavaExtensions - -[![codecov.io](http://codecov.io/github/akarnokd/RxJavaExtensions/coverage.svg?branch=master)](http://codecov.io/github/akarnokd/RxJavaExtensions?branch=master) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.akarnokd/rxjava2-extensions/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.akarnokd/rxjava2-extensions) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava) +[![Maven Central](https://maven-badges.sml.io/sonatype-central/com.github.akarnokd/rxjava4-extensions/badge.svg)](https://maven-badges.sml.io/sonatype-central/com.github.akarnokd/rxjava4-extensions) +[![codecov.io](http://codecov.io/github/akarnokd/RxJavaExtensions/coverage.svg?branch=4.x)](https://codecov.io/gh/akarnokd/RxJavaExtensions/branch/4.x) +[![Java CI with Gradle](https://github.com/akarnokd/RxJavaExtensions/actions/workflows/gradle.yml/badge.svg)](https://github.com/akarnokd/RxJavaExtensions/actions/workflows/gradle.yml) -RxJava 2.x implementation of extra sources, operators and components and ports of many 1.x companion libraries. +[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/akarnokd/RxJavaExtensions/badge)](https://securityscorecards.dev/viewer/?uri=github.com/akarnokd/RxJavaExtensions) + +RxJava 4.x implementation of extra sources, operators and components and ports of many 1.x companion libraries. # Releases @@ -13,11 +14,11 @@ RxJava 2.x implementation of extra sources, operators and components and ports o ``` dependencies { -    compile "com.github.akarnokd:rxjava2-extensions:0.20.10" + implementation "com.github.akarnokd:rxjava4-extensions:4.0.0" } ``` -Javadoc: https://akarnokd.github.com/RxJavaExtensions/javadoc/index.html +Javadoc: https://akarnokd.github.io/RxJavaExtensions/javadoc/index.html Maven search: @@ -56,7 +57,7 @@ Maven search: - [cacheLast()](#flowabletransformerscachelast), [timeoutLast()](#flowabletransformerstimeoutlast--timeoutlastabsolute), [timeoutLastAbsolute()](#flowabletransformerstimeoutlast--timeoutlastabsolute), - [debounceFirst()](#flowabletransformersdebouncefirst), [switchFlatMap()](#flowabletransformersswitchflatmap), [flatMapSync()](#flowabletransformersflatmapsync), - [flatMapAsync()](#flowabletransformersflatmapasync), [switchIfEmpty()](#flowabletransformersswitchifempty--switchifemptyarray), - - [expand()](#flowabletransformersexpand), [mapAsync()](#flowabletransformersmapasync), [filterAsync()](#flowabletransformerfilterasync), + - [expand()](#flowabletransformersexpand), [mapAsync()](#flowabletransformersmapasync), [filterAsync()](#flowabletransformersfilterasync), - [zipLatest()](#flowablesziplatest), [coalesce()](#flowabletransformerscoalesce), - [windowWhile()](#flowabletransformerswindowwhile), [windowUntil()](#flowabletransformerswindowuntil), [windowSplit()](#flowabletransformerswindowsplit), - [indexOf()](#flowabletransformersindexof), [requestObserveOn()](#flowabletransformersrequestobserveon), [requestSample()](#flowabletransformersrequestsample) @@ -80,7 +81,7 @@ Maven search: Support the join-patterns and async-util with functional interfaces of consumers with 3-9 type arguments and have functional interfaces of functions without the `throws Exception`. - - `Supplier` - `Callable` without `throws Exception` + - `SimpleCallable` - `Callable` without `throws Exception` - `Consumer3` - 3 argument `Consumer` - `Consumer4` - 4 argument `Consumer` - `Consumer5` - 5 argument `Consumer` @@ -162,7 +163,7 @@ Flowable.just("ab", ":cde:" "fg") ## Asynchronous jumpstarting a sequence Wrap functions and consumers into Flowables and Observables or into another layer of Functions. -Most of these can now be achieved via `fromCallable` and some function composition in plain RxJava (1.x and 2.x alike). +Most of these can now be achieved via `fromCallable` and some function composition in plain RxJava. ### start @@ -201,7 +202,7 @@ func.apply(1) ``` ### startFuture -Run a Callable that returns a Future to call blocking get() on to get the solo value or exception. +Run a Supplier that returns a Future to call blocking get() on to get the solo value or exception. ```java ExecutorService exec = Executors.newSingleThreadedScheduler(); @@ -216,7 +217,7 @@ exec.shutdown(); ### deferFuture -Run a Callable that returns a Future to call blocking get() on to get a `Publisher` to stream back. +Run a Supplier that returns a Future to call blocking get() on to get a `Publisher` to stream back. ```java ExecutorService exec = Executors.newSingleThreadedScheduler(); @@ -378,7 +379,7 @@ TBD: examples ## Debug support -By default, RxJava 2's RxJavaPlugins only offers the ability to hook into the assembly process (i.e., when you apply an operator on a sequence or create one) unlike 1.x where there is an `RxJavaHooks.enableAssemblyTracking()` method. Since the standard format is of discussion there, 2.x doesn't have such feature built in but only +By default, RxJava 3's RxJavaPlugins only offers the ability to hook into the assembly process (i.e., when you apply an operator on a sequence or create one) unlike 1.x where there is an `RxJavaHooks.enableAssemblyTracking()` method. Since the standard format is of discussion there, 3.x doesn't have such feature built in but only in this extension library. ### Usage @@ -404,8 +405,8 @@ In debug mode, you can walk through the reference graph of Disposables and Subsc ``` RxJavaAssemblyException: assembled at io.reactivex.Completable.error(Completable.java:280) -at hu.akarnokd.rxjava2.debug.RxJava2AssemblyTrackingTest.createCompletable(RxJava2AssemblyTrackingTest.java:78) -at hu.akarnokd.rxjava2.debug.RxJava2AssemblyTrackingTest.completable(RxJava2AssemblyTrackingTest.java:185) +at hu.akarnokd.rxjava3.debug.RxJava3AssemblyTrackingTest.createCompletable(RxJava3AssemblyTrackingTest.java:78) +at hu.akarnokd.rxjava3.debug.RxJava3AssemblyTrackingTest.completable(RxJava3AssemblyTrackingTest.java:185) ``` This is a filtered list of stacktrace elements (skipping threading, unit test and self-related entries). Most modern IDEs should allow you to navigate to the locations when printed on (or pasted into) its console. @@ -459,7 +460,7 @@ name (t1 .. t9) and the tag provided. Custom operators and sources sometimes contain bugs that manifest themselves in odd sequence behavior or crashes from within the standard operators. Since the revealing stacktraces is often missing or incomplete, diagnosing -such failures can be tiresome. Therefore, the `hu.akarnokd.rxjava2.debug.validator.RxJavaProtocolValidator` +such failures can be tiresome. Therefore, the `hu.akarnokd.rxjava3.debug.validator.RxJavaProtocolValidator` class offers assembly hooks for the standard reactive base types. The validation hooks can be enabled via `RxJavaProtocolValidator.enable()` and disabled via `RxJavaProtocolValidator.disable()`. @@ -506,7 +507,7 @@ The standard `RxJavaPlugins` allows only one hook to be associated with each mai If multiple hooks should be invoked, that option is not directly supported by `RxJavaPlugins` but can be built upon the single hook scheme. -The `hu.akarnokd.rxjava2.debug.multihook` package offers hook managers that can work with multiple hooks +The `hu.akarnokd.rxjava3.debug.multihook` package offers hook managers that can work with multiple hooks themselves. The various multi-hook managers are built upon the generic `MultiHandlerManager` class. The class offers the `register` @@ -566,7 +567,7 @@ Note that calling `onComplete` after `onNext` is optional with `SoloProcessor` b ### MulticastProcessor -*Moved to RxJava as standard processor: [`io.reactivex.processors.MulticastProcessor`](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/processors/MulticastProcessor.html)*. +*Moved to RxJava as standard processor: [`io.reactivex.rxjava3.processors.MulticastProcessor`](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/processors/MulticastProcessor.html)*. ### UnicastWorkSubject @@ -595,7 +596,7 @@ asynchronously. If there are no `Observer`s (or they all disposed), the `Dispatc `Observer`s can resume the consumption of the buffer. ```java -DispatchWorkSubject dws = DispatchWorkSubject.create(); +DispatchWorkSubject dws = DispatchWorkSubject.create(Schedulers.computation()); Single> asList = dws.toList(); @@ -616,11 +617,11 @@ assertEquals(1000000, to.values().get().size()); ### DispatchWorkProcessor A `FlowableProcessor` variant that buffers items and allows one or more `Subscriber`s to exclusively consume one of the items in the buffer -asynchronously. If there are no `Subscriber`s (or they all disposed), the `DispatchWorkSubscriber` will keep buffering and later +asynchronously. If there are no `Subscriber`s (or they all canceled), the `DispatchWorkProcessor` will keep buffering and later `Subscriber`s can resume the consumption of the buffer. ```java -DispatchWorkProcessor dwp = DispatchWorkProcessor.create(); +DispatchWorkProcessor dwp = DispatchWorkProcessor.create(Schedulers.computation()); Single> asList = dwp.toList(); @@ -628,7 +629,7 @@ TestObserver> to = Single .zip(asList, asList, (a, b) -> a.addAll(b)) .test(); -Flowable.range(1, 1000000).subscribe(dws); +Flowable.range(1, 1000000).subscribe(dwp); to.awaitDone(5, TimeUnit.SECONDS) .assertValueCount(1) @@ -721,7 +722,7 @@ public static void main(String[] args) { ## Custom operators and transformers -The custom transformers (to be applied with `Flowable.compose` for example), can be found in `hu.akarnokd.rxjava2.operators.FlowableTransformers` class. The custom source-like operators can be found in `hu.akarnokd.rxjava2.operators.Flowables` class. The operators and transformers for the other base +The custom transformers (to be applied with `Flowable.compose` for example), can be found in `hu.akarnokd.rxjava3.operators.FlowableTransformers` class. The custom source-like operators can be found in `hu.akarnokd.rxjava3.operators.Flowables` class. The operators and transformers for the other base reactive classes (will) follow the usual naming scheme. ### FlowableTransformers.valve() @@ -876,12 +877,12 @@ Flowable.repeat("doesn't matter") .assertResult(true); ``` -### Flowables.repeatCallable() +### Flowables.repeatSupplier() -Repeatedly calls a callable, indefinitely (until the downstream actually cancels) or if the callable throws or returns null (when it signals `NullPointerException`), honoring backpressure and supporting synchronous fusion and/or conditional fusion. +Repeatedly calls a supplier, indefinitely (until the downstream actually cancels) or if the supplier throws or returns null (when it signals `NullPointerException`), honoring backpressure and supporting synchronous fusion and/or conditional fusion. ```java -Flowable.repeatCallable(() -> ThreadLocalRandom.current().nextDouble()) +Flowable.repeatSupplier(() -> ThreadLocalRandom.current().nextDouble()) .take(100) .all(v -> v < 1d) .test() @@ -1079,9 +1080,9 @@ Flowable.just(new File(".")) // ~/git/RxJavaExtensions/src/main/java // ~/git/RxJavaExtensions/src/main/java/hu // ~/git/RxJavaExtensions/src/main/java/hu/akarnokd -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2 -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/operators -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/operators/FlowableExpand.java +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3 +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/operators +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/operators/FlowableExpand.java // ... // ~/git/RxJavaExtensions/src/test // ~/git/RxJavaExtensions/src/test/java @@ -1116,14 +1117,14 @@ Flowable.just(new File(".")) // ~/git/RxJavaExtensions/src/main/java // ~/git/RxJavaExtensions/src/main/java/hu // ~/git/RxJavaExtensions/src/main/java/hu/akarnokd -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2 -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/operators -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/math -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/async -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/debug +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3 +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/operators +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/math +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/async +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/debug // ... -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/operators/FlowableExpand.java -// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava2/operators/FlowableTransformers.java +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/operators/FlowableExpand.java +// ~/git/RxJavaExtensions/src/main/java/hu/akarnokd/rxjava3/operators/FlowableTransformers.java ``` ### FlowableTransformers.mapAsync() @@ -1176,8 +1177,8 @@ Flowable.range(1, 10) ### FlowableTransformers.refCount() *Moved to RxJava as standard operators: -[ConnectableObservable.refCount](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/observables/ConnectableObservable.html#refCount-int-long-java.util.concurrent.TimeUnit-io.reactivex.Scheduler-), -[ConnectableFlowable.refCount](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/flowables/ConnectableFlowable.html#refCount-int-long-java.util.concurrent.TimeUnit-io.reactivex.Scheduler-). +[ConnectableObservable.refCount](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/observables/ConnectableObservable.html#refCount-int-long-java.util.concurrent.TimeUnit-io.reactivex.rxjava3.core.Scheduler-), +[ConnectableFlowable.refCount](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/flowables/ConnectableFlowable.html#refCount-int-long-java.util.concurrent.TimeUnit-io.reactivex.rxjava3.core.Scheduler-). ### Flowables.zipLatest() @@ -1651,24 +1652,24 @@ Availability: - `Single` - `SingleTransformers.flatMap` (use with `Single.compose()`) - - `Singles.flatMapCompletable` (use with `Single.as()`) - - `Singles.flatMapMaybe` (use with `Single.as()`) - - `Singles.flatMapObservable` (use with `Single.as()`) - - `Singles.flatMapFlowable` (use with `Single.as()`) + - `Singles.flatMapCompletable` (use with `Single.to()`) + - `Singles.flatMapMaybe` (use with `Single.to()`) + - `Singles.flatMapObservable` (use with `Single.to()`) + - `Singles.flatMapFlowable` (use with `Single.to()`) - `Maybe` - `MaybeTransformers.flatMap` (use with `Maybe.compose()`) - - `Maybes.flatMapCompletable` (use with `Maybe.as()`) - - `Maybes.flatMapSingle` (use with `Maybe.as()`) - - `Maybes.flatMapObservable` (use with `Maybe.as()`) - - `Maybes.flatMapFlowable` (use with `Maybe.as()`) + - `Maybes.flatMapCompletable` (use with `Maybe.to()`) + - `Maybes.flatMapSingle` (use with `Maybe.to()`) + - `Maybes.flatMapObservable` (use with `Maybe.to()`) + - `Maybes.flatMapFlowable` (use with `Maybe.to()`) - `Completable` - `CompletableTransformers.flatMap` (use with `Completable.compose()`) - - `Completables.flatMapSingle` (use with `Completable.as()`) - - `Completables.flatMapMaybe` (use with `Completable.as()`) - - `Completables.flatMapObservable` (use with `Completable.as()`) - - `Completables.flatMapFlowable` (use with `Completable.as()`) + - `Completables.flatMapSingle` (use with `Completable.to()`) + - `Completables.flatMapMaybe` (use with `Completable.to()`) + - `Completables.flatMapObservable` (use with `Completable.to()`) + - `Completables.flatMapFlowable` (use with `Completable.to()`) -Note: same-type transformations for [Flowable.flatMap](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html#flatMap-io.reactivex.functions.Function-io.reactivex.functions.Function-java.util.concurrent.Callable-), [Observable.flatMap](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#flatMap-io.reactivex.functions.Function-io.reactivex.functions.Function-java.util.concurrent.Callable-) already exist in RxJava. +Note: same-type transformations for [Flowable.flatMap](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/Flowable.html#flatMap-io.reactivex.functions.Function-io.reactivex.functions.Function-io.reactivex.functions.Supplier-), [Observable.flatMap](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/Observable.html#flatMap-io.reactivex.functions.Function-io.reactivex.functions.Function-io.reactivex.functions.Supplier-) already exist in RxJava. ## Custom parallel operators and transformers @@ -1846,7 +1847,7 @@ ts.assertResult(1); ## Custom consumers -The utility classes can be found in `hu.akarnokd.rxjava2.consumers` package. +The utility classes can be found in `hu.akarnokd.rxjava3.consumers` package. ### FlowableConsumers diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..75abb1dc --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,54 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ------- | ------------------ | +| 4.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +If you believe you have found a **real** security vulnerability in RxJavaExtensions, please report it privately via [GitHub Security Advisories](https://github.com/akarnokd/RxJavaExtensions/security/advisories/new). + +**Do not open a public issue.** + +### What is actually in scope + +RxJavaExtensions is a pure operator / utility library. It contains: + +- No network code +- No serialization / deserialization +- No native code +- No file-system or process interaction +- No privileged operations +- No authentication, authorization, or cryptographic primitives + +Therefore the only issues that will ever be considered security vulnerabilities are those that allow **remote code execution, privilege escalation, or unintended data exfiltration** when the library is used as documented. + +The following are **explicitly out of scope** (and will be closed immediately): + +- Resource exhaustion / OutOfMemoryError caused by a malicious or buggy upstream +- Violations of the Reactive Streams protocol by the caller +- “Theoretical” issues that require the application developer to already be doing something insane +- Style nits, missing null-checks, or “this could be DoS’d if you pass a hostile Observable” +- Anything an LLM hallucinated after a 30-second glance at the repo + +### A note to low-effort researchers + +If you contacted the maintainer *before* even skimming the README or source tree to notice that this library has essentially zero classic attack surface, please go back and do that first. It will save everyone time. + +We are happy to look at genuine findings. We are not interested in AI-generated noise or CVSS-inflated correctness bugs. + +## Disclosure Policy + +- We aim to acknowledge reports within 72 hours. +- We will keep you informed of progress. +- CVEs (if any) will only be requested **after** a fix is released. +- We follow coordinated disclosure. Please give us at least 90 days before any public disclosure. + +Thank you for helping keep the reactive ecosystem safe — the right way. + +------ + +🪐 via Grok diff --git a/build.gradle b/build.gradle index 3af6f5d1..903358e0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,28 @@ -buildscript { - repositories { - mavenCentral() - maven { - url "https://plugins.gradle.org/m2/" - } - } - - dependencies { - classpath 'gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0' - classpath "me.champeau.gradle:jmh-gradle-plugin:0.2.0" - classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.2.0' - } +plugins { + id("java-library") + id("checkstyle") + id("eclipse") + id("maven-publish") + id("me.champeau.jmh") version "0.7.3" + id("com.github.hierynomus.license") version "0.16.1" + id("biz.aQute.bnd.builder") version "7.4.0" + id("com.vanniktech.maven.publish") version "0.37.0" + id("org.beryx.jar") version "2.0.0" + id("signing") +} + +ext { + reactiveStreamsVersion = "1.0.4" + junitVersion = "4.13.2" + testNgVersion = "7.12.0" + mockitoVersion = "5.24.0" + mockitoJUnitVersion = "5.24.0" + jmhLibVersion = "1.37" + guavaVersion = "33.6.0-jre" + jupiterVersion = "6.1.3" + jupiterLauncherVersion = "6.1.3" + rxJavaVersion = "4.0.0-alpha-21" } - -apply plugin: 'java' -apply plugin: 'eclipse' -apply plugin: "me.champeau.gradle.jmh" -apply plugin: 'pmd' -apply plugin: 'jacoco' -apply plugin: 'ru.vyarus.animalsniffer' -apply plugin: "com.github.hierynomus.license" - -sourceCompatibility = '1.6' -targetCompatibility = '1.6' - group = "com.github.akarnokd" ext.githubProjectName = 'RxJavaExtensions' @@ -35,171 +34,206 @@ if (!hasProperty('mainClass')) { repositories { mavenCentral() - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } - maven { url 'https://oss.sonatype.org/content/groups/public' } - maven { url 'https://oss.jfrog.org/libs-snapshot' } - maven { url 'http://repo.spring.io/libs-snapshot' } + maven { url 'https://central.sonatype.com/repository/maven-snapshots' } } -apply from: file('gradle/maven.gradle') -apply plugin: 'maven' -apply plugin: 'osgi' - dependencies { - signature 'org.codehaus.mojo.signature:java16:1.1@signature' + api "io.reactivex.rxjava4:rxjava:$rxJavaVersion" - compile "org.reactivestreams:reactive-streams:1.0.2" - compile "io.reactivex.rxjava2:rxjava:2.2.10" + testImplementation "org.mockito:mockito-core:$mockitoVersion" + compileOnly "org.mockito:mockito-core:$mockitoVersion" + testImplementation "org.mockito:mockito-junit-jupiter:$mockitoJUnitVersion" - testCompile group: 'junit', name: 'junit', version: '4.12' + testImplementation "org.junit.jupiter:junit-jupiter:$jupiterVersion" + compileOnly "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" - testCompile 'org.mockito:mockito-core:2.28.2' -} + testImplementation "org.junit.platform:junit-platform-commons:$jupiterLauncherVersion" + compileOnly "org.junit.platform:junit-platform-commons:$jupiterLauncherVersion" + testImplementation "org.junit.platform:junit-platform-launcher:$jupiterLauncherVersion" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:$jupiterLauncherVersion" -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource } +// === Experimental JDK handling for Outreach Program === +def experimental = System.getenv("JDK_EXPERIMENTAL") +def toolchainJdk = "26" // default / baseline -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir +if (experimental != null && !experimental.trim().isEmpty()) { + toolchainJdk = experimental // e.g. "27" } -artifacts { - archives jar - archives sourcesJar - archives javadocJar +java { + toolchain { + languageVersion = JavaLanguageVersion.of(toolchainJdk) + } + sourceCompatibility = JavaVersion.VERSION_26 + targetCompatibility = JavaVersion.VERSION_26 } -//uploadMavenCentral { -// repositories { -// mavenDeployer { -// pom.whenConfigured { -// p -> p.dependencies = p.dependencies.findAll { -// dep -> dep.artifactId != "rxjava" -// } -// } -// } -// } -//} - -jar { - manifest { - name = 'rxjava2-extensions' - instruction 'Bundle-Vendor', 'akarnokd' - instruction 'Bundle-DocURL', 'https://github.com/akarnokd/RxJavaExtensions' - instruction 'Import-Package', '!org.junit,!junit.framework,!org.mockito.*,*' - instruction 'Eclipse-ExtensibleAPI', 'true' - } +tasks.withType(JavaCompile) { + options.compilerArgs << "-parameters" + options.compilerArgs += '-Xlint:-module' + options.compilerArgs += '-Xlint:unchecked' + modularity.inferModulePath = true } -apply plugin: 'maven-publish' +moduleConfig { + moduleInfoPath = 'src/main/module/module-info.java' + multiReleaseVersion = 9 + version = project.version +} -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - artifact (sourcesJar) { - classifier = 'sources' - } - } - } +checkstyle { + configFile = project.file("config/checkstyle/checkstyle.xml") + configProperties = [ + "checkstyle.suppressions.file": project.file("config/checkstyle/suppressions.xml"), + "checkstyle.header.file" : project.file("config/license/HEADER_JAVA"), + "project_loc" : project.projectDir.absolutePath + ] + checkstyleMain.exclude '**/module-info.java' } +apply plugin: "com.vanniktech.maven.publish" + jmh { - jmhVersion = '1.16' + jmhVersion = '1.37' humanOutputFile = null - if (project.hasProperty('jmh')) { - include = ".*" + project.jmh + ".*" - } else { - include = ".*" - } -} - -plugins.withType(EclipsePlugin) { - project.eclipse.classpath.plusConfigurations += [ configurations.jmh ] } javadoc { + source = sourceSets.main.allJava.matching { + include 'io/reactivex/rxjava4/**' + exclude '**/internal/**' + exclude '**/test/**' + exclude '**/perf/**' + exclude '**/jmh/**' + exclude 'module-info.java' + } + + // Explicitly disable modularity inference (prevents Gradle adding module flags) + modularity.inferModulePath = false + + classpath = sourceSets.main.runtimeClasspath + sourceSets.main.output + + options { + windowTitle = "RxJava Javadoc ${project.version}" + } + // Clear the following options to make the docs consistent with the old format + options.addStringOption("top").value = "" + options.addStringOption("doctitle").value = "" + options.addStringOption("header").value = "" + options.addBooleanOption('Xdoclint:none', true) // disables all doclint checks (modern JDKs) + failOnError = false - options.stylesheetFile = new File(projectDir, "gradle/stylesheet.css"); - + options.links( - "https://docs.oracle.com/javase/7/docs/api/", - "http://www.reactive-streams.org/reactive-streams-1.0.2-javadoc/", - "http://reactivex.io/RxJava/2.x/javadoc/" + "https://docs.oracle.com/en/java/javase/26/docs/api/", + "https://reactivex.io/RxJava/4.x/javadoc/", + "https://reactivex.io/RxJava/org.reactivestreams.javadoc/${reactiveStreamsVersion}/" ) - + + // modularity.inferModulePath = true // let Gradle handle deps on --module-path } -test { - maxHeapSize = "2g" - testLogging { - events "started", "failed" // "skipped", "passed" - // showStandardStreams = true - exceptionFormat="full" +import aQute.bnd.gradle.Bundle // ← important import + +tasks.register('bundle', Bundle) { + archiveBaseName.set('rxjava') // or archiveFileName = "rxjava-${version}.jar" + archiveVersion.set(project.version) + archiveClassifier.set('') // empty → no classifier + + from sourceSets.main.output // your classes + from('.') { + include 'LICENSE' + include 'COPYRIGHT' + into 'META-INF/' } -} -license { - header rootProject.file('HEADER') - ext.year = Calendar.getInstance().get(Calendar.YEAR) - skipExistingHeaders true - ignoreFailures true - excludes(["**/*.md", "**/*.txt"]) + // Exclude module-info.class from root (you already had this) + exclude 'module-info.class' + + // All your Bnd instructions go here + bundle { + bnd('-fixupmessages': '^Classes found in the wrong directory: \\{META-INF/versions/9/module-info\\.class=module-info\\}$') + + bnd('Bundle-Name': 'rxjava-extensions') + bnd('Bundle-Vendor': 'David Karnok') + bnd('Bundle-Description': 'RxJava 4.x extra sources, operators and components and ports of many older companion libraries.') + bnd('Import-Package': '!org.junit,!junit.framework,!org.mockito.*,!org.testng.*,*') + bnd('Bundle-DocURL': 'https://github.com/akarnokd/RxJavaExtensions') + bnd('Eclipse-ExtensibleAPI': 'true') + bnd('Export-Package': '!hu.akarnokd.rxjava4.internal.*,hu.akarnokd.rxjava4.*') + bnd('Bundle-SymbolicName': 'hu.akarnokd.rxjava4') + bnd('Multi-Release': 'true') + } } -jacoco { - toolVersion = '0.7.7.201606060606' // See http://www.eclemma.org/jacoco/. +def isCI = System.getenv("CI") != null +def testLoggingConfig = ["skipped", "failed"] +def parallelism = Runtime.runtime.availableProcessors() + +if (!isCI) { + testLoggingConfig = ["failed"] + parallelism = parallelism.intdiv(2) ?: 1 } -jacocoTestReport { - reports { - xml.enabled = true - html.enabled = true - } +test { + maxHeapSize = "1200m" + maxParallelForks = parallelism + timeout = Duration.ofMinutes(30) + + useJUnitPlatform() } -build.dependsOn jacocoTestReport +tasks.withType(Test) { + testLogging { + events = testLoggingConfig + exceptionFormat = "full" -check.dependsOn jacocoTestReport + debug.events = testLoggingConfig + debug.exceptionFormat = "full" -pmd { - toolVersion = '5.4.2' - ignoreFailures = true - sourceSets = [sourceSets.main] - ruleSets = [] - ruleSetFiles = files('pmd.xml') -} + info.events = testLoggingConfig + info.exceptionFormat = "full" -pmdMain { - reports { - html.enabled = true - xml.enabled = true + warn.events = testLoggingConfig + warn.exceptionFormat = "full" } } -task pmdPrint(dependsOn: 'pmdMain') << { - File file = rootProject.file('build/reports/pmd/main.xml') - if (file.exists()) { +license { + header rootProject.file('config/license/HEADER') + ext.year = Calendar.getInstance().get(Calendar.YEAR) + skipExistingHeaders true + ignoreFailures true + excludes(["**/*.md", "**/*.txt"]) +} - println("Listing first 100 PMD violations") +apply plugin: "jacoco" - file.eachLine { line, count -> - if (count <= 100) { - println(line) - } - } +jacocoTestReport { + dependsOn test - } else { - println("PMD file not found.") + reports { + xml.required.set(true) + csv.required.set(false) + html.required.set(true) } } -build.dependsOn pmdPrint -check.dependsOn pmdPrint +check.dependsOn jacocoTestReport -animalsniffer { - annotation = 'rx.internal.util.SuppressAnimalSniffer' +checkstyle { + configFile = project.file("config/checkstyle/checkstyle.xml") + configProperties = [ + "checkstyle.suppressions.file": project.file("config/checkstyle/suppressions.xml"), + "checkstyle.header.file" : project.file("config/license/HEADER_JAVA"), + "project_loc" : project.projectDir.absolutePath + ] + checkstyleMain.exclude '**/module-info.java' } + +mavenPublishing { + publishToMavenCentral(true, com.vanniktech.maven.publish.DeploymentValidation.PUBLISHED) + + signAllPublications() +} \ No newline at end of file diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 00000000..51f045af --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 00000000..2152f261 --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/HEADER b/config/license/HEADER similarity index 93% rename from HEADER rename to config/license/HEADER index 47ae1290..5847934d 100644 --- a/HEADER +++ b/config/license/HEADER @@ -1,4 +1,4 @@ -Copyright 2016-${year} David Karnok +Copyright 2016-present David Karnok Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/config/license/HEADER_JAVA b/config/license/HEADER_JAVA new file mode 100644 index 00000000..1d47b265 --- /dev/null +++ b/config/license/HEADER_JAVA @@ -0,0 +1,15 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/gradle.properties b/gradle.properties index 205b489f..bf6a3e5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,22 @@ -version=0.20.10 +GROUP=com.github.akarnokd +VERSION_NAME=4.0.0-alpha-19 +version=4.0.0-alpha-19 + +POM_ARTIFACT_ID=rxjava4-extensions +POM_NAME=RxJava 4 extra sources, operators and components +POM_PACKAGING=jar + +POM_DESCRIPTION=RxJava 3.x extra sources, operators and components and ports of many 1.x companion libraries. +POM_INCEPTION_YEAR=2026 + +POM_URL=https://github.com/akarnokd/RxJavaExtensions +POM_SCM_URL=https://github.com/akarnokd/RxJavaExtensions +POM_SCM_CONNECTION=scm:git:git://github.com/akarnokd/RxJavaExtensions.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/akarnokd/RxJavaExtensions.git + +POM_LICENCE_NAME=The Apache Software License, Version 2.0 +POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_DIST=repo + +POM_DEVELOPER_ID=akarnokd +POM_DEVELOPER_NAME=David Karnok diff --git a/gradle/maven.gradle b/gradle/maven.gradle deleted file mode 100644 index f898ea28..00000000 --- a/gradle/maven.gradle +++ /dev/null @@ -1,69 +0,0 @@ -apply plugin: 'maven' // Java plugin has to have been already applied for the conf2scope mappings to work -apply plugin: 'signing' - -project.status = 'release' - -signing { - required { gradle.taskGraph.hasTask(uploadMavenCentral) } - sign configurations.archives -} - -/** - * Publishing to Maven Central example provided from http://jedicoder.blogspot.com/2011/11/automated-gradle-project-deployment-to.html - * artifactory will execute uploadArchives to force generation of ivy.xml, and we don't want that to trigger an upload to maven - * central, so using custom upload task. - */ -task uploadMavenCentral(type:Upload, dependsOn: signArchives) { - configuration = configurations.archives - onlyIf { ['release', 'snapshot'].contains(project.status) } - repositories.mavenDeployer { - beforeDeployment { signing.signPom(it) } - - // To test deployment locally, use the following instead of oss.sonatype.org - //repository(url: "file://localhost/${rootProject.rootDir}/repo") - - def sonatypeUsername = rootProject.hasProperty('sonatypeUsername')?rootProject.sonatypeUsername:'' - def sonatypePassword = rootProject.hasProperty('sonatypePassword')?rootProject.sonatypePassword:'' - - repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - - snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - - // Prevent datastamp from being appending to artifacts during deployment - uniqueVersion = false - - // Closure to configure all the POM with extra info, common to all projects - pom.project { - name "${project.name}" - description "${project.name} developed by David Karnok" - developers { - developer { - id 'akarnokd' - name 'David Karnok' - email 'akarnokd@gmail.com' - } - } - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - url "https://github.com/akarnokd/${rootProject.githubProjectName}" - scm { - connection "scm:git:git@github.com:akarnokd/${rootProject.githubProjectName}.git" - url "scm:git:git@github.com:akarnokd/${rootProject.githubProjectName}.git" - developerConnection "scm:git:git@github.com:akarnokd/${rootProject.githubProjectName}.git" - } - issueManagement { - system 'github' - url "https://github.com/akarnokd/${rootProject.githubProjectName}/issues" - } - } - } - } diff --git a/gradle/stylesheet.css b/gradle/stylesheet.css deleted file mode 100644 index 60f1d665..00000000 --- a/gradle/stylesheet.css +++ /dev/null @@ -1,573 +0,0 @@ -/* Javadoc style sheet */ -/* -Overall document style -*/ - -@import url('resources/fonts/dejavu.css'); - -body { - background-color:#ffffff; - color:#353833; - font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; - font-size:14px; - margin:0; -} -a:link, a:visited { - text-decoration:none; - color:#4A6782; -} -a:hover, a:focus { - text-decoration:none; - color:#bb7a2a; -} -a:active { - text-decoration:none; - color:#4A6782; -} -a[name] { - color:#353833; -} -a[name]:hover { - text-decoration:none; - color:#353833; -} -pre { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; -} -h1 { - font-size:20px; -} -h2 { - font-size:18px; -} -h3 { - font-size:16px; - font-style:italic; -} -h4 { - font-size:13px; -} -h5 { - font-size:12px; -} -h6 { - font-size:11px; -} -ul { - list-style-type:disc; -} -code, tt { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; - padding-top:4px; - margin-top:8px; - line-height:1.4em; -} -dt code { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; - padding-top:4px; -} -table tr td dt code { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; - vertical-align:top; - padding-top:4px; -} -sup { - font-size:8px; -} -/* -Document title and Copyright styles -*/ -.clear { - clear:both; - height:0px; - overflow:hidden; -} -.aboutLanguage { - float:right; - padding:0px 21px; - font-size:11px; - z-index:200; - margin-top:-9px; -} -.legalCopy { - margin-left:.5em; -} -.bar a, .bar a:link, .bar a:visited, .bar a:active { - color:#FFFFFF; - text-decoration:none; -} -.bar a:hover, .bar a:focus { - color:#bb7a2a; -} -.tab { - background-color:#0066FF; - color:#ffffff; - padding:8px; - width:5em; - font-weight:bold; -} -/* -Navigation bar styles -*/ -.bar { - background-color:#4D7A97; - color:#FFFFFF; - padding:.8em .5em .4em .8em; - height:auto;/*height:1.8em;*/ - font-size:11px; - margin:0; -} -.topNav { - background-color:#4D7A97; - color:#FFFFFF; - float:left; - padding:0; - width:100%; - clear:right; - height:2.8em; - padding-top:10px; - overflow:hidden; - font-size:12px; -} -.bottomNav { - margin-top:10px; - background-color:#4D7A97; - color:#FFFFFF; - float:left; - padding:0; - width:100%; - clear:right; - height:2.8em; - padding-top:10px; - overflow:hidden; - font-size:12px; -} -.subNav { - background-color:#dee3e9; - float:left; - width:100%; - overflow:hidden; - font-size:12px; -} -.subNav div { - clear:left; - float:left; - padding:0 0 5px 6px; - text-transform:uppercase; -} -ul.navList, ul.subNavList { - float:left; - margin:0 25px 0 0; - padding:0; -} -ul.navList li{ - list-style:none; - float:left; - padding: 5px 6px; - text-transform:uppercase; -} -ul.subNavList li{ - list-style:none; - float:left; -} -.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { - color:#FFFFFF; - text-decoration:none; - text-transform:uppercase; -} -.topNav a:hover, .bottomNav a:hover { - text-decoration:none; - color:#bb7a2a; - text-transform:uppercase; -} -.navBarCell1Rev { - background-color:#F8981D; - color:#253441; - margin: auto 5px; -} -.skipNav { - position:absolute; - top:auto; - left:-9999px; - overflow:hidden; -} -/* -Page header and footer styles -*/ -.header, .footer { - clear:both; - margin:0 20px; - padding:5px 0 0 0; -} -.indexHeader { - margin:10px; - position:relative; -} -.indexHeader span{ - margin-right:15px; -} -.indexHeader h1 { - font-size:13px; -} -.title { - color:#2c4557; - margin:10px 0; -} -.subTitle { - margin:5px 0 0 0; -} -.header ul { - margin:0 0 15px 0; - padding:0; -} -.footer ul { - margin:20px 0 5px 0; -} -.header ul li, .footer ul li { - list-style:none; - font-size:13px; -} -/* -Heading styles -*/ -div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { - background-color:#dee3e9; - border:1px solid #d0d9e0; - margin:0 0 6px -8px; - padding:7px 5px; -} -ul.blockList ul.blockList ul.blockList li.blockList h3 { - background-color:#dee3e9; - border:1px solid #d0d9e0; - margin:0 0 6px -8px; - padding:7px 5px; -} -ul.blockList ul.blockList li.blockList h3 { - padding:0; - margin:15px 0; -} -ul.blockList li.blockList h2 { - padding:0px 0 20px 0; -} -/* -Page layout container styles -*/ -.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { - clear:both; - padding:10px 20px; - position:relative; -} -.indexContainer { - margin:10px; - position:relative; - font-size:12px; -} -.indexContainer h2 { - font-size:13px; - padding:0 0 3px 0; -} -.indexContainer ul { - margin:0; - padding:0; -} -.indexContainer ul li { - list-style:none; - padding-top:2px; -} -.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { - font-size:12px; - font-weight:bold; - margin:10px 0 0 0; - color:#4E4E4E; -} -.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { - /* margin:5px 0 10px 0px; */ - font-size:14px; - font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; -} -.serializedFormContainer dl.nameValue dt { - margin-left:1px; - font-size:1.1em; - display:inline; - font-weight:bold; -} -.serializedFormContainer dl.nameValue dd { - margin:0 0 0 1px; - font-size:1.1em; - display:inline; -} -/* -List styles -*/ -ul.horizontal li { - display:inline; - font-size:0.9em; -} -ul.inheritance { - margin:0; - padding:0; -} -ul.inheritance li { - display:inline; - list-style:none; -} -ul.inheritance li ul.inheritance { - margin-left:15px; - padding-left:15px; - padding-top:1px; -} -ul.blockList, ul.blockListLast { - margin:10px 0 10px 0; - padding:0; -} -ul.blockList li.blockList, ul.blockListLast li.blockList { - list-style:none; - margin-bottom:15px; - line-height:1.4; -} -ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { - padding:0px 20px 5px 10px; - border:1px solid #ededed; - background-color:#f8f8f8; -} -ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { - padding:0 0 5px 8px; - background-color:#ffffff; - border:none; -} -ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { - margin-left:0; - padding-left:0; - padding-bottom:15px; - border:none; -} -ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { - list-style:none; - border-bottom:none; - padding-bottom:0; -} -table tr td dl, table tr td dl dt, table tr td dl dd { - margin-top:0; - margin-bottom:1px; -} -/* -Table styles -*/ -.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { - width:100%; - border-left:1px solid #EEE; - border-right:1px solid #EEE; - border-bottom:1px solid #EEE; -} -.overviewSummary, .memberSummary { - padding:0px; -} -.overviewSummary caption, .memberSummary caption, .typeSummary caption, -.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { - position:relative; - text-align:left; - background-repeat:no-repeat; - color:#253441; - font-weight:bold; - clear:none; - overflow:hidden; - padding:0px; - padding-top:10px; - padding-left:1px; - margin:0px; - white-space:pre; -} -.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, -.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, -.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, -.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, -.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, -.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, -.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, -.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { - color:#FFFFFF; -} -.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, -.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { - white-space:nowrap; - padding-top:5px; - padding-left:12px; - padding-right:12px; - padding-bottom:7px; - display:inline-block; - float:left; - background-color:#F8981D; - border: none; - height:16px; -} -.memberSummary caption span.activeTableTab span { - white-space:nowrap; - padding-top:5px; - padding-left:12px; - padding-right:12px; - margin-right:3px; - display:inline-block; - float:left; - background-color:#F8981D; - height:16px; -} -.memberSummary caption span.tableTab span { - white-space:nowrap; - padding-top:5px; - padding-left:12px; - padding-right:12px; - margin-right:3px; - display:inline-block; - float:left; - background-color:#4D7A97; - height:16px; -} -.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { - padding-top:0px; - padding-left:0px; - padding-right:0px; - background-image:none; - float:none; - display:inline; -} -.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, -.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { - display:none; - width:5px; - position:relative; - float:left; - background-color:#F8981D; -} -.memberSummary .activeTableTab .tabEnd { - display:none; - width:5px; - margin-right:3px; - position:relative; - float:left; - background-color:#F8981D; -} -.memberSummary .tableTab .tabEnd { - display:none; - width:5px; - margin-right:3px; - position:relative; - background-color:#4D7A97; - float:left; - -} -.overviewSummary td, .memberSummary td, .typeSummary td, -.useSummary td, .constantsSummary td, .deprecatedSummary td { - text-align:left; - padding:0px 0px 12px 10px; -} -th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, -td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ - vertical-align:top; - padding-right:0px; - padding-top:8px; - padding-bottom:3px; -} -th.colFirst, th.colLast, th.colOne, .constantsSummary th { - background:#dee3e9; - text-align:left; - padding:8px 3px 3px 7px; -} -td.colFirst, th.colFirst { - white-space:nowrap; - font-size:13px; -} -td.colLast, th.colLast { - font-size:13px; -} -td.colOne, th.colOne { - font-size:13px; -} -.overviewSummary td.colFirst, .overviewSummary th.colFirst, -.useSummary td.colFirst, .useSummary th.colFirst, -.overviewSummary td.colOne, .overviewSummary th.colOne, -.memberSummary td.colFirst, .memberSummary th.colFirst, -.memberSummary td.colOne, .memberSummary th.colOne, -.typeSummary td.colFirst{ - width:25%; - vertical-align:top; -} -td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { - font-weight:bold; -} -.tableSubHeadingColor { - background-color:#EEEEFF; -} -.altColor { - background-color:#FFFFFF; -} -.rowColor { - background-color:#EEEEEF; -} -/* -Content styles -*/ -.description pre { - margin-top:0; -} -.deprecatedContent { - margin:0; - padding:10px 0; -} -.docSummary { - padding:0; -} - -ul.blockList ul.blockList ul.blockList li.blockList h3 { - font-style:normal; -} - -div.block { - font-size:14px; - font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; -} - -td.colLast div { - padding-top:0px; -} - -td.colLast a { - padding-bottom:3px; -} -/* -Formatting effect styles -*/ -.sourceLineNo { - color:green; - padding:0 30px 0 0; -} -h1.hidden { - visibility:hidden; - overflow:hidden; - font-size:10px; -} -.block { - display:block; - margin:3px 10px 2px 0px; - color:#474747; -} -.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, -.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, -.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { - font-weight:bold; -} -.deprecationComment, .emphasizedPhrase, .interfaceName { - font-style:italic; -} - -div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, -div.block div.block span.interfaceName { - font-style:normal; -} - -div.contentContainer ul.blockList li.blockList h2{ - padding-bottom:0px; -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d3b83982..9fa7f288 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4a33c5b4..2e7bb9fd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,9 @@ -#Tue Jul 05 21:36:15 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.1-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip diff --git a/gradlew b/gradlew index 27309d92..249efbb0 100644 --- a/gradlew +++ b/gradlew @@ -1,78 +1,128 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# gradlew start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh gradlew +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,84 +131,118 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 832fdb60..03754c4c 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,90 +1,112 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem gradlew startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +@rem Catch executions from older scripts and ensure they exit cleanly. +@rem This can be removed once we can be reasonably confident that few people +@rem will be migrating directly to this new wrapper. +goto afterSafetyNet +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +goto exitWithErrorLevel +:afterSafetyNet + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +1>&2 echo. +1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +1>&2 echo. +1>&2 echo Please set the JAVA_HOME variable in your environment to match the +1>&2 echo location of your Java installation. + +"%COMSPEC%" /c exit 1 +goto exitWithErrorLevel + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +1>&2 echo. +1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +1>&2 echo. +1>&2 echo Please set the JAVA_HOME variable in your environment to match the +1>&2 echo location of your Java installation. + +"%COMSPEC%" /c exit 1 +goto exitWithErrorLevel + +:execute +@rem Setup the command line + + + +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel + +@rem This label must not be changed. We rely on old scripts being able to jump to this point. +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/push.sh b/push.sh index efca7b5e..63f398df 100644 --- a/push.sh +++ b/push.sh @@ -9,24 +9,23 @@ targetRepo=github.com/akarnokd/RxJavaExtensions.git # ======================================================================= # only for main pushes, for now -# if [ "$TRAVIS_PULL_REQUEST" == "true" ] || [ "$TRAVIS_TAG" == "" ]; then -if [ "$TRAVIS_PULL_REQUEST" == "true" ]; then +if [ "$CI_PULL_REQUEST" == "true" ]; then echo -e "Pull request detected, skipping JavaDocs pushback." exit 0 fi # check if the token is actually there -if [ "$GITHUB_TOKEN" == "" ]; then +if [ "$JAVADOCS_TOKEN" == "" ]; then echo -e "No access to GitHub, skipping JavaDocs pushback." exit 0 fi # prepare the git information -git config --global user.email "travis@travis-ci.org" -git config --global user.name "Travis CI" +git config --global user.email "akarnokd@gmail.com" +git config --global user.name "akarnokd" # setup the remote -git remote add origin-pages https://${GITHUB_TOKEN}@${targetRepo} > /dev/null 2>&1 +git remote add origin-pages https://${JAVADOCS_TOKEN}@${targetRepo} > /dev/null 2>&1 # stash changes due to chmod git stash @@ -39,6 +38,7 @@ git checkout -b gh-pages origin-pages/gh-pages # remove old dir rm -rf javadoc +ls ./build # copy and overwrite new doc yes | cp -rfv ./build/docs/javadoc/ javadoc/ @@ -49,7 +49,7 @@ git add *.js git add javadoc/package-list # commit all -git commit --message "Travis build: $TRAVIS_BUILD_NUMBER" +git commit --message "CI build: $CI_BUILD_NUMBER" # push it diff --git a/settings.gradle b/settings.gradle index 19d10c69..fc42e62b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'rxjava-extensions' +rootProject.name = 'rxjava4-extensions' diff --git a/src/jmh/java/hu/akarnokd/rxjava2/ExamplePerf.java b/src/jmh/java/hu/akarnokd/rxjava4/ExamplePerf.java similarity index 90% rename from src/jmh/java/hu/akarnokd/rxjava2/ExamplePerf.java rename to src/jmh/java/hu/akarnokd/rxjava4/ExamplePerf.java index 7bca5dbf..85fc6eb2 100644 --- a/src/jmh/java/hu/akarnokd/rxjava2/ExamplePerf.java +++ b/src/jmh/java/hu/akarnokd/rxjava4/ExamplePerf.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2; +package hu.akarnokd.rxjava4; import java.util.concurrent.TimeUnit; @@ -36,6 +36,9 @@ public class ExamplePerf { @Param({"1", "10", "100", "1000", "10000", "100000", "1000000"}) public int count; + /** + * Insert setup code here. + */ @Setup public void setup() { diff --git a/src/jmh/java/hu/akarnokd/rxjava2/FlatMapExPerf.java b/src/jmh/java/hu/akarnokd/rxjava4/FlatMapExPerf.java similarity index 86% rename from src/jmh/java/hu/akarnokd/rxjava2/FlatMapExPerf.java rename to src/jmh/java/hu/akarnokd/rxjava4/FlatMapExPerf.java index 119234cf..8177bf27 100644 --- a/src/jmh/java/hu/akarnokd/rxjava2/FlatMapExPerf.java +++ b/src/jmh/java/hu/akarnokd/rxjava4/FlatMapExPerf.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2; +package hu.akarnokd.rxjava4; import java.util.Arrays; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import org.reactivestreams.Publisher; -import hu.akarnokd.rxjava2.operators.FlowableTransformers; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.operators.FlowableTransformers; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.core.config.StandardConcurrentBufferedConfig; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.schedulers.Schedulers; /** * Example benchmark. Run from command line as @@ -71,6 +72,9 @@ public class FlatMapExPerf { Flowable asyncAsyncB; + /** + * Prepare fields. + */ @Setup public void setup() { Integer[] array = new Integer[count]; @@ -95,13 +99,13 @@ public Publisher apply(Integer v) throws Exception { } }; - standardSync = source.flatMap(f1, 32); + standardSync = source.flatMap(f1, new StandardConcurrentBufferedConfig(32)); - standardAsync = source.flatMap(f2, 32); + standardAsync = source.flatMap(f2, new StandardConcurrentBufferedConfig(32)); - observeOnSync = source.flatMap(f1, 32).observeOn(Schedulers.single()); + observeOnSync = source.flatMap(f1, new StandardConcurrentBufferedConfig(32)).observeOn(Schedulers.single()); - observeOnAsync = source.flatMap(f2, 32).observeOn(Schedulers.single()); + observeOnAsync = source.flatMap(f2, new StandardConcurrentBufferedConfig(32)).observeOn(Schedulers.single()); syncSync = source.compose(FlowableTransformers.flatMapSync(f1)); diff --git a/src/jmh/java/hu/akarnokd/rxjava2/PerfAsyncConsumer.java b/src/jmh/java/hu/akarnokd/rxjava4/PerfAsyncConsumer.java similarity index 85% rename from src/jmh/java/hu/akarnokd/rxjava2/PerfAsyncConsumer.java rename to src/jmh/java/hu/akarnokd/rxjava4/PerfAsyncConsumer.java index 66641863..128cb918 100644 --- a/src/jmh/java/hu/akarnokd/rxjava2/PerfAsyncConsumer.java +++ b/src/jmh/java/hu/akarnokd/rxjava4/PerfAsyncConsumer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2; +package hu.akarnokd.rxjava4; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; import org.openjdk.jmh.infra.Blackhole; -import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; public final class PerfAsyncConsumer extends CountDownLatch @@ -69,6 +69,10 @@ public void onComplete() { countDown(); } + /** + * Wait either via spinning or sleeping. + * @param count how much value is expected to be received + */ public void await(long count) { if (count <= 1000) { while (getCount() != 0) { } diff --git a/src/jmh/java/hu/akarnokd/rxjava2/PerfConsumer.java b/src/jmh/java/hu/akarnokd/rxjava4/PerfConsumer.java similarity index 87% rename from src/jmh/java/hu/akarnokd/rxjava2/PerfConsumer.java rename to src/jmh/java/hu/akarnokd/rxjava4/PerfConsumer.java index b5adf169..d5c519ba 100644 --- a/src/jmh/java/hu/akarnokd/rxjava2/PerfConsumer.java +++ b/src/jmh/java/hu/akarnokd/rxjava4/PerfConsumer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2; +package hu.akarnokd.rxjava4; + +import java.util.concurrent.Flow.*; import org.openjdk.jmh.infra.Blackhole; -import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; public final class PerfConsumer implements Subscriber, Observer, SingleObserver, MaybeObserver, CompletableObserver { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDoFinally.java b/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDoFinally.java deleted file mode 100644 index 32dcea5a..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDoFinally.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.basetypes; - -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.SoloDoFinally.DoFinallySubscriber; -import io.reactivex.functions.Action; - -/** - * Execute an action exactly once after the upstream terminates or the - * downstream cancels. - * @param the input and output element type - */ -final class PerhapsDoFinally extends Perhaps { - - final Perhaps source; - - final Action onFinally; - - PerhapsDoFinally(Perhaps source, Action onFinally) { - this.source = source; - this.onFinally = onFinally; - } - - @Override - protected void subscribeActual(Subscriber s) { - source.subscribe(new DoFinallySubscriber(s, onFinally)); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsSubscribeOn.java b/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsSubscribeOn.java deleted file mode 100644 index 53d4f23c..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsSubscribeOn.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.basetypes; - -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.SoloSubscribeOn.SubscribeOnSubscriber; -import io.reactivex.Scheduler; -import io.reactivex.Scheduler.Worker; -import io.reactivex.internal.disposables.DisposableHelper; - -/** - * Subscribe to the upstream on the specified scheduler. - * - * @param the value type - */ -final class PerhapsSubscribeOn extends Perhaps { - - final Perhaps source; - - final Scheduler scheduler; - - PerhapsSubscribeOn(Perhaps source, Scheduler scheduler) { - this.source = source; - this.scheduler = scheduler; - } - - @Override - protected void subscribeActual(Subscriber s) { - Worker worker = scheduler.createWorker(); - - SubscribeOnSubscriber parent = new SubscribeOnSubscriber(s, worker, source); - s.onSubscribe(parent); - - DisposableHelper.replace(parent.task, worker.schedule(parent)); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTimer.java b/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTimer.java deleted file mode 100644 index 4377eb93..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTimer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.basetypes; - -import java.util.concurrent.TimeUnit; - -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.SoloTimer.TimerSubscriber; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; - -/** - * Signal a 0L after the specified time delay. - */ -final class PerhapsTimer extends Perhaps { - - final long delay; - - final TimeUnit unit; - - final Scheduler scheduler; - - PerhapsTimer(long delay, TimeUnit unit, Scheduler scheduler) { - this.delay = delay; - this.unit = unit; - this.scheduler = scheduler; - } - - @Override - protected void subscribeActual(Subscriber s) { - TimerSubscriber parent = new TimerSubscriber(s); - s.onSubscribe(parent); - - Disposable d = scheduler.scheduleDirect(parent, delay, unit); - DisposableHelper.replace(parent.task, d); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsUsing.java b/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsUsing.java deleted file mode 100644 index b5e55ec8..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsUsing.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.basetypes; - -import java.util.concurrent.Callable; - -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.SoloUsing.UsingSubscriber; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * Use a resource while the actual Perhaps is running. - * @param the element type of the supplied Perhaps - * @param the resource type - */ -final class PerhapsUsing extends Perhaps { - - final Callable resourceSupplier; - - final Function> sourceSupplier; - - final Consumer disposer; - - final boolean eager; - - PerhapsUsing(Callable resourceSupplier, - Function> sourceSupplier, - Consumer disposer, boolean eager) { - this.resourceSupplier = resourceSupplier; - this.sourceSupplier = sourceSupplier; - this.disposer = disposer; - this.eager = eager; - } - - @Override - protected void subscribeActual(Subscriber s) { - R resource; - - try { - resource = resourceSupplier.call(); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - EmptySubscription.error(ex, s); - return; - } - - Perhaps np; - - try { - np = ObjectHelper.requireNonNull(sourceSupplier.apply(resource), "The sourceSupplier returned a null Nono"); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - if (eager) { - try { - disposer.accept(resource); - } catch (Throwable exc) { - Exceptions.throwIfFatal(exc); - ex = new CompositeException(ex, exc); - } - - EmptySubscription.error(ex, s); - } else { - EmptySubscription.error(ex, s); - try { - disposer.accept(resource); - } catch (Throwable exc) { - Exceptions.throwIfFatal(exc); - RxJavaPlugins.onError(exc); - } - } - return; - } - - np.subscribe(new UsingSubscriber(s, resource, disposer, eager)); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyConnectableResettable.java b/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyConnectableResettable.java deleted file mode 100644 index 1a8e4d94..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyConnectableResettable.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.debug; - -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.debug.FlowableOnAssembly.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.flowables.ConnectableFlowable; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.disposables.ResettableConnectable; -import io.reactivex.internal.fuseable.ConditionalSubscriber; - -/** - * Wraps a Publisher and inject the assembly info. - * - * @param the value type - */ -final class FlowableOnAssemblyConnectableResettable extends ConnectableFlowable -implements ResettableConnectable { - - final ConnectableFlowable source; - - final RxJavaAssemblyException assembled; - - FlowableOnAssemblyConnectableResettable(ConnectableFlowable source) { - this.source = source; - this.assembled = new RxJavaAssemblyException(); - } - - @Override - protected void subscribeActual(Subscriber s) { - if (s instanceof ConditionalSubscriber) { - source.subscribe(new OnAssemblyConditionalSubscriber((ConditionalSubscriber)s, assembled)); - } else { - source.subscribe(new OnAssemblySubscriber(s, assembled)); - } - } - - @Override - public void connect(Consumer connection) { - source.connect(connection); - } - - @Override - public void resetIf(Disposable connection) { - ((ResettableConnectable)source).resetIf(connection); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyConnectableResettable.java b/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyConnectableResettable.java deleted file mode 100644 index 44f91bfb..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyConnectableResettable.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.debug; - -import hu.akarnokd.rxjava2.debug.ObservableOnAssembly.OnAssemblyObserver; -import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.disposables.ResettableConnectable; -import io.reactivex.observables.ConnectableObservable; - -/** - * Wraps a ObservableSource and inject the assembly info. - * - * @param the value type - */ -final class ObservableOnAssemblyConnectableResettable extends ConnectableObservable -implements ResettableConnectable { - - final ConnectableObservable source; - - final RxJavaAssemblyException assembled; - - ObservableOnAssemblyConnectableResettable(ConnectableObservable source) { - this.source = source; - this.assembled = new RxJavaAssemblyException(); - } - - @Override - protected void subscribeActual(Observer observer) { - source.subscribe(new OnAssemblyObserver(observer, assembled)); - } - - @Override - public void connect(Consumer connection) { - source.connect(connection); - } - - @Override - public void resetIf(Disposable connection) { - ((ResettableConnectable)source).resetIf(connection); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer3.java b/src/main/java/hu/akarnokd/rxjava2/functions/Consumer3.java deleted file mode 100644 index 1dff87e9..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer3.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.functions; - -/** - * Functional interface for a callback that consumes multipe values at the same - * and may throw a checked exception. - * - * @param the first value type - * @param the second value type - * @param the third value type - */ -public interface Consumer3 { - - /** - * Consum the input parameters. - * @param t1 the first parameter - * @param t2 the second parameter - * @param t3 the third parameter - * @throws Exception on error - */ - void accept(T1 t1, T2 t2, T3 t3) throws Exception; -} diff --git a/src/main/java/hu/akarnokd/rxjava2/math/MathFlowable.java b/src/main/java/hu/akarnokd/rxjava2/math/MathFlowable.java deleted file mode 100644 index 804113aa..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/math/MathFlowable.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.math; - -import java.util.Comparator; - -import org.reactivestreams.Publisher; - -import hu.akarnokd.rxjava2.util.SelfComparator; -import io.reactivex.Flowable; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * Utility methods to work with numerical Flowable sources: sum, min, max and average. - */ -public final class MathFlowable { - /** Utility class. */ - private MathFlowable() { - throw new IllegalStateException("No instances!"); - } - - public static Flowable sumInt(Publisher source) { - return RxJavaPlugins.onAssembly(new FlowableSumInt(source)); - } - - public static Flowable sumLong(Publisher source) { - return RxJavaPlugins.onAssembly(new FlowableSumLong(source)); - } - - public static Flowable sumFloat(Publisher source) { - return RxJavaPlugins.onAssembly(new FlowableSumFloat(source)); - } - - public static Flowable sumDouble(Publisher source) { - return RxJavaPlugins.onAssembly(new FlowableSumDouble(source)); - } - - public static > Flowable max(Publisher source) { - Comparator comp = SelfComparator.instance(); - return max(source, comp); - } - - public static Flowable max(Publisher source, Comparator comparator) { - return RxJavaPlugins.onAssembly(new FlowableMinMax(source, comparator, -1)); - } - - public static > Flowable min(Publisher source) { - Comparator comp = SelfComparator.instance(); - return min(source, comp); - } - - public static Flowable min(Publisher source, Comparator comparator) { - return RxJavaPlugins.onAssembly(new FlowableMinMax(source, comparator, 1)); - } - - @SuppressWarnings("unchecked") - public static Flowable averageFloat(Publisher source) { - return RxJavaPlugins.onAssembly(new FlowableAverageFloat((Publisher)source)); - } - - @SuppressWarnings("unchecked") - public static Flowable averageDouble(Publisher source) { - return RxJavaPlugins.onAssembly(new FlowableAverageDouble((Publisher)source)); - } - -} diff --git a/src/main/java/hu/akarnokd/rxjava2/math/MathObservable.java b/src/main/java/hu/akarnokd/rxjava2/math/MathObservable.java deleted file mode 100644 index 98beb15c..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/math/MathObservable.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.math; - -import java.util.Comparator; - -import hu.akarnokd.rxjava2.util.SelfComparator; -import io.reactivex.*; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * Utility methods to work with numerical Observable sources: sum, min, max and average. - */ -public final class MathObservable { - /** Utility class. */ - private MathObservable() { - throw new IllegalStateException("No instances!"); - } - - public static Observable sumInt(ObservableSource source) { - return RxJavaPlugins.onAssembly(new ObservableSumInt(source)); - } - - public static Observable sumLong(ObservableSource source) { - return RxJavaPlugins.onAssembly(new ObservableSumLong(source)); - } - - public static Observable sumFloat(ObservableSource source) { - return RxJavaPlugins.onAssembly(new ObservableSumFloat(source)); - } - - public static Observable sumDouble(ObservableSource source) { - return RxJavaPlugins.onAssembly(new ObservableSumDouble(source)); - } - - public static > Observable max(ObservableSource source) { - Comparator comp = SelfComparator.instance(); - return max(source, comp); - } - - public static Observable max(ObservableSource source, Comparator comparator) { - return RxJavaPlugins.onAssembly(new ObservableMinMax(source, comparator, -1)); - } - - public static > Observable min(ObservableSource source) { - Comparator comp = SelfComparator.instance(); - return min(source, comp); - } - - public static Observable min(ObservableSource source, Comparator comparator) { - return RxJavaPlugins.onAssembly(new ObservableMinMax(source, comparator, 1)); - } - - @SuppressWarnings("unchecked") - public static Observable averageFloat(ObservableSource source) { - return RxJavaPlugins.onAssembly(new ObservableAverageFloat((ObservableSource)source)); - } - - @SuppressWarnings("unchecked") - public static Observable averageDouble(ObservableSource source) { - return RxJavaPlugins.onAssembly(new ObservableAverageDouble((ObservableSource)source)); - } - -} diff --git a/src/main/java/hu/akarnokd/rxjava2/schedulers/BlockingScheduler.java b/src/main/java/hu/akarnokd/rxjava2/schedulers/BlockingScheduler.java deleted file mode 100644 index 91c84258..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/schedulers/BlockingScheduler.java +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.schedulers; - -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; -import java.util.concurrent.locks.*; - -import io.reactivex.Scheduler; -import io.reactivex.disposables.*; -import io.reactivex.functions.Action; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.functions.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; - -/** - * A Scheduler that uses the current thread, in an event-loop and - * blocking fashion to execute actions. - *

- * Use the {@link #execute()} to start waiting for tasks (from other - * threads) or {@link #execute(Action)} to start with a first action. - *


- * public static void main(String[] args) {
- *     BlockingScheduler scheduler = new BlockingScheduler();
- *     scheduler.execute(() -> {
- *         // This executes in the blocking event loop.
- *         // Usually the rest of the "main" method should
- *         // be moved here.
- *
- *         someApi.methodCall()
- *           .subscribeOn(Schedulers.io())
- *           .observeOn(scheduler)
- *           .subscribe(v -> { /* on the main thread */ });
- *     });
- * }
- * 
- * - * In the example code above, {@code observeOn(scheduler)} will execute - * on the main thread of the Java application. - * - * @since 0.15.1 - */ -public final class BlockingScheduler extends Scheduler { - - static final Action SHUTDOWN = new Action() { - @Override - public void run() throws Exception { - // deliberately no-op - } - }; - - static final int SPIN_LIMIT = 64; - - final ConcurrentLinkedQueue queue; - - final AtomicLong wip; - - final Lock lock; - - final Condition condition; - - final AtomicBoolean running; - - final AtomicBoolean shutdown; - - final Scheduler timedHelper; - - volatile Thread thread; - - public BlockingScheduler() { - this.queue = new ConcurrentLinkedQueue(); - this.lock = new ReentrantLock(); - this.condition = this.lock.newCondition(); - this.running = new AtomicBoolean(); - this.shutdown = new AtomicBoolean(); - this.wip = new AtomicLong(); - this.timedHelper = Schedulers.single(); - } - - /** - * Begin executing the blocking event loop without any initial action. - *

- * This method will block until the {@link #shutdown()} is invoked. - * @see #execute(Action) - */ - public void execute() { - execute(Functions.EMPTY_ACTION); - } - - /** - * Begin executing the blocking event loop with the given initial action - * (usually contain the rest of the 'main' method). - *

- * This method will block until the {@link #shutdown()} is invoked. - * @param action the action to execute - */ - public void execute(Action action) { - ObjectHelper.requireNonNull(action, "action is null"); - if (!running.get() && running.compareAndSet(false, true)) { - thread = Thread.currentThread(); - queue.offer(action); - wip.getAndIncrement(); - drainLoop(); - } - } - - void drainLoop() { - final AtomicBoolean stop = shutdown; - final AtomicLong wip = this.wip; - - for (;;) { - if (stop.get()) { - cancelAll(); - return; - } - do { - Action a = queue.poll(); - if (a == SHUTDOWN) { - cancelAll(); - return; - } - try { - a.run(); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - } - } while (wip.decrementAndGet() != 0); - - if (wip.get() == 0 && !stop.get()) { - lock.lock(); - try { - while (wip.get() == 0 && !stop.get()) { - condition.await(); - } - } catch (InterruptedException ex) { - // deliberately ignored - } finally { - lock.unlock(); - } - } - } - } - - void cancelAll() { - final ConcurrentLinkedQueue q = queue; - - Action a; - - while ((a = q.poll()) != null) { - if (a instanceof Disposable) { - ((Disposable)a).dispose(); - } - } - } - - @Override - public Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit) { - ObjectHelper.requireNonNull(run, "run is null"); - ObjectHelper.requireNonNull(unit, "unit is null"); - if (shutdown.get()) { - return Disposables.disposed(); - } - - final BlockingDirectTask task = new BlockingDirectTask(run); - - if (delay == 0L) { - enqueue(task); - return task; - } - - SequentialDisposable inner = new SequentialDisposable(); - final SequentialDisposable outer = new SequentialDisposable(inner); - - Disposable d = timedHelper.scheduleDirect(new Runnable() { - @Override - public void run() { - outer.replace(task); - enqueue(task); - } - }, delay, unit); - - if (d == Disposables.disposed()) { - return d; - } - - inner.replace(d); - - return outer; - } - - @Override - public void shutdown() { - if (shutdown.compareAndSet(false, true)) { - enqueue(SHUTDOWN); - } - } - - void enqueue(Action action) { - queue.offer(action); - if (wip.getAndIncrement() == 0L) { - lock.lock(); - try { - condition.signal(); - } finally { - lock.unlock(); - } - } - } - - @Override - public Worker createWorker() { - return new BlockingWorker(); - } - - static final int READY = 0; - static final int RUNNING = 1; - static final int INTERRUPTING = 2; - static final int INTERRUPTED = 3; - static final int FINISHED = 4; - static final int CANCELLED = 5; - - final class BlockingDirectTask - extends AtomicInteger - implements Action, Disposable { - - private static final long serialVersionUID = -9165914884456950194L; - final Runnable task; - - BlockingDirectTask(Runnable task) { - this.task = task; - } - - @Override - public void run() throws Exception { - try { - if (compareAndSet(READY, RUNNING)) { - try { - task.run(); - } finally { - compareAndSet(RUNNING, FINISHED); - } - } - } finally { - while (get() == INTERRUPTING) { } - - if (get() == INTERRUPTED) { - Thread.interrupted(); - } - } - } - - @Override - public void dispose() { - for (;;) { - int s = get(); - if (s >= INTERRUPTING) { - break; - } - - if (s == READY && compareAndSet(READY, CANCELLED)) { - break; - } - if (compareAndSet(RUNNING, INTERRUPTING)) { - Thread t = thread; - if (t != null) { - t.interrupt(); - } - set(INTERRUPTED); - break; - } - } - } - - @Override - public boolean isDisposed() { - return get() >= INTERRUPTING; - } - } - - final class BlockingWorker extends Worker { - - final CompositeDisposable tasks; - - BlockingWorker() { - this.tasks = new CompositeDisposable(); - } - - @Override - public void dispose() { - tasks.dispose(); - } - - @Override - public boolean isDisposed() { - return tasks.isDisposed(); - } - - @Override - public Disposable schedule(Runnable run, long delay, TimeUnit unit) { - ObjectHelper.requireNonNull(run, "run is null"); - ObjectHelper.requireNonNull(unit, "unit is null"); - - if (shutdown.get() || isDisposed()) { - return Disposables.disposed(); - } - - final BlockingTask task = new BlockingTask(run); - tasks.add(task); - - if (delay == 0L) { - enqueue(task); - return task; - } - - SequentialDisposable inner = new SequentialDisposable(); - final SequentialDisposable outer = new SequentialDisposable(inner); - - Disposable d = timedHelper.scheduleDirect(new Runnable() { - @Override - public void run() { - outer.replace(task); - enqueue(task); - } - }, delay, unit); - - if (d == Disposables.disposed()) { - return d; - } - - inner.replace(d); - - return outer; - } - - final class BlockingTask - extends AtomicInteger - implements Action, Disposable { - - private static final long serialVersionUID = -9165914884456950194L; - - final Runnable task; - - BlockingTask(Runnable task) { - this.task = task; - } - - @Override - public void run() throws Exception { - try { - if (compareAndSet(READY, RUNNING)) { - try { - task.run(); - } finally { - compareAndSet(RUNNING, FINISHED); - tasks.remove(this); - } - } - } finally { - while (get() == INTERRUPTING) { } - - if (get() == INTERRUPTED) { - Thread.interrupted(); - } - } - } - - @Override - public void dispose() { - for (;;) { - int s = get(); - if (s >= INTERRUPTING) { - return; - } - - if (s == READY && compareAndSet(READY, CANCELLED)) { - break; - } - if (compareAndSet(RUNNING, INTERRUPTING)) { - Thread t = thread; - if (t != null) { - t.interrupt(); - } - set(INTERRUPTED); - break; - } - } - tasks.remove(this); - } - - @Override - public boolean isDisposed() { - return get() >= INTERRUPTING; - } - } - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/schedulers/ParallelScheduler.java b/src/main/java/hu/akarnokd/rxjava2/schedulers/ParallelScheduler.java deleted file mode 100644 index 9b345bbe..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/schedulers/ParallelScheduler.java +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.schedulers; - -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicReference; - -import io.reactivex.Scheduler; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.disposables.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.schedulers.RxThreadFactory; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * Scheduler with a configurable fixed amount of thread-pools. - */ -public final class ParallelScheduler extends Scheduler { - - static final ScheduledExecutorService[] SHUTDOWN; - - static final ScheduledExecutorService REJECTING; - - final ThreadFactory factory; - - final int parallelism; - - final boolean tracking; - - final AtomicReference pool; - - int n; - - static { - SHUTDOWN = new ScheduledExecutorService[0]; - - REJECTING = Executors.newSingleThreadScheduledExecutor(); - REJECTING.shutdownNow(); - } - - public ParallelScheduler() { - this(Runtime.getRuntime().availableProcessors()); - } - - public ParallelScheduler(String threadNamePrefix) { - this(Runtime.getRuntime().availableProcessors(), new RxThreadFactory(threadNamePrefix)); - } - - public ParallelScheduler(int parallelism) { - this(parallelism, true); - } - - public ParallelScheduler(int parallelism, boolean tracking) { - this(parallelism, tracking, Thread.NORM_PRIORITY); - } - - public ParallelScheduler(int parallelism, boolean tracking, int priority) { - this(parallelism, tracking, priority, "RxParallelScheduler"); - } - - public ParallelScheduler(int parallelism, boolean tracking, int priority, String threadNamePrefix) { - this(parallelism, new RxThreadFactory(threadNamePrefix, checkPriority(priority)), tracking); - } - - static int checkPriority(int priority) { - if (priority < Thread.MIN_PRIORITY || priority > Thread.MAX_PRIORITY) { - throw new IllegalArgumentException("priority out of range"); - } - return priority; - } - - public ParallelScheduler(int parallelism, ThreadFactory factory) { - this(parallelism, factory, true); - } - - public ParallelScheduler(int parallelism, ThreadFactory factory, boolean tracking) { - if (parallelism <= 0) { - throw new IllegalArgumentException("parallelism > 0 required but it was " + parallelism); - } - this.parallelism = parallelism; - this.factory = factory; - this.tracking = tracking; - this.pool = new AtomicReference(SHUTDOWN); - start(); - } - - @Override - public void start() { - ScheduledExecutorService[] next = null; - for (;;) { - ScheduledExecutorService[] current = pool.get(); - if (current != SHUTDOWN) { - if (next != null) { - for (ScheduledExecutorService exec : next) { - exec.shutdownNow(); - } - } - return; - } - if (next == null) { - next = new ScheduledExecutorService[parallelism]; - for (int i = 0; i < next.length; i++) { - next[i] = Executors.newSingleThreadScheduledExecutor(factory); - } - } - - if (pool.compareAndSet(current, next)) { - return; - } - } - } - - @Override - public void shutdown() { - for (;;) { - ScheduledExecutorService[] current = pool.get(); - if (current == SHUTDOWN) { - return; - } - if (pool.compareAndSet(current, SHUTDOWN)) { - for (ScheduledExecutorService exec : current) { - exec.shutdownNow(); - } - } - } - } - - ScheduledExecutorService pick() { - ScheduledExecutorService[] current = pool.get(); - if (current.length == 0) { - return REJECTING; - } - int idx = this.n; - if (idx >= parallelism) { - idx = 0; - } - this.n = idx + 1; // may race, we don't care - return current[idx]; - } - - @Override - public Worker createWorker() { - if (tracking) { - return new TrackingParallelWorker(pick()); - } - return new NonTrackingParallelWorker(pick()); - } - - @Override - public Disposable scheduleDirect(Runnable run) { - ScheduledExecutorService exec = pick(); - if (exec == REJECTING) { - return Disposables.disposed(); - } - try { - return Disposables.fromFuture(exec.submit(RxJavaPlugins.onSchedule(run))); - } catch (RejectedExecutionException ex) { - return Disposables.disposed(); - } - } - - @Override - public Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit) { - ScheduledExecutorService exec = pick(); - if (exec == REJECTING) { - return Disposables.disposed(); - } - try { - return Disposables.fromFuture(exec.schedule(RxJavaPlugins.onSchedule(run), delay, unit)); - } catch (RejectedExecutionException ex) { - return Disposables.disposed(); - } - } - - @Override - public Disposable schedulePeriodicallyDirect(Runnable run, long initialDelay, long period, TimeUnit unit) { - ScheduledExecutorService exec = pick(); - if (exec == REJECTING) { - return Disposables.disposed(); - } - try { - return Disposables.fromFuture(exec.scheduleAtFixedRate(RxJavaPlugins.onSchedule(run), initialDelay, period, unit)); - } catch (RejectedExecutionException ex) { - return Disposables.disposed(); - } - } - - static final class NonTrackingParallelWorker extends Worker { - - final ScheduledExecutorService exec; - - volatile boolean shutdown; - - NonTrackingParallelWorker(ScheduledExecutorService exec) { - this.exec = exec; - } - - @Override - public void dispose() { - shutdown = true; - } - - @Override - public boolean isDisposed() { - return shutdown; - } - - @Override - public Disposable schedule(Runnable run) { - if (!shutdown) { - try { - NonTrackingTask ntt = new NonTrackingTask(RxJavaPlugins.onSchedule(run)); - exec.submit(ntt); - return ntt; - } catch (RejectedExecutionException ex) { - // just let it fall through - } - } - return Disposables.disposed(); - } - - @Override - public Disposable schedule(Runnable run, long delay, TimeUnit unit) { - if (!shutdown) { - try { - NonTrackingTask ntt = new NonTrackingTask(RxJavaPlugins.onSchedule(run)); - exec.schedule(ntt, delay, unit); - return ntt; - } catch (RejectedExecutionException ex) { - // just let it fall through - } - } - return Disposables.disposed(); - } - - // Not implementing a custom schedulePeriodically as it would require tracking the Future. - - final class NonTrackingTask implements Callable, Disposable { - - final Runnable actual; - - volatile boolean disposed; - - NonTrackingTask(Runnable actual) { - this.actual = actual; - } - - @Override - public Object call() throws Exception { - if (!disposed && !shutdown) { - try { - actual.run(); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - RxJavaPlugins.onError(ex); - } - } - return null; - } - - @Override - public void dispose() { - disposed = true; - } - - @Override - public boolean isDisposed() { - return disposed; - } - } - } - - static final class TrackingParallelWorker extends Worker { - - final ScheduledExecutorService exec; - - final CompositeDisposable tasks; - - TrackingParallelWorker(ScheduledExecutorService exec) { - this.exec = exec; - this.tasks = new CompositeDisposable(); - } - - @Override - public void dispose() { - tasks.dispose(); - } - - @Override - public boolean isDisposed() { - return tasks.isDisposed(); - } - - @Override - public Disposable schedule(Runnable run) { - if (!isDisposed()) { - TrackedAction ta = new TrackedAction(RxJavaPlugins.onSchedule(run), tasks); - if (tasks.add(ta)) { - try { - Future f = exec.submit(ta); - ta.setFuture(f); - return ta; - } catch (RejectedExecutionException ex) { - // let it fall through - } - } - } - return Disposables.disposed(); - } - - @Override - public Disposable schedule(Runnable run, long delay, TimeUnit unit) { - if (!isDisposed()) { - TrackedAction ta = new TrackedAction(RxJavaPlugins.onSchedule(run), tasks); - if (tasks.add(ta)) { - try { - Future f = exec.schedule(ta, delay, unit); - ta.setFuture(f); - return ta; - } catch (RejectedExecutionException ex) { - // let it fall through - } - } - } - return Disposables.disposed(); - } - - static final class TrackedAction - extends AtomicReference - implements Callable, Disposable { - - static final Future FINISHED; - - static final Future DISPOSED; - - static { - FINISHED = new FutureTask(Functions.EMPTY_RUNNABLE, null); - FINISHED.cancel(false); - DISPOSED = new FutureTask(Functions.EMPTY_RUNNABLE, null); - DISPOSED.cancel(false); - } - - private static final long serialVersionUID = 4949851341419870956L; - - final AtomicReference> future; - - final Runnable actual; - - TrackedAction(Runnable actual, DisposableContainer parent) { - this.actual = actual; - this.lazySet(parent); - this.future = new AtomicReference>(); - } - - @Override - public Object call() { - try { - actual.run(); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - RxJavaPlugins.onError(ex); - } - complete(); - return null; - } - - void complete() { - DisposableContainer cd = get(); - if (cd != null && compareAndSet(cd, null)) { - cd.delete(this); - } - for (;;) { - Future f = future.get(); - if (f == DISPOSED || future.compareAndSet(f, FINISHED)) { - break; - } - } - } - - @Override - public void dispose() { - DisposableContainer cd = getAndSet(null); - if (cd != null) { - cd.delete(this); - } - Future f = future.get(); - if (f != FINISHED && f != DISPOSED) { - f = future.getAndSet(DISPOSED); - if (f != null && f != FINISHED && f != DISPOSED) { - f.cancel(true); - } - } - } - - @Override - public boolean isDisposed() { - return get() == null; - } - - void setFuture(Future d) { - Future f = future.get(); - if (f != FINISHED) { - if (f == DISPOSED) { - d.cancel(true); - } else - if (!future.compareAndSet(f, d)) { - f = future.get(); - if (f == DISPOSED) { - d.cancel(true); - } - } - } - } - } - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/schedulers/SharedScheduler.java b/src/main/java/hu/akarnokd/rxjava2/schedulers/SharedScheduler.java deleted file mode 100644 index 3639e9e2..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/schedulers/SharedScheduler.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.schedulers; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import io.reactivex.Scheduler; -import io.reactivex.disposables.*; -import io.reactivex.internal.disposables.*; - -/** - * A Scheduler implementation that uses one of the Workers from another Scheduler - * and shares the access to it through its own Workers. - *

- * Disposing a worker doesn't dispose the underlying shared worker so other - * workers of this class can continue their work; use {@link #shutdown()} to release - * the underlying shared worker. - *

- * This scheduler doesn't support {@link #start()} (it's a no-op) and once {@link #shutdown()} - * it can't be revived. - * @since 0.6.2 - */ -public final class SharedScheduler extends Scheduler { - - final Worker worker; - - /** - * Constructs a SharedScheduler and asks for a Worker from the provided other Scheduler. - * @param other the other Scheduler instance, not null - */ - public SharedScheduler(Scheduler other) { - this.worker = other.createWorker(); - } - - /** - * Constructs a SharedScheduler and uses the Worker instance provided. - * @param worker the worker to use, not null - */ - public SharedScheduler(Worker worker) { - this.worker = worker; - } - - @Override - public void shutdown() { - worker.dispose(); - } - - @Override - public Disposable scheduleDirect(Runnable run) { - return worker.schedule(run); - } - - @Override - public Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit) { - return worker.schedule(run, delay, unit); - } - - @Override - public Disposable schedulePeriodicallyDirect(Runnable run, long initialDelay, long period, TimeUnit unit) { - return worker.schedulePeriodically(run, initialDelay, period, unit); - } - - @Override - public long now(TimeUnit unit) { - return worker.now(unit); - } - - @Override - public Worker createWorker() { - return new SharedWorker(worker); - } - - static final class SharedWorker extends Worker { - - final Worker worker; - - final CompositeDisposable tasks; - - SharedWorker(Worker worker) { - this.worker = worker; - this.tasks = new CompositeDisposable(); - } - - @Override - public void dispose() { - tasks.dispose(); - } - - @Override - public boolean isDisposed() { - return tasks.isDisposed(); - } - - @Override - public Disposable schedule(Runnable run, long delay, TimeUnit unit) { - if (isDisposed() || worker.isDisposed()) { - return Disposables.disposed(); - } - SharedAction sa = new SharedAction(run, tasks); - tasks.add(sa); - - Disposable task; - if (delay <= 0L) { - task = worker.schedule(sa); - } else { - task = worker.schedule(sa, delay, unit); - } - sa.setFuture(task); - - return sa; - } - - @Override - public long now(TimeUnit unit) { - return worker.now(unit); - } - - static final class SharedAction - extends AtomicReference - implements Runnable, Disposable { - private static final long serialVersionUID = 4949851341419870956L; - - final AtomicReference future; - - final Runnable actual; - - SharedAction(Runnable actual, DisposableContainer parent) { - this.actual = actual; - this.lazySet(parent); - this.future = new AtomicReference(); - } - - @Override - public void run() { - try { - actual.run(); - } finally { - complete(); - } - } - - void complete() { - DisposableContainer cd = get(); - if (cd != null && compareAndSet(cd, null)) { - cd.delete(this); - } - for (;;) { - Disposable f = future.get(); - if (f == DisposableHelper.DISPOSED || future.compareAndSet(f, this)) { - break; - } - } - } - - @Override - public void dispose() { - DisposableContainer cd = getAndSet(null); - if (cd != null) { - cd.delete(this); - } - DisposableHelper.dispose(future); - } - - @Override - public boolean isDisposed() { - return get() == null; - } - - void setFuture(Disposable d) { - Disposable f = future.get(); - if (f != this) { - if (f == DisposableHelper.DISPOSED) { - d.dispose(); - } else - if (!future.compareAndSet(f, d)) { - f = future.get(); - if (f == DisposableHelper.DISPOSED) { - d.dispose(); - } - } - } - } - } - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/schedulers/package-info.java b/src/main/java/hu/akarnokd/rxjava2/schedulers/package-info.java deleted file mode 100644 index 25eecc07..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/schedulers/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Special scheduler implementations, such as - * {@link hu.akarnokd.rxjava2.schedulers.BlockingScheduler BlockingScheduler}, - * {@link hu.akarnokd.rxjava2.schedulers.ParallelScheduler ParallelScheduler} and - * {@link hu.akarnokd.rxjava2.schedulers.SharedScheduler SharedScheduler}. - */ -package hu.akarnokd.rxjava2.schedulers; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/util/SelfComparator.java b/src/main/java/hu/akarnokd/rxjava2/util/SelfComparator.java deleted file mode 100644 index 7892df20..00000000 --- a/src/main/java/hu/akarnokd/rxjava2/util/SelfComparator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.util; - -import java.util.Comparator; - -/** - * Comparator that compares Comparables. - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -public enum SelfComparator implements Comparator { - INSTANCE; - - public static > Comparator instance() { - return (Comparator)INSTANCE; - } - - @Override - public int compare(Comparable o1, Comparable o2) { - return o1.compareTo(o2); - } -} diff --git a/src/main/java/hu/akarnokd/rxjava2/async/AnyValue.java b/src/main/java/hu/akarnokd/rxjava4/async/AnyValue.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/async/AnyValue.java rename to src/main/java/hu/akarnokd/rxjava4/async/AnyValue.java index 762853ed..b3ad05ba 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/AnyValue.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/AnyValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; /** * Placeholder instance when one has to return something (and used to return {@code null} in 1.x). diff --git a/src/main/java/hu/akarnokd/rxjava2/async/AsyncFlowable.java b/src/main/java/hu/akarnokd/rxjava4/async/AsyncFlowable.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/async/AsyncFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/async/AsyncFlowable.java index f9cd04b4..1fbfa202 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/AsyncFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/AsyncFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; import java.util.concurrent.*; - -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.functions.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscribers.LambdaSubscriber; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.*; -import io.reactivex.schedulers.Schedulers; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.functions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.*; +import io.reactivex.rxjava4.schedulers.Schedulers; /** * Utility methods to convert functions and actions into asynchronous operations through the Publisher/Subscriber @@ -63,7 +60,7 @@ private AsyncFlowable() { * @see RxJava Wiki: start() * @see MSDN: Observable.Start */ - public static Flowable start(Callable func) { + public static Flowable start(Supplier func) { return start(func, Schedulers.computation()); } @@ -89,8 +86,8 @@ public static Flowable start(Callable func) { * @see RxJava Wiki: start() * @see MSDN: Observable.Start */ - public static Flowable start(Callable func, Scheduler scheduler) { - return Flowable.fromCallable(func).subscribeOn(scheduler).subscribeWith(AsyncProcessor.create()); + public static Flowable start(Supplier func, Scheduler scheduler) { + return Flowable.fromSupplier(func).subscribeOn(scheduler).subscribeWith(AsyncProcessor.create()); } /** @@ -99,7 +96,7 @@ public static Flowable start(Callable func, Scheduler schedu * *

*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the SimpleCallable honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -108,7 +105,7 @@ public static Flowable start(Callable func, Scheduler schedu * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(Action action) { + public static SimpleCallable> toAsync(Action action) { return toAsync(action, Schedulers.computation()); } @@ -118,9 +115,9 @@ public static Supplier> toAsync(Action action) { * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the SimpleCallable honors downstream backpressure.
*
Scheduler:
- *
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
+ *
{@code toAsyncCallable} by default operates on the {@code computation} {@link Scheduler}.
*
* * @param the result value type @@ -129,8 +126,29 @@ public static Supplier> toAsync(Action action) { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(Callable func) { - return toAsync(func, Schedulers.computation()); + public static SimpleCallable> toAsyncCallable(Callable func) { + return toAsyncCallable(func, Schedulers.computation()); + } + + /** + * Convert a synchronous function call into an asynchronous function call through a Flowable. + *

+ * + *

+ *
Backpressure:
+ *
The Flowable returned by the SimpleCallable honors downstream backpressure.
+ *
Scheduler:
+ *
{@code toAsyncSupplier} by default operates on the {@code computation} {@link Scheduler}.
+ *
+ * + * @param the result value type + * @param func the function to convert + * @return a function that returns an Flowable that executes the {@code func} and emits its returned value + * @see RxJava Wiki: toAsync() + * @see MSDN: Observable.ToAsync + */ + public static SimpleCallable> toAsyncSupplier(Supplier func) { + return toAsyncSupplier(func, Schedulers.computation()); } /** @@ -139,7 +157,7 @@ public static Supplier> toAsync(Callable func) { * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -160,7 +178,7 @@ public static PlainFunction> toAsync(Consumer *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -182,7 +200,7 @@ public static PlainFunction> toAsync(Function *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -204,7 +222,7 @@ public static PlainBiFunction> toAsync(BiConsu * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -227,7 +245,7 @@ public static PlainBiFunction> toAsync(BiFunctio * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -250,7 +268,7 @@ public static PlainFunction3> toAsync( * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -274,7 +292,7 @@ public static PlainFunction3> toAsync(Fu * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -298,7 +316,7 @@ public static PlainFunction4> * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -323,7 +341,7 @@ public static PlainFunction4> to * *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -338,7 +356,8 @@ public static PlainFunction4> to * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(Consumer5 action) { + public static PlainFunction5> toAsync( + Consumer5 action) { return toAsync(action, Schedulers.computation()); } @@ -348,7 +367,7 @@ public static PlainFunction5 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -364,7 +383,8 @@ public static PlainFunction5RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(Function5 func) { + public static PlainFunction5> toAsync( + Function5 func) { return toAsync(func, Schedulers.computation()); } @@ -374,7 +394,7 @@ public static PlainFunction5 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -390,7 +410,8 @@ public static PlainFunction5RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(Consumer6 action) { + public static PlainFunction6> toAsync( + Consumer6 action) { return toAsync(action, Schedulers.computation()); } @@ -400,7 +421,7 @@ public static PlainFunction6 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -417,7 +438,8 @@ public static PlainFunction6RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(Function6 func) { + public static PlainFunction6> toAsync( + Function6 func) { return toAsync(func, Schedulers.computation()); } @@ -427,7 +449,7 @@ public static PlainFunction6 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -444,7 +466,8 @@ public static PlainFunction6RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction7> toAsync(Consumer7 action) { + public static PlainFunction7> toAsync( + Consumer7 action) { return toAsync(action, Schedulers.computation()); } @@ -454,7 +477,7 @@ public static PlainFunction7 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -472,7 +495,8 @@ public static PlainFunction7RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction7> toAsync(Function7 func) { + public static PlainFunction7> toAsync( + Function7 func) { return toAsync(func, Schedulers.computation()); } @@ -482,7 +506,7 @@ public static PlainFunction7 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -500,7 +524,8 @@ public static PlainFunction7RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction8> toAsync(Consumer8 action) { + public static PlainFunction8> toAsync( + Consumer8 action) { return toAsync(action, Schedulers.computation()); } @@ -510,7 +535,7 @@ public static PlainFunction8 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -529,7 +554,8 @@ public static PlainFunction8RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction8> toAsync(Function8 func) { + public static PlainFunction8> toAsync( + Function8 func) { return toAsync(func, Schedulers.computation()); } @@ -539,7 +565,7 @@ public static PlainFunction8 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -558,7 +584,8 @@ public static PlainFunction8RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction9> toAsync(Consumer9 action) { + public static PlainFunction9> toAsync( + Consumer9 action) { return toAsync(action, Schedulers.computation()); } @@ -568,7 +595,7 @@ public static PlainFunction9 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -588,7 +615,8 @@ public static PlainFunction9RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction9> toAsync(Function9 func) { + public static PlainFunction9> toAsync( + Function9 func) { return toAsync(func, Schedulers.computation()); } @@ -598,7 +626,7 @@ public static PlainFunction9 *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsyncArray} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -617,7 +645,7 @@ public static PlainFunction> toAsyncArray(Consumer *
*
Backpressure:
- *
The Flowable returned by the Callable honors downstream backpressure.
+ *
The Flowable returned by the function honors downstream backpressure.
*
Scheduler:
*
{@code toAsyncArray} by default operates on the {@code computation} {@link Scheduler}.
*
@@ -637,7 +665,7 @@ public static PlainFunction> toAsyncArray(Function *
*
Backpressure:
- *
The Flowable returned by the Supplier honors downstream backpressure.
+ *
The Flowable returned by the SimpleCallable honors downstream backpressure.
*
Scheduler:
*
You specify the {@link Scheduler} {@code toAsync} works on.
*
@@ -647,13 +675,13 @@ public static PlainFunction> toAsyncArray(FunctionRxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(final Action action, final Scheduler scheduler) { - return new Supplier>() { + public static SimpleCallable> toAsync(final Action action, final Scheduler scheduler) { + return new SimpleCallable>() { @Override public Flowable call() { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.run(); return AnyValue.INSTANCE; } @@ -669,9 +697,35 @@ public Object call() throws Exception { * *
*
Backpressure:
- *
The Flowable returned by the Supplier honors downstream backpressure.
+ *
The Flowable returned by the SimpleCallable honors downstream backpressure.
*
Scheduler:
- *
You specify the {@link Scheduler} {@code toAsync} works on.
+ *
You specify the {@link Scheduler} {@code toAsyncCallable} works on.
+ *
+ * @param the result value type + * @param func the function to convert + * @param scheduler the Scheduler used to call the {@code func} + * @return a function that returns an Flowable that executes the {@code func} and emits its returned value + * @see RxJava Wiki: toAsync() + * @see MSDN: Observable.ToAsync + */ + public static SimpleCallable> toAsyncCallable(final Callable func, final Scheduler scheduler) { + return new SimpleCallable>() { + @Override + public Flowable call() { + return Flowable.fromCallable(func).subscribeOn(scheduler); + } + }; + } + + /** + * Convert a synchronous function call into an asynchronous function call through a Flowable. + *

+ * + *

+ *
Backpressure:
+ *
The Flowable returned by the SimpleCallable honors downstream backpressure.
+ *
Scheduler:
+ *
You specify the {@link Scheduler} {@code toAsyncSupplier} works on.
*
* @param the result value type * @param func the function to convert @@ -680,11 +734,11 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(final Callable func, final Scheduler scheduler) { - return new Supplier>() { + public static SimpleCallable> toAsyncSupplier(final Supplier func, final Scheduler scheduler) { + return new SimpleCallable>() { @Override public Flowable call() { - return Flowable.fromCallable(func).subscribeOn(scheduler); + return Flowable.fromSupplier(func).subscribeOn(scheduler); } }; } @@ -711,9 +765,9 @@ public static PlainFunction> toAsync(final Consumer>() { @Override public Flowable apply(final T1 t1) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1); return AnyValue.INSTANCE; } @@ -746,9 +800,9 @@ public static PlainFunction> toAsync(final Function>() { @Override public Flowable apply(final T1 t1) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1); } }) @@ -780,9 +834,9 @@ public static PlainBiFunction> toAsync(final B return new PlainBiFunction>() { @Override public Flowable apply(final T1 t1, final T2 t2) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2); return AnyValue.INSTANCE; } @@ -816,9 +870,9 @@ public static PlainBiFunction> toAsync(final BiF return new PlainBiFunction>() { @Override public Flowable apply(final T1 t1, final T2 t2) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2); } }) @@ -851,9 +905,9 @@ public static PlainFunction3> toAsync( return new PlainFunction3>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3); return AnyValue.INSTANCE; } @@ -884,13 +938,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction3> toAsync(final Function3 func, final Scheduler scheduler) { + public static PlainFunction3> toAsync( + final Function3 func, final Scheduler scheduler) { return new PlainFunction3>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3); } }) @@ -920,13 +975,14 @@ public R call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction4> toAsync(final Consumer4 action, final Scheduler scheduler) { + public static PlainFunction4> toAsync( + final Consumer4 action, final Scheduler scheduler) { return new PlainFunction4>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4); return AnyValue.INSTANCE; } @@ -958,13 +1014,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction4> toAsync(final Function4 func, final Scheduler scheduler) { + public static PlainFunction4> toAsync( + final Function4 func, final Scheduler scheduler) { return new PlainFunction4>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4); } }) @@ -995,13 +1052,14 @@ public R call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(final Consumer5 action, final Scheduler scheduler) { + public static PlainFunction5> toAsync( + final Consumer5 action, final Scheduler scheduler) { return new PlainFunction5>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5); return AnyValue.INSTANCE; } @@ -1034,13 +1092,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(final Function5 func, final Scheduler scheduler) { + public static PlainFunction5> toAsync( + final Function5 func, final Scheduler scheduler) { return new PlainFunction5>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5); } }) @@ -1072,13 +1131,14 @@ public R call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(final Consumer6 action, final Scheduler scheduler) { + public static PlainFunction6> toAsync( + final Consumer6 action, final Scheduler scheduler) { return new PlainFunction6>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6); return AnyValue.INSTANCE; } @@ -1112,13 +1172,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(final Function6 func, final Scheduler scheduler) { + public static PlainFunction6> toAsync( + final Function6 func, final Scheduler scheduler) { return new PlainFunction6>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6); } }) @@ -1156,9 +1217,9 @@ public static PlainFunction7>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6, t7); return AnyValue.INSTANCE; } @@ -1198,9 +1259,9 @@ public static PlainFunction7>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6, t7); } }) @@ -1239,9 +1300,9 @@ public static PlainFunction8>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6, t7, t8); return AnyValue.INSTANCE; } @@ -1282,9 +1343,9 @@ public static PlainFunction8>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6, t7, t8); } }) @@ -1324,9 +1385,9 @@ public static PlainFunction9>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8, final T9 t9) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6, t7, t8, t9); return AnyValue.INSTANCE; } @@ -1364,13 +1425,14 @@ public Object call() throws Exception { * @see MSDN: Observable.ToAsync */ public static PlainFunction9> toAsync( - final Function9 func, final Scheduler scheduler) { + final Function9 func, + final Scheduler scheduler) { return new PlainFunction9>() { @Override public Flowable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8, final T9 t9) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6, t7, t8, t9); } }) @@ -1399,9 +1461,9 @@ public static PlainFunction> toAsyncArray(final Consu return new PlainFunction>() { @Override public Flowable apply(final Object[] t) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t); return AnyValue.INSTANCE; } @@ -1432,9 +1494,9 @@ public static PlainFunction> toAsyncArray(final Functi return new PlainFunction>() { @Override public Flowable apply(final Object[] t) { - return Flowable.fromCallable(new Callable() { + return Flowable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t); } }) @@ -1459,14 +1521,14 @@ public R call() throws Exception { * @param the result type * @param functionAsync the asynchronous function to run * @return an Observable that surfaces the result of the future - * @see #startFuture(Callable, Scheduler) + * @see #startFuture(Supplier, Scheduler) * @see RxJava Wiki: startFuture() */ - public static Flowable startFuture(final Callable> functionAsync) { - return RxJavaPlugins.onAssembly(new FlowableFromCallableNull(new Callable() { + public static Flowable startFuture(final Supplier> functionAsync) { + return RxJavaPlugins.onAssembly(new FlowableFromSupplierNull<>(new Supplier() { @Override - public T call() throws Exception { - return functionAsync.call().get(); + public T get() throws Throwable { + return functionAsync.get().get(); } })); } @@ -1489,7 +1551,7 @@ public T call() throws Exception { * @return an Observable that surfaces the result of the future * @see RxJava Wiki: startFuture() */ - public static Flowable startFuture(Callable> functionAsync, + public static Flowable startFuture(Supplier> functionAsync, Scheduler scheduler) { return startFuture(functionAsync).subscribeOn(scheduler); } @@ -1511,10 +1573,10 @@ public static Flowable startFuture(Callable * @param the result type * @param publisherFactoryAsync the asynchronous function to start for each observer * @return the Observable emitting items produced by the asynchronous observer produced by the factory - * @see #deferFuture(Callable, Scheduler) + * @see #deferFuture(Supplier, Scheduler) * @see RxJava Wiki: deferFuture() */ - public static Flowable deferFuture(Callable>> publisherFactoryAsync) { + public static Flowable deferFuture(Supplier>> publisherFactoryAsync) { return deferFuture(publisherFactoryAsync, Schedulers.computation()); } @@ -1537,12 +1599,12 @@ public static Flowable deferFuture(CallableRxJava Wiki: deferFuture() */ public static Flowable deferFuture( - final Callable>> publisherFactoryAsync, + final Supplier>> publisherFactoryAsync, Scheduler scheduler) { - return Flowable.defer(new Callable>() { + return Flowable.defer(new Supplier>() { @Override - public Publisher call() throws Exception { - return publisherFactoryAsync.call().get(); + public Publisher get() throws Throwable { + return publisherFactoryAsync.get().get(); } }).subscribeOn(scheduler); } @@ -1720,9 +1782,9 @@ public static Future forEachFuture( Scheduler scheduler) { SequentialDisposable d = new SequentialDisposable(); - final FutureCompletable f = new FutureCompletable(d); + final FutureCompletable f = new FutureCompletable<>(d); - LambdaSubscriber ls = new LambdaSubscriber(onNext, + LambdaSubscriber ls = new LambdaSubscriber<>(onNext, new Consumer() { @Override public void accept(Throwable e) throws Exception { diff --git a/src/main/java/hu/akarnokd/rxjava2/async/AsyncObservable.java b/src/main/java/hu/akarnokd/rxjava4/async/AsyncObservable.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/async/AsyncObservable.java rename to src/main/java/hu/akarnokd/rxjava4/async/AsyncObservable.java index 9f2be727..a6c46c87 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/AsyncObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/AsyncObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; import java.util.concurrent.*; -import hu.akarnokd.rxjava2.functions.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.observers.LambdaObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.*; +import hu.akarnokd.rxjava4.functions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.*; /** * Utility methods to convert functions and actions into asynchronous operations through the Observable/Observer @@ -59,7 +57,7 @@ private AsyncObservable() { * @see RxJava Wiki: start() * @see MSDN: Observable.Start */ - public static Observable start(Callable func) { + public static Observable start(Supplier func) { return start(func, Schedulers.computation()); } @@ -83,8 +81,8 @@ public static Observable start(Callable func) { * @see RxJava Wiki: start() * @see MSDN: Observable.Start */ - public static Observable start(Callable func, Scheduler scheduler) { - return Observable.fromCallable(func).subscribeOn(scheduler).subscribeWith(AsyncSubject.create()); + public static Observable start(Supplier func, Scheduler scheduler) { + return Observable.fromSupplier(func).subscribeOn(scheduler).subscribeWith(AsyncSubject.create()); } /** @@ -100,7 +98,7 @@ public static Observable start(Callable func, Scheduler sche * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(Action action) { + public static SimpleCallable> toAsync(Action action) { return toAsync(action, Schedulers.computation()); } @@ -110,7 +108,7 @@ public static Supplier> toAsync(Action action) { * *
*
Scheduler:
- *
{@code toAsync} by default operates on the {@code computation} {@link Scheduler}.
+ *
{@code toAsyncCallable} by default operates on the {@code computation} {@link Scheduler}.
*
* * @param the result value type @@ -119,8 +117,27 @@ public static Supplier> toAsync(Action action) { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(Callable func) { - return toAsync(func, Schedulers.computation()); + public static SimpleCallable> toAsyncCallable(Callable func) { + return toAsyncCallable(func, Schedulers.computation()); + } + + /** + * Convert a synchronous function call into an asynchronous function call through a Observable. + *

+ * + *

+ *
Scheduler:
+ *
{@code toAsyncSupplier} by default operates on the {@code computation} {@link Scheduler}.
+ *
+ * + * @param the result value type + * @param func the function to convert + * @return a function that returns an Observable that executes the {@code func} and emits its returned value + * @see RxJava Wiki: toAsync() + * @see MSDN: Observable.ToAsync + */ + public static SimpleCallable> toAsyncSupplier(Supplier func) { + return toAsyncSupplier(func, Schedulers.computation()); } /** @@ -310,7 +327,8 @@ public static PlainFunction4> * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(Consumer5 action) { + public static PlainFunction5> toAsync( + Consumer5 action) { return toAsync(action, Schedulers.computation()); } @@ -334,7 +352,8 @@ public static PlainFunction5RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(Function5 func) { + public static PlainFunction5> toAsync( + Function5 func) { return toAsync(func, Schedulers.computation()); } @@ -358,7 +377,8 @@ public static PlainFunction5RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(Consumer6 action) { + public static PlainFunction6> toAsync( + Consumer6 action) { return toAsync(action, Schedulers.computation()); } @@ -383,7 +403,8 @@ public static PlainFunction6RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(Function6 func) { + public static PlainFunction6> toAsync( + Function6 func) { return toAsync(func, Schedulers.computation()); } @@ -408,7 +429,8 @@ public static PlainFunction6RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction7> toAsync(Consumer7 action) { + public static PlainFunction7> toAsync( + Consumer7 action) { return toAsync(action, Schedulers.computation()); } @@ -434,7 +456,8 @@ public static PlainFunction7RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction7> toAsync(Function7 func) { + public static PlainFunction7> toAsync( + Function7 func) { return toAsync(func, Schedulers.computation()); } @@ -460,7 +483,8 @@ public static PlainFunction7RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction8> toAsync(Consumer8 action) { + public static PlainFunction8> toAsync( + Consumer8 action) { return toAsync(action, Schedulers.computation()); } @@ -487,7 +511,8 @@ public static PlainFunction8RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction8> toAsync(Function8 func) { + public static PlainFunction8> toAsync( + Function8 func) { return toAsync(func, Schedulers.computation()); } @@ -514,7 +539,8 @@ public static PlainFunction8RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction9> toAsync(Consumer9 action) { + public static PlainFunction9> toAsync( + Consumer9 action) { return toAsync(action, Schedulers.computation()); } @@ -542,7 +568,8 @@ public static PlainFunction9RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction9> toAsync(Function9 func) { + public static PlainFunction9> toAsync( + Function9 func) { return toAsync(func, Schedulers.computation()); } @@ -595,13 +622,13 @@ public static PlainFunction> toAsyncArray(FunctionRxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(final Action action, final Scheduler scheduler) { - return new Supplier>() { + public static SimpleCallable> toAsync(final Action action, final Scheduler scheduler) { + return new SimpleCallable>() { @Override public Observable call() { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.run(); return AnyValue.INSTANCE; } @@ -617,7 +644,31 @@ public Object call() throws Exception { * *
*
Scheduler:
- *
You specify the {@link Scheduler} {@code toAsync} works on.
+ *
You specify the {@link Scheduler} {@code toAsyncCallable} works on.
+ *
+ * @param the result value type + * @param func the function to convert + * @param scheduler the Scheduler used to call the {@code func} + * @return a function that returns an Observable that executes the {@code func} and emits its returned value + * @see RxJava Wiki: toAsync() + * @see MSDN: Observable.ToAsync + */ + public static SimpleCallable> toAsyncCallable(final Callable func, final Scheduler scheduler) { + return new SimpleCallable>() { + @Override + public Observable call() { + return Observable.fromCallable(func).subscribeOn(scheduler); + } + }; + } + + /** + * Convert a synchronous function call into an asynchronous function call through a Observable. + *

+ * + *

+ *
Scheduler:
+ *
You specify the {@link Scheduler} {@code toAsyncSupplier} works on.
*
* @param the result value type * @param func the function to convert @@ -626,11 +677,11 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static Supplier> toAsync(final Callable func, final Scheduler scheduler) { - return new Supplier>() { + public static SimpleCallable> toAsyncSupplier(final Supplier func, final Scheduler scheduler) { + return new SimpleCallable>() { @Override public Observable call() { - return Observable.fromCallable(func).subscribeOn(scheduler); + return Observable.fromSupplier(func).subscribeOn(scheduler); } }; } @@ -655,9 +706,9 @@ public static PlainFunction> toAsync(final Consumer< return new PlainFunction>() { @Override public Observable apply(final T1 t1) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1); return AnyValue.INSTANCE; } @@ -688,9 +739,9 @@ public static PlainFunction> toAsync(final Function>() { @Override public Observable apply(final T1 t1) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1); } }) @@ -720,9 +771,9 @@ public static PlainBiFunction> toAsync(final return new PlainBiFunction>() { @Override public Observable apply(final T1 t1, final T2 t2) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2); return AnyValue.INSTANCE; } @@ -754,9 +805,9 @@ public static PlainBiFunction> toAsync(final B return new PlainBiFunction>() { @Override public Observable apply(final T1 t1, final T2 t2) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2); } }) @@ -787,9 +838,9 @@ public static PlainFunction3> toAsyn return new PlainFunction3>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3); return AnyValue.INSTANCE; } @@ -818,13 +869,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction3> toAsync(final Function3 func, final Scheduler scheduler) { + public static PlainFunction3> toAsync( + final Function3 func, final Scheduler scheduler) { return new PlainFunction3>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3); } }) @@ -852,13 +904,14 @@ public R call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction4> toAsync(final Consumer4 action, final Scheduler scheduler) { + public static PlainFunction4> toAsync( + final Consumer4 action, final Scheduler scheduler) { return new PlainFunction4>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4); return AnyValue.INSTANCE; } @@ -888,13 +941,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction4> toAsync(final Function4 func, final Scheduler scheduler) { + public static PlainFunction4> toAsync( + final Function4 func, final Scheduler scheduler) { return new PlainFunction4>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4); } }) @@ -923,13 +977,14 @@ public R call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(final Consumer5 action, final Scheduler scheduler) { + public static PlainFunction5> toAsync( + final Consumer5 action, final Scheduler scheduler) { return new PlainFunction5>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5); return AnyValue.INSTANCE; } @@ -960,13 +1015,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction5> toAsync(final Function5 func, final Scheduler scheduler) { + public static PlainFunction5> toAsync( + final Function5 func, final Scheduler scheduler) { return new PlainFunction5>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5); } }) @@ -996,13 +1052,14 @@ public R call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(final Consumer6 action, final Scheduler scheduler) { + public static PlainFunction6> toAsync( + final Consumer6 action, final Scheduler scheduler) { return new PlainFunction6>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6); return AnyValue.INSTANCE; } @@ -1034,13 +1091,14 @@ public Object call() throws Exception { * @see RxJava Wiki: toAsync() * @see MSDN: Observable.ToAsync */ - public static PlainFunction6> toAsync(final Function6 func, final Scheduler scheduler) { + public static PlainFunction6> toAsync( + final Function6 func, final Scheduler scheduler) { return new PlainFunction6>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6); } }) @@ -1076,9 +1134,9 @@ public static PlainFunction7>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6, t7); return AnyValue.INSTANCE; } @@ -1116,9 +1174,9 @@ public static PlainFunction7>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6, t7); } }) @@ -1155,9 +1213,9 @@ public static PlainFunction8>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6, t7, t8); return AnyValue.INSTANCE; } @@ -1196,9 +1254,9 @@ public static PlainFunction8>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6, t7, t8); } }) @@ -1236,9 +1294,9 @@ public static PlainFunction9>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8, final T9 t9) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t1, t2, t3, t4, t5, t6, t7, t8, t9); return AnyValue.INSTANCE; } @@ -1274,13 +1332,14 @@ public Object call() throws Exception { * @see MSDN: Observable.ToAsync */ public static PlainFunction9> toAsync( - final Function9 func, final Scheduler scheduler) { + final Function9 func, + final Scheduler scheduler) { return new PlainFunction9>() { @Override public Observable apply(final T1 t1, final T2 t2, final T3 t3, final T4 t4, final T5 t5, final T6 t6, final T7 t7, final T8 t8, final T9 t9) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t1, t2, t3, t4, t5, t6, t7, t8, t9); } }) @@ -1307,9 +1366,9 @@ public static PlainFunction> toAsyncArray(final Con return new PlainFunction>() { @Override public Observable apply(final Object[] t) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Throwable { action.accept(t); return AnyValue.INSTANCE; } @@ -1338,9 +1397,9 @@ public static PlainFunction> toAsyncArray(final Func return new PlainFunction>() { @Override public Observable apply(final Object[] t) { - return Observable.fromCallable(new Callable() { + return Observable.fromSupplier(new Supplier() { @Override - public R call() throws Exception { + public R get() throws Throwable { return func.apply(t); } }) @@ -1363,14 +1422,14 @@ public R call() throws Exception { * @param the result type * @param functionAsync the asynchronous function to run * @return an Observable that surfaces the result of the future - * @see #startFuture(Callable, Scheduler) + * @see #startFuture(Supplier, Scheduler) * @see RxJava Wiki: startFuture() */ - public static Observable startFuture(final Callable> functionAsync) { - return RxJavaPlugins.onAssembly(new ObservableFromCallableNull(new Callable() { + public static Observable startFuture(final Supplier> functionAsync) { + return RxJavaPlugins.onAssembly(new ObservableFromSupplierNull<>(new Supplier() { @Override - public T call() throws Exception { - return functionAsync.call().get(); + public T get() throws Throwable { + return functionAsync.get().get(); } })); } @@ -1391,7 +1450,7 @@ public T call() throws Exception { * @return an Observable that surfaces the result of the future * @see RxJava Wiki: startFuture() */ - public static Observable startFuture(Callable> functionAsync, + public static Observable startFuture(Supplier> functionAsync, Scheduler scheduler) { return startFuture(functionAsync).subscribeOn(scheduler); } @@ -1411,10 +1470,10 @@ public static Observable startFuture(Callable the result type * @param publisherFactoryAsync the asynchronous function to start for each observer * @return the Observable emitting items produced by the asynchronous observer produced by the factory - * @see #deferFuture(Callable, Scheduler) + * @see #deferFuture(Supplier, Scheduler) * @see RxJava Wiki: deferFuture() */ - public static Observable deferFuture(Callable>> publisherFactoryAsync) { + public static Observable deferFuture(Supplier>> publisherFactoryAsync) { return deferFuture(publisherFactoryAsync, Schedulers.computation()); } @@ -1435,12 +1494,12 @@ public static Observable deferFuture(CallableRxJava Wiki: deferFuture() */ public static Observable deferFuture( - final Callable>> publisherFactoryAsync, + final Supplier>> publisherFactoryAsync, Scheduler scheduler) { - return Observable.defer(new Callable>() { + return Observable.defer(new Supplier>() { @Override - public ObservableSource call() throws Exception { - return publisherFactoryAsync.call().get(); + public ObservableSource get() throws Throwable { + return publisherFactoryAsync.get().get(); } }).subscribeOn(scheduler); } @@ -1606,9 +1665,9 @@ public static Future forEachFuture( Scheduler scheduler) { SequentialDisposable d = new SequentialDisposable(); - final FutureCompletable f = new FutureCompletable(d); + final FutureCompletable f = new FutureCompletable<>(d); - LambdaObserver ls = new LambdaObserver(onNext, + LambdaObserver ls = new LambdaObserver<>(onNext, new Consumer() { @Override public void accept(Throwable e) throws Exception { diff --git a/src/main/java/hu/akarnokd/rxjava2/async/DisposableFlowable.java b/src/main/java/hu/akarnokd/rxjava4/async/DisposableFlowable.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/async/DisposableFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/async/DisposableFlowable.java index 513c1332..f5c847e6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/DisposableFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/DisposableFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; -import io.reactivex.Flowable; -import io.reactivex.disposables.Disposable; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.disposables.Disposable; /** * A {@link Flowable} that also offers a means to dispose it, cancelling/disposing diff --git a/src/main/java/hu/akarnokd/rxjava2/async/DisposableObservable.java b/src/main/java/hu/akarnokd/rxjava4/async/DisposableObservable.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/async/DisposableObservable.java rename to src/main/java/hu/akarnokd/rxjava4/async/DisposableObservable.java index 54dabd6b..4a508b66 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/DisposableObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/DisposableObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.disposables.Disposable; /** * A {@link Observable} that also offers a means to dispose it, cancelling/disposing diff --git a/src/main/java/hu/akarnokd/rxjava2/async/FlowableFromCallableNull.java b/src/main/java/hu/akarnokd/rxjava4/async/FlowableFromCallableNull.java similarity index 69% rename from src/main/java/hu/akarnokd/rxjava2/async/FlowableFromCallableNull.java rename to src/main/java/hu/akarnokd/rxjava4/async/FlowableFromCallableNull.java index 67d04912..ead91d93 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/FlowableFromCallableNull.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/FlowableFromCallableNull.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,32 +14,31 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** - * Runs a callable and treats a null result as completion. + * Runs a Supplier and treats a null result as completion. * * @param the value type */ -final class FlowableFromCallableNull extends Flowable implements Callable { +final class FlowableFromSupplierNull extends Flowable implements Supplier { - final Callable callable; + final Supplier supplier; - FlowableFromCallableNull(Callable callable) { - this.callable = callable; + FlowableFromSupplierNull(Supplier supplier) { + this.supplier = supplier; } @Override protected void subscribeActual(Subscriber s) { - CallableNullSubscription deferred = new CallableNullSubscription(s); + CallableNullSubscription deferred = new CallableNullSubscription<>(s); s.onSubscribe(deferred); if (!deferred.isCancelled()) { @@ -47,7 +46,7 @@ protected void subscribeActual(Subscriber s) { T v; try { - v = callable.call(); + v = supplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); if (!deferred.isCancelled()) { @@ -67,8 +66,8 @@ protected void subscribeActual(Subscriber s) { } @Override - public T call() throws Exception { - return callable.call(); + public T get() throws Throwable { + return supplier.get(); } static final class CallableNullSubscription extends DeferredScalarSubscription { diff --git a/src/main/java/hu/akarnokd/rxjava2/async/FutureCompletable.java b/src/main/java/hu/akarnokd/rxjava4/async/FutureCompletable.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/async/FutureCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/async/FutureCompletable.java index 5755bf19..c9e05a9a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/FutureCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/FutureCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; +import java.util.Objects; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * A Future implementation that can be terminated externally. @@ -79,7 +79,7 @@ public void complete(T value) { * @param error the error to complete exceptionally */ public void completeExceptionally(Throwable error) { - ObjectHelper.requireNonNull(error, "error is null"); + Objects.requireNonNull(error, "error is null"); if (once.compareAndSet(0, STATE_ERROR)) { this.onCancel = null; this.error = error; diff --git a/src/main/java/hu/akarnokd/rxjava2/async/ObservableFromCallableNull.java b/src/main/java/hu/akarnokd/rxjava4/async/ObservableFromSupplierNull.java similarity index 62% rename from src/main/java/hu/akarnokd/rxjava2/async/ObservableFromCallableNull.java rename to src/main/java/hu/akarnokd/rxjava4/async/ObservableFromSupplierNull.java index 70df501c..6c115bd1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/ObservableFromCallableNull.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/ObservableFromSupplierNull.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,30 +14,29 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; -import java.util.concurrent.Callable; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.observers.DeferredScalarDisposable; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** - * Runs a callable and treats a null result as completion. + * Runs a supplier and treats a null result as completion. * * @param the value type */ -final class ObservableFromCallableNull extends Observable implements Callable { +final class ObservableFromSupplierNull extends Observable implements Supplier { - final Callable callable; + final Supplier supplier; - ObservableFromCallableNull(Callable callable) { - this.callable = callable; + ObservableFromSupplierNull(Supplier supplier) { + this.supplier = supplier; } @Override protected void subscribeActual(Observer observer) { - CallableNullDisposable deferred = new CallableNullDisposable(observer); + SupplierNullDisposable deferred = new SupplierNullDisposable<>(observer); observer.onSubscribe(deferred); if (!deferred.isDisposed()) { @@ -45,7 +44,7 @@ protected void subscribeActual(Observer observer) { T v; try { - v = callable.call(); + v = supplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); if (!deferred.isDisposed()) { @@ -65,15 +64,15 @@ protected void subscribeActual(Observer observer) { } @Override - public T call() throws Exception { - return callable.call(); + public T get() throws Throwable { + return supplier.get(); } - static final class CallableNullDisposable extends DeferredScalarDisposable { + static final class SupplierNullDisposable extends DeferredScalarDisposable { private static final long serialVersionUID = -7088349936918117528L; - CallableNullDisposable(Observer downstream) { + SupplierNullDisposable(Observer downstream) { super(downstream); } diff --git a/src/main/java/hu/akarnokd/rxjava2/async/package-info.java b/src/main/java/hu/akarnokd/rxjava4/async/package-info.java similarity index 78% rename from src/main/java/hu/akarnokd/rxjava2/async/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/async/package-info.java index 7fb7a2a5..75ec0e83 100644 --- a/src/main/java/hu/akarnokd/rxjava2/async/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/async/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ /** * Utility methods to jumpstart a reactive sequence via - * {@link hu.akarnokd.rxjava2.async.AsyncFlowable AsyncFlowable} - * and {@link hu.akarnokd.rxjava2.async.AsyncObservable AsyncObservable}; + * {@link hu.akarnokd.rxjava4.async.AsyncFlowable AsyncFlowable} + * and {@link hu.akarnokd.rxjava4.async.AsyncObservable AsyncObservable}; * port of the RxJavaAsyncUtil library. */ -package hu.akarnokd.rxjava2.async; \ No newline at end of file +package hu.akarnokd.rxjava4.async; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicEmptyQueueSubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicEmptyQueueSubscription.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BasicEmptyQueueSubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BasicEmptyQueueSubscription.java index 2f560c05..baa6041c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicEmptyQueueSubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicEmptyQueueSubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import io.reactivex.internal.fuseable.QueueSubscription; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Base class for empty, async-fuseable intermediate operators. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicNonoIntQueueSubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicNonoIntQueueSubscription.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BasicNonoIntQueueSubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BasicNonoIntQueueSubscription.java index a20d8897..4416f220 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicNonoIntQueueSubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicNonoIntQueueSubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.internal.fuseable.QueueSubscription; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Base class for atomic integer, async-fuseable intermediate operators. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicNonoSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicNonoSubscriber.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BasicNonoSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BasicNonoSubscriber.java index 6633042d..e0eda3d9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicNonoSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicNonoSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Basic subscriber that supports queue fusion and defaults onSubscribe, onNext and cancel. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicRefNonoSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicRefNonoSubscriber.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BasicRefNonoSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BasicRefNonoSubscriber.java index 8f96ed67..cb41a428 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicRefNonoSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicRefNonoSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Basic subscriber that supports queue fusion, has an atomic reference and defaults onSubscribe, onNext and cancel. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicRefQueueSubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicRefQueueSubscription.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BasicRefQueueSubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BasicRefQueueSubscription.java index ccd18ef8..acd99714 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicRefQueueSubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicRefQueueSubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.internal.fuseable.QueueSubscription; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Base class extending AtomicReference (resource tracking) and QueueSubscription (fusion). diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicSoloQueueSubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicSoloQueueSubscription.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BasicSoloQueueSubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BasicSoloQueueSubscription.java index 1b073744..bdcbacdc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BasicSoloQueueSubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BasicSoloQueueSubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import io.reactivex.internal.fuseable.QueueSubscription; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Base class that defaults the offer() methods of QueueSubscription. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/BlockingGetSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/BlockingGetSubscriber.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/BlockingGetSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/BlockingGetSubscriber.java index b9920786..a4e5d9f2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/BlockingGetSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/BlockingGetSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Blocks until the source terminates and returns the (last) value it produced if any. diff --git a/src/main/java/hu/akarnokd/rxjava2/util/CompositeSubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/CompositeSubscription.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/util/CompositeSubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/CompositeSubscription.java index 85ff03e6..82691fdf 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/CompositeSubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/CompositeSubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscription; +import java.util.concurrent.Flow.Subscription; -import io.reactivex.internal.util.OpenHashSet; +import hu.akarnokd.rxjava4.internal.rxcopy.OpenHashSet; /** * Container for Subscriptions and atomic operations on them. */ -public final class CompositeSubscription implements Subscription { +final class CompositeSubscription implements Subscription { OpenHashSet set; @@ -35,7 +35,7 @@ public boolean add(Subscription s) { if (!cancelled) { OpenHashSet h = set; if (h == null) { - h = new OpenHashSet(); + h = new OpenHashSet<>(); set = h; } h.add(s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/FuturePerhapsSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/FuturePerhapsSubscriber.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/FuturePerhapsSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/FuturePerhapsSubscriber.java index 7e4e0dff..160f4599 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/FuturePerhapsSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/FuturePerhapsSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * A Subscriber + Future that expects exactly one upstream value and provides it @@ -40,7 +39,7 @@ final class FuturePerhapsSubscriber extends CountDownLatch FuturePerhapsSubscriber() { super(1); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/Nono.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/Nono.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/Nono.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/Nono.java index 2d947fdb..74c29173 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/Nono.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/Nono.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; import java.util.concurrent.*; - -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.annotations.SchedulerSupport; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.annotations.SchedulerSupport; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; /** * Represents the base reactive class with fluent API for Publisher-based, @@ -68,7 +67,7 @@ protected static Nono onAssembly(Nono source) { Function f = onAssemblyHandler; if (f != null) { try { - return ObjectHelper.requireNonNull(f.apply(source), "The onAssemblyHandler returned a null Nono"); + return Objects.requireNonNull(f.apply(source), "The onAssemblyHandler returned a null Nono"); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } @@ -105,7 +104,7 @@ public static void setOnAssemblyHandler(Function handler) { * @return the new Nono instance */ public static Nono create(CompletableOnSubscribe onCreate) { - ObjectHelper.requireNonNull(onCreate, "onCreate is null"); + Objects.requireNonNull(onCreate, "onCreate is null"); return onAssembly(new NonoCreate(onCreate)); } @@ -132,18 +131,18 @@ public static Nono never() { * @return the new Nono instance */ public static Nono error(Throwable ex) { - ObjectHelper.requireNonNull(ex, "ex is null"); + Objects.requireNonNull(ex, "ex is null"); return onAssembly(new NonoError(ex)); } /** * Returns a Nono that signals a Throwable generated by the - * callable for each individual subscriber. + * supplier for each individual subscriber. * @param errorSupplier the Throwable error supplier, not null * @return the new Nono instance */ - public static Nono error(Callable errorSupplier) { - ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); + public static Nono error(Supplier errorSupplier) { + Objects.requireNonNull(errorSupplier, "errorSupplier is null"); return onAssembly(new NonoErrorSupplier(errorSupplier)); } @@ -154,8 +153,8 @@ public static Nono error(Callable errorSupplier) { * subscriber. * @return the new Nono instance */ - public static Nono defer(Callable supplier) { - ObjectHelper.requireNonNull(supplier, "supplier is null"); + public static Nono defer(Supplier supplier) { + Objects.requireNonNull(supplier, "supplier is null"); return onAssembly(new NonoDefer(supplier)); } @@ -166,7 +165,7 @@ public static Nono defer(Callable supplier) { * @return the new nono instance */ public static Nono fromAction(Action action) { - ObjectHelper.requireNonNull(action, "action is null"); + Objects.requireNonNull(action, "action is null"); return onAssembly(new NonoFromAction(action)); } @@ -177,7 +176,7 @@ public static Nono fromAction(Action action) { * @return the new Nono instance */ public static Nono fromFuture(Future future) { - ObjectHelper.requireNonNull(future, "future is null"); + Objects.requireNonNull(future, "future is null"); return onAssembly(new NonoFromFuture(future, 0L, TimeUnit.NANOSECONDS)); } @@ -190,8 +189,8 @@ public static Nono fromFuture(Future future) { * @return the new Nono instance */ public static Nono fromFuture(Future future, long timeout, TimeUnit unit) { - ObjectHelper.requireNonNull(future, "future is null"); - ObjectHelper.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(future, "future is null"); + Objects.requireNonNull(unit, "unit is null"); return onAssembly(new NonoFromFuture(future, timeout, unit)); } @@ -202,7 +201,7 @@ public static Nono fromFuture(Future future, long timeout, TimeUnit unit) { * @return the new Nono instance */ public static Nono amb(Iterable sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoAmbIterable(sources)); } @@ -213,7 +212,7 @@ public static Nono amb(Iterable sources) { * @return the new Nono instance */ public static Nono ambArray(Nono... sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoAmbArray(sources)); } @@ -223,7 +222,7 @@ public static Nono ambArray(Nono... sources) { * @return the new Nono instances */ public static Nono concat(Iterable sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoConcatIterable(sources, false)); } @@ -244,7 +243,7 @@ public static Nono concat(Publisher sources) { * @return the new Nono instance */ public static Nono concat(Publisher sources, int prefetch) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return onAssembly(new NonoConcat(sources, prefetch, ErrorMode.IMMEDIATE)); } @@ -255,7 +254,7 @@ public static Nono concat(Publisher sources, int prefetch) { * @return the new Nono instances */ public static Nono concatArray(Nono... sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoConcatArray(sources, false)); } @@ -266,7 +265,7 @@ public static Nono concatArray(Nono... sources) { * @return the new Nono instances */ public static Nono concatDelayError(Iterable sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoConcatIterable(sources, true)); } @@ -290,7 +289,7 @@ public static Nono concatDelayError(Publisher sources) { * @return the new Nono instances */ public static Nono concatDelayError(Publisher sources, int prefetch, boolean tillTheEnd) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); return onAssembly(new NonoConcat(sources, prefetch, tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY)); } @@ -302,7 +301,7 @@ public static Nono concatDelayError(Publisher sources, int prefe * @return the new Nono instances */ public static Nono concatArrayDelayError(Nono... sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoConcatArray(sources, true)); } @@ -323,7 +322,7 @@ public static Nono merge(Iterable sources) { * @return the new Nono instance */ public static Nono merge(Iterable sources, int maxConcurrency) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return onAssembly(new NonoMergeIterable(sources, false, maxConcurrency)); } @@ -345,7 +344,7 @@ public static Nono merge(Publisher sources) { * @return the new Nono instance */ public static Nono merge(Publisher sources, int maxConcurrency) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return onAssembly(new NonoMerge(sources, false, maxConcurrency)); } @@ -368,7 +367,7 @@ public static Nono mergeArray(Nono... sources) { */ public static Nono mergeArray(int maxConcurrency, Nono... sources) { ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoMergeArray(sources, false, maxConcurrency)); } @@ -390,7 +389,7 @@ public static Nono mergeDelayError(Iterable sources) { * @return the new Nono instance */ public static Nono mergeDelayError(Iterable sources, int maxConcurrency) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return onAssembly(new NonoMergeIterable(sources, true, maxConcurrency)); } @@ -414,7 +413,7 @@ public static Nono mergeDelayError(Publisher sources) { * @return the new Nono instance */ public static Nono mergeDelayError(Publisher sources, int maxConcurrency) { - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); return onAssembly(new NonoMerge(sources, true, maxConcurrency)); } @@ -438,7 +437,7 @@ public static Nono mergeArrayDelayError(Nono... sources) { */ public static Nono mergeArrayDelayError(int maxConcurrency, Nono... sources) { ObjectHelper.verifyPositive(maxConcurrency, "maxConcurrency"); - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(sources, "sources is null"); return onAssembly(new NonoMergeArray(sources, true, maxConcurrency)); } @@ -462,8 +461,8 @@ public static Nono timer(long delay, TimeUnit unit) { */ @SchedulerSupport(SchedulerSupport.CUSTOM) public static Nono timer(long delay, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new NonoTimer(delay, unit, scheduler)); } @@ -478,7 +477,7 @@ public static Nono timer(long delay, TimeUnit unit, Scheduler scheduler) { * downstream cancels * @return the new Nono instance */ - public static Nono using(Callable resourceSupplier, Function sourceSupplier, + public static Nono using(Supplier resourceSupplier, Function sourceSupplier, Consumer disposer) { return using(resourceSupplier, sourceSupplier, disposer, true); } @@ -496,12 +495,12 @@ public static Nono using(Callable resourceSupplier, Function Nono using(Callable resourceSupplier, Function sourceSupplier, + public static Nono using(Supplier resourceSupplier, Function sourceSupplier, Consumer disposer, boolean eager) { - ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null"); - ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null"); - ObjectHelper.requireNonNull(disposer, "disposer is null"); - return onAssembly(new NonoUsing(resourceSupplier, sourceSupplier, disposer, eager)); + Objects.requireNonNull(resourceSupplier, "resourceSupplier is null"); + Objects.requireNonNull(sourceSupplier, "sourceSupplier is null"); + Objects.requireNonNull(disposer, "disposer is null"); + return onAssembly(new NonoUsing<>(resourceSupplier, sourceSupplier, disposer, eager)); } /** @@ -514,7 +513,7 @@ public static Nono fromPublisher(Publisher source) { if (source instanceof Nono) { return (Nono)source; } - ObjectHelper.requireNonNull(source, "source is null"); + Objects.requireNonNull(source, "source is null"); return onAssembly(new NonoFromPublisher(source)); } @@ -525,7 +524,7 @@ public static Nono fromPublisher(Publisher source) { * @return the new Nono instance */ public static Nono fromSingle(SingleSource source) { - ObjectHelper.requireNonNull(source, "source is null"); + Objects.requireNonNull(source, "source is null"); return onAssembly(new NonoFromSingle(source)); } @@ -536,7 +535,7 @@ public static Nono fromSingle(SingleSource source) { * @return the new Nono instance */ public static Nono fromMaybe(MaybeSource source) { - ObjectHelper.requireNonNull(source, "source is null"); + Objects.requireNonNull(source, "source is null"); return onAssembly(new NonoFromMaybe(source)); } @@ -547,7 +546,7 @@ public static Nono fromMaybe(MaybeSource source) { * @return the new Nono instance */ public static Nono fromCompletable(CompletableSource source) { - ObjectHelper.requireNonNull(source, "source is null"); + Objects.requireNonNull(source, "source is null"); return onAssembly(new NonoFromCompletable(source)); } @@ -558,7 +557,7 @@ public static Nono fromCompletable(CompletableSource source) { * @return the new Nono instance */ public static Nono fromObservable(ObservableSource source) { - ObjectHelper.requireNonNull(source, "source is null"); + Objects.requireNonNull(source, "source is null"); return onAssembly(new NonoFromObservable(source)); } @@ -574,7 +573,7 @@ public static Nono fromObservable(ObservableSource source) { * @return the new Flowable instance */ public final Flowable andThen(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); return RxJavaPlugins.onAssembly(new NonoAndThenPublisher(this, other)); } @@ -584,7 +583,7 @@ public final Flowable andThen(Publisher other) { * @return the new Nono instance */ public final Nono andThen(Nono other) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); return onAssembly(new NonoAndThen(this, other)); } @@ -610,8 +609,8 @@ public final Nono delay(long delay, TimeUnit unit) { */ @SchedulerSupport(SchedulerSupport.CUSTOM) public final Nono delay(long delay, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new NonoDelay(this, delay, unit, scheduler)); } @@ -622,7 +621,7 @@ public final Nono delay(long delay, TimeUnit unit, Scheduler scheduler) { * @return the new Nono instance */ public final Nono delaySubscription(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); return onAssembly(new NonoDelaySubscription(this, other)); } @@ -694,9 +693,9 @@ public final Nono timeout(long timeout, TimeUnit unit, Scheduler scheduler) { * @return the new Nono instance */ public final Nono timeout(long timeout, TimeUnit unit, Scheduler scheduler, Nono fallback) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - ObjectHelper.requireNonNull(fallback, "fallback is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(fallback, "fallback is null"); return timeout(timer(timeout, unit, scheduler), fallback); } @@ -707,7 +706,7 @@ public final Nono timeout(long timeout, TimeUnit unit, Scheduler scheduler, Nono * @return the new Nono instance */ public final Nono timeout(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); return onAssembly(new NonoTimeout(this, other, null)); } @@ -719,8 +718,8 @@ public final Nono timeout(Publisher other) { * @return the new Nono instance */ public final Nono timeout(Publisher other, Nono fallback) { - ObjectHelper.requireNonNull(other, "other is null"); - ObjectHelper.requireNonNull(fallback, "fallback is null"); + Objects.requireNonNull(other, "other is null"); + Objects.requireNonNull(fallback, "fallback is null"); return onAssembly(new NonoTimeout(this, other, fallback)); } @@ -740,7 +739,7 @@ public final Nono onErrorComplete() { * @return the new Nono instance */ public final Nono onErrorResumeNext(Function errorHandler) { - ObjectHelper.requireNonNull(errorHandler, "errorHandler is null"); + Objects.requireNonNull(errorHandler, "errorHandler is null"); return onAssembly(new NonoOnErrorResume(this, errorHandler)); } @@ -751,7 +750,7 @@ public final Nono onErrorResumeNext(Function * @return the new Nono instance */ public final Nono mapError(Function mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(mapper, "mapper is null"); return onAssembly(new NonoMapError(this, mapper)); } @@ -761,15 +760,15 @@ public final Nono mapError(Function mapp * @param the value type * @param onErrorMapper the function that receives the upstream error and * returns a Publisher to emit events of - * @param onCompleteMapper the callable that returns a Publisher to emit + * @param onCompleteMapper the supplier that returns a Publisher to emit * events of * @return the new Flowable instance */ public final Flowable flatMap(Function> onErrorMapper, - Callable> onCompleteMapper) { - ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null"); - ObjectHelper.requireNonNull(onCompleteMapper, "onCompleteMapper is null"); - return RxJavaPlugins.onAssembly(new NonoFlatMapSignal(this, onErrorMapper, onCompleteMapper)); + Supplier> onCompleteMapper) { + Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); + Objects.requireNonNull(onCompleteMapper, "onCompleteMapper is null"); + return RxJavaPlugins.onAssembly(new NonoFlatMapSignal<>(this, onErrorMapper, onCompleteMapper)); } /** @@ -804,7 +803,7 @@ public final R to(Function converter) { * @return the new Nono instance */ public final Nono lift(Function, Subscriber> lifter) { - ObjectHelper.requireNonNull(lifter, "lifter is null"); + Objects.requireNonNull(lifter, "lifter is null"); return onAssembly(new NonoLift(this, lifter)); } @@ -860,7 +859,7 @@ public final Perhaps toPerhaps() { * @return the new Nono instance */ public final Nono subscribeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new NonoSubscribeOn(this, scheduler)); } @@ -871,7 +870,7 @@ public final Nono subscribeOn(Scheduler scheduler) { * @return the new Nono instance */ public final Nono observeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new NonoObserveOn(this, scheduler)); } @@ -882,7 +881,7 @@ public final Nono observeOn(Scheduler scheduler) { * @return the new Nono instance */ public final Nono unsubscribeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new NonoUnsubscribeOn(this, scheduler)); } @@ -893,7 +892,7 @@ public final Nono unsubscribeOn(Scheduler scheduler) { * @return the new Nolo instance */ public final Nono doOnComplete(Action onComplete) { - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); return onAssembly(new NonoDoOnLifecycle(this, Functions.emptyConsumer(), onComplete, @@ -911,7 +910,7 @@ public final Nono doOnComplete(Action onComplete) { * @return the new Nolo instance */ public final Nono doOnError(Consumer onError) { - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onError, "onError is null"); return onAssembly(new NonoDoOnLifecycle(this, onError, Functions.EMPTY_ACTION, @@ -928,7 +927,7 @@ public final Nono doOnError(Consumer onError) { * @return the new Nolo instance */ public final Nono doOnSubscribe(Consumer onSubscribe) { - ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); + Objects.requireNonNull(onSubscribe, "onSubscribe is null"); return onAssembly(new NonoDoOnLifecycle(this, Functions.emptyConsumer(), Functions.EMPTY_ACTION, @@ -945,7 +944,7 @@ public final Nono doOnSubscribe(Consumer onSubscribe) { * @return the new Nolo instance */ public final Nono doOnRequest(LongConsumer onRequest) { - ObjectHelper.requireNonNull(onRequest, "onRequest is null"); + Objects.requireNonNull(onRequest, "onRequest is null"); return onAssembly(new NonoDoOnLifecycle(this, Functions.emptyConsumer(), Functions.EMPTY_ACTION, @@ -963,7 +962,7 @@ public final Nono doOnRequest(LongConsumer onRequest) { * @return the new Nono instance */ public final Nono doAfterTerminate(Action onAfterTerminate) { - ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); + Objects.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); return onAssembly(new NonoDoOnLifecycle(this, Functions.emptyConsumer(), Functions.EMPTY_ACTION, @@ -981,7 +980,7 @@ public final Nono doAfterTerminate(Action onAfterTerminate) { * @return the new Nono instance */ public final Nono doFinally(Action onFinally) { - ObjectHelper.requireNonNull(onFinally, "action is null"); + Objects.requireNonNull(onFinally, "action is null"); return onAssembly(new NonoDoFinally(this, onFinally)); } @@ -991,7 +990,7 @@ public final Nono doFinally(Action onFinally) { * @return the new Nono instance */ public final Nono doOnCancel(Action onCancel) { - ObjectHelper.requireNonNull(onCancel, "action is null"); + Objects.requireNonNull(onCancel, "action is null"); return onAssembly(new NonoDoOnLifecycle(this, Functions.emptyConsumer(), Functions.EMPTY_ACTION, @@ -1025,7 +1024,7 @@ public final Nono repeat(long times) { * @return the new Nono instance */ public final Nono repeat(BooleanSupplier stop) { - ObjectHelper.requireNonNull(stop, "stop is null"); + Objects.requireNonNull(stop, "stop is null"); return onAssembly(new NonoRepeatUntil(this, stop)); } @@ -1038,7 +1037,7 @@ public final Nono repeat(BooleanSupplier stop) { * @return the new Nono instance */ public final Nono repeatWhen(Function, ? extends Publisher> handler) { - ObjectHelper.requireNonNull(handler, "handler is null"); + Objects.requireNonNull(handler, "handler is null"); return onAssembly(new NonoRepeatWhen(this, handler)); } @@ -1066,7 +1065,7 @@ public final Nono retry(long times) { * @return the new Nono instance */ public final Nono retry(Predicate predicate) { - ObjectHelper.requireNonNull(predicate, "predicate is null"); + Objects.requireNonNull(predicate, "predicate is null"); return onAssembly(new NonoRetryWhile(this, predicate)); } @@ -1079,7 +1078,7 @@ public final Nono retry(Predicate predicate) { * @return the new Nono instance */ public final Nono retryWhen(Function, ? extends Publisher> handler) { - ObjectHelper.requireNonNull(handler, "handler is null"); + Objects.requireNonNull(handler, "handler is null"); return onAssembly(new NonoRetryWhen(this, handler)); } @@ -1101,7 +1100,7 @@ public final Nono hide() { * @return the new Nono instance */ public final Nono takeUntil(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); return onAssembly(new NonoTakeUntil(this, other)); } @@ -1122,7 +1121,7 @@ public final Nono cache() { @Override public final void subscribe(Subscriber s) { - ObjectHelper.requireNonNull(s, "s is null"); + Objects.requireNonNull(s, "s is null"); try { subscribeActual(s); @@ -1164,7 +1163,7 @@ public final > E subscribeWith(E subscriber) { */ @SchedulerSupport(SchedulerSupport.NONE) public final TestSubscriber test() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); subscribe(ts); return ts; } @@ -1177,7 +1176,7 @@ public final TestSubscriber test() { */ @SchedulerSupport(SchedulerSupport.NONE) public final TestSubscriber test(boolean cancelled) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); if (cancelled) { ts.cancel(); } @@ -1193,9 +1192,9 @@ public final TestSubscriber test(boolean cancelled) { */ @SchedulerSupport(SchedulerSupport.NONE) public final Throwable blockingAwait() { - if (this instanceof Callable) { + if (this instanceof Supplier) { try { - ((Callable)this).call(); + ((Supplier)this).get(); return null; } catch (Throwable ex) { Exceptions.throwIfFatal(ex); @@ -1217,16 +1216,16 @@ public final Throwable blockingAwait() { */ @SchedulerSupport(SchedulerSupport.NONE) public final Throwable blockingAwait(long timeout, TimeUnit unit) { - if (this instanceof Callable) { + if (this instanceof Supplier) { try { - ((Callable)this).call(); + ((Supplier)this).get(); return null; } catch (Throwable ex) { Exceptions.throwIfFatal(ex); return ex; } } - ObjectHelper.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(unit, "unit is null"); NonoBlockingAwaitSubscriber s = new NonoBlockingAwaitSubscriber(); subscribe(s); return s.blockingAwait(timeout, unit); @@ -1264,8 +1263,8 @@ public final Disposable subscribe(Action onComplete) { */ @SchedulerSupport(SchedulerSupport.NONE) public final Disposable subscribe(Action onComplete, Consumer onError) { - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onError, "onError is null"); NonoLambdaSubscriber s = new NonoLambdaSubscriber(onComplete, onError); subscribe(s); return s; @@ -1296,8 +1295,8 @@ public final void blockingSubscribe(Action onComplete) { * @param onError the Consumer to call when this Nono terminates with an error */ public final void blockingSubscribe(Action onComplete, Consumer onError) { - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onError, "onError is null"); Throwable ex = blockingAwait(); if (ex != null) { try { @@ -1322,7 +1321,7 @@ public final void blockingSubscribe(Action onComplete, Consumer toFuture() { - FuturePerhapsSubscriber fs = new FuturePerhapsSubscriber(); + FuturePerhapsSubscriber fs = new FuturePerhapsSubscriber<>(); subscribe(fs); return fs; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAmbArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAmbArray.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAmbArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAmbArray.java index 4ee95172..ebd87e2d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAmbArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAmbArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.NonoAmbIterable.AmbSubscriber; -import io.reactivex.exceptions.Exceptions; +import hu.akarnokd.rxjava4.basetypes.NonoAmbIterable.AmbSubscriber; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Terminate as soon as one of the Mono sources terminates. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAmbIterable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAmbIterable.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAmbIterable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAmbIterable.java index 7559ff87..f9139e63 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAmbIterable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAmbIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import hu.akarnokd.rxjava2.util.CompositeSubscription; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.subscriptions.BasicIntQueueSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicIntQueueSubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Terminate as soon as one of the Mono sources terminates. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAndThen.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAndThen.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAndThen.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAndThen.java index 95bc0fb3..ed50a993 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAndThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAndThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Run a Nono after another Nono. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAndThenPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAndThenPublisher.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAndThenPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAndThenPublisher.java index 48c44cf9..2897c61e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoAndThenPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoAndThenPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.Flowable; /** * Run the Nono before switching to the Publisher and relaying its values. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoBlockingAwaitSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoBlockingAwaitSubscriber.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoBlockingAwaitSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoBlockingAwaitSubscriber.java index 421821f9..8d9435d4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoBlockingAwaitSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoBlockingAwaitSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Block until the upstream terminates. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoCache.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoCache.java similarity index 95% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoCache.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoCache.java index 6fb69b10..792b140b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoCache.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - /** * Cache the terminal event of the upstream source. * @@ -42,7 +41,7 @@ final class NonoCache extends Nono implements Subscriber { NonoCache(Nono source) { this.source = source; this.once = new AtomicBoolean(); - this.subscribers = new AtomicReference(EMPTY); + this.subscribers = new AtomicReference<>(EMPTY); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoComplete.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoComplete.java similarity index 71% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoComplete.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoComplete.java index 9d487ad4..8d880da9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoComplete.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoComplete.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.functions.Supplier; /** * Completes the subscriber immediately. */ -final class NonoComplete extends Nono implements Callable { +final class NonoComplete extends Nono implements Supplier { static final NonoComplete INSTANCE = new NonoComplete(); @@ -35,7 +34,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public Void call() throws Exception { + public Void get() throws Exception { return null; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoConcat.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoConcat.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoConcat.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoConcat.java index 6520131d..e33ef92c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoConcat.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoConcat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.queue.*; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.ErrorMode; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.operators.*; /** * Concatenate sources emitted by a Publisher one after another and complete after each complete. @@ -64,7 +61,7 @@ abstract static class AbstractConcatSubscriber extends BasicIntQueueSubscription final int limit; - final AtomicThrowable error; + final AtomicThrowable errors; final InnerSubscriber inner; @@ -86,7 +83,7 @@ abstract static class AbstractConcatSubscriber extends BasicIntQueueSubscription this.downstream = downstream; this.prefetch = prefetch; this.limit = prefetch - (prefetch >> 2); - this.error = new AtomicThrowable(); + this.errors = new AtomicThrowable(); this.inner = new InnerSubscriber(); } @@ -148,13 +145,13 @@ public final void onSubscribe(Subscription s) { } if (prefetch == Integer.MAX_VALUE) { - queue = new SpscLinkedArrayQueue(bufferSize()); + queue = new SpscLinkedArrayQueue<>(bufferSize()); downstream.onSubscribe(this); s.request(Long.MAX_VALUE); } else { - queue = new SpscArrayQueue(prefetch); + queue = new SpscArrayQueue<>(prefetch); downstream.onSubscribe(this); @@ -240,14 +237,14 @@ static final class ConcatImmediateSubscriber extends AbstractConcatSubscriber { @Override public void onError(Throwable t) { - cancel(); - HalfSerializer.onError(downstream, t, this, error); + cancelIf(true); + HalfSerializer.onError(downstream, t, this, errors); } @Override public void innerError(Throwable t) { - cancel(); - HalfSerializer.onError(downstream, t, this, error); + cancelIf(true); + HalfSerializer.onError(downstream, t, this, errors); } @Override @@ -258,13 +255,21 @@ public void onComplete() { @Override public void cancel() { + cancelIf(false); + } + + void cancelIf(boolean error) { cancelled = true; upstream.cancel(); inner.dispose(); + if (!error) { + errors.tryTerminateAndReport(); + } if (wip.getAndIncrement() == 0) { queue.clear(); } + } @Override @@ -289,14 +294,14 @@ public void drain() { Exceptions.throwIfFatal(ex); upstream.cancel(); queue.clear(); - HalfSerializer.onError(downstream, ex, this, error); + HalfSerializer.onError(downstream, ex, this, errors); return; } boolean empty = np == null; if (d && empty) { - HalfSerializer.onComplete(downstream, this, error); + HalfSerializer.onComplete(downstream, this, errors); return; } @@ -324,11 +329,9 @@ static final class ConcatDelayedSubscriber extends AbstractConcatSubscriber { @Override public void onError(Throwable t) { - if (error.addThrowable(t)) { + if (errors.tryAddThrowableOrReport(t)) { done = true; drain(); - } else { - RxJavaPlugins.onError(t); } } @@ -343,6 +346,7 @@ public void cancel() { cancelled = true; upstream.cancel(); inner.dispose(); + errors.tryTerminateAndReport(); if (getAndIncrement() == 0) { queue.clear(); @@ -362,9 +366,9 @@ void drain() { } if (!active) { - if (!tillTheEnd && error.get() != null) { + if (!tillTheEnd && errors.get() != null) { queue.clear(); - downstream.onError(error.terminate()); + errors.tryTerminateConsumer(downstream); return; } @@ -378,21 +382,16 @@ void drain() { Exceptions.throwIfFatal(ex); upstream.cancel(); queue.clear(); - error.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); - downstream.onError(error.terminate()); + errors.tryTerminateConsumer(downstream); return; } boolean empty = np == null; if (d && empty) { - Throwable ex = error.terminate(); - if (ex != null) { - downstream.onError(ex); - } else { - downstream.onComplete(); - } + errors.tryTerminateConsumer(downstream); return; } @@ -408,14 +407,12 @@ void drain() { @Override void innerError(Throwable t) { - if (error.addThrowable(t)) { + if (errors.tryAddThrowableOrReport(t)) { if (!tillTheEnd) { upstream.cancel(); } active = false; drain(); - } else { - RxJavaPlugins.onError(t); } } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoConcatArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoConcatArray.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoConcatArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoConcatArray.java index b85552fe..6d3f1fa8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoConcatArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoConcatArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicInteger; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.AtomicThrowable; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Subscribe to the Nono sources one at a time and complete if all of them complete. @@ -70,6 +68,9 @@ static final class ConcatSubscriber extends BasicRefQueueSubscription s) { Iterator it; try { - it = ObjectHelper.requireNonNull(sources.iterator(), "The sources Iterable returned a null Iterator"); + it = Objects.requireNonNull(sources.iterator(), "The sources Iterable returned a null Iterator"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); @@ -81,6 +78,9 @@ static final class ConcatSubscriber extends BasicRefQueueSubscription supplier; + final Supplier supplier; - NonoDefer(Callable supplier) { + NonoDefer(Supplier supplier) { this.supplier = supplier; } @@ -37,7 +36,7 @@ protected void subscribeActual(Subscriber s) { Nono np; try { - np = ObjectHelper.requireNonNull(supplier.call(), "The supplier returned a null Nono"); + np = Objects.requireNonNull(supplier.get(), "The supplier returned a null Nono"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDelay.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDelay.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDelay.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDelay.java index 44118133..7cb6ef0f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDelay.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDelay.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.Flow.Subscriber; + +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; -import org.reactivestreams.Subscriber; +import java.util.concurrent.TimeUnit; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; /** * Emit the terminal events on the specified Scheduler. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDelaySubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDelaySubscription.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDelaySubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDelaySubscription.java index e8f69509..d4348db9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDelaySubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDelaySubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Delay subscribing to the main Nono until the other Publisher signals diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDoFinally.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDoFinally.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDoFinally.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDoFinally.java index b2a51dd3..50a23527 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDoFinally.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDoFinally.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Action; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Action; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Execute an action exactly once after the upstream terminates or the diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDoOnLifecycle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDoOnLifecycle.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDoOnLifecycle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDoOnLifecycle.java index 226b6c3a..2d7df68a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoDoOnLifecycle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoDoOnLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Execute callbacks at various points in the lifecycle. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoError.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoError.java similarity index 67% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoError.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoError.java index a6a8c69e..536bea17 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoError.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoError.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.util.SneakyThrows; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.functions.Supplier; /** * Signals a constant Throwable to the subscriber. */ -final class NonoError extends Nono implements Callable { +final class NonoError extends Nono implements Supplier { final Throwable error; @@ -40,7 +38,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public Void call() throws Exception { - throw SneakyThrows.justThrow(error); + public Void get() throws Throwable { + throw error; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoErrorSupplier.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoErrorSupplier.java similarity index 56% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoErrorSupplier.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoErrorSupplier.java index 84cd1196..58c8c1c9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoErrorSupplier.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoErrorSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.util.SneakyThrows; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Signals a constant Throwable to the subscriber. */ -final class NonoErrorSupplier extends Nono implements Callable { +final class NonoErrorSupplier extends Nono implements Supplier { - final Callable errorSupplier; + final Supplier errorSupplier; - NonoErrorSupplier(Callable errorSupplier) { + NonoErrorSupplier(Supplier errorSupplier) { this.errorSupplier = errorSupplier; } @@ -40,7 +38,7 @@ final class NonoErrorSupplier extends Nono implements Callable { protected void subscribeActual(Subscriber s) { Throwable ex; try { - ex = ObjectHelper.requireNonNull(errorSupplier.call(), "The errorSupplier returned a null Throwable"); + ex = Objects.requireNonNull(errorSupplier.get(), "The errorSupplier returned a null Throwable"); } catch (Throwable e) { Exceptions.throwIfFatal(e); ex = e; @@ -50,14 +48,14 @@ protected void subscribeActual(Subscriber s) { } @Override - public Void call() throws Exception { + public Void get() throws Throwable { Throwable ex; try { - ex = ObjectHelper.requireNonNull(errorSupplier.call(), "The errorSupplier returned a null Throwable"); + ex = Objects.requireNonNull(errorSupplier.get(), "The errorSupplier returned a null Throwable"); } catch (Throwable e) { Exceptions.throwIfFatal(e); ex = e; } - throw SneakyThrows.justThrow(ex); + throw ex; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFlatMapSignal.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFlatMapSignal.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFlatMapSignal.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFlatMapSignal.java index 71ed665a..b0edc1ca 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFlatMapSignal.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFlatMapSignal.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Map the terminal events of a Nono into Publisher and stream its events. @@ -38,10 +36,10 @@ final class NonoFlatMapSignal extends Flowable { final Function> onErrorMapper; - final Callable> onCompleteMapper; + final Supplier> onCompleteMapper; NonoFlatMapSignal(Nono source, Function> onErrorMapper, - Callable> onCompleteMapper) { + Supplier> onCompleteMapper) { this.source = source; this.onErrorMapper = onErrorMapper; this.onCompleteMapper = onCompleteMapper; @@ -49,7 +47,7 @@ final class NonoFlatMapSignal extends Flowable { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new FlatMapSignalSubscriber(s, onErrorMapper, onCompleteMapper)); + source.subscribe(new FlatMapSignalSubscriber<>(s, onErrorMapper, onCompleteMapper)); } static final class FlatMapSignalSubscriber extends AtomicReference @@ -61,7 +59,7 @@ static final class FlatMapSignalSubscriber extends AtomicReference> onErrorMapper; - final Callable> onCompleteMapper; + final Supplier> onCompleteMapper; final AtomicLong requested; @@ -69,7 +67,7 @@ static final class FlatMapSignalSubscriber extends AtomicReference downstream, Function> onErrorMapper, - Callable> onCompleteMapper) { + Supplier> onCompleteMapper) { this.downstream = downstream; this.onErrorMapper = onErrorMapper; this.onCompleteMapper = onCompleteMapper; @@ -105,7 +103,7 @@ public void onNext(Void t) { public void onError(Throwable t) { Publisher p; try { - p = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Nono"); + p = Objects.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Nono"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -119,7 +117,7 @@ public void onError(Throwable t) { public void onComplete() { Publisher p; try { - p = ObjectHelper.requireNonNull(onCompleteMapper.call(), "The onCompleteMapper returned a null Nono"); + p = Objects.requireNonNull(onCompleteMapper.get(), "The onCompleteMapper returned a null Nono"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromAction.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromAction.java similarity index 73% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromAction.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromAction.java index a7cd665c..70ec65aa 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromAction.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Action; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Execute an action and complete the sequence or relay it error. */ -final class NonoFromAction extends Nono implements Callable { +final class NonoFromAction extends Nono implements Supplier { final Action action; @@ -49,7 +47,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public Void call() throws Exception { + public Void get() throws Throwable { action.run(); return null; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromCompletable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromCompletable.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromCompletable.java index 7dd41ff5..028bbea1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert a CompletableSource into a Nono. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromFuture.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromFuture.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromFuture.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromFuture.java index 10923acf..1097ccd9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromFuture.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromFuture.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.*; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Block until the Future completes or times out. */ -final class NonoFromFuture extends Nono implements Callable { +final class NonoFromFuture extends Nono implements Supplier { final Future future; @@ -62,7 +62,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public Void call() throws Exception { + public Void get() throws Throwable { if (timeout > 0L) { future.get(timeout, unit); } else { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromMaybe.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromMaybe.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromMaybe.java index 0f1a26ae..2389b688 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert a MaybeSource into a Nono. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromObservable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromObservable.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromObservable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromObservable.java index a196f4be..1e9994ef 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert a ObservableSource into a Nono. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromPublisher.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromPublisher.java index 48594746..0d8d4df9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Convert a Publisher into a Nono. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromSingle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromSingle.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromSingle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromSingle.java index 7efed3ae..1447eb86 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoFromSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoFromSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert a SingleSource into a Nono. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoHide.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoHide.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoHide.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoHide.java index cc5d54c4..9a7d1716 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoHide.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoHide.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloHide.HideSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.HideSubscriber; /** * Hides the identity of the upstream and downstream including diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoLambdaSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoLambdaSubscriber.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoLambdaSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoLambdaSubscriber.java index 04208fa4..69d746e1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoLambdaSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoLambdaSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Calls the appropriate function when this Subscriber terminates. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoLift.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoLift.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoLift.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoLift.java index f7aaec70..10ae5347 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoLift.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoLift.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Transform the downstream Subscriber into an upstream Subscriber. @@ -42,7 +42,7 @@ protected void subscribeActual(Subscriber s) { Subscriber z; try { - z = ObjectHelper.requireNonNull(lifter.apply(s), "The lifter returned a null Subscriber"); + z = Objects.requireNonNull(lifter.apply(s), "The lifter returned a null Subscriber"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMapError.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMapError.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMapError.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMapError.java index 7e958bd5..e49ecd66 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMapError.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMapError.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Function; /** * Map an upstream error into another Throwable. @@ -54,7 +54,7 @@ static final class MapErrorSubscriber extends BasicNonoSubscriber { public void onError(Throwable t) { Throwable ex; try { - ex = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Throwable"); + ex = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Throwable"); } catch (Throwable exc) { Exceptions.throwIfFatal(exc); ex = new CompositeException(t, exc); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMerge.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMerge.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMerge.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMerge.java index e452d7a7..78022f09 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMerge.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMerge.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.disposables.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Run Nonos at the same time and terminate when one or all terminate. @@ -98,14 +96,11 @@ public void onNext(Nono t) { @Override public void onError(Throwable t) { - if (errors.addThrowable(t)) { + if (errors.tryAddThrowable(t)) { if (!delayErrors) { set.dispose(); - Throwable ex = errors.terminate(); - if (ex != ExceptionHelper.TERMINATED) { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); } else { onComplete(); } @@ -117,12 +112,7 @@ public void onError(Throwable t) { @Override public void onComplete() { if (decrementAndGet() == 0) { - Throwable ex = errors.terminate(); - if (ex != null) { - downstream.onError(ex); - } else { - downstream.onComplete(); - } + errors.tryTerminateConsumer(downstream); } } @@ -146,7 +136,7 @@ void complete() { void innerError(Disposable inner, Throwable error) { set.delete(inner); - if (errors.addThrowable(error)) { + if (errors.tryAddThrowableOrReport(error)) { if (!delayErrors) { set.dispose(); @@ -157,8 +147,6 @@ void innerError(Disposable inner, Throwable error) { } else { complete(); } - } else { - RxJavaPlugins.onError(error); } } @@ -166,6 +154,7 @@ void innerError(Disposable inner, Throwable error) { public void cancel() { upstream.cancel(); set.dispose(); + errors.tryTerminateAndReport(); } final class MergeInnerSubscriber extends AtomicReference implements Subscriber, Disposable { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMergeArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMergeArray.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMergeArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMergeArray.java index 33730ab7..20feedac 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMergeArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMergeArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.util.CompositeSubscription; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Run Nono sources in parallel and complete when all complete. @@ -108,6 +104,7 @@ public void request(long n) { public void cancel() { cancelled = true; set.cancel(); + errors.tryTerminateAndReport(); } void subscribe(int n) { @@ -143,16 +140,13 @@ void subscribe(int n) { Nono np = srcs[i]; if (np == null) { - errors.addThrowable(new NullPointerException("A source is null")); + errors.tryAddThrowableOrReport(new NullPointerException("A source is null")); if (delayErrors) { i = f; break; } set.cancel(); - Throwable ex = errors.terminate(); - if (ex != ExceptionHelper.TERMINATED) { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); return; } @@ -190,20 +184,15 @@ void subscribe(int n) { @Override public void innerError(InnerSubscriber inner, Throwable ex) { set.delete(inner); - if (errors.addThrowable(ex)) { + if (errors.tryAddThrowableOrReport(ex)) { if (!delayErrors) { set.cancel(); - ex = errors.terminate(); - if (ex != ExceptionHelper.TERMINATED) { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); } else { subscribe(1); complete(); } - } else { - RxJavaPlugins.onError(ex); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMergeIterable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMergeIterable.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMergeIterable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMergeIterable.java index 5a752ea0..945dff60 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoMergeIterable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoMergeIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.Iterator; +import java.util.*; +import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.atomic.AtomicInteger; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.NonoMergeArray.*; -import hu.akarnokd.rxjava2.util.CompositeSubscription; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.AtomicThrowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.basetypes.NonoMergeArray.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Run Nono sources in parallel and complete when all complete. @@ -51,7 +46,7 @@ protected void subscribeActual(Subscriber s) { Iterator it; try { - it = ObjectHelper.requireNonNull(sources.iterator(), "The source Iterable returned a null Iterator"); + it = Objects.requireNonNull(sources.iterator(), "The source Iterable returned a null Iterator"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); @@ -119,6 +114,7 @@ public void request(long n) { public void cancel() { cancelled = true; set.cancel(); + errors.tryTerminateAndReport(); } void subscribe(int n) { @@ -154,11 +150,11 @@ void subscribe(int n) { try { hasNext = srcs.hasNext(); if (hasNext) { - np = ObjectHelper.requireNonNull(srcs.next(), "The iterator returned a null Nono"); + np = Objects.requireNonNull(srcs.next(), "The iterator returned a null Nono"); } } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - errors.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); complete(); return; } @@ -190,17 +186,15 @@ void subscribe(int n) { @Override public void innerError(InnerSubscriber inner, Throwable ex) { set.delete(inner); - if (errors.addThrowable(ex)) { + if (errors.tryAddThrowableOrReport(ex)) { if (!delayErrors) { set.cancel(); - downstream.onError(errors.terminate()); + errors.tryTerminateConsumer(downstream); } else { subscribe(1); complete(); } - } else { - RxJavaPlugins.onError(ex); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoNever.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoNever.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoNever.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoNever.java index 23146e48..57747ecc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoNever.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoNever.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; /** * Completes the subscriber immediately. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoObserveOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoObserveOn.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoObserveOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoObserveOn.java index d3f242c1..de9052aa 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoObserveOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoObserveOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; /** * Emit the terminal events on the specified Scheduler. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoOnErrorComplete.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoOnErrorComplete.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoOnErrorComplete.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoOnErrorComplete.java index 6a01279e..0cc3dffc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoOnErrorComplete.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoOnErrorComplete.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; /** * If the upstream signals an error, turn it into an onComplete. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoOnErrorResume.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoOnErrorResume.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoOnErrorResume.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoOnErrorResume.java index a78cb551..5ded6900 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoOnErrorResume.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoOnErrorResume.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Function; /** * If the main source fails, resume with another Nono returned from diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoProcessor.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoProcessor.java similarity index 96% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoProcessor.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoProcessor.java index a60eb946..f71b81cf 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoProcessor.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * A hot Nono that signals the terminal event to Subscribers. @@ -50,7 +49,7 @@ public static NonoProcessor create() { } NonoProcessor() { - subscribers = new AtomicReference(EMPTY); + subscribers = new AtomicReference<>(EMPTY); once = new AtomicBoolean(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeat.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeat.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeat.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeat.java index ae37c6ad..bfccb06d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeat.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Repeatedly re-subscribe to the source Nono. @@ -62,7 +61,7 @@ abstract static class RedoSubscriber extends BasicNonoIntQueueSubscription this.downstream = downstream; this.times = times; this.source = source; - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeatUntil.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeatUntil.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeatUntil.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeatUntil.java index 339a404b..d7113b80 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeatUntil.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeatUntil.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * Repeat until the supplier returns true. @@ -65,7 +64,7 @@ static final class RepeatUntilSubscriber extends BasicNonoIntQueueSubscription this.downstream = downstream; this.stop = stop; this.source = source; - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeatWhen.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeatWhen.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeatWhen.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeatWhen.java index ced3fb5a..52e16623 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRepeatWhen.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRepeatWhen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.*; /** * Repeat when the Publisher signals an item. @@ -92,7 +91,7 @@ static final class RepeatWhenMainSubscriber extends BasicNonoIntQueueSubscriptio RepeatWhenMainSubscriber(Subscriber downstream, FlowableProcessor processor, Nono source) { this.downstream = downstream; - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.inner = new RedoInnerSubscriber(this); this.once = new AtomicBoolean(); this.processor = processor; diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetry.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetry.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetry.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetry.java index da781af7..83675163 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetry.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetry.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.NonoRepeat.RedoSubscriber; +import hu.akarnokd.rxjava4.basetypes.NonoRepeat.RedoSubscriber; /** * Repeatedly re-subscribe to the source Nono if it fails. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetryWhen.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetryWhen.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetryWhen.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetryWhen.java index b203dd1f..a3cb7bce 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetryWhen.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetryWhen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.basetypes.NonoRepeatWhen.*; -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.*; +import hu.akarnokd.rxjava4.basetypes.NonoRepeatWhen.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.*; /** * Retry when the Publisher signals an item. @@ -84,7 +83,7 @@ static final class RetryWhenMainSubscriber extends BasicNonoIntQueueSubscription RetryWhenMainSubscriber(Subscriber downstream, FlowableProcessor processor, Nono source) { this.downstream = downstream; - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.inner = new RedoInnerSubscriber(this); this.once = new AtomicBoolean(); this.processor = processor; diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetryWhile.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetryWhile.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetryWhile.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetryWhile.java index e2c13169..3796b817 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoRetryWhile.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoRetryWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Predicate; /** * Retry while the predicate returns true. @@ -65,7 +64,7 @@ static final class RetryUntilSubscriber extends BasicNonoIntQueueSubscription this.downstream = downstream; this.predicate = predicate; this.source = source; - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoSubscribeOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoSubscribeOn.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoSubscribeOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoSubscribeOn.java index 19aee90c..da531c8c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoSubscribeOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoSubscribeOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; /** * Subscribe to the source Nono on a specified scheduler. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTakeUntil.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTakeUntil.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTakeUntil.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTakeUntil.java index 8928a67a..d228c1f7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTakeUntil.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTakeUntil.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Run the main Nono until a Publisher signals an item or completes. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTimeout.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTimeout.java similarity index 95% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTimeout.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTimeout.java index 61124133..5a967855 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTimeout.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTimeout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Signal a TimeoutException or switch to a fallback Mono if the diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTimer.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTimer.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTimer.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTimer.java index 8b89016a..4f7c16b0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoTimer.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoTimer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.Flow.Subscriber; + +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; -import org.reactivestreams.Subscriber; +import java.util.concurrent.TimeUnit; -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; /** * Signal onComplete after the specified delay on the given scheduler. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoToMaybe.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoToMaybe.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoToMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoToMaybe.java index a9edba5d..f6b0cb25 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoToMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoToMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert to an empty Maybe. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoToPerhaps.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoToPerhaps.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoToPerhaps.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoToPerhaps.java index 88d9fcea..6eef68db 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoToPerhaps.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoToPerhaps.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Convert a Nono into an empty Perhaps. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoUnsubscribeOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoUnsubscribeOn.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoUnsubscribeOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoUnsubscribeOn.java index d57243b0..263b0dc2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoUnsubscribeOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoUnsubscribeOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.Scheduler; +import io.reactivex.rxjava4.core.Scheduler; /** * Execute the downstream cancel call on the specified scheduler. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoUsing.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoUsing.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/NonoUsing.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/NonoUsing.java index 18f42e1e..f2651360 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/NonoUsing.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/NonoUsing.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Use a resource while the actual Nono is running. @@ -32,7 +30,7 @@ */ final class NonoUsing extends Nono { - final Callable resourceSupplier; + final Supplier resourceSupplier; final Function sourceSupplier; @@ -40,7 +38,7 @@ final class NonoUsing extends Nono { final boolean eager; - NonoUsing(Callable resourceSupplier, + NonoUsing(Supplier resourceSupplier, Function sourceSupplier, Consumer disposer, boolean eager) { this.resourceSupplier = resourceSupplier; @@ -54,7 +52,7 @@ protected void subscribeActual(Subscriber s) { R resource; try { - resource = resourceSupplier.call(); + resource = resourceSupplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); @@ -64,7 +62,7 @@ protected void subscribeActual(Subscriber s) { Nono np; try { - np = ObjectHelper.requireNonNull(sourceSupplier.apply(resource), "The sourceSupplier returned a null Nono"); + np = Objects.requireNonNull(sourceSupplier.apply(resource), "The sourceSupplier returned a null Nono"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); if (eager) { @@ -88,7 +86,7 @@ protected void subscribeActual(Subscriber s) { return; } - np.subscribe(new UsingSubscriber(s, resource, disposer, eager)); + np.subscribe(new UsingSubscriber<>(s, resource, disposer, eager)); } static final class UsingSubscriber extends BasicNonoIntQueueSubscription diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/Perhaps.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/Perhaps.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/Perhaps.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/Perhaps.java index 92673eba..86f91499 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/Perhaps.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/Perhaps.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; import java.util.concurrent.*; - -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; -import io.reactivex.internal.subscribers.LambdaSubscriber; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.config.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; /** * A 0-1-error base reactive type, similar to Maybe, implementing the Reactive-Streams Publisher @@ -94,8 +93,8 @@ protected static Perhaps onAssembly(Perhaps source) { * @return th new Perhaps instance */ public static Perhaps create(MaybeOnSubscribe onCreate) { - ObjectHelper.requireNonNull(onCreate, "onCreate is null"); - return onAssembly(new PerhapsCreate(onCreate)); + Objects.requireNonNull(onCreate, "onCreate is null"); + return onAssembly(new PerhapsCreate<>(onCreate)); } /** @@ -105,8 +104,8 @@ public static Perhaps create(MaybeOnSubscribe onCreate) { * @return the new Perhaps instance */ public static Perhaps just(T item) { - ObjectHelper.requireNonNull(item, "item is null"); - return onAssembly(new PerhapsJust(item)); + Objects.requireNonNull(item, "item is null"); + return onAssembly(new PerhapsJust<>(item)); } /** @@ -125,7 +124,7 @@ public static Perhaps empty() { * @return the new Perhaps instance */ public static Perhaps error(Throwable error) { - ObjectHelper.requireNonNull(error, "error is null"); + Objects.requireNonNull(error, "error is null"); return onAssembly(new PerhapsError(error)); } @@ -137,8 +136,8 @@ public static Perhaps error(Throwable error) { * return a Throwable to be signalled * @return the new Perhaps instance */ - public static Perhaps error(Callable errorSupplier) { - ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); + public static Perhaps error(Supplier errorSupplier) { + Objects.requireNonNull(errorSupplier, "errorSupplier is null"); return onAssembly(new PerhapsErrorSupplier(errorSupplier)); } @@ -159,8 +158,8 @@ public static Perhaps never() { * @return the new Perhaps instance */ public static Perhaps fromCallable(Callable callable) { - ObjectHelper.requireNonNull(callable, "callable is null"); - return onAssembly(new PerhapsFromCallable(callable)); + Objects.requireNonNull(callable, "callable is null"); + return onAssembly(new PerhapsFromCallable<>(callable)); } /** @@ -170,7 +169,7 @@ public static Perhaps fromCallable(Callable callable) { * @return the new Perhaps instance */ public static Perhaps fromAction(Action action) { - ObjectHelper.requireNonNull(action, "action is null"); + Objects.requireNonNull(action, "action is null"); return onAssembly(new PerhapsFromAction(action)); } @@ -183,7 +182,7 @@ public static Perhaps fromAction(Action action) { * @return the new Perhaps instance */ public static Perhaps fromFuture(Future future) { - ObjectHelper.requireNonNull(future, "future is null"); + Objects.requireNonNull(future, "future is null"); return onAssembly(new PerhapsFromFuture(future, 0, null)); } @@ -199,8 +198,8 @@ public static Perhaps fromFuture(Future future) { * @return the new Perhaps instance */ public static Perhaps fromFuture(Future future, long timeout, TimeUnit unit) { - ObjectHelper.requireNonNull(future, "future is null"); - ObjectHelper.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(future, "future is null"); + Objects.requireNonNull(unit, "unit is null"); return onAssembly(new PerhapsFromFuture(future, timeout, unit)); } @@ -212,8 +211,8 @@ public static Perhaps fromFuture(Future future, long timeout * @return the new Perhaps instance */ public static Perhaps fromPublisher(Publisher source) { - ObjectHelper.requireNonNull(source, "source is null"); - return onAssembly(new PerhapsFromPublisher(source)); + Objects.requireNonNull(source, "source is null"); + return onAssembly(new PerhapsFromPublisher<>(source)); } /** @@ -223,8 +222,8 @@ public static Perhaps fromPublisher(Publisher source) { * @return the new Perhaps instance */ public static Perhaps fromSingle(SingleSource source) { - ObjectHelper.requireNonNull(source, "source is null"); - return onAssembly(new PerhapsFromSingle(source)); + Objects.requireNonNull(source, "source is null"); + return onAssembly(new PerhapsFromSingle<>(source)); } /** @@ -234,8 +233,8 @@ public static Perhaps fromSingle(SingleSource source) { * @return the new Perhaps instance */ public static Perhaps fromMaybe(MaybeSource source) { - ObjectHelper.requireNonNull(source, "source is null"); - return onAssembly(new PerhapsFromMaybe(source)); + Objects.requireNonNull(source, "source is null"); + return onAssembly(new PerhapsFromMaybe<>(source)); } /** @@ -245,22 +244,22 @@ public static Perhaps fromMaybe(MaybeSource source) { * @return the new Perhaps instance */ public static Perhaps fromCompletable(CompletableSource source) { - ObjectHelper.requireNonNull(source, "source is null"); + Objects.requireNonNull(source, "source is null"); return onAssembly(new PerhapsFromCompletable(source)); } /** * Defers the creation of the actual Perhaps instance until * subscription time and for each downstream Subscriber the given - * callable is called. + * Supplier is called. * @param the value type - * @param supplier the Callable called for each individual Subscriber + * @param supplier the Supplier called for each individual Subscriber * to return a Perhaps to be subscribe to. * @return the new Perhaps instance */ - public static Perhaps defer(Callable> supplier) { - ObjectHelper.requireNonNull(supplier, "supplier is null"); - return onAssembly(new PerhapsDefer(supplier)); + public static Perhaps defer(Supplier> supplier) { + Objects.requireNonNull(supplier, "supplier is null"); + return onAssembly(new PerhapsDefer<>(supplier)); } /** @@ -270,8 +269,8 @@ public static Perhaps defer(Callable> supp * @return the new Perhaps instance */ public static Perhaps amb(Iterable> sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); - return onAssembly(new PerhapsAmbIterable(sources)); + Objects.requireNonNull(sources, "sources is null"); + return onAssembly(new PerhapsAmbIterable<>(sources)); } /** @@ -280,9 +279,10 @@ public static Perhaps amb(Iterable> source * @param sources the array of Perhaps sources * @return the new Perhaps instance */ + @SafeVarargs public static Perhaps ambArray(Perhaps... sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); - return onAssembly(new PerhapsAmbArray(sources)); + Objects.requireNonNull(sources, "sources is null"); + return onAssembly(new PerhapsAmbArray<>(sources)); } /** @@ -313,7 +313,7 @@ public static Flowable concat(Publisher> s * @return the new Flowable instance */ public static Flowable concat(Publisher> sources, int prefetch) { - return Flowable.concat(sources, prefetch); + return Flowable.concat(sources, new StandardBufferedConfig(prefetch)); } /** @@ -322,6 +322,7 @@ public static Flowable concat(Publisher> s * @param sources the sequence of sources * @return the new Flowable instance */ + @SafeVarargs public static Flowable concatArray(Perhaps... sources) { return Flowable.concatArray(sources); } @@ -334,7 +335,7 @@ public static Flowable concatArray(Perhaps... sources) { * @return the new Flowable instance */ public static Flowable concatDelayError(Iterable> sources) { - return Flowable.concatDelayError(sources); + return Flowable.concat(sources, StandardBufferedConfig.DELAY_ERRORS); } /** @@ -345,7 +346,7 @@ public static Flowable concatDelayError(Iterable Flowable concatDelayError(Publisher> sources) { - return Flowable.concatDelayError(sources); + return Flowable.concat(sources, StandardBufferedConfig.DELAY_ERRORS); } /** @@ -357,7 +358,7 @@ public static Flowable concatDelayError(Publisher Flowable concatDelayError(Publisher> sources, int prefetch) { - return Flowable.concatDelayError(sources, prefetch, false); + return Flowable.concat(sources, new StandardBufferedConfig(ErrorMode.BOUNDARY, prefetch)); } /** @@ -371,7 +372,7 @@ public static Flowable concatDelayError(Publisher Flowable concatDelayError(Publisher> sources, int prefetch, boolean tillTheEnd) { - return Flowable.concatDelayError(sources, prefetch, tillTheEnd); + return Flowable.concat(sources, new StandardBufferedConfig(tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch)); } /** @@ -381,8 +382,9 @@ public static Flowable concatDelayError(Publisher Flowable concatArrayDelayError(Perhaps... sources) { - return Flowable.concatArrayDelayError(sources); + return Flowable.concatArray(StandardBufferedConfig.DELAY_ERRORS, sources); } /** @@ -403,7 +405,7 @@ public static Flowable merge(Iterable> sou * @return the new Flowable instance */ public static Flowable merge(Iterable> sources, int maxConcurrency) { - return Flowable.merge(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(maxConcurrency)); } /** @@ -424,7 +426,7 @@ public static Flowable merge(Publisher> so * @return the new Flowable instance */ public static Flowable merge(Publisher> sources, int maxConcurrency) { - return Flowable.merge(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(maxConcurrency)); } /** @@ -433,6 +435,7 @@ public static Flowable merge(Publisher> so * @param sources the sequence of sources * @return the new Flowable instance */ + @SafeVarargs public static Flowable mergeArray(Perhaps... sources) { return Flowable.mergeArray(sources); } @@ -444,8 +447,9 @@ public static Flowable mergeArray(Perhaps... sources) { * @param maxConcurrency the maximum number of active subscriptions * @return the new Flowable instance */ + @SafeVarargs public static Flowable mergeArray(int maxConcurrency, Perhaps... sources) { - return Flowable.mergeArray(maxConcurrency, 1, sources); + return Flowable.mergeArray(new StandardConcurrentBufferedConfig(ErrorMode.IMMEDIATE, maxConcurrency, 1), sources); } /** @@ -456,7 +460,7 @@ public static Flowable mergeArray(int maxConcurrency, Perhaps Flowable mergeDelayError(Iterable> sources) { - return Flowable.mergeDelayError(sources); + return Flowable.merge(sources, StandardConcurrentBufferedConfig.DELAY_ERRORS); } /** @@ -468,7 +472,7 @@ public static Flowable mergeDelayError(Iterable Flowable mergeDelayError(Iterable> sources, int maxConcurrency) { - return Flowable.mergeDelayError(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(ErrorMode.END, maxConcurrency)); } /** @@ -479,7 +483,7 @@ public static Flowable mergeDelayError(Iterable Flowable mergeDelayError(Publisher> sources) { - return Flowable.mergeDelayError(sources); + return Flowable.merge(sources, StandardConcurrentBufferedConfig.DELAY_ERRORS); } /** @@ -491,7 +495,7 @@ public static Flowable mergeDelayError(Publisher Flowable mergeDelayError(Publisher> sources, int maxConcurrency) { - return Flowable.mergeDelayError(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(ErrorMode.END, maxConcurrency)); } /** @@ -501,8 +505,9 @@ public static Flowable mergeDelayError(Publisher Flowable mergeArrayDelayError(Perhaps... sources) { - return Flowable.mergeArrayDelayError(sources); + return Flowable.mergeArray(StandardConcurrentBufferedConfig.DELAY_ERRORS, sources); } /** @@ -513,8 +518,9 @@ public static Flowable mergeArrayDelayError(Perhaps... sourc * @param maxConcurrency the maximum number of active subscriptions * @return the new Flowable instance */ + @SafeVarargs public static Flowable mergeArrayDelayError(int maxConcurrency, Perhaps... sources) { - return Flowable.mergeArrayDelayError(maxConcurrency, 1, sources); + return Flowable.mergeArray(new StandardConcurrentBufferedConfig(ErrorMode.END, maxConcurrency, 1), sources); } /** @@ -537,8 +543,8 @@ public static Perhaps timer(long delay, TimeUnit unit) { * @return the new Perhaps instance */ public static Perhaps timer(long delay, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new PerhapsTimer(delay, unit, scheduler)); } @@ -554,7 +560,7 @@ public static Perhaps timer(long delay, TimeUnit unit, Scheduler scheduler * downstream cancels * @return the new Perhaps instance */ - public static Perhaps using(Callable resourceSupplier, + public static Perhaps using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer) { return using(resourceSupplier, sourceSupplier, disposer, true); @@ -574,13 +580,13 @@ public static Perhaps using(Callable resourceSupplier, * if false, the resource is disposed after the terminal event has been emitted * @return the new Perhaps instance */ - public static Perhaps using(Callable resourceSupplier, + public static Perhaps using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { - ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null"); - ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null"); - ObjectHelper.requireNonNull(disposer, "disposer is null"); - return onAssembly(new PerhapsUsing(resourceSupplier, sourceSupplier, disposer, eager)); + Objects.requireNonNull(resourceSupplier, "resourceSupplier is null"); + Objects.requireNonNull(sourceSupplier, "sourceSupplier is null"); + Objects.requireNonNull(disposer, "disposer is null"); + return onAssembly(new PerhapsUsing<>(resourceSupplier, sourceSupplier, disposer, eager)); } /** @@ -593,8 +599,8 @@ public static Perhaps using(Callable resourceSupplier, * @return the new Perhaps instance */ public static Perhaps zip(Iterable> sources, Function zipper) { - ObjectHelper.requireNonNull(sources, "sources is null"); - ObjectHelper.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(zipper, "zipper is null"); return onAssembly(new PerhapsZipIterable(sources, zipper)); } @@ -607,9 +613,10 @@ public static Perhaps zip(Iterable> sou * @param zipper the function takin in an array of values and returns a Perhaps value * @return the new Perhaps instance */ + @SafeVarargs public static Perhaps zipArray(Function zipper, Perhaps... sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); - ObjectHelper.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(zipper, "zipper is null"); return onAssembly(new PerhapsZipArray(sources, zipper)); } @@ -623,7 +630,6 @@ public static Perhaps zipArray(Function * @param other the other Perhaps instance * @return the new Perhaps instance */ - @SuppressWarnings("unchecked") public final Perhaps ambWith(Perhaps other) { return ambArray(this, other); } @@ -636,8 +642,8 @@ public final Perhaps ambWith(Perhaps other) { * @return the new Perhaps instance */ public final Perhaps andThen(Nono other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new PerhapsAndThenNono(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new PerhapsAndThenNono<>(this, other)); } /** @@ -647,8 +653,8 @@ public final Perhaps andThen(Nono other) { * @return the new Flowable instance */ public final Flowable andThen(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return Flowable.concat(this, other); + Objects.requireNonNull(other, "other is null"); + return Flowable.concatArray(this, other); } /** @@ -658,8 +664,8 @@ public final Flowable andThen(Publisher other) { * @return the new Flowable instance */ public final Flowable concatWith(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return Flowable.concat(this, other); + Objects.requireNonNull(other, "other is null"); + return Flowable.concatArray(this, other); } /** @@ -669,8 +675,8 @@ public final Flowable concatWith(Publisher other) { * @return the new Flowable instance */ public final Flowable mergeWith(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return Flowable.merge(this, other); + Objects.requireNonNull(other, "other is null"); + return Flowable.mergeArray(this, other); } /** @@ -683,10 +689,9 @@ public final Flowable mergeWith(Publisher other) { * return a value to be emitted * @return the new Perhaps instance */ - @SuppressWarnings("unchecked") public final Perhaps zipWith(Perhaps other, BiFunction zipper) { - ObjectHelper.requireNonNull(other, "other is null"); - ObjectHelper.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(other, "other is null"); + Objects.requireNonNull(zipper, "zipper is null"); return zipArray(Functions.toFunction(zipper), this, other); } @@ -699,7 +704,7 @@ public final Perhaps zipWith(Perhaps other, BiFunction Perhaps map(Function mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(mapper, "mapper is null"); return onAssembly(new PerhapsMap(this, mapper)); } @@ -710,8 +715,8 @@ public final Perhaps map(Function mapper) { * @return the new Perhaps instance */ public final Perhaps mapError(Function errorMapper) { - ObjectHelper.requireNonNull(errorMapper, "errorMapper is null"); - return onAssembly(new PerhapsMapError(this, errorMapper)); + Objects.requireNonNull(errorMapper, "errorMapper is null"); + return onAssembly(new PerhapsMapError<>(this, errorMapper)); } /** @@ -722,8 +727,8 @@ public final Perhaps mapError(Function filter(Predicate predicate) { - ObjectHelper.requireNonNull(predicate, "predicate is null"); - return onAssembly(new PerhapsFilter(this, predicate)); + Objects.requireNonNull(predicate, "predicate is null"); + return onAssembly(new PerhapsFilter<>(this, predicate)); } /** @@ -742,7 +747,7 @@ public final Nono ignoreElement() { * @return the new Perhaps instance */ public final Perhaps hide() { - return onAssembly(new PerhapsHide(this)); + return onAssembly(new PerhapsHide<>(this)); } /** @@ -754,8 +759,8 @@ public final Perhaps hide() { * @return the new Perhaps instance */ public final Perhaps flatMap(Function> mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - return onAssembly(new PerhapsFlatMap(this, mapper)); + Objects.requireNonNull(mapper, "mapper is null"); + return onAssembly(new PerhapsFlatMap<>(this, mapper)); } /** @@ -772,11 +777,11 @@ public final Perhaps flatMap(Function Perhaps flatMap(Function> onSuccessMapper, Function> onErrorMapper, - Callable> onCompleteMapper) { - ObjectHelper.requireNonNull(onSuccessMapper, "onSuccessMapper is null"); - ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null"); - ObjectHelper.requireNonNull(onCompleteMapper, "onCompleteMapper is null"); - return onAssembly(new PerhapsFlatMapSignal(this, onSuccessMapper, onErrorMapper, onCompleteMapper)); + Supplier> onCompleteMapper) { + Objects.requireNonNull(onSuccessMapper, "onSuccessMapper is null"); + Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); + Objects.requireNonNull(onCompleteMapper, "onCompleteMapper is null"); + return onAssembly(new PerhapsFlatMapSignal<>(this, onSuccessMapper, onErrorMapper, onCompleteMapper)); } /** @@ -787,8 +792,8 @@ public final Perhaps flatMap(Function Flowable flatMapPublisher(Function> mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - return RxJavaPlugins.onAssembly(new PerhapsFlatMapPublisher(this, mapper)); + Objects.requireNonNull(mapper, "mapper is null"); + return RxJavaPlugins.onAssembly(new PerhapsFlatMapPublisher<>(this, mapper)); } /** @@ -796,7 +801,7 @@ public final Flowable flatMapPublisher(Function onErrorComplete() { - return onAssembly(new PerhapsOnErrorReturnItem(this, null)); + return onAssembly(new PerhapsOnErrorReturnItem<>(this, null)); } /** @@ -806,8 +811,8 @@ public final Perhaps onErrorComplete() { * @return the new Perhaps instance */ public final Perhaps onErrorReturnItem(T item) { - ObjectHelper.requireNonNull(item, "item is null"); - return onAssembly(new PerhapsOnErrorReturnItem(this, item)); + Objects.requireNonNull(item, "item is null"); + return onAssembly(new PerhapsOnErrorReturnItem<>(this, item)); } /** @@ -817,8 +822,8 @@ public final Perhaps onErrorReturnItem(T item) { * @return the new Perhaps instance */ public final Perhaps onErrorResumeWith(Perhaps fallback) { - ObjectHelper.requireNonNull(fallback, "fallback is null"); - return onAssembly(new PerhapsOnErrorResumeWith(this, fallback)); + Objects.requireNonNull(fallback, "fallback is null"); + return onAssembly(new PerhapsOnErrorResumeWith<>(this, fallback)); } /** @@ -830,8 +835,8 @@ public final Perhaps onErrorResumeWith(Perhaps fallback) { * @return the new Perhaps instance */ public final Perhaps onErrorResumeNext(Function> fallbackSupplier) { - ObjectHelper.requireNonNull(fallbackSupplier, "fallbackSupplier is null"); - return onAssembly(new PerhapsOnErrorResumeNext(this, fallbackSupplier)); + Objects.requireNonNull(fallbackSupplier, "fallbackSupplier is null"); + return onAssembly(new PerhapsOnErrorResumeNext<>(this, fallbackSupplier)); } /** @@ -889,8 +894,8 @@ public final Perhaps timeout(long timeout, TimeUnit unit, Scheduler scheduler * @return the new Perhaps instance */ public final Perhaps timeout(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new PerhapsTimeout(this, other, null)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new PerhapsTimeout<>(this, other, null)); } /** @@ -901,9 +906,9 @@ public final Perhaps timeout(Publisher other) { * @return the new Perhaps instance */ public final Perhaps timeout(Publisher other, Perhaps fallback) { - ObjectHelper.requireNonNull(other, "other is null"); - ObjectHelper.requireNonNull(fallback, "fallback is null"); - return onAssembly(new PerhapsTimeout(this, other, fallback)); + Objects.requireNonNull(other, "other is null"); + Objects.requireNonNull(fallback, "fallback is null"); + return onAssembly(new PerhapsTimeout<>(this, other, fallback)); } /** @@ -912,8 +917,8 @@ public final Perhaps timeout(Publisher other, Perhaps fallbac * @return the new Perhaps instance */ public final Perhaps defaultIfEmpty(T item) { - ObjectHelper.requireNonNull(item, "item is null"); - return onAssembly(new PerhapsDefaultIfEmpty(this, item)); + Objects.requireNonNull(item, "item is null"); + return onAssembly(new PerhapsDefaultIfEmpty<>(this, item)); } /** @@ -922,8 +927,8 @@ public final Perhaps defaultIfEmpty(T item) { * @return the new Perhaps instance */ public final Perhaps switchIfEmpty(Perhaps other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new PerhapsSwitchIfEmpty(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new PerhapsSwitchIfEmpty<>(this, other)); } /** @@ -971,7 +976,7 @@ public final Flowable repeatWhen(Function, ? extends * @return the new Perhaps instance */ public final Perhaps retry() { - return onAssembly(new PerhapsRetry(this, Long.MAX_VALUE)); + return onAssembly(new PerhapsRetry<>(this, Long.MAX_VALUE)); } /** @@ -983,7 +988,7 @@ public final Perhaps retry(long times) { if (times < 0L) { throw new IllegalArgumentException("times >= 0 required but it was " + times); } - return onAssembly(new PerhapsRetry(this, times)); + return onAssembly(new PerhapsRetry<>(this, times)); } /** @@ -994,8 +999,8 @@ public final Perhaps retry(long times) { * @return the new Perhaps instance */ public final Perhaps retry(Predicate predicate) { - ObjectHelper.requireNonNull(predicate, "predicate is null"); - return onAssembly(new PerhapsRetryWhile(this, predicate)); + Objects.requireNonNull(predicate, "predicate is null"); + return onAssembly(new PerhapsRetryWhile<>(this, predicate)); } /** @@ -1007,8 +1012,8 @@ public final Perhaps retry(Predicate predicate) { * @return the new Perhaps instance */ public final Perhaps retryWhen(Function, ? extends Publisher> handler) { - ObjectHelper.requireNonNull(handler, "handler is null"); - return onAssembly(new PerhapsRetryWhen(this, handler)); + Objects.requireNonNull(handler, "handler is null"); + return onAssembly(new PerhapsRetryWhen<>(this, handler)); } /** @@ -1018,8 +1023,8 @@ public final Perhaps retryWhen(Function, ? extend * @return the new Perhaps instance */ public final Perhaps subscribeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return onAssembly(new PerhapsSubscribeOn(this, scheduler)); + Objects.requireNonNull(scheduler, "scheduler is null"); + return onAssembly(new PerhapsSubscribeOn<>(this, scheduler)); } /** @@ -1028,8 +1033,8 @@ public final Perhaps subscribeOn(Scheduler scheduler) { * @return the new Perhaps instance */ public final Perhaps observeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return onAssembly(new PerhapsObserveOn(this, scheduler)); + Objects.requireNonNull(scheduler, "scheduler is null"); + return onAssembly(new PerhapsObserveOn<>(this, scheduler)); } /** @@ -1040,8 +1045,8 @@ public final Perhaps observeOn(Scheduler scheduler) { * @return the new Perhaps instance */ public final Perhaps unsubscribeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return onAssembly(new PerhapsUnsubscribeOn(this, scheduler)); + Objects.requireNonNull(scheduler, "scheduler is null"); + return onAssembly(new PerhapsUnsubscribeOn<>(this, scheduler)); } /** @@ -1050,8 +1055,8 @@ public final Perhaps unsubscribeOn(Scheduler scheduler) { * @return the new Perhaps instance */ public final Perhaps doOnSubscribe(Consumer onSubscribe) { - ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onSubscribe, "onSubscribe is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1069,8 +1074,8 @@ public final Perhaps doOnSubscribe(Consumer onSubscribe * @return the new Perhaps instance */ public final Perhaps doOnRequest(LongConsumer onRequest) { - ObjectHelper.requireNonNull(onRequest, "onRequest is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onRequest, "onRequest is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1088,8 +1093,8 @@ public final Perhaps doOnRequest(LongConsumer onRequest) { * @return the new Perhaps instance */ public final Perhaps doOnCancel(Action onCancel) { - ObjectHelper.requireNonNull(onCancel, "onCancel is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onCancel, "onCancel is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1108,8 +1113,8 @@ public final Perhaps doOnCancel(Action onCancel) { * @return the new Perhaps instance */ public final Perhaps doOnNext(Consumer onNext) { - ObjectHelper.requireNonNull(onNext, "onNext is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onNext, "onNext is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, onNext, Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1128,8 +1133,8 @@ public final Perhaps doOnNext(Consumer onNext) { * @return the new Perhaps instance */ public final Perhaps doAfterNext(Consumer onAfterNext) { - ObjectHelper.requireNonNull(onAfterNext, "onAfterNext is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onAfterNext, "onAfterNext is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), onAfterNext, Functions.emptyConsumer(), @@ -1148,8 +1153,8 @@ public final Perhaps doAfterNext(Consumer onAfterNext) { * @return the new Perhaps instance */ public final Perhaps doOnError(Consumer onError) { - ObjectHelper.requireNonNull(onError, "onError is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onError, "onError is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), onError, @@ -1168,8 +1173,8 @@ public final Perhaps doOnError(Consumer onError) { * @return the new Perhaps instance */ public final Perhaps doOnComplete(Action onComplete) { - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onComplete, "onComplete is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1188,8 +1193,8 @@ public final Perhaps doOnComplete(Action onComplete) { * @return the new Perhaps instance */ public final Perhaps doAfterTerminate(Action onAfterTerminate) { - ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); - return onAssembly(new PerhapsDoOnLifecycle(this, + Objects.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); + return onAssembly(new PerhapsDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1208,8 +1213,8 @@ public final Perhaps doAfterTerminate(Action onAfterTerminate) { * @return the new Perhaps instance */ public final Perhaps doFinally(Action onFinally) { - ObjectHelper.requireNonNull(onFinally, "onFinally is null"); - return onAssembly(new PerhapsDoFinally(this, onFinally)); + Objects.requireNonNull(onFinally, "onFinally is null"); + return onAssembly(new PerhapsDoFinally<>(this, onFinally)); } /** @@ -1242,8 +1247,8 @@ public final Perhaps delay(long delay, TimeUnit unit, Scheduler scheduler) { * @return the new Perhaps instance */ public final Perhaps delay(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new PerhapsDelayPublisher(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new PerhapsDelayPublisher<>(this, other)); } /** @@ -1276,8 +1281,8 @@ public final Perhaps delaySubscription(long delay, TimeUnit unit, Scheduler s * @return the new Perhaps instance */ public final Perhaps delaySubscription(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new PerhapsDelaySubscription(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new PerhapsDelaySubscription<>(this, other)); } /** @@ -1288,8 +1293,8 @@ public final Perhaps delaySubscription(Publisher other) { * @return the new Perhaps type */ public final Perhaps lift(Function, Subscriber> onLift) { - ObjectHelper.requireNonNull(onLift, "onLift is null"); - return onAssembly(new PerhapsLift(this, onLift)); + Objects.requireNonNull(onLift, "onLift is null"); + return onAssembly(new PerhapsLift<>(this, onLift)); } /** @@ -1323,8 +1328,8 @@ public final Perhaps compose(Function, ? extends Perha * @return the new Perhaps instance */ public final Perhaps takeUntil(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new PerhapsTakeUntil(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new PerhapsTakeUntil<>(this, other)); } /** @@ -1332,7 +1337,7 @@ public final Perhaps takeUntil(Publisher other) { * @return the new Flowable instance */ public final Flowable toFlowable() { - return RxJavaPlugins.onAssembly(new PerhapsToFlowable(this)); + return RxJavaPlugins.onAssembly(new PerhapsToFlowable<>(this)); } /** @@ -1340,7 +1345,7 @@ public final Flowable toFlowable() { * @return the new Observable instance */ public final Observable toObservable() { - return RxJavaPlugins.onAssembly(new PerhapsToObservable(this)); + return RxJavaPlugins.onAssembly(new PerhapsToObservable<>(this)); } /** @@ -1348,7 +1353,7 @@ public final Observable toObservable() { * @return the new Maybe instance */ public final Maybe toMaybe() { - return RxJavaPlugins.onAssembly(new PerhapsToMaybe(this)); + return RxJavaPlugins.onAssembly(new PerhapsToMaybe<>(this)); } /** @@ -1359,7 +1364,7 @@ public final Maybe toMaybe() { * @since 0.14.1 */ public final Perhaps cache() { - return onAssembly(new PerhapsCache(this)); + return onAssembly(new PerhapsCache<>(this)); } // ---------------------------------------------------- @@ -1368,7 +1373,7 @@ public final Perhaps cache() { @Override public final void subscribe(Subscriber s) { - ObjectHelper.requireNonNull(s, "s is null"); + Objects.requireNonNull(s, "s is null"); try { subscribeActual(s); } catch (NullPointerException ex) { @@ -1433,7 +1438,7 @@ public final Disposable subscribe(Consumer onNext, Consumer onNext, Consumer onError, Action onComplete) { - LambdaSubscriber s = new LambdaSubscriber(onNext, onError, onComplete, Functions.REQUEST_MAX); + LambdaSubscriber s = new LambdaSubscriber<>(onNext, onError, onComplete, Functions.REQUEST_MAX); subscribe(s); return s; } @@ -1471,10 +1476,10 @@ public final void blockingSubscribe(Consumer onNext, Consumer onNext, Consumer onError, Action onComplete) { - ObjectHelper.requireNonNull(onNext, "onNext is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); - BlockingGetSubscriber s = new BlockingGetSubscriber(); + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + BlockingGetSubscriber s = new BlockingGetSubscriber<>(); subscribe(s); s.blockingCall(onNext, onError, onComplete); } @@ -1485,7 +1490,7 @@ public final void blockingSubscribe(Consumer onNext, Consumer s = new BlockingGetSubscriber(); + BlockingGetSubscriber s = new BlockingGetSubscriber<>(); subscribe(s); return s.blockingGet(); } @@ -1499,7 +1504,7 @@ public final T blockingGet() { * @return the success value of this Perhaps */ public final T blockingGet(long timeout, TimeUnit unit) { - BlockingGetSubscriber s = new BlockingGetSubscriber(); + BlockingGetSubscriber s = new BlockingGetSubscriber<>(); subscribe(s); return s.blockingGet(timeout, unit); } @@ -1542,7 +1547,7 @@ public final TestSubscriber test(long initialRequest) { * @return the new TestSubscriber */ public final TestSubscriber test(long initialRequest, boolean cancel) { - TestSubscriber ts = new TestSubscriber(initialRequest); + TestSubscriber ts = new TestSubscriber<>(initialRequest); if (cancel) { ts.cancel(); } @@ -1556,7 +1561,7 @@ public final TestSubscriber test(long initialRequest, boolean cancel) { * @return the new Future instance */ public final Future toFuture() { - FuturePerhapsSubscriber fs = new FuturePerhapsSubscriber(); + FuturePerhapsSubscriber fs = new FuturePerhapsSubscriber<>(); subscribe(fs); return fs; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAmbArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAmbArray.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAmbArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAmbArray.java index d55aa677..b538a868 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAmbArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAmbArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicBoolean; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.util.CompositeSubscription; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Signal the events of the first source that signals. @@ -39,7 +37,7 @@ final class PerhapsAmbArray extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - AmbSubscriber parent = new AmbSubscriber(s); + AmbSubscriber parent = new AmbSubscriber<>(s); s.onSubscribe(parent); for (Perhaps source : sources) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAmbIterable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAmbIterable.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAmbIterable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAmbIterable.java index a05e8574..da600550 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAmbIterable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAmbIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloAmbArray.AmbSubscriber; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.basetypes.SoloAmbArray.AmbSubscriber; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Signal the events of the first source that signals. @@ -37,12 +37,12 @@ final class PerhapsAmbIterable extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - AmbSubscriber parent = new AmbSubscriber(s); + AmbSubscriber parent = new AmbSubscriber<>(s); s.onSubscribe(parent); try { for (Perhaps source : sources) { - ObjectHelper.requireNonNull(source, "One of the sources is null") + Objects.requireNonNull(source, "One of the sources is null") .subscribe(parent); } } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAndThenNono.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAndThenNono.java similarity index 95% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAndThenNono.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAndThenNono.java index 6720a764..2b583d6b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsAndThenNono.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsAndThenNono.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Execute a Nono after the source Perhaps. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsCache.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsCache.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsCache.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsCache.java index 09786ac9..78082970 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsCache.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; /** * Cache the success value or error from upstream and relay/replay @@ -51,12 +50,12 @@ final class PerhapsCache extends Perhaps implements Subscriber { PerhapsCache(Perhaps source) { this.source = source; this.once = new AtomicBoolean(); - this.subscribers = new AtomicReference[]>(EMPTY); + this.subscribers = new AtomicReference<>(EMPTY); } @Override protected void subscribeActual(Subscriber s) { - CacheSubscription inner = new CacheSubscription(s, this); + CacheSubscription inner = new CacheSubscription<>(s, this); s.onSubscribe(inner); if (add(inner)) { @@ -180,7 +179,7 @@ static final class CacheSubscription extends DeferredScalarSubscription { CacheSubscription(Subscriber downstream, PerhapsCache parent) { super(downstream); - this.parent = new AtomicReference(parent); + this.parent = new AtomicReference<>(parent); } @SuppressWarnings("unchecked") diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsCreate.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsCreate.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsCreate.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsCreate.java index 8a43e0d4..7bfd9340 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsCreate.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsCreate.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.Subscriber; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Cancellable; -import io.reactivex.internal.disposables.*; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Cancellable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Create a Perhaps that for each incoming Subscriber calls a callback to @@ -44,7 +42,7 @@ final class PerhapsCreate extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - PerhapsEmitter parent = new PerhapsEmitter(s); + PerhapsEmitter parent = new PerhapsEmitter<>(s); s.onSubscribe(parent); try { @@ -63,7 +61,7 @@ static final class PerhapsEmitter extends DeferredScalarSubscription imple PerhapsEmitter(Subscriber downstream) { super(downstream); - this.resource = new AtomicReference(); + this.resource = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDefaultIfEmpty.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDefaultIfEmpty.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDefaultIfEmpty.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDefaultIfEmpty.java index 78e75f82..810c79a8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDefaultIfEmpty.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDefaultIfEmpty.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Return an item if the upstream is empty. @@ -38,7 +38,7 @@ final class PerhapsDefaultIfEmpty extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new OnErrorReturnItemSubscriber(s, item)); + source.subscribe(new OnErrorReturnItemSubscriber<>(s, item)); } static final class OnErrorReturnItemSubscriber extends DeferredScalarSubscription diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDefer.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDefer.java similarity index 66% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDefer.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDefer.java index 5bc4da1e..e18c494a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDefer.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDefer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Defers the creation of the actual Perhaps until subscription time. @@ -31,9 +30,9 @@ */ final class PerhapsDefer extends Perhaps { - final Callable> supplier; + final Supplier> supplier; - PerhapsDefer(Callable> supplier) { + PerhapsDefer(Supplier> supplier) { this.supplier = supplier; } @@ -42,7 +41,7 @@ protected void subscribeActual(Subscriber s) { Perhaps sp; try { - sp = ObjectHelper.requireNonNull(supplier.call(), "The supplier returned a null Solo"); + sp = Objects.requireNonNull(supplier.get(), "The supplier returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelay.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelay.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelay.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelay.java index 823b6789..e5d5b824 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelay.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelay.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.CompositeException; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Delay the emission of signals from the upstream until the diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelayPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelayPublisher.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelayPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelayPublisher.java index 65818513..74dd9736 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelayPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelayPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.CompositeException; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Delay events until another Publisher signals an item or completes. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelaySubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelaySubscription.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelaySubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelaySubscription.java index 02e5be84..5d49fd22 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDelaySubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDelaySubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Delay events until another Publisher signals an item or completes. @@ -41,7 +40,7 @@ final class PerhapsDelaySubscription extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - other.subscribe(new DelaySubscriber(s, source)); + other.subscribe(new DelaySubscriber<>(s, source)); } static final class DelaySubscriber extends DeferredScalarSubscription diff --git a/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDoFinally.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDoFinally.java new file mode 100644 index 00000000..44dd8a59 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDoFinally.java @@ -0,0 +1,156 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.basetypes; + +import java.io.Serial; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.annotations.Nullable; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Action; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Execute an action exactly once after the upstream terminates or the + * downstream cancels. + * @param the input and output element type + */ +final class PerhapsDoFinally extends Perhaps { + + final Perhaps source; + + final Action onFinally; + + PerhapsDoFinally(Perhaps source, Action onFinally) { + this.source = source; + this.onFinally = onFinally; + } + + @Override + protected void subscribeActual(Subscriber s) { + source.subscribe(new DoFinallySubscriber(s, onFinally)); + } + + static final class DoFinallySubscriber extends BasicIntQueueSubscription implements FlowableSubscriber { + + @Serial + private static final long serialVersionUID = 4109457741734051389L; + + final Subscriber downstream; + + final Action onFinally; + + Subscription upstream; + + QueueSubscription qs; + + boolean syncFused; + + DoFinallySubscriber(Subscriber downstream, Action onFinally) { + this.downstream = downstream; + this.onFinally = onFinally; + } + + @SuppressWarnings("unchecked") + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + if (s instanceof QueueSubscription) { + this.qs = (QueueSubscription)s; + } + + downstream.onSubscribe(this); + } + } + + @Override + public void onNext(T t) { + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + downstream.onError(t); + runFinally(); + } + + @Override + public void onComplete() { + downstream.onComplete(); + runFinally(); + } + + @Override + public void cancel() { + upstream.cancel(); + runFinally(); + } + + @Override + public void request(long n) { + upstream.request(n); + } + + @Override + public int requestFusion(int mode) { + QueueSubscription qs = this.qs; + if (qs != null && (mode & BOUNDARY) == 0) { + int m = qs.requestFusion(mode); + if (m != NONE) { + syncFused = m == SYNC; + } + return m; + } + return NONE; + } + + @Override + public void clear() { + qs.clear(); + } + + @Override + public boolean isEmpty() { + return qs.isEmpty(); + } + + @Nullable + @Override + public T poll() throws Throwable { + T v = qs.poll(); + if (v == null && syncFused) { + runFinally(); + } + return v; + } + + void runFinally() { + if (compareAndSet(0, 1)) { + try { + onFinally.run(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + RxJavaPlugins.onError(ex); + } + } + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDoOnLifecycle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDoOnLifecycle.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDoOnLifecycle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDoOnLifecycle.java index a1c913a5..67bbb601 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsDoOnLifecycle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsDoOnLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Execute callbacks at various points in the lifecycle. @@ -227,7 +227,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { T v = queue.poll(); if (v != null) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsEmpty.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsEmpty.java similarity index 73% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsEmpty.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsEmpty.java index bb79e08e..b0783056 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsEmpty.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsEmpty.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.functions.Supplier; /** * Completes the subscriber immediately. */ -final class PerhapsEmpty extends Perhaps implements Callable { +final class PerhapsEmpty extends Perhaps implements Supplier { static final PerhapsEmpty INSTANCE = new PerhapsEmpty(); @@ -40,7 +39,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public Object call() throws Exception { + public Object get() throws Exception { return null; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsError.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsError.java similarity index 66% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsError.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsError.java index 32160aae..aefefb4f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsError.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsError.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.util.SneakyThrows; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.functions.Supplier; /** * Signals a Throwable. * * @param the value type */ -final class PerhapsError extends Perhaps implements Callable { +final class PerhapsError extends Perhaps implements Supplier { final Throwable error; @@ -42,7 +40,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public T call() throws Exception { - throw SneakyThrows.justThrow(error); + public T get() throws Throwable { + throw error; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsErrorSupplier.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsErrorSupplier.java similarity index 54% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsErrorSupplier.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsErrorSupplier.java index 45cf5179..241a6f44 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsErrorSupplier.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsErrorSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.util.SneakyThrows; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** - * Signals a Throwable returned by a callable. + * Signals a Throwable returned by a Supplier. * * @param the value type */ -final class PerhapsErrorSupplier extends Perhaps implements Callable { +final class PerhapsErrorSupplier extends Perhaps implements Supplier { - final Callable errorSupplier; + final Supplier errorSupplier; - PerhapsErrorSupplier(Callable errorSupplier) { + PerhapsErrorSupplier(Supplier errorSupplier) { this.errorSupplier = errorSupplier; } @@ -43,7 +41,7 @@ protected void subscribeActual(Subscriber s) { Throwable ex; try { - ex = ObjectHelper.requireNonNull(errorSupplier.call(), "The errorSupplier returned a null Throwable"); + ex = Objects.requireNonNull(errorSupplier.get(), "The errorSupplier returned a null Throwable"); } catch (Throwable exc) { Exceptions.throwIfFatal(exc); ex = exc; @@ -53,7 +51,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public T call() throws Exception { - throw SneakyThrows.justThrow(ObjectHelper.requireNonNull(errorSupplier.call(), "The errorSupplier returned a null Throwable")); + public T get() throws Throwable { + throw Objects.requireNonNull(errorSupplier.get(), "The errorSupplier returned a null Throwable"); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFilter.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFilter.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFilter.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFilter.java index 14869584..21c65927 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFilter.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscribers.BasicFuseableSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicFuseableSubscriber; +import io.reactivex.rxjava4.functions.Predicate; /** * Filter the upstream value with a predicate. @@ -74,7 +74,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { T v = qs.poll(); return v == null || predicate.test(v) ? v : null; diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMap.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMap.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMap.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMap.java index 8029dcc8..ab6d7c9d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMap.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Map the success value of the upstream into a Perhaps and emit @@ -85,7 +84,7 @@ public void onNext(T t) { Perhaps ph; try { - ph = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Perhaps"); + ph = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Perhaps"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMapPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMapPublisher.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMapPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMapPublisher.java index b44a6759..0edb2881 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMapPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMapPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Map the success value of the upstream into a Publisher and emit @@ -88,7 +87,7 @@ public void onNext(T t) { Publisher ph; try { - ph = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); + ph = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMapSignal.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMapSignal.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMapSignal.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMapSignal.java index 8cdca2d3..059a93e2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFlatMapSignal.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFlatMapSignal.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Map the signals of the upstream into a Perhaps and emit @@ -41,13 +39,13 @@ final class PerhapsFlatMapSignal extends Perhaps { final Function> onErrorMapper; - final Callable> onCompleteMapper; + final Supplier> onCompleteMapper; PerhapsFlatMapSignal(Perhaps source, Function> onSuccessMapper, Function> onErrorMapper, - Callable> onCompleteMapper - ) { + Supplier> onCompleteMapper + ) { this.source = source; this.onSuccessMapper = onSuccessMapper; this.onErrorMapper = onErrorMapper; @@ -68,7 +66,7 @@ static final class FlatMapSubscriber extends DeferredScalarSubscription final Function> onErrorMapper; - final Callable> onCompleteMapper; + final Supplier> onCompleteMapper; final InnerSubscriber inner; @@ -79,7 +77,7 @@ static final class FlatMapSubscriber extends DeferredScalarSubscription FlatMapSubscriber(Subscriber downstream, Function> onSuccessMapper, Function> onErrorMapper, - Callable> onCompleteMapper) { + Supplier> onCompleteMapper) { super(downstream); this.onSuccessMapper = onSuccessMapper; this.onErrorMapper = onErrorMapper; @@ -104,7 +102,7 @@ public void onNext(T t) { Perhaps ph; try { - ph = ObjectHelper.requireNonNull(onSuccessMapper.apply(t), "The onSuccessMapper returned a null Perhaps"); + ph = Objects.requireNonNull(onSuccessMapper.apply(t), "The onSuccessMapper returned a null Perhaps"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -118,7 +116,7 @@ public void onNext(T t) { public void onError(Throwable t) { Perhaps ph; try { - ph = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Perhaps"); + ph = Objects.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Perhaps"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -132,7 +130,7 @@ public void onComplete() { if (!hasValue) { Perhaps ph; try { - ph = ObjectHelper.requireNonNull(onCompleteMapper.call(), "The onCompleteMapper returned a null Perhaps"); + ph = Objects.requireNonNull(onCompleteMapper.get(), "The onCompleteMapper returned a null Perhaps"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromAction.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromAction.java similarity index 72% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromAction.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromAction.java index 314822f6..93011681 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromAction.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Action; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Executes an Action and terminates. * * @param the value type */ -final class PerhapsFromAction extends Perhaps implements Callable { +final class PerhapsFromAction extends Perhaps implements Supplier { final Action action; @@ -42,7 +40,7 @@ protected void subscribeActual(Subscriber s) { s.onSubscribe(EmptySubscription.INSTANCE); try { - call(); + get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); s.onError(ex); @@ -53,7 +51,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public T call() throws Exception { + public T get() throws Throwable { action.run(); return null; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromCallable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromCallable.java similarity index 78% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromCallable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromCallable.java index 02d7748e..56248ca6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromCallable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Executes a callable and signals its resulting value. @@ -39,7 +38,7 @@ final class PerhapsFromCallable extends Perhaps implements Callable { @Override protected void subscribeActual(Subscriber s) { - DeferredScalarSubscription dss = new DeferredScalarSubscription(s); + DeferredScalarSubscription dss = new DeferredScalarSubscription<>(s); s.onSubscribe(dss); T v; @@ -61,6 +60,6 @@ protected void subscribeActual(Subscriber s) { @Override public T call() throws Exception { - return ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value"); + return Objects.requireNonNull(callable.call(), "The callable returned a null value"); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromCompletable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromCompletable.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromCompletable.java index 54727f66..9027a63f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Wrap a Completable into a Perhaps. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromFuture.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromFuture.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromFuture.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromFuture.java index 878369bd..63efff4d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromFuture.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromFuture.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.concurrent.*; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; /** * Await a Future's result. @@ -45,7 +44,7 @@ final class PerhapsFromFuture extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - DeferredScalarSubscription dss = new DeferredScalarSubscription(s); + DeferredScalarSubscription dss = new DeferredScalarSubscription<>(s); s.onSubscribe(dss); T v; diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromMaybe.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromMaybe.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromMaybe.java index 77d96e9f..2cb2fd01 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Wrap a Maybe into a Perhaps. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromPublisher.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromPublisher.java index c4f47f9f..960ee18c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Signals the 0 or 1 value of the source Publisher. @@ -85,4 +85,4 @@ public void onComplete() { } } } - } +} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromSingle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromSingle.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromSingle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromSingle.java index dfaf58da..a6747b3d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsFromSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsFromSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloFromSingle.FromSingleObserver; -import io.reactivex.SingleSource; +import hu.akarnokd.rxjava4.basetypes.SoloFromSingle.FromSingleObserver; +import io.reactivex.rxjava4.core.SingleSource; /** * Wrap a Single into a Perhaps. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsHide.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsHide.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsHide.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsHide.java index 07ca987f..344c40c9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsHide.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsHide.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloHide.HideSubscriber; +import hu.akarnokd.rxjava4.basetypes.SoloHide.HideSubscriber; /** * Hides the identity of the upstream Solo and its Subscription. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsJust.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsJust.java similarity index 68% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsJust.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsJust.java index f18f3fe7..2fa58af2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsJust.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsJust.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.internal.fuseable.ScalarCallable; -import io.reactivex.internal.subscriptions.ScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.ScalarSubscription; +import io.reactivex.rxjava4.operators.ScalarSupplier; /** * Signals exactly one value. * * @param the value type */ -final class PerhapsJust extends Perhaps implements ScalarCallable { +final class PerhapsJust extends Perhaps implements ScalarSupplier { final T value; @@ -36,11 +36,11 @@ final class PerhapsJust extends Perhaps implements ScalarCallable { @Override protected void subscribeActual(Subscriber s) { - s.onSubscribe(new ScalarSubscription(s, value)); + s.onSubscribe(new ScalarSubscription<>(s, value)); } @Override - public T call() { + public T get() { return value; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsLift.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsLift.java similarity index 76% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsLift.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsLift.java index ca541dbc..4faedd4e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsLift.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsLift.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Map the downstream Subscriber into an upstream Subscriber. @@ -45,7 +45,7 @@ protected void subscribeActual(Subscriber s) { Subscriber parent; try { - parent = ObjectHelper.requireNonNull(onLift.apply(s), "The onLift returned a null Subscriber"); + parent = Objects.requireNonNull(onLift.apply(s), "The onLift returned a null Subscriber"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsMap.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsMap.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsMap.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsMap.java index 2626a1f9..7cf84361 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsMap.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloMap.MapSubscriber; -import io.reactivex.functions.Function; +import hu.akarnokd.rxjava4.basetypes.SoloMap.MapSubscriber; +import io.reactivex.rxjava4.functions.Function; /** * Map the value of upstream via a function. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsMapError.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsMapError.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsMapError.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsMapError.java index a240b3fd..4649c63e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsMapError.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsMapError.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloMapError.MapErrorSubscriber; -import io.reactivex.functions.Function; +import hu.akarnokd.rxjava4.basetypes.SoloMapError.MapErrorSubscriber; +import io.reactivex.rxjava4.functions.Function; /** * Map the error of upstream to another Throwable. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsNever.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsNever.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsNever.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsNever.java index e1cda184..71a40385 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsNever.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsNever.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; /** * Never signals an event other than onSubscribe. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsObserveOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsObserveOn.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsObserveOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsObserveOn.java index b122db27..76fed5c4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsObserveOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsObserveOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloObserveOn.ObserveOnSubscriber; -import io.reactivex.Scheduler; +import hu.akarnokd.rxjava4.basetypes.SoloObserveOn.ObserveOnSubscriber; +import io.reactivex.rxjava4.core.Scheduler; /** * Delivers the upstream's onNext, onError and onComplete on the specified diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorResumeNext.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorResumeNext.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorResumeNext.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorResumeNext.java index 981c37ff..84f86af5 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorResumeNext.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorResumeNext.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * If the upstream fails, use the Throwable to get a fallback Perhaps and resume with it. @@ -44,7 +43,7 @@ final class PerhapsOnErrorResumeNext extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new OnErrorResumeNextSubscriber(s, fallbackSupplier)); + source.subscribe(new OnErrorResumeNextSubscriber<>(s, fallbackSupplier)); } static final class OnErrorResumeNextSubscriber extends DeferredScalarSubscription @@ -85,7 +84,7 @@ public void onError(Throwable t) { Perhaps ph; try { - ph = ObjectHelper.requireNonNull(fallbackSupplier.apply(t), "The fallbackSupplier returned a null Perhaps"); + ph = Objects.requireNonNull(fallbackSupplier.apply(t), "The fallbackSupplier returned a null Perhaps"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(new CompositeException(t, ex)); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorResumeWith.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorResumeWith.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorResumeWith.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorResumeWith.java index fa373638..1ab356fe 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorResumeWith.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorResumeWith.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Resume with another Perhaps if the upstream fails. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorReturnItem.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorReturnItem.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorReturnItem.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorReturnItem.java index 7d0897a9..e2e15304 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsOnErrorReturnItem.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsOnErrorReturnItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Return an item if the upstream fails. @@ -38,7 +38,7 @@ final class PerhapsOnErrorReturnItem extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new OnErrorReturnItemSubscriber(s, item)); + source.subscribe(new OnErrorReturnItemSubscriber<>(s, item)); } static final class OnErrorReturnItemSubscriber extends DeferredScalarSubscription diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsProcessor.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsProcessor.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsProcessor.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsProcessor.java index 7542df9a..e395d71e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsProcessor.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * A Processor based on the Perhaps type that emits an onNext+onComplete, only onComplete or an onError. @@ -53,7 +52,7 @@ public final class PerhapsProcessor extends Perhaps implements Processor PerhapsProcessor create() { - return new PerhapsProcessor(); + return new PerhapsProcessor<>(); } /** @@ -61,13 +60,13 @@ public static PerhapsProcessor create() { */ @SuppressWarnings("unchecked") private PerhapsProcessor() { - subscribers = new AtomicReference[]>(EMPTY); + subscribers = new AtomicReference<>(EMPTY); once = new AtomicBoolean(); } @Override protected void subscribeActual(Subscriber s) { - InnerSubscription inner = new InnerSubscription(s, this); + InnerSubscription inner = new InnerSubscription<>(s, this); s.onSubscribe(inner); if (add(inner)) { if (inner.isCancelled()) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetry.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetry.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetry.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetry.java index efcf3efc..24178ef6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetry.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetry.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Retries the source Perhaps at most the given number of times. @@ -40,7 +39,7 @@ final class PerhapsRetry extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - RetrySubscriber parent = new RetrySubscriber(s, times, source); + RetrySubscriber parent = new RetrySubscriber<>(s, times, source); s.onSubscribe(parent); parent.subscribeNext(); } @@ -65,7 +64,7 @@ static final class RetrySubscriber extends DeferredScalarSubscription this.times = times; this.source = source; this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetryWhen.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetryWhen.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetryWhen.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetryWhen.java index 22408462..58a031db 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetryWhen.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetryWhen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.NoSuchElementException; +import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.*; /** * Retry this solo if the Publisher returned by the handler signals an item @@ -52,14 +50,14 @@ protected void subscribeActual(Subscriber s) { Publisher when; try { - when = ObjectHelper.requireNonNull(handler.apply(pp), "The handler returned a null Publisher"); + when = Objects.requireNonNull(handler.apply(pp), "The handler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); return; } - RetrySubscriber parent = new RetrySubscriber(s, pp, source); + RetrySubscriber parent = new RetrySubscriber<>(s, pp, source); s.onSubscribe(parent); when.subscribe(parent.other); @@ -91,7 +89,7 @@ static final class RetrySubscriber extends DeferredScalarSubscription this.source = source; this.other = new OtherSubscriber(); this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.once = new AtomicBoolean(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetryWhile.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetryWhile.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetryWhile.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetryWhile.java index 14421972..6ccebf08 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsRetryWhile.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsRetryWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Predicate; /** * Retries the source Perhaps if the predicate returns true. @@ -42,7 +41,7 @@ final class PerhapsRetryWhile extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - RetrySubscriber parent = new RetrySubscriber(s, predicate, source); + RetrySubscriber parent = new RetrySubscriber<>(s, predicate, source); s.onSubscribe(parent); parent.subscribeNext(); } @@ -67,7 +66,7 @@ static final class RetrySubscriber extends DeferredScalarSubscription this.predicate = predicate; this.source = source; this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsSubscribeOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsSubscribeOn.java new file mode 100644 index 00000000..94151c91 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsSubscribeOn.java @@ -0,0 +1,155 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.basetypes; + +import java.io.Serial; +import java.util.concurrent.Flow.*; +import java.util.concurrent.atomic.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; + +/** + * Subscribe to the upstream on the specified scheduler. + * + * @param the value type + */ +final class PerhapsSubscribeOn extends Perhaps { + + final Perhaps source; + + final Scheduler scheduler; + + PerhapsSubscribeOn(Perhaps source, Scheduler scheduler) { + this.source = source; + this.scheduler = scheduler; + } + + @Override + protected void subscribeActual(Subscriber s) { + Worker worker = scheduler.createWorker(); + + SubscribeOnSubscriber parent = new SubscribeOnSubscriber<>(s, worker, source, false); + s.onSubscribe(parent); + + worker.schedule(parent); + } + + static final class SubscribeOnSubscriber extends AtomicReference + implements FlowableSubscriber, Subscription, Runnable { + + @Serial + private static final long serialVersionUID = 8094547886072529208L; + + final Subscriber downstream; + + final Scheduler.Worker worker; + + final AtomicReference upstream; + + final AtomicLong requested; + + final boolean nonScheduledRequests; + + Publisher source; + + SubscribeOnSubscriber(Subscriber downstream, Scheduler.Worker worker, Publisher source, boolean requestOn) { + this.downstream = downstream; + this.worker = worker; + this.source = source; + this.upstream = new AtomicReference<>(); + this.requested = new AtomicLong(); + this.nonScheduledRequests = !requestOn; + } + + @Override + public void run() { + lazySet(Thread.currentThread()); + Publisher src = source; + source = null; + src.subscribe(this); + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.setOnce(this.upstream, s)) { + long r = requested.getAndSet(0L); + if (r != 0L) { + requestUpstream(r, s); + } + } + } + + @Override + public void onNext(T t) { + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + downstream.onError(t); + worker.dispose(); + } + + @Override + public void onComplete() { + downstream.onComplete(); + worker.dispose(); + } + + @Override + public void request(final long n) { + if (SubscriptionHelper.validate(n)) { + Subscription s = this.upstream.get(); + if (s != null) { + requestUpstream(n, s); + } else { + BackpressureHelper.add(requested, n); + s = this.upstream.get(); + if (s != null) { + long r = requested.getAndSet(0L); + if (r != 0L) { + requestUpstream(r, s); + } + } + } + } + } + + void requestUpstream(final long n, final Subscription s) { + if (nonScheduledRequests || Thread.currentThread() == get()) { + s.request(n); + } else { + worker.schedule(new Request(s, n)); + } + } + + @Override + public void cancel() { + SubscriptionHelper.cancel(upstream); + worker.dispose(); + } + + record Request(Subscription upstream, long n) implements Runnable { + + @Override + public void run() { + upstream.request(n); + } + } + }} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsSwitchIfEmpty.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsSwitchIfEmpty.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsSwitchIfEmpty.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsSwitchIfEmpty.java index 05feb894..f533e6d1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsSwitchIfEmpty.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsSwitchIfEmpty.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Switch to another Perhaps if the main is empty. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTakeUntil.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTakeUntil.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTakeUntil.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTakeUntil.java index f57bb87b..7d80d46d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTakeUntil.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTakeUntil.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Take until the other Publisher signals an item or completes, completing this Perhaps. @@ -41,7 +40,7 @@ final class PerhapsTakeUntil extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - TakeUntilSubscriber parent = new TakeUntilSubscriber(s); + TakeUntilSubscriber parent = new TakeUntilSubscriber<>(s); s.onSubscribe(parent); other.subscribe(parent.other); @@ -62,7 +61,7 @@ static final class TakeUntilSubscriber extends DeferredScalarSubscription TakeUntilSubscriber(Subscriber downstream) { super(downstream); this.other = new OtherSubscriber(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.once = new AtomicBoolean(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTimeout.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTimeout.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTimeout.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTimeout.java index fdcea667..2983cabc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsTimeout.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTimeout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Switch to another Perhaps if this doesn't signal events before the other @@ -46,7 +45,7 @@ final class PerhapsTimeout extends Perhaps { @Override protected void subscribeActual(Subscriber s) { - TimeoutSubscriber parent = new TimeoutSubscriber(s, fallback); + TimeoutSubscriber parent = new TimeoutSubscriber<>(s, fallback); s.onSubscribe(parent); other.subscribe(parent.other); @@ -70,7 +69,7 @@ static final class TimeoutSubscriber extends DeferredScalarSubscription TimeoutSubscriber(Subscriber downstream, Perhaps fallback) { super(downstream); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.fallback = fallback; this.once = new AtomicBoolean(); this.other = new OtherSubscriber(); diff --git a/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTimer.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTimer.java new file mode 100644 index 00000000..24bd7b58 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsTimer.java @@ -0,0 +1,99 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.basetypes; + +import java.io.Serial; +import java.util.concurrent.Flow.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.MissingBackpressureException; + +/** + * Signal a 0L after the specified time delay. + */ +final class PerhapsTimer extends Perhaps { + + final long delay; + + final TimeUnit unit; + + final Scheduler scheduler; + + PerhapsTimer(long delay, TimeUnit unit, Scheduler scheduler) { + this.delay = delay; + this.unit = unit; + this.scheduler = scheduler; + } + + @Override + protected void subscribeActual(Subscriber s) { + TimerSubscriber parent = new TimerSubscriber(s); + s.onSubscribe(parent); + + Disposable d = scheduler.scheduleDirect(parent, delay, unit); + DisposableHelper.replace(parent, d); + } + + static final class TimerSubscriber extends AtomicReference + implements Subscription, Runnable { + + @Serial + private static final long serialVersionUID = -2809475196591179431L; + + final Subscriber downstream; + + volatile boolean requested; + + TimerSubscriber(Subscriber downstream) { + this.downstream = downstream; + } + + @Override + public void request(long n) { + if (SubscriptionHelper.validate(n)) { + requested = true; + } + } + + @Override + public void cancel() { + DisposableHelper.dispose(this); + } + + @Override + public void run() { + if (get() != DisposableHelper.DISPOSED) { + if (requested) { + downstream.onNext(0L); + lazySet(EmptyDisposable.INSTANCE); + downstream.onComplete(); + } else { + lazySet(EmptyDisposable.INSTANCE); + downstream.onError(MissingBackpressureException.createDefault()); + } + } + } + + public void setResource(Disposable d) { + DisposableHelper.trySet(this, d); + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToFlowable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToFlowable.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToFlowable.java index bce170f5..1df361ef 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.Flowable; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; /** * Convert the Perhaps into a Flowable. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToMaybe.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToMaybe.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToMaybe.java index 5d99c72c..9e38867a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert the Perhaps into an Maybe. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToObservable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToObservable.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToObservable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToObservable.java index 69928507..7b908ee8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsToObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsToObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.internal.observers.DeferredScalarDisposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; /** * Convert the Perhaps into an Observable. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsUnsubscribeOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsUnsubscribeOn.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsUnsubscribeOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsUnsubscribeOn.java index d97016a4..69c5fbdc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsUnsubscribeOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsUnsubscribeOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloUnsubscribeOn.UnsubscribeOnSubscriber; -import io.reactivex.Scheduler; +import hu.akarnokd.rxjava4.basetypes.SoloUnsubscribeOn.UnsubscribeOnSubscriber; +import io.reactivex.rxjava4.core.Scheduler; /** * Call cancel from downstream on the specified Scheduler. diff --git a/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsUsing.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsUsing.java new file mode 100644 index 00000000..b6a1f5a5 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsUsing.java @@ -0,0 +1,202 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.basetypes; + +import java.io.Serial; +import java.util.Objects; +import java.util.concurrent.Flow.*; +import java.util.concurrent.atomic.AtomicBoolean; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Use a resource while the actual Perhaps is running. + * @param the element type of the supplied Perhaps + * @param the resource type + */ +final class PerhapsUsing extends Perhaps { + + final Supplier resourceSupplier; + + final Function> sourceSupplier; + + final Consumer disposer; + + final boolean eager; + + PerhapsUsing(Supplier resourceSupplier, + Function> sourceSupplier, + Consumer disposer, boolean eager) { + this.resourceSupplier = resourceSupplier; + this.sourceSupplier = sourceSupplier; + this.disposer = disposer; + this.eager = eager; + } + + @Override + protected void subscribeActual(Subscriber s) { + R resource; + + try { + resource = resourceSupplier.get(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + EmptySubscription.error(ex, s); + return; + } + + Perhaps np; + + try { + np = Objects.requireNonNull(sourceSupplier.apply(resource), "The sourceSupplier returned a null Nono"); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + if (eager) { + try { + disposer.accept(resource); + } catch (Throwable exc) { + Exceptions.throwIfFatal(exc); + ex = new CompositeException(ex, exc); + } + + EmptySubscription.error(ex, s); + } else { + EmptySubscription.error(ex, s); + try { + disposer.accept(resource); + } catch (Throwable exc) { + Exceptions.throwIfFatal(exc); + RxJavaPlugins.onError(exc); + } + } + return; + } + + np.subscribe(new UsingSubscriber(s, resource, disposer, eager)); + } + + static final class UsingSubscriber extends AtomicBoolean implements FlowableSubscriber, Subscription { + + @Serial + private static final long serialVersionUID = 5904473792286235046L; + + final Subscriber downstream; + final D resource; + final Consumer disposer; + final boolean eager; + + Subscription upstream; + + UsingSubscriber(Subscriber downstream, D resource, Consumer disposer, boolean eager) { + this.downstream = downstream; + this.resource = resource; + this.disposer = disposer; + this.eager = eager; + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); + } + } + + @Override + public void onNext(T t) { + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + if (eager) { + Throwable innerError = null; + if (compareAndSet(false, true)) { + try { + disposer.accept(resource); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + innerError = e; + } + } + + if (innerError != null) { + downstream.onError(new CompositeException(t, innerError)); + } else { + downstream.onError(t); + } + } else { + downstream.onError(t); + disposeResource(); + } + } + + @Override + public void onComplete() { + if (eager) { + if (compareAndSet(false, true)) { + try { + disposer.accept(resource); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + downstream.onError(e); + return; + } + } + + downstream.onComplete(); + } else { + downstream.onComplete(); + disposeResource(); + } + } + + @Override + public void request(long n) { + upstream.request(n); + } + + @Override + public void cancel() { + if (eager) { + disposeResource(); + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + } else { + upstream.cancel(); + upstream = SubscriptionHelper.CANCELLED; + disposeResource(); + } + } + + void disposeResource() { + if (compareAndSet(false, true)) { + try { + disposer.accept(resource); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + // can't call actual.onError unless it is serialized, which is expensive + RxJavaPlugins.onError(e); + } + } + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsZipArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsZipArray.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsZipArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsZipArray.java index 7b4fc73d..5531adad 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsZipArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsZipArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.Arrays; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Waits till all sources produce a value and calls a function @@ -49,7 +48,7 @@ final class PerhapsZipArray extends Perhaps { protected void subscribeActual(Subscriber s) { Perhaps[] srcs = sources; int n = srcs.length; - ZipCoordinator parent = new ZipCoordinator(s, zipper, n); + ZipCoordinator parent = new ZipCoordinator<>(s, zipper, n); s.onSubscribe(parent); parent.subscribe(srcs, n); @@ -74,7 +73,7 @@ static final class ZipCoordinator extends DeferredScalarSubscription { this.wip = new AtomicInteger(n); this.subscribers = new ZipInnerSubscriber[n]; for (int i = 0; i < n; i++) { - subscribers[i] = new ZipInnerSubscriber(i, this); + subscribers[i] = new ZipInnerSubscriber<>(i, this); } this.values = new Object[n]; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsZipIterable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsZipIterable.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsZipIterable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsZipIterable.java index edb0bd15..4101c871 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/PerhapsZipIterable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/PerhapsZipIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.Arrays; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.PerhapsZipArray.ZipCoordinator; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.basetypes.PerhapsZipArray.ZipCoordinator; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Waits till all sources produce a value and calls a function @@ -63,7 +62,7 @@ protected void subscribeActual(Subscriber s) { return; } - ZipCoordinator parent = new ZipCoordinator(s, zipper, n); + ZipCoordinator parent = new ZipCoordinator<>(s, zipper, n); s.onSubscribe(parent); parent.subscribe(srcs, n); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/Solo.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/Solo.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/Solo.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/Solo.java index af638355..33e3ba14 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/Solo.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/Solo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; import java.util.concurrent.*; - -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; -import io.reactivex.internal.subscribers.LambdaSubscriber; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.config.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; /** * Base class with fluent API for supporting a Publisher with @@ -94,8 +93,8 @@ protected static Solo onAssembly(Solo source) { * @return th new Solo instance */ public static Solo create(SingleOnSubscribe onCreate) { - ObjectHelper.requireNonNull(onCreate, "onCreate is null"); - return onAssembly(new SoloCreate(onCreate)); + Objects.requireNonNull(onCreate, "onCreate is null"); + return onAssembly(new SoloCreate<>(onCreate)); } /** @@ -105,8 +104,8 @@ public static Solo create(SingleOnSubscribe onCreate) { * @return the new Solo instance */ public static Solo just(T item) { - ObjectHelper.requireNonNull(item, "item is null"); - return onAssembly(new SoloJust(item)); + Objects.requireNonNull(item, "item is null"); + return onAssembly(new SoloJust<>(item)); } /** @@ -116,7 +115,7 @@ public static Solo just(T item) { * @return the new Solo instance */ public static Solo error(Throwable error) { - ObjectHelper.requireNonNull(error, "error is null"); + Objects.requireNonNull(error, "error is null"); return onAssembly(new SoloError(error)); } @@ -128,8 +127,8 @@ public static Solo error(Throwable error) { * return a Throwable to be signalled * @return the new Solo instance */ - public static Solo error(Callable errorSupplier) { - ObjectHelper.requireNonNull(errorSupplier, "errorSupplier is null"); + public static Solo error(Supplier errorSupplier) { + Objects.requireNonNull(errorSupplier, "errorSupplier is null"); return onAssembly(new SoloErrorSupplier(errorSupplier)); } @@ -140,8 +139,8 @@ public static Solo error(Callable errorSupplier) { * @return the new Solo instance */ public static Solo fromCallable(Callable callable) { - ObjectHelper.requireNonNull(callable, "callable is null"); - return onAssembly(new SoloFromCallable(callable)); + Objects.requireNonNull(callable, "callable is null"); + return onAssembly(new SoloFromCallable<>(callable)); } /** @@ -160,9 +159,9 @@ public static Solo never() { * @param supplier the supplier of the actual Solo * @return the new Solo instance */ - public static Solo defer(Callable> supplier) { - ObjectHelper.requireNonNull(supplier, "supplier is null"); - return onAssembly(new SoloDefer(supplier)); + public static Solo defer(Supplier> supplier) { + Objects.requireNonNull(supplier, "supplier is null"); + return onAssembly(new SoloDefer<>(supplier)); } /** @@ -177,8 +176,8 @@ public static Solo fromPublisher(Publisher source) { if (source instanceof Solo) { return (Solo)source; } - ObjectHelper.requireNonNull(source, "source is null"); - return onAssembly(new SoloFromPublisher(source)); + Objects.requireNonNull(source, "source is null"); + return onAssembly(new SoloFromPublisher<>(source)); } /** @@ -188,8 +187,8 @@ public static Solo fromPublisher(Publisher source) { * @return the new Solo instance */ public static Solo fromSingle(SingleSource source) { - ObjectHelper.requireNonNull(source, "source is null"); - return onAssembly(new SoloFromSingle(source)); + Objects.requireNonNull(source, "source is null"); + return onAssembly(new SoloFromSingle<>(source)); } /** @@ -203,7 +202,7 @@ public static Solo fromSingle(SingleSource source) { * @since 0.14.0 */ public static Solo fromFuture(Future future) { - ObjectHelper.requireNonNull(future, "future is null"); + Objects.requireNonNull(future, "future is null"); return onAssembly(new SoloFromFuture(future, 0, null)); } @@ -221,8 +220,8 @@ public static Solo fromFuture(Future future) { * @since 0.14.0 */ public static Solo fromFuture(Future future, long timeout, TimeUnit unit) { - ObjectHelper.requireNonNull(future, "future is null"); - ObjectHelper.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(future, "future is null"); + Objects.requireNonNull(unit, "unit is null"); return onAssembly(new SoloFromFuture(future, timeout, unit)); } @@ -233,8 +232,8 @@ public static Solo fromFuture(Future future, long timeout, T * @return the new Solo instance */ public static Solo amb(Iterable> sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); - return onAssembly(new SoloAmbIterable(sources)); + Objects.requireNonNull(sources, "sources is null"); + return onAssembly(new SoloAmbIterable<>(sources)); } /** @@ -243,9 +242,10 @@ public static Solo amb(Iterable> sources) { * @param sources the array of Solo sources * @return the new Solo instance */ + @SafeVarargs public static Solo ambArray(Solo... sources) { - ObjectHelper.requireNonNull(sources, "sources is null"); - return onAssembly(new SoloAmbArray(sources)); + Objects.requireNonNull(sources, "sources is null"); + return onAssembly(new SoloAmbArray<>(sources)); } /** @@ -276,7 +276,7 @@ public static Flowable concat(Publisher> sour * @return the new Flowable instance */ public static Flowable concat(Publisher> sources, int prefetch) { - return Flowable.concat(sources, prefetch); + return Flowable.concat(sources, new StandardBufferedConfig(prefetch)); } /** @@ -285,6 +285,7 @@ public static Flowable concat(Publisher> sour * @param sources the sequence of sources * @return the new Flowable instance */ + @SafeVarargs public static Flowable concatArray(Solo... sources) { return Flowable.concatArray(sources); } @@ -297,7 +298,7 @@ public static Flowable concatArray(Solo... sources) { * @return the new Flowable instance */ public static Flowable concatDelayError(Iterable> sources) { - return Flowable.concatDelayError(sources); + return Flowable.concat(sources, StandardBufferedConfig.DELAY_ERRORS); } /** @@ -334,7 +335,7 @@ public static Flowable concatDelayError(Publisher Flowable concatDelayError(Publisher> sources, int prefetch, boolean tillTheEnd) { - return Flowable.concatDelayError(sources, prefetch, tillTheEnd); + return Flowable.concat(sources, new StandardBufferedConfig(tillTheEnd ? ErrorMode.END : ErrorMode.BOUNDARY, prefetch)); } /** @@ -344,8 +345,9 @@ public static Flowable concatDelayError(Publisher Flowable concatArrayDelayError(Solo... sources) { - return Flowable.concatArrayDelayError(sources); + return Flowable.concatArray(StandardBufferedConfig.DELAY_ERRORS, sources); } /** @@ -366,7 +368,7 @@ public static Flowable merge(Iterable> source * @return the new Flowable instance */ public static Flowable merge(Iterable> sources, int maxConcurrency) { - return Flowable.merge(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(maxConcurrency)); } /** @@ -387,7 +389,7 @@ public static Flowable merge(Publisher> sourc * @return the new Flowable instance */ public static Flowable merge(Publisher> sources, int maxConcurrency) { - return Flowable.merge(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(maxConcurrency)); } /** @@ -396,6 +398,7 @@ public static Flowable merge(Publisher> sourc * @param sources the sequence of sources * @return the new Flowable instance */ + @SafeVarargs public static Flowable mergeArray(Solo... sources) { return mergeArray(Integer.MAX_VALUE, sources); } @@ -407,8 +410,9 @@ public static Flowable mergeArray(Solo... sources) { * @param maxConcurrency the maximum number of active subscriptions * @return the new Flowable instance */ + @SafeVarargs public static Flowable mergeArray(int maxConcurrency, Solo... sources) { - return Flowable.mergeArray(maxConcurrency, 1, sources); + return Flowable.mergeArray(new StandardConcurrentBufferedConfig(ErrorMode.IMMEDIATE, maxConcurrency, 1), sources); } /** @@ -431,7 +435,7 @@ public static Flowable mergeDelayError(Iterable Flowable mergeDelayError(Iterable> sources, int maxConcurrency) { - return Flowable.mergeDelayError(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(ErrorMode.END, maxConcurrency)); } /** @@ -454,7 +458,7 @@ public static Flowable mergeDelayError(Publisher Flowable mergeDelayError(Publisher> sources, int maxConcurrency) { - return Flowable.mergeDelayError(sources, maxConcurrency); + return Flowable.merge(sources, new StandardConcurrentBufferedConfig(ErrorMode.END, maxConcurrency)); } /** @@ -464,6 +468,7 @@ public static Flowable mergeDelayError(Publisher Flowable mergeArrayDelayError(Solo... sources) { return mergeArrayDelayError(Integer.MAX_VALUE, sources); } @@ -476,8 +481,9 @@ public static Flowable mergeArrayDelayError(Solo... sources) * @param maxConcurrency the maximum number of active subscriptions * @return the new Flowable instance */ + @SafeVarargs public static Flowable mergeArrayDelayError(int maxConcurrency, Solo... sources) { - return Flowable.mergeArrayDelayError(maxConcurrency, 1, sources); + return Flowable.mergeArray(new StandardConcurrentBufferedConfig(ErrorMode.END, maxConcurrency, 1), sources); } /** @@ -500,8 +506,8 @@ public static Solo timer(long delay, TimeUnit unit) { * @return the new Solo instance */ public static Solo timer(long delay, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return onAssembly(new SoloTimer(delay, unit, scheduler)); } @@ -518,7 +524,7 @@ public static Solo timer(long delay, TimeUnit unit, Scheduler scheduler) { * @return the new Solo instance */ public static Solo using( - Callable resourceSupplier, + Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer ) { @@ -540,15 +546,15 @@ public static Solo using( * @return the new Solo instance */ public static Solo using( - Callable resourceSupplier, + Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager ) { - ObjectHelper.requireNonNull(resourceSupplier, "resourceSupplier is null"); - ObjectHelper.requireNonNull(sourceSupplier, "sourceSupplier is null"); - ObjectHelper.requireNonNull(disposer, "disposer is null"); - return onAssembly(new SoloUsing(resourceSupplier, sourceSupplier, disposer, eager)); + Objects.requireNonNull(resourceSupplier, "resourceSupplier is null"); + Objects.requireNonNull(sourceSupplier, "sourceSupplier is null"); + Objects.requireNonNull(disposer, "disposer is null"); + return onAssembly(new SoloUsing<>(resourceSupplier, sourceSupplier, disposer, eager)); } /** @@ -564,8 +570,8 @@ public static Solo zip( Iterable> sources, Function zipper ) { - ObjectHelper.requireNonNull(sources, "sources is null"); - ObjectHelper.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(zipper, "zipper is null"); return onAssembly(new SoloZipIterable(sources, zipper)); } @@ -578,12 +584,13 @@ public static Solo zip( * @param zipper the function takin in an array of values and returns a solo value * @return the new Solo instance */ + @SafeVarargs public static Solo zipArray( Function zipper, Solo... sources ) { - ObjectHelper.requireNonNull(sources, "sources is null"); - ObjectHelper.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(zipper, "zipper is null"); return onAssembly(new SoloZipArray(sources, zipper)); } @@ -597,7 +604,6 @@ public static Solo zipArray( * @param other the other Solo * @return the new Solo instance */ - @SuppressWarnings("unchecked") public final Solo ambWith(Solo other) { return ambArray(this, other); } @@ -609,8 +615,8 @@ public final Solo ambWith(Solo other) { * @return the new Solo instance */ public final Solo andThen(Nono other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new SoloAndThen(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new SoloAndThen<>(this, other)); } /** @@ -620,7 +626,7 @@ public final Solo andThen(Nono other) { * @return the new Flowable instance */ public final Flowable andThen(Publisher other) { - return Flowable.concat(this, other); + return Flowable.concatArray(this, other); } /** @@ -630,7 +636,7 @@ public final Flowable andThen(Publisher other) { * @return the new Flowable instance */ public final Flowable concatWith(Solo other) { - return Flowable.concat(this, other); + return Flowable.concatArray(this, other); } /** @@ -640,7 +646,7 @@ public final Flowable concatWith(Solo other) { * @return the new Flowable instance */ public final Flowable mergeWith(Solo other) { - return Flowable.merge(this, other); + return Flowable.mergeArray(this, other); } /** @@ -652,7 +658,6 @@ public final Flowable mergeWith(Solo other) { * the other Solo and returns a solo value to be emitted. * @return the new Solo instance */ - @SuppressWarnings("unchecked") public final Solo zipWith(Solo other, BiFunction zipper) { return Solo.zipArray(Functions.toFunction(zipper), this, other); } @@ -665,7 +670,7 @@ public final Solo zipWith(Solo other, BiFunction Solo map(Function mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(mapper, "mapper is null"); return onAssembly(new SoloMap(this, mapper)); } @@ -676,8 +681,8 @@ public final Solo map(Function mapper) { * @return the new Solo instance */ public final Solo mapError(Function errorMapper) { - ObjectHelper.requireNonNull(errorMapper, "errorMapper is null"); - return onAssembly(new SoloMapError(this, errorMapper)); + Objects.requireNonNull(errorMapper, "errorMapper is null"); + return onAssembly(new SoloMapError<>(this, errorMapper)); } /** @@ -687,8 +692,8 @@ public final Solo mapError(Function e * @return the new Perhaps instance */ public final Perhaps filter(Predicate predicate) { - ObjectHelper.requireNonNull(predicate, "predicate is null"); - return Perhaps.onAssembly(new SoloFilter(this, predicate)); + Objects.requireNonNull(predicate, "predicate is null"); + return Perhaps.onAssembly(new SoloFilter<>(this, predicate)); } /** @@ -747,8 +752,8 @@ public final Solo timeout(long timeout, TimeUnit unit, Scheduler scheduler, S * @return the new Solo instance */ public final Solo timeout(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new SoloTimeout(this, other, null)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new SoloTimeout<>(this, other, null)); } /** @@ -760,9 +765,9 @@ public final Solo timeout(Publisher other) { * @return the new Solo instance */ public final Solo timeout(Publisher other, Solo fallback) { - ObjectHelper.requireNonNull(other, "other is null"); - ObjectHelper.requireNonNull(fallback, "fallback is null"); - return onAssembly(new SoloTimeout(this, other, fallback)); + Objects.requireNonNull(other, "other is null"); + Objects.requireNonNull(fallback, "fallback is null"); + return onAssembly(new SoloTimeout<>(this, other, fallback)); } /** @@ -771,8 +776,8 @@ public final Solo timeout(Publisher other, Solo fallback) { * @return the new Solo instance */ public final Solo onErrorReturnItem(T item) { - ObjectHelper.requireNonNull(item, "item is null"); - return onAssembly(new SoloOnErrorReturnItem(this, item)); + Objects.requireNonNull(item, "item is null"); + return onAssembly(new SoloOnErrorReturnItem<>(this, item)); } /** @@ -782,8 +787,8 @@ public final Solo onErrorReturnItem(T item) { * @return the new Solo instance */ public final Solo onErrorResumeWith(Solo next) { - ObjectHelper.requireNonNull(next, "next is null"); - return onAssembly(new SoloOnErrorResumeWith(this, next)); + Objects.requireNonNull(next, "next is null"); + return onAssembly(new SoloOnErrorResumeWith<>(this, next)); } /** @@ -794,8 +799,8 @@ public final Solo onErrorResumeWith(Solo next) { * @return the new Solo instance */ public final Solo onErrorResumeNext(Function> errorHandler) { - ObjectHelper.requireNonNull(errorHandler, "errorHandler is null"); - return onAssembly(new SoloOnErrorResumeNext(this, errorHandler)); + Objects.requireNonNull(errorHandler, "errorHandler is null"); + return onAssembly(new SoloOnErrorResumeNext<>(this, errorHandler)); } /** @@ -808,8 +813,8 @@ public final Solo onErrorResumeNext(Function Solo flatMap( Function> mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - return onAssembly(new SoloFlatMap(this, mapper)); + Objects.requireNonNull(mapper, "mapper is null"); + return onAssembly(new SoloFlatMap<>(this, mapper)); } /** @@ -826,9 +831,9 @@ public final Solo flatMap( Function> onSuccessMapper, Function> onErrorMapper ) { - ObjectHelper.requireNonNull(onSuccessMapper, "onSuccessMapper is null"); - ObjectHelper.requireNonNull(onErrorMapper, "onErrorMapper is null"); - return onAssembly(new SoloFlatMapSignal(this, onSuccessMapper, onErrorMapper)); + Objects.requireNonNull(onSuccessMapper, "onSuccessMapper is null"); + Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); + return onAssembly(new SoloFlatMapSignal<>(this, onSuccessMapper, onErrorMapper)); } /** @@ -842,8 +847,8 @@ public final Solo flatMap( public final Flowable flatMapPublisher( Function> mapper ) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - return RxJavaPlugins.onAssembly(new SoloFlatMapPublisher(this, mapper)); + Objects.requireNonNull(mapper, "mapper is null"); + return RxJavaPlugins.onAssembly(new SoloFlatMapPublisher<>(this, mapper)); } /** @@ -853,8 +858,8 @@ public final Flowable flatMapPublisher( * @return the new Solo instance */ public final Solo takeUntil(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new SoloTakeUntil(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new SoloTakeUntil<>(this, other)); } /** @@ -877,8 +882,8 @@ public final Solo delay(long delay, TimeUnit unit) { * @return the new Solo instance */ public final Solo delay(long delay, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return delay(timer(delay, unit, scheduler)); } @@ -890,8 +895,8 @@ public final Solo delay(long delay, TimeUnit unit, Scheduler scheduler) { * @return the new Solo instance */ public final Solo delay(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new SoloDelayPublisher(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new SoloDelayPublisher<>(this, other)); } /** @@ -901,8 +906,8 @@ public final Solo delay(Publisher other) { * @return the new Solo type */ public final Solo delaySubscription(Publisher other) { - ObjectHelper.requireNonNull(other, "other is null"); - return onAssembly(new SoloDelaySubscription(this, other)); + Objects.requireNonNull(other, "other is null"); + return onAssembly(new SoloDelaySubscription<>(this, other)); } /** @@ -931,7 +936,7 @@ public final Solo delaySubscription(long delay, TimeUnit unit, Scheduler sche * @return the new Flowable instance */ public final Flowable toFlowable() { - return RxJavaPlugins.onAssembly(new SoloToFlowable(this)); + return RxJavaPlugins.onAssembly(new SoloToFlowable<>(this)); } /** @@ -939,7 +944,7 @@ public final Flowable toFlowable() { * @return the new Observable instance */ public final Observable toObservable() { - return RxJavaPlugins.onAssembly(new SoloToObservable(this)); + return RxJavaPlugins.onAssembly(new SoloToObservable<>(this)); } /** @@ -947,7 +952,7 @@ public final Observable toObservable() { * @return the new Single instance */ public final Single toSingle() { - return RxJavaPlugins.onAssembly(new SoloToSingle(this)); + return RxJavaPlugins.onAssembly(new SoloToSingle<>(this)); } /** @@ -956,8 +961,8 @@ public final Single toSingle() { * @return the new Solo instance */ public final Solo doOnSubscribe(Consumer onSubscribe) { - ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onSubscribe, "onSubscribe is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -975,8 +980,8 @@ public final Solo doOnSubscribe(Consumer onSubscribe) { * @return the new Solo instance */ public final Solo doOnRequest(LongConsumer onRequest) { - ObjectHelper.requireNonNull(onRequest, "onRequest is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onRequest, "onRequest is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -994,8 +999,8 @@ public final Solo doOnRequest(LongConsumer onRequest) { * @return the new Solo instance */ public final Solo doOnCancel(Action onCancel) { - ObjectHelper.requireNonNull(onCancel, "onCancel is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onCancel, "onCancel is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1014,8 +1019,8 @@ public final Solo doOnCancel(Action onCancel) { * @return the new Solo instance */ public final Solo doOnNext(Consumer onNext) { - ObjectHelper.requireNonNull(onNext, "onNext is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onNext, "onNext is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, onNext, Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1034,8 +1039,8 @@ public final Solo doOnNext(Consumer onNext) { * @return the new Solo instance */ public final Solo doAfterNext(Consumer onAfterNext) { - ObjectHelper.requireNonNull(onAfterNext, "onAfterNext is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onAfterNext, "onAfterNext is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), onAfterNext, Functions.emptyConsumer(), @@ -1054,8 +1059,8 @@ public final Solo doAfterNext(Consumer onAfterNext) { * @return the new Solo instance */ public final Solo doOnError(Consumer onError) { - ObjectHelper.requireNonNull(onError, "onError is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onError, "onError is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), onError, @@ -1074,8 +1079,8 @@ public final Solo doOnError(Consumer onError) { * @return the new Solo instance */ public final Solo doOnComplete(Action onComplete) { - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onComplete, "onComplete is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1094,8 +1099,8 @@ public final Solo doOnComplete(Action onComplete) { * @return the new Solo instance */ public final Solo doAfterTerminate(Action onAfterTerminate) { - ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); - return onAssembly(new SoloDoOnLifecycle(this, + Objects.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); + return onAssembly(new SoloDoOnLifecycle<>(this, Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyConsumer(), @@ -1114,8 +1119,8 @@ public final Solo doAfterTerminate(Action onAfterTerminate) { * @return the new Solo instance */ public final Solo doFinally(Action onFinally) { - ObjectHelper.requireNonNull(onFinally, "onFinally is null"); - return onAssembly(new SoloDoFinally(this, onFinally)); + Objects.requireNonNull(onFinally, "onFinally is null"); + return onAssembly(new SoloDoFinally<>(this, onFinally)); } /** @@ -1133,7 +1138,7 @@ public final Nono ignoreElement() { * @return the new Solo instance */ public final Solo hide() { - return onAssembly(new SoloHide(this)); + return onAssembly(new SoloHide<>(this)); } /** @@ -1168,8 +1173,8 @@ public final Solo compose(Function, ? extends Solo> co * @return the new Solo type */ public final Solo lift(Function, Subscriber> onLift) { - ObjectHelper.requireNonNull(onLift, "onLift is null"); - return onAssembly(new SoloLift(this, onLift)); + Objects.requireNonNull(onLift, "onLift is null"); + return onAssembly(new SoloLift<>(this, onLift)); } /** @@ -1217,7 +1222,7 @@ public final Flowable repeatWhen(Function, ? extends * @return the new Solo instance */ public final Solo retry() { - return onAssembly(new SoloRetry(this, Long.MAX_VALUE)); + return onAssembly(new SoloRetry<>(this, Long.MAX_VALUE)); } /** @@ -1229,7 +1234,7 @@ public final Solo retry(long times) { if (times < 0L) { throw new IllegalArgumentException("times >= 0 required but it was " + times); } - return onAssembly(new SoloRetry(this, times)); + return onAssembly(new SoloRetry<>(this, times)); } /** @@ -1240,8 +1245,8 @@ public final Solo retry(long times) { * @return the new Solo instance */ public final Solo retry(Predicate predicate) { - ObjectHelper.requireNonNull(predicate, "predicate is null"); - return onAssembly(new SoloRetryWhile(this, predicate)); + Objects.requireNonNull(predicate, "predicate is null"); + return onAssembly(new SoloRetryWhile<>(this, predicate)); } /** @@ -1253,8 +1258,8 @@ public final Solo retry(Predicate predicate) { * @return the new Solo instance */ public final Solo retryWhen(Function, ? extends Publisher> handler) { - ObjectHelper.requireNonNull(handler, "handler is null"); - return onAssembly(new SoloRetryWhen(this, handler)); + Objects.requireNonNull(handler, "handler is null"); + return onAssembly(new SoloRetryWhen<>(this, handler)); } /** @@ -1264,8 +1269,8 @@ public final Solo retryWhen(Function, ? extends P * @return the new Solo instance */ public final Solo subscribeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return onAssembly(new SoloSubscribeOn(this, scheduler)); + Objects.requireNonNull(scheduler, "scheduler is null"); + return onAssembly(new SoloSubscribeOn<>(this, scheduler)); } /** @@ -1275,8 +1280,8 @@ public final Solo subscribeOn(Scheduler scheduler) { * @return the new Solo instance */ public final Solo observeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return onAssembly(new SoloObserveOn(this, scheduler)); + Objects.requireNonNull(scheduler, "scheduler is null"); + return onAssembly(new SoloObserveOn<>(this, scheduler)); } /** @@ -1286,8 +1291,8 @@ public final Solo observeOn(Scheduler scheduler) { * @return the new Solo instance */ public final Solo unsubscribeOn(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return onAssembly(new SoloUnsubscribeOn(this, scheduler)); + Objects.requireNonNull(scheduler, "scheduler is null"); + return onAssembly(new SoloUnsubscribeOn<>(this, scheduler)); } /** @@ -1298,7 +1303,7 @@ public final Solo unsubscribeOn(Scheduler scheduler) { * @since 0.14.1 */ public final Solo cache() { - return onAssembly(new SoloCache(this)); + return onAssembly(new SoloCache<>(this)); } // ---------------------------------------------------- @@ -1307,7 +1312,7 @@ public final Solo cache() { @Override public final void subscribe(Subscriber s) { - ObjectHelper.requireNonNull(s, "s is null"); + Objects.requireNonNull(s, "s is null"); try { subscribeActual(s); } catch (NullPointerException ex) { @@ -1372,7 +1377,7 @@ public final Disposable subscribe(Consumer onNext, Consumer onNext, Consumer onError, Action onComplete) { - LambdaSubscriber s = new LambdaSubscriber(onNext, onError, onComplete, Functions.REQUEST_MAX); + LambdaSubscriber s = new LambdaSubscriber<>(onNext, onError, onComplete, Functions.REQUEST_MAX); subscribe(s); return s; } @@ -1410,10 +1415,10 @@ public final void blockingSubscribe(Consumer onNext, Consumer onNext, Consumer onError, Action onComplete) { - ObjectHelper.requireNonNull(onNext, "onNext is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); - BlockingGetSubscriber s = new BlockingGetSubscriber(); + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + BlockingGetSubscriber s = new BlockingGetSubscriber<>(); subscribe(s); s.blockingCall(onNext, onError, onComplete); } @@ -1424,7 +1429,7 @@ public final void blockingSubscribe(Consumer onNext, Consumer s = new BlockingGetSubscriber(); + BlockingGetSubscriber s = new BlockingGetSubscriber<>(); subscribe(s); return s.blockingGet(); } @@ -1438,7 +1443,7 @@ public final T blockingGet() { * @return the success value of this Solo */ public final T blockingGet(long timeout, TimeUnit unit) { - BlockingGetSubscriber s = new BlockingGetSubscriber(); + BlockingGetSubscriber s = new BlockingGetSubscriber<>(); subscribe(s); return s.blockingGet(timeout, unit); } @@ -1481,7 +1486,7 @@ public final TestSubscriber test(long initialRequest) { * @return the new TestSubscriber */ public final TestSubscriber test(long initialRequest, boolean cancel) { - TestSubscriber ts = new TestSubscriber(initialRequest); + TestSubscriber ts = new TestSubscriber<>(initialRequest); if (cancel) { ts.cancel(); } @@ -1495,7 +1500,7 @@ public final TestSubscriber test(long initialRequest, boolean cancel) { * @return the new Future instance */ public final Future toFuture() { - FuturePerhapsSubscriber fs = new FuturePerhapsSubscriber(); + FuturePerhapsSubscriber fs = new FuturePerhapsSubscriber<>(); subscribe(fs); return fs; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAmbArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAmbArray.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAmbArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAmbArray.java index 96d187ce..5318a8bb 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAmbArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAmbArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicBoolean; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.util.CompositeSubscription; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Signal the events of the first source that signals. @@ -39,7 +37,7 @@ final class SoloAmbArray extends Solo { @Override protected void subscribeActual(Subscriber s) { - AmbSubscriber parent = new AmbSubscriber(s); + AmbSubscriber parent = new AmbSubscriber<>(s); s.onSubscribe(parent); for (Solo source : sources) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAmbIterable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAmbIterable.java similarity index 74% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAmbIterable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAmbIterable.java index f9511c50..dbfc6f9b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAmbIterable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAmbIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.basetypes.SoloAmbArray.AmbSubscriber; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.basetypes.SoloAmbArray.AmbSubscriber; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Signal the events of the first source that signals. @@ -37,12 +37,12 @@ final class SoloAmbIterable extends Solo { @Override protected void subscribeActual(Subscriber s) { - AmbSubscriber parent = new AmbSubscriber(s); + AmbSubscriber parent = new AmbSubscriber<>(s); s.onSubscribe(parent); try { for (Solo source : sources) { - ObjectHelper.requireNonNull(source, "One of the sources is null") + Objects.requireNonNull(source, "One of the sources is null") .subscribe(parent); } } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAndThen.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAndThen.java similarity index 95% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAndThen.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAndThen.java index e694e42c..50056392 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloAndThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloAndThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Run the given Nono after this Solo completes successfully and diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloCache.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloCache.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloCache.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloCache.java index ffd2f770..92a03d9a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloCache.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; /** * Cache the success value or error from upstream and relay/replay @@ -51,12 +50,12 @@ final class SoloCache extends Solo implements Subscriber { SoloCache(Solo source) { this.source = source; this.once = new AtomicBoolean(); - this.subscribers = new AtomicReference[]>(EMPTY); + this.subscribers = new AtomicReference<>(EMPTY); } @Override protected void subscribeActual(Subscriber s) { - CacheSubscription inner = new CacheSubscription(s, this); + CacheSubscription inner = new CacheSubscription<>(s, this); s.onSubscribe(inner); if (add(inner)) { @@ -168,7 +167,7 @@ static final class CacheSubscription extends DeferredScalarSubscription { CacheSubscription(Subscriber downstream, SoloCache parent) { super(downstream); - this.parent = new AtomicReference(parent); + this.parent = new AtomicReference<>(parent); } @SuppressWarnings("unchecked") diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloCreate.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloCreate.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloCreate.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloCreate.java index 6e389776..aa3f7773 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloCreate.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloCreate.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.atomic.*; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.Subscriber; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Cancellable; -import io.reactivex.internal.disposables.*; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Cancellable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Create a Solo that for each incoming Subscriber calls a callback to @@ -44,7 +42,7 @@ final class SoloCreate extends Solo { @Override protected void subscribeActual(Subscriber s) { - SoloEmitter parent = new SoloEmitter(s); + SoloEmitter parent = new SoloEmitter<>(s); s.onSubscribe(parent); try { @@ -63,7 +61,7 @@ static final class SoloEmitter extends DeferredScalarSubscription implemen SoloEmitter(Subscriber downstream) { super(downstream); - this.resource = new AtomicReference(); + this.resource = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDefer.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDefer.java similarity index 67% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDefer.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDefer.java index 33487292..e7cbd8dc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDefer.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDefer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Defers the creation of the actual Solo until subscription time. @@ -31,9 +30,9 @@ */ final class SoloDefer extends Solo { - final Callable> supplier; + final Supplier> supplier; - SoloDefer(Callable> supplier) { + SoloDefer(Supplier> supplier) { this.supplier = supplier; } @@ -42,7 +41,7 @@ protected void subscribeActual(Subscriber s) { Solo sp; try { - sp = ObjectHelper.requireNonNull(supplier.call(), "The supplier returned a null Solo"); + sp = Objects.requireNonNull(supplier.get(), "The supplier returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelay.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelay.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelay.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelay.java index d8495f4a..594805e6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelay.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelay.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Delay signals by the given time amount. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelayPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelayPublisher.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelayPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelayPublisher.java index c4d0e7a5..9990d4ae 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelayPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelayPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.CompositeException; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Delay signals till the other signals an item or completes. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelaySubscription.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelaySubscription.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelaySubscription.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelaySubscription.java index f8ef8864..676401a8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDelaySubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDelaySubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Delay the subscription to this Solo until the other Publisher @@ -41,7 +40,7 @@ final class SoloDelaySubscription extends Solo { @Override protected void subscribeActual(Subscriber s) { - DelaySubscriptionSubscriber parent = new DelaySubscriptionSubscriber(s, source); + DelaySubscriptionSubscriber parent = new DelaySubscriptionSubscriber<>(s, source); s.onSubscribe(parent); other.subscribe(parent.other); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDoFinally.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDoFinally.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDoFinally.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDoFinally.java index 6bcaac97..7d901d82 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDoFinally.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDoFinally.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Action; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Action; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Execute an action exactly once after the upstream terminates or the @@ -125,7 +125,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { T v = queue.poll(); if (sourceMode == SYNC && v == null) { runFinally(); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDoOnLifecycle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDoOnLifecycle.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDoOnLifecycle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDoOnLifecycle.java index f9e43456..9c62e9ab 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloDoOnLifecycle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloDoOnLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Execute callbacks at various points in the lifecycle. @@ -227,7 +227,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { T v = queue.poll(); if (v != null) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloError.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloError.java similarity index 67% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloError.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloError.java index 1491e91c..80fda688 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloError.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloError.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.util.SneakyThrows; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.functions.Supplier; /** * Signals a Throwable. * * @param the value type */ -final class SoloError extends Solo implements Callable { +final class SoloError extends Solo implements Supplier { final Throwable error; @@ -42,7 +40,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public T call() throws Exception { - throw SneakyThrows.justThrow(error); + public T get() throws Throwable { + throw error; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloErrorSupplier.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloErrorSupplier.java similarity index 51% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloErrorSupplier.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloErrorSupplier.java index 4c48500e..bb9cff8f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloErrorSupplier.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloErrorSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.util.SneakyThrows; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** - * Signals a Throwable returned by a callable. + * Signals a Throwable returned by a supplier. * * @param the value type */ -final class SoloErrorSupplier extends Solo implements Callable { +final class SoloErrorSupplier extends Solo implements Supplier { - final Callable errorSupplier; + final Supplier errorSupplier; - SoloErrorSupplier(Callable errorSupplier) { + SoloErrorSupplier(Supplier errorSupplier) { this.errorSupplier = errorSupplier; } @@ -43,7 +41,7 @@ protected void subscribeActual(Subscriber s) { Throwable ex; try { - ex = ObjectHelper.requireNonNull(errorSupplier.call(), "The errorSupplier returned a null Throwable"); + ex = Objects.requireNonNull(errorSupplier.get(), "The errorSupplier returned a null Throwable"); } catch (Throwable exc) { Exceptions.throwIfFatal(exc); ex = exc; @@ -53,7 +51,7 @@ protected void subscribeActual(Subscriber s) { } @Override - public T call() throws Exception { - throw SneakyThrows.justThrow(ObjectHelper.requireNonNull(errorSupplier.call(), "The errorSupplier returned a null Throwable")); + public T get() throws Throwable { + throw Objects.requireNonNull(errorSupplier.get(), "The errorSupplier returned a null Throwable"); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFilter.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFilter.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFilter.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFilter.java index b3bbeb16..45d02e0a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFilter.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscribers.BasicFuseableSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicFuseableSubscriber; +import io.reactivex.rxjava4.functions.Predicate; /** * Tests the single value from upstream and emits it or completes. @@ -77,7 +77,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { T v = qs.poll(); if (v != null) { if (predicate.test(v)) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMap.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMap.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMap.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMap.java index 42211706..2c609d09 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMap.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the success value of this Solo into another Solo and @@ -80,7 +79,7 @@ public void onNext(T t) { Solo sp; try { - sp = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Solo"); + sp = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMapPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMapPublisher.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMapPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMapPublisher.java index ef710699..1d5c4b7f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMapPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMapPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the success value of this Solo into a Publisher and @@ -85,7 +84,7 @@ public void onNext(T t) { Publisher p; try { - p = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); + p = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMapSignal.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMapSignal.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMapSignal.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMapSignal.java index 9e8f1548..da9bcc6c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFlatMapSignal.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFlatMapSignal.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the success value or the failure of this Solo into another @@ -90,7 +89,7 @@ public void onNext(T t) { Solo sp; try { - sp = ObjectHelper.requireNonNull(onSuccessMapper.apply(t), "The onSuccessMapper returned a null Solo"); + sp = Objects.requireNonNull(onSuccessMapper.apply(t), "The onSuccessMapper returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -105,7 +104,7 @@ public void onError(Throwable t) { Solo sp; try { - sp = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Solo"); + sp = Objects.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromCallable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromCallable.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromCallable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromCallable.java index 7fe63d1c..aeb44f45 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromCallable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.NoSuchElementException; +import java.util.*; import java.util.concurrent.Callable; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Executes a callable and signals its resulting value. @@ -40,7 +38,7 @@ final class SoloFromCallable extends Solo implements Callable { @Override protected void subscribeActual(Subscriber s) { - DeferredScalarSubscription dss = new DeferredScalarSubscription(s); + DeferredScalarSubscription dss = new DeferredScalarSubscription<>(s); s.onSubscribe(dss); T v; @@ -62,6 +60,6 @@ protected void subscribeActual(Subscriber s) { @Override public T call() throws Exception { - return ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value"); + return Objects.requireNonNull(callable.call(), "The callable returned a null value"); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromFuture.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromFuture.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromFuture.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromFuture.java index 65182ad7..dcaa7bfd 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromFuture.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromFuture.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.NoSuchElementException; import java.util.concurrent.*; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; /** * Await a Future's result. @@ -46,7 +45,7 @@ final class SoloFromFuture extends Solo { @Override protected void subscribeActual(Subscriber s) { - DeferredScalarSubscription dss = new DeferredScalarSubscription(s); + DeferredScalarSubscription dss = new DeferredScalarSubscription<>(s); s.onSubscribe(dss); T v; diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromPublisher.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromPublisher.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromPublisher.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromPublisher.java index f7fd26bb..ad28de66 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromPublisher.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.NoSuchElementException; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Signals the solo value of the source Publisher. @@ -87,4 +86,4 @@ public void onComplete() { } } } - } +} diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromSingle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromSingle.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromSingle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromSingle.java index b12a8254..5f8984ed 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloFromSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloFromSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Wrap a Single into a Solo. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloHide.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloHide.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloHide.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloHide.java index 65096265..4260a849 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloHide.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloHide.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; /** * Hides the identity of the upstream Solo and its Subscription. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloJust.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloJust.java similarity index 68% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloJust.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloJust.java index 483f042f..f43c161a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloJust.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloJust.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.internal.fuseable.ScalarCallable; -import io.reactivex.internal.subscriptions.ScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.ScalarSubscription; +import io.reactivex.rxjava4.operators.ScalarSupplier; /** * Signals exactly one value. * * @param the value type */ -final class SoloJust extends Solo implements ScalarCallable { +final class SoloJust extends Solo implements ScalarSupplier { final T value; @@ -36,11 +36,11 @@ final class SoloJust extends Solo implements ScalarCallable { @Override protected void subscribeActual(Subscriber s) { - s.onSubscribe(new ScalarSubscription(s, value)); + s.onSubscribe(new ScalarSubscription<>(s, value)); } @Override - public T call() { + public T get() { return value; } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloLift.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloLift.java similarity index 76% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloLift.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloLift.java index 7b8f8678..5ff10e91 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloLift.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloLift.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Map the downstream Subscriber into an upstream Subscriber. @@ -45,7 +45,7 @@ protected void subscribeActual(Subscriber s) { Subscriber parent; try { - parent = ObjectHelper.requireNonNull(onLift.apply(s), "The onLift returned a null Subscriber"); + parent = Objects.requireNonNull(onLift.apply(s), "The onLift returned a null Subscriber"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloMap.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloMap.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloMap.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloMap.java index 17bb792f..0cf3f63b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloMap.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscribers.BasicFuseableSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicFuseableSubscriber; +import io.reactivex.rxjava4.functions.Function; /** * Map the success value to another value. @@ -60,7 +60,7 @@ public void onNext(T t) { R v; try { - v = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null value"); + v = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null value"); } catch (Throwable ex) { fail(ex); return; @@ -79,10 +79,10 @@ public int requestFusion(int mode) { } @Override - public R poll() throws Exception { + public R poll() throws Throwable { T v = qs.poll(); if (v != null) { - return ObjectHelper.requireNonNull(mapper.apply(v), "The mapper returned a null value"); + return Objects.requireNonNull(mapper.apply(v), "The mapper returned a null value"); } return null; } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloMapError.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloMapError.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloMapError.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloMapError.java index c42d90a1..ebce6683 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloMapError.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloMapError.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscribers.BasicFuseableSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicFuseableSubscriber; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Maps the error from upstream into another Throwable. @@ -65,7 +65,7 @@ public void onError(Throwable t) { Throwable ex; try { - ex = ObjectHelper.requireNonNull(errorMapper.apply(t), "The errorMapper returned a null Throwable"); + ex = Objects.requireNonNull(errorMapper.apply(t), "The errorMapper returned a null Throwable"); } catch (Throwable exc) { Exceptions.throwIfFatal(exc); ex = new CompositeException(t, exc); @@ -81,7 +81,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { return qs.poll(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloNever.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloNever.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloNever.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloNever.java index 57b677c3..be3cbc89 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloNever.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloNever.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; /** * Never signals an event other than onSubscribe. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloObserveOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloObserveOn.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloObserveOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloObserveOn.java index f6a2c566..4164e889 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloObserveOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloObserveOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import hu.akarnokd.rxjava2.util.SpscOneQueue; -import io.reactivex.Scheduler; -import io.reactivex.Scheduler.Worker; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.util.SpscOneQueue; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.operators.*; /** * Delivers the upstream's onNext, onError and onComplete on the specified @@ -106,7 +106,7 @@ public void onSubscribe(Subscription s) { } } - queue = new SpscOneQueue(); + queue = new SpscOneQueue<>(); downstream.onSubscribe(this); @@ -146,7 +146,7 @@ public void clear() { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { return queue.poll(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorResumeNext.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorResumeNext.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorResumeNext.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorResumeNext.java index 933984bd..82e70836 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorResumeNext.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorResumeNext.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Function; /** * If the upstream signals an error, switch over to the next Solo @@ -43,7 +42,7 @@ final class SoloOnErrorResumeNext extends Solo { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new OnErrorReturnItemSubscriber(s, errorHandler)); + source.subscribe(new OnErrorReturnItemSubscriber<>(s, errorHandler)); } static final class OnErrorReturnItemSubscriber extends DeferredScalarSubscription @@ -84,7 +83,7 @@ public void onError(Throwable t) { Solo sp; try { - sp = ObjectHelper.requireNonNull(errorHandler.apply(t), "The errorHandler returned a null Solo"); + sp = Objects.requireNonNull(errorHandler.apply(t), "The errorHandler returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(new CompositeException(t, ex)); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorResumeWith.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorResumeWith.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorResumeWith.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorResumeWith.java index 69d688bf..470f7ea3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorResumeWith.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorResumeWith.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * If the upstream signals an error, switch over to the next Solo @@ -40,7 +39,7 @@ final class SoloOnErrorResumeWith extends Solo { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new OnErrorResumeWithSubscriber(s, next)); + source.subscribe(new OnErrorResumeWithSubscriber<>(s, next)); } static final class OnErrorResumeWithSubscriber extends DeferredScalarSubscription diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorReturnItem.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorReturnItem.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorReturnItem.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorReturnItem.java index 519a1249..0893d864 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloOnErrorReturnItem.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloOnErrorReturnItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * If the upstream signals an error, signal an item instead. @@ -38,7 +38,7 @@ final class SoloOnErrorReturnItem extends Solo { @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new OnErrorReturnItemSubscriber(s, item)); + source.subscribe(new OnErrorReturnItemSubscriber<>(s, item)); } static final class OnErrorReturnItemSubscriber extends DeferredScalarSubscription diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloProcessor.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloProcessor.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloProcessor.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloProcessor.java index 51b602d7..f3815bf2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloProcessor.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.NoSuchElementException; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * A Processor based on the Solo type that emits an onNext+onComplete or an onError. @@ -55,7 +54,7 @@ public final class SoloProcessor extends Solo implements Processor { * @return the new SoloProcessor instance */ public static SoloProcessor create() { - return new SoloProcessor(); + return new SoloProcessor<>(); } /** @@ -63,13 +62,13 @@ public static SoloProcessor create() { */ @SuppressWarnings("unchecked") private SoloProcessor() { - subscribers = new AtomicReference[]>(EMPTY); + subscribers = new AtomicReference<>(EMPTY); once = new AtomicBoolean(); } @Override protected void subscribeActual(Subscriber s) { - InnerSubscription inner = new InnerSubscription(s, this); + InnerSubscription inner = new InnerSubscription<>(s, this); s.onSubscribe(inner); if (add(inner)) { if (inner.isCancelled()) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetry.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetry.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetry.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetry.java index 0b246661..dda323eb 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetry.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetry.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; /** * Retries the source Solo at most the given number of times. @@ -40,7 +39,7 @@ final class SoloRetry extends Solo { @Override protected void subscribeActual(Subscriber s) { - RetrySubscriber parent = new RetrySubscriber(s, times, source); + RetrySubscriber parent = new RetrySubscriber<>(s, times, source); s.onSubscribe(parent); parent.subscribeNext(); } @@ -65,7 +64,7 @@ static final class RetrySubscriber extends DeferredScalarSubscription this.times = times; this.source = source; this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetryWhen.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetryWhen.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetryWhen.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetryWhen.java index 66ad8dd5..09e80fd3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetryWhen.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetryWhen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.NoSuchElementException; +import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.*; /** * Retry this solo if the Publisher returned by the handler signals an item @@ -52,14 +50,14 @@ protected void subscribeActual(Subscriber s) { Publisher when; try { - when = ObjectHelper.requireNonNull(handler.apply(pp), "The handler returned a null Publisher"); + when = Objects.requireNonNull(handler.apply(pp), "The handler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); return; } - RetrySubscriber parent = new RetrySubscriber(s, pp, source); + RetrySubscriber parent = new RetrySubscriber<>(s, pp, source); s.onSubscribe(parent); when.subscribe(parent.other); @@ -91,7 +89,7 @@ static final class RetrySubscriber extends DeferredScalarSubscription this.source = source; this.other = new OtherSubscriber(); this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.once = new AtomicBoolean(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetryWhile.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetryWhile.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetryWhile.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetryWhile.java index b13e8ced..4460e934 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloRetryWhile.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloRetryWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Predicate; /** * Retries the source Solo at most the given number of times. @@ -42,7 +41,7 @@ final class SoloRetryWhile extends Solo { @Override protected void subscribeActual(Subscriber s) { - RetrySubscriber parent = new RetrySubscriber(s, predicate, source); + RetrySubscriber parent = new RetrySubscriber<>(s, predicate, source); s.onSubscribe(parent); parent.subscribeNext(); } @@ -67,7 +66,7 @@ static final class RetrySubscriber extends DeferredScalarSubscription this.predicate = predicate; this.source = source; this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloSubscribeOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloSubscribeOn.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloSubscribeOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloSubscribeOn.java index d1a44fc2..c685b3ec 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloSubscribeOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloSubscribeOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Scheduler; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.disposables.Disposable; /** * Subscribe to the upstream on the specified scheduler. @@ -46,7 +44,7 @@ final class SoloSubscribeOn extends Solo { protected void subscribeActual(Subscriber s) { Worker worker = scheduler.createWorker(); - SubscribeOnSubscriber parent = new SubscribeOnSubscriber(s, worker, source); + SubscribeOnSubscriber parent = new SubscribeOnSubscriber<>(s, worker, source); s.onSubscribe(parent); DisposableHelper.replace(parent.task, worker.schedule(parent)); @@ -72,7 +70,7 @@ static final class SubscribeOnSubscriber this.downstream = downstream; this.worker = worker; this.source = source; - this.task = new AtomicReference(); + this.task = new AtomicReference<>(); this.requested = new AtomicBoolean(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTakeUntil.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTakeUntil.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTakeUntil.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTakeUntil.java index a5d0fc97..cb9b39c7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTakeUntil.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTakeUntil.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; import java.util.NoSuchElementException; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Signal a NoSuchElementException if the other signals before this @@ -43,7 +42,7 @@ final class SoloTakeUntil extends Solo { @Override protected void subscribeActual(Subscriber s) { - TakeUntilSubscriber parent = new TakeUntilSubscriber(s); + TakeUntilSubscriber parent = new TakeUntilSubscriber<>(s); s.onSubscribe(parent); other.subscribe(parent.other); @@ -63,7 +62,7 @@ static final class TakeUntilSubscriber extends DeferredScalarSubscription TakeUntilSubscriber(Subscriber downstream) { super(downstream); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.other = new OtherSubscriber(); this.once = new AtomicBoolean(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTimeout.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTimeout.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTimeout.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTimeout.java index 57465324..661a3470 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTimeout.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTimeout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; final class SoloTimeout extends Solo { @@ -40,7 +39,7 @@ final class SoloTimeout extends Solo { @Override protected void subscribeActual(Subscriber s) { - TimeoutSubscriber parent = new TimeoutSubscriber(s, fallback); + TimeoutSubscriber parent = new TimeoutSubscriber<>(s, fallback); s.onSubscribe(parent); other.subscribe(parent.other); @@ -64,7 +63,7 @@ static final class TimeoutSubscriber extends DeferredScalarSubscription TimeoutSubscriber(Subscriber downstream, Solo fallback) { super(downstream); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.fallback = fallback; this.once = new AtomicBoolean(); this.other = new OtherSubscriber(); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTimer.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTimer.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTimer.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTimer.java index 03f67745..915f7938 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloTimer.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloTimer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; +import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.Subscriber; - -import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.subscriptions.DeferredScalarSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.Disposable; /** * Signal a 0L after the specified time delay. @@ -61,7 +59,7 @@ static final class TimerSubscriber extends DeferredScalarSubscription TimerSubscriber(Subscriber downstream) { super(downstream); - this.task = new AtomicReference(); + this.task = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToFlowable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToFlowable.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToFlowable.java index 800a9eaa..e7ce6fa4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.Flowable; +import io.reactivex.rxjava4.core.Flowable; /** * Converts a Solo into a Flowable. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToObservable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToObservable.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToObservable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToObservable.java index cbf02bba..e0721790 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.internal.observers.DeferredScalarDisposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; /** * Converts a Solo into an Observable. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToSingle.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToSingle.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToSingle.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToSingle.java index 5ec4b803..83e1f88d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloToSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloToSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Convert a Solo into a Single. diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloUnsubscribeOn.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloUnsubscribeOn.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloUnsubscribeOn.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloUnsubscribeOn.java index dbf99550..f19bc45c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloUnsubscribeOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloUnsubscribeOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.Scheduler; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscribers.BasicFuseableSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicFuseableSubscriber; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.operators.QueueSubscription; /** * Call cancel from downstream on the specified Scheduler. @@ -70,7 +70,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { return qs.poll(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloUsing.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloUsing.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloUsing.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloUsing.java index ca8acd5e..4fd35a7b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloUsing.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloUsing.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicBoolean; -import org.reactivestreams.*; - -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Use a resource while the actual Solo is running. @@ -34,7 +32,7 @@ */ final class SoloUsing extends Solo { - final Callable resourceSupplier; + final Supplier resourceSupplier; final Function> sourceSupplier; @@ -42,7 +40,7 @@ final class SoloUsing extends Solo { final boolean eager; - SoloUsing(Callable resourceSupplier, Function> sourceSupplier, + SoloUsing(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { this.resourceSupplier = resourceSupplier; this.sourceSupplier = sourceSupplier; @@ -55,7 +53,7 @@ protected void subscribeActual(Subscriber s) { R resource; try { - resource = resourceSupplier.call(); + resource = resourceSupplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); @@ -65,7 +63,7 @@ protected void subscribeActual(Subscriber s) { Solo np; try { - np = ObjectHelper.requireNonNull(sourceSupplier.apply(resource), "The sourceSupplier returned a null Nono"); + np = Objects.requireNonNull(sourceSupplier.apply(resource), "The sourceSupplier returned a null Nono"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); if (eager) { diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloZipArray.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloZipArray.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloZipArray.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloZipArray.java index 620e7fc9..6901da26 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloZipArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloZipArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.Arrays; +import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Combines the solo values of all the sources via a zipper function into a @@ -48,7 +46,7 @@ final class SoloZipArray extends Solo { protected void subscribeActual(Subscriber s) { Solo[] a = sources; int n = a.length; - ZipCoordinator parent = new ZipCoordinator(s, zipper, n); + ZipCoordinator parent = new ZipCoordinator<>(s, zipper, n); s.onSubscribe(parent); parent.subscribe(a, n); @@ -73,7 +71,7 @@ static final class ZipCoordinator extends DeferredScalarSubscription { @SuppressWarnings("unchecked") ZipSubscriber[] a = new ZipSubscriber[n]; for (int i = 0; i < n; i++) { - a[i] = new ZipSubscriber(i, this); + a[i] = new ZipSubscriber<>(i, this); } this.subscribers = a; this.wip = new AtomicInteger(n); @@ -100,7 +98,7 @@ void onSuccess(int index, T value) { if (wip.decrementAndGet() == 0) { R v; try { - v = ObjectHelper.requireNonNull(zipper.apply(values), "The zipper returned a null value"); + v = Objects.requireNonNull(zipper.apply(values), "The zipper returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); Arrays.fill(values, null); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloZipIterable.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloZipIterable.java similarity index 72% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/SoloZipIterable.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/SoloZipIterable.java index 6a9c8b67..f6bea7a3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/SoloZipIterable.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/SoloZipIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import java.util.Arrays; +import java.util.*; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.basetypes.SoloMap.MapSubscriber; -import hu.akarnokd.rxjava2.basetypes.SoloZipArray.ZipCoordinator; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.basetypes.SoloMap.MapSubscriber; +import hu.akarnokd.rxjava4.basetypes.SoloZipArray.ZipCoordinator; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Combines the solo values of all the sources via a zipper function into a @@ -45,7 +43,7 @@ final class SoloZipIterable extends Solo implements Function { } @Override - public R apply(T t) throws Exception { + public R apply(T t) throws Throwable { return zipper.apply(new Object[] { t }); } @@ -60,7 +58,7 @@ protected void subscribeActual(Subscriber s) { if (n == array.length) { array = Arrays.copyOf(array, n + (n >> 1)); } - array[n++] = ObjectHelper.requireNonNull(inner, "One of the source Solo is null"); + array[n++] = Objects.requireNonNull(inner, "One of the source Solo is null"); } } catch (Throwable ex) { Exceptions.throwIfFatal(ex); @@ -73,11 +71,11 @@ protected void subscribeActual(Subscriber s) { return; } else if (n == 1) { - array[0].subscribe(new MapSubscriber(s, this)); + array[0].subscribe(new MapSubscriber<>(s, this)); return; } - ZipCoordinator parent = new ZipCoordinator(s, zipper, n); + ZipCoordinator parent = new ZipCoordinator<>(s, zipper, n); s.onSubscribe(parent); parent.subscribe(array, n); diff --git a/src/main/java/hu/akarnokd/rxjava2/basetypes/package-info.java b/src/main/java/hu/akarnokd/rxjava4/basetypes/package-info.java similarity index 72% rename from src/main/java/hu/akarnokd/rxjava2/basetypes/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/basetypes/package-info.java index 68e150b3..a8f92093 100644 --- a/src/main/java/hu/akarnokd/rxjava2/basetypes/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/basetypes/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ /** * Proof-of-concept backpressure enabled 0..1 element reactive types: - * {@link hu.akarnokd.rxjava2.basetypes.Solo Solo}, {@link hu.akarnokd.rxjava2.basetypes.Perhaps Perhaps} - * and {@link hu.akarnokd.rxjava2.basetypes.Nono Nono}. + * {@link hu.akarnokd.rxjava4.basetypes.Solo Solo}, {@link hu.akarnokd.rxjava4.basetypes.Perhaps Perhaps} + * and {@link hu.akarnokd.rxjava4.basetypes.Nono Nono}. */ -package hu.akarnokd.rxjava2.basetypes; \ No newline at end of file +package hu.akarnokd.rxjava4.basetypes; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/AbstractDisposableAutoRelease.java b/src/main/java/hu/akarnokd/rxjava4/consumers/AbstractDisposableAutoRelease.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/consumers/AbstractDisposableAutoRelease.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/AbstractDisposableAutoRelease.java index 81c12aff..f94b8f95 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/AbstractDisposableAutoRelease.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/AbstractDisposableAutoRelease.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Wraps lambda callbacks and when the upstream terminates or the observer gets disposed, - * removes itself from a {@link io.reactivex.disposables.CompositeDisposable}. + * removes itself from a {@link io.reactivex.rxjava4.disposables.CompositeDisposable}. * @since 0.18.0 */ abstract class AbstractDisposableAutoRelease @@ -49,7 +49,7 @@ abstract class AbstractDisposableAutoRelease ) { this.onError = onError; this.onComplete = onComplete; - this.composite = new AtomicReference(composite); + this.composite = new AtomicReference<>(composite); } public final void onError(Throwable t) { diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/CompletableConsumers.java b/src/main/java/hu/akarnokd/rxjava4/consumers/CompletableConsumers.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/consumers/CompletableConsumers.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/CompletableConsumers.java index 2c0d3159..bb795594 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/CompletableConsumers.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/CompletableConsumers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.Completable; -import io.reactivex.disposables.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; +import java.util.Objects; + +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Completable; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.functions.*; /** - * Utility methods for creating and using consumers {@link io.reactivex.Completable}s. + * Utility methods for creating and using consumers {@link io.reactivex.rxjava4.core.Completable}s. * @since 0.18.0 */ public final class CompletableConsumers { @@ -48,11 +50,11 @@ public static Disposable subscribeAutoDispose( Completable source, CompositeDisposable composite, Action onComplete) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, Functions.emptyConsumer(), null, onComplete); composite.add(observer); source.subscribe(observer); @@ -77,12 +79,12 @@ public static Disposable subscribeAutoDispose( CompositeDisposable composite, Action onComplete, Consumer onError) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onComplete, "onSuccess is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onComplete, "onSuccess is null"); + Objects.requireNonNull(onError, "onError is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, Functions.emptyConsumer(), onError, onComplete); composite.add(observer); source.subscribe(observer); diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseMultiObserver.java b/src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseMultiObserver.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseMultiObserver.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseMultiObserver.java index 5afa3b06..02636ada 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseMultiObserver.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseMultiObserver.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.*; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.CompositeDisposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Wraps lambda callbacks and when the upstream terminates or this (Single | Maybe | Completable) - * observer gets disposed, removes itself from a {@link io.reactivex.disposables.CompositeDisposable}. + * observer gets disposed, removes itself from a {@link io.reactivex.rxjava4.disposables.CompositeDisposable}. * @param the element type consumed * @since 0.18.0 */ diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseObserver.java b/src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseObserver.java similarity index 78% rename from src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseObserver.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseObserver.java index ce47480b..a32bdb3b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseObserver.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseObserver.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.Observer; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.CompositeDisposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Wraps lambda callbacks and when the upstream terminates or this observer gets disposed, - * removes itself from a {@link io.reactivex.disposables.CompositeDisposable}. + * removes itself from a {@link io.reactivex.rxjava4.disposables.CompositeDisposable}. * @param the element type consumed * @since 0.18.0 */ diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseSubscriber.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseSubscriber.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseSubscriber.java index b6af0c53..90a18fb6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/DisposableAutoReleaseSubscriber.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/DisposableAutoReleaseSubscriber.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,22 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; +import java.util.concurrent.Flow.Subscription; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.Subscription; - -import io.reactivex.FlowableSubscriber; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Wraps lambda callbacks and when the upstream terminates or this subscriber gets disposed, - * removes itself from a {@link io.reactivex.disposables.CompositeDisposable}. + * removes itself from a {@link io.reactivex.rxjava4.disposables.CompositeDisposable}. * @param the element type consumed * @since 0.18.0 */ @@ -57,7 +56,7 @@ final class DisposableAutoReleaseSubscriber this.onNext = onNext; this.onError = onError; this.onComplete = onComplete; - this.composite = new AtomicReference(composite); + this.composite = new AtomicReference<>(composite); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/FlowableConsumers.java b/src/main/java/hu/akarnokd/rxjava4/consumers/FlowableConsumers.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/consumers/FlowableConsumers.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/FlowableConsumers.java index 26e6cd21..ba9f7f88 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/FlowableConsumers.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/FlowableConsumers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.Flowable; -import io.reactivex.disposables.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; +import java.util.Objects; + +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.functions.*; /** - * Utility methods for creating and using consumers {@link io.reactivex.Flowable}s. + * Utility methods for creating and using consumers {@link io.reactivex.rxjava4.core.Flowable}s. * @since 0.18.0 */ public final class FlowableConsumers { @@ -49,11 +51,11 @@ public static Disposable subscribeAutoDispose( Flowable source, CompositeDisposable composite, Consumer onNext) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onNext, "onNext is null"); - DisposableAutoReleaseSubscriber subscriber = new DisposableAutoReleaseSubscriber( + DisposableAutoReleaseSubscriber subscriber = new DisposableAutoReleaseSubscriber<>( composite, onNext, null, Functions.EMPTY_ACTION); composite.add(subscriber); source.subscribe(subscriber); @@ -79,12 +81,12 @@ public static Disposable subscribeAutoDispose( CompositeDisposable composite, Consumer onNext, Consumer onError) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onNext, "onNext is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); - DisposableAutoReleaseSubscriber subscriber = new DisposableAutoReleaseSubscriber( + DisposableAutoReleaseSubscriber subscriber = new DisposableAutoReleaseSubscriber<>( composite, onNext, onError, Functions.EMPTY_ACTION); composite.add(subscriber); source.subscribe(subscriber); @@ -112,13 +114,13 @@ public static Disposable subscribeAutoDispose( Consumer onNext, Consumer onError, Action onComplete) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onNext, "onNext is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); - DisposableAutoReleaseSubscriber subscriber = new DisposableAutoReleaseSubscriber( + DisposableAutoReleaseSubscriber subscriber = new DisposableAutoReleaseSubscriber<>( composite, onNext, onError, onComplete); composite.add(subscriber); source.subscribe(subscriber); diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/MaybeConsumers.java b/src/main/java/hu/akarnokd/rxjava4/consumers/MaybeConsumers.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/consumers/MaybeConsumers.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/MaybeConsumers.java index 7bb295f6..3345be22 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/MaybeConsumers.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/MaybeConsumers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.Maybe; -import io.reactivex.disposables.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; +import java.util.Objects; + +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Maybe; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.functions.*; /** - * Utility methods for creating and using consumers {@link io.reactivex.Maybe}s. + * Utility methods for creating and using consumers {@link io.reactivex.rxjava4.core.Maybe}s. * @since 0.18.0 */ public final class MaybeConsumers { @@ -49,11 +51,11 @@ public static Disposable subscribeAutoDispose( Maybe source, CompositeDisposable composite, Consumer onSuccess) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onSuccess, "onSuccess is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, onSuccess, null, Functions.EMPTY_ACTION); composite.add(observer); source.subscribe(observer); @@ -79,12 +81,12 @@ public static Disposable subscribeAutoDispose( CompositeDisposable composite, Consumer onSuccess, Consumer onError) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onSuccess, "onSuccess is null"); + Objects.requireNonNull(onError, "onError is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, onSuccess, onError, Functions.EMPTY_ACTION); composite.add(observer); source.subscribe(observer); @@ -112,13 +114,13 @@ public static Disposable subscribeAutoDispose( Consumer onSuccess, Consumer onError, Action onComplete) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onSuccess, "onSuccess is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, onSuccess, onError, onComplete); composite.add(observer); source.subscribe(observer); diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/ObservableConsumers.java b/src/main/java/hu/akarnokd/rxjava4/consumers/ObservableConsumers.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/consumers/ObservableConsumers.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/ObservableConsumers.java index fb7a4bcc..453a6f74 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/ObservableConsumers.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/ObservableConsumers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.Observable; -import io.reactivex.disposables.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; +import java.util.Objects; + +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.functions.*; /** - * Utility methods for creating and using consumers {@link io.reactivex.Observable}s. + * Utility methods for creating and using consumers {@link io.reactivex.rxjava4.core.Observable}s. * @since 0.18.0 */ public final class ObservableConsumers { @@ -49,11 +51,11 @@ public static Disposable subscribeAutoDispose( Observable source, CompositeDisposable composite, Consumer onNext) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onNext, "onNext is null"); - DisposableAutoReleaseObserver observer = new DisposableAutoReleaseObserver( + DisposableAutoReleaseObserver observer = new DisposableAutoReleaseObserver<>( composite, onNext, null, Functions.EMPTY_ACTION); composite.add(observer); source.subscribe(observer); @@ -79,12 +81,12 @@ public static Disposable subscribeAutoDispose( CompositeDisposable composite, Consumer onNext, Consumer onError) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onNext, "onNext is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); - DisposableAutoReleaseObserver observer = new DisposableAutoReleaseObserver( + DisposableAutoReleaseObserver observer = new DisposableAutoReleaseObserver<>( composite, onNext, onError, Functions.EMPTY_ACTION); composite.add(observer); source.subscribe(observer); @@ -112,13 +114,13 @@ public static Disposable subscribeAutoDispose( Consumer onNext, Consumer onError, Action onComplete) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onNext, "onNext is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); - ObjectHelper.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); - DisposableAutoReleaseObserver observer = new DisposableAutoReleaseObserver( + DisposableAutoReleaseObserver observer = new DisposableAutoReleaseObserver<>( composite, onNext, onError, onComplete); composite.add(observer); source.subscribe(observer); diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/SingleConsumers.java b/src/main/java/hu/akarnokd/rxjava4/consumers/SingleConsumers.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/consumers/SingleConsumers.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/SingleConsumers.java index 1ed48d88..61f5dbf0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/SingleConsumers.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/SingleConsumers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import io.reactivex.Single; -import io.reactivex.disposables.*; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.functions.*; +import java.util.Objects; + +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Single; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.functions.Consumer; /** - * Utility methods for creating and using consumers {@link io.reactivex.SingleObserver}s. + * Utility methods for creating and using consumers {@link io.reactivex.rxjava4.core.SingleObserver}s. * @since 0.18.0 */ public final class SingleConsumers { @@ -49,11 +51,11 @@ public static Disposable subscribeAutoDispose( Single source, CompositeDisposable composite, Consumer onSuccess) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onSuccess, "onSuccess is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, onSuccess, null, Functions.EMPTY_ACTION); composite.add(observer); source.subscribe(observer); @@ -79,12 +81,12 @@ public static Disposable subscribeAutoDispose( CompositeDisposable composite, Consumer onSuccess, Consumer onError) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(composite, "composite is null"); - ObjectHelper.requireNonNull(onSuccess, "onSuccess is null"); - ObjectHelper.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(composite, "composite is null"); + Objects.requireNonNull(onSuccess, "onSuccess is null"); + Objects.requireNonNull(onError, "onError is null"); - DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver( + DisposableAutoReleaseMultiObserver observer = new DisposableAutoReleaseMultiObserver<>( composite, onSuccess, onError, Functions.EMPTY_ACTION); composite.add(observer); source.subscribe(observer); diff --git a/src/main/java/hu/akarnokd/rxjava2/consumers/package-info.java b/src/main/java/hu/akarnokd/rxjava4/consumers/package-info.java similarity index 64% rename from src/main/java/hu/akarnokd/rxjava2/consumers/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/consumers/package-info.java index 8a9f4e1e..d2a9bd4d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/consumers/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/consumers/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ /** * Utility methods to create special consumer types, such as auto-release consumers via - * {@link hu.akarnokd.rxjava2.consumers.FlowableConsumers FlowableConsumers}, - * {@link hu.akarnokd.rxjava2.consumers.ObservableConsumers ObservableConsumers}, - * {@link hu.akarnokd.rxjava2.consumers.MaybeConsumers MaybeConsumers}, - * {@link hu.akarnokd.rxjava2.consumers.SingleConsumers SingleConsumers} and - * {@link hu.akarnokd.rxjava2.consumers.CompletableConsumers CompletableConsumers}. + * {@link hu.akarnokd.rxjava4.consumers.FlowableConsumers FlowableConsumers}, + * {@link hu.akarnokd.rxjava4.consumers.ObservableConsumers ObservableConsumers}, + * {@link hu.akarnokd.rxjava4.consumers.MaybeConsumers MaybeConsumers}, + * {@link hu.akarnokd.rxjava4.consumers.SingleConsumers SingleConsumers} and + * {@link hu.akarnokd.rxjava4.consumers.CompletableConsumers CompletableConsumers}. */ -package hu.akarnokd.rxjava2.consumers; \ No newline at end of file +package hu.akarnokd.rxjava4.consumers; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssembly.java b/src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssembly.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssembly.java rename to src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssembly.java index 1e1863e0..1e128151 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssembly.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssembly.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Wraps a CompletableSource and inject the assembly info. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssemblyScalarCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssemblyScalarSupplier.java similarity index 69% rename from src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssemblyScalarCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssemblyScalarSupplier.java index 625ccc3b..10e283a3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssemblyScalarCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssemblyScalarSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,22 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import hu.akarnokd.rxjava2.debug.CompletableOnAssembly.OnAssemblyCompletableObserver; -import io.reactivex.*; -import io.reactivex.internal.fuseable.ScalarCallable; +import hu.akarnokd.rxjava4.debug.CompletableOnAssembly.OnAssemblyCompletableObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.ScalarSupplier; /** * Wraps a CompletableSource and inject the assembly info. */ -final class CompletableOnAssemblyScalarCallable extends Completable implements ScalarCallable { +final class CompletableOnAssemblyScalarSupplier extends Completable implements ScalarSupplier { final CompletableSource source; final RxJavaAssemblyException assembled; - CompletableOnAssemblyScalarCallable(CompletableSource source) { + CompletableOnAssemblyScalarSupplier(CompletableSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -41,7 +41,7 @@ protected void subscribeActual(CompletableObserver observer) { @SuppressWarnings("unchecked") @Override - public Object call() { - return ((ScalarCallable)source).call(); + public Object get() { + return ((ScalarSupplier)source).get(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssemblyCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssemblySupplier.java similarity index 65% rename from src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssemblyCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssemblySupplier.java index 6de9a2a6..3e208ff3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/CompletableOnAssemblyCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/CompletableOnAssemblySupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import java.util.concurrent.Callable; - -import hu.akarnokd.rxjava2.debug.CompletableOnAssembly.OnAssemblyCompletableObserver; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; +import hu.akarnokd.rxjava4.debug.CompletableOnAssembly.OnAssemblyCompletableObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Wraps a CompletableSource and inject the assembly info. */ -final class CompletableOnAssemblyCallable extends Completable implements Callable { +final class CompletableOnAssemblySupplier extends Completable implements Supplier { final CompletableSource source; final RxJavaAssemblyException assembled; - CompletableOnAssemblyCallable(CompletableSource source) { + CompletableOnAssemblySupplier(CompletableSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -43,12 +42,12 @@ protected void subscribeActual(CompletableObserver observer) { @SuppressWarnings("unchecked") @Override - public Object call() throws Exception { + public Object get() throws Throwable { try { - return ((Callable)source).call(); - } catch (Exception ex) { + return ((Supplier)source).get(); + } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - throw (Exception)assembled.appendLast(ex); + throw assembled.appendLast(ex); } } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssembly.java b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssembly.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssembly.java rename to src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssembly.java index 3b8137f8..593c4b79 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssembly.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssembly.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.Flowable; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.subscribers.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.operators.*; /** * Wraps a Publisher and inject the assembly info. @@ -78,7 +78,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { return qs.poll(); } } @@ -119,7 +119,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { return qs.poll(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyConnectable.java b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblyConnectable.java similarity index 76% rename from src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyConnectable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblyConnectable.java index f9e87bde..b0e5dd3d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyConnectable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblyConnectable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.debug.FlowableOnAssembly.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.flowables.ConnectableFlowable; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.fuseable.ConditionalSubscriber; +import hu.akarnokd.rxjava4.debug.FlowableOnAssembly.*; +import io.reactivex.rxjava4.core.ConnectableFlowable; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; /** * Wraps a Publisher and inject the assembly info. @@ -53,4 +53,9 @@ protected void subscribeActual(Subscriber s) { public void connect(Consumer connection) { source.connect(connection); } + + @Override + public void reset() { + source.reset(); + } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyScalarCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblyScalarSupplier.java similarity index 72% rename from src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyScalarCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblyScalarSupplier.java index 9cde2875..8efe96a8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyScalarCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblyScalarSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,26 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import hu.akarnokd.rxjava2.debug.FlowableOnAssembly.*; -import io.reactivex.Flowable; -import io.reactivex.internal.fuseable.*; +import hu.akarnokd.rxjava4.debug.FlowableOnAssembly.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.operators.*; /** * Wraps a Publisher and inject the assembly info. * * @param the value type */ -final class FlowableOnAssemblyScalarCallable extends Flowable implements ScalarCallable { +final class FlowableOnAssemblyScalarSupplier extends Flowable implements ScalarSupplier { final Publisher source; final RxJavaAssemblyException assembled; - FlowableOnAssemblyScalarCallable(Publisher source) { + FlowableOnAssemblyScalarSupplier(Publisher source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -49,7 +49,7 @@ protected void subscribeActual(Subscriber s) { @SuppressWarnings("unchecked") @Override - public T call() { - return ((ScalarCallable)source).call(); + public T get() { + return ((ScalarSupplier)source).get(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblySupplier.java similarity index 66% rename from src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblySupplier.java index a62e1b98..afdf15db 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/FlowableOnAssemblyCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/FlowableOnAssemblySupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,29 +14,28 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.debug.FlowableOnAssembly.*; -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.fuseable.ConditionalSubscriber; +import hu.akarnokd.rxjava4.debug.FlowableOnAssembly.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; /** * Wraps a Publisher and inject the assembly info. * * @param the value type */ -final class FlowableOnAssemblyCallable extends Flowable implements Callable { +final class FlowableOnAssemblySupplier extends Flowable implements Supplier { final Publisher source; final RxJavaAssemblyException assembled; - FlowableOnAssemblyCallable(Publisher source) { + FlowableOnAssemblySupplier(Publisher source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -52,12 +51,12 @@ protected void subscribeActual(Subscriber s) { @SuppressWarnings("unchecked") @Override - public T call() throws Exception { + public T get() throws Throwable { try { - return ((Callable)source).call(); - } catch (Exception ex) { + return ((Supplier)source).get(); + } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - throw (Exception)assembled.appendLast(ex); + throw assembled.appendLast(ex); } } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssembly.java b/src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssembly.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssembly.java rename to src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssembly.java index 24a144e1..75f8ee6e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssembly.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssembly.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Wraps a MaybeSource and inject the assembly info. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssemblyScalarCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssemblyScalarSupplier.java similarity index 70% rename from src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssemblyScalarCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssemblyScalarSupplier.java index be2b57aa..c24afd58 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssemblyScalarCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssemblyScalarSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import hu.akarnokd.rxjava2.debug.MaybeOnAssembly.OnAssemblyMaybeObserver; -import io.reactivex.*; -import io.reactivex.internal.fuseable.ScalarCallable; +import hu.akarnokd.rxjava4.debug.MaybeOnAssembly.OnAssemblyMaybeObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.ScalarSupplier; /** * Wraps a MaybeSource and inject the assembly info. * * @param the value type */ -final class MaybeOnAssemblyScalarCallable extends Maybe implements ScalarCallable { +final class MaybeOnAssemblyScalarSupplier extends Maybe implements ScalarSupplier { final MaybeSource source; final RxJavaAssemblyException assembled; - MaybeOnAssemblyScalarCallable(MaybeSource source) { + MaybeOnAssemblyScalarSupplier(MaybeSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -43,7 +43,7 @@ protected void subscribeActual(MaybeObserver observer) { @SuppressWarnings("unchecked") @Override - public T call() { - return ((ScalarCallable)source).call(); + public T get() { + return ((ScalarSupplier)source).get(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssemblyCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssemblySupplier.java similarity index 69% rename from src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssemblyCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssemblySupplier.java index ddcfe706..e9f2ee19 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/MaybeOnAssemblyCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/MaybeOnAssemblySupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import java.util.concurrent.Callable; - -import hu.akarnokd.rxjava2.debug.MaybeOnAssembly.OnAssemblyMaybeObserver; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; +import hu.akarnokd.rxjava4.debug.MaybeOnAssembly.OnAssemblyMaybeObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Wraps a MaybeSource and inject the assembly info. * * @param the value type */ -final class MaybeOnAssemblyCallable extends Maybe implements Callable { +final class MaybeOnAssemblySupplier extends Maybe implements Supplier { final MaybeSource source; final RxJavaAssemblyException assembled; - MaybeOnAssemblyCallable(MaybeSource source) { + MaybeOnAssemblySupplier(MaybeSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -45,10 +44,10 @@ protected void subscribeActual(MaybeObserver observer) { @SuppressWarnings("unchecked") @Override - public T call() throws Exception { + public T get() throws Throwable { try { - return ((Callable)source).call(); - } catch (Exception ex) { + return ((Supplier)source).get(); + } catch (Throwable ex) { Exceptions.throwIfFatal(ex); throw (Exception)assembled.appendLast(ex); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssembly.java b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssembly.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssembly.java rename to src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssembly.java index c2e82007..ae4ee1f4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssembly.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssembly.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import io.reactivex.*; -import io.reactivex.internal.fuseable.QueueDisposable; -import io.reactivex.internal.observers.BasicFuseableObserver; +import hu.akarnokd.rxjava4.internal.rxcopy.BasicFuseableObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.QueueDisposable; /** * Wraps a ObservableSource and inject the assembly info. @@ -72,7 +72,7 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { + public T poll() throws Throwable { return qd.poll(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyConnectable.java b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblyConnectable.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyConnectable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblyConnectable.java index 7ba37e6c..b3b96410 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyConnectable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblyConnectable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import hu.akarnokd.rxjava2.debug.ObservableOnAssembly.OnAssemblyObserver; -import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; -import io.reactivex.observables.ConnectableObservable; +import hu.akarnokd.rxjava4.debug.ObservableOnAssembly.OnAssemblyObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Consumer; /** * Wraps a ObservableSource and inject the assembly info. @@ -47,4 +46,9 @@ protected void subscribeActual(Observer observer) { public void connect(Consumer connection) { source.connect(connection); } + + @Override + public void reset() { + source.reset(); + } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyScalarCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblyScalarSupplier.java similarity index 69% rename from src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyScalarCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblyScalarSupplier.java index cbdbedeb..b1095436 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyScalarCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblyScalarSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import hu.akarnokd.rxjava2.debug.ObservableOnAssembly.OnAssemblyObserver; -import io.reactivex.*; -import io.reactivex.internal.fuseable.ScalarCallable; +import hu.akarnokd.rxjava4.debug.ObservableOnAssembly.OnAssemblyObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.ScalarSupplier; /** * Wraps a ObservableSource and inject the assembly info. * * @param the value type */ -final class ObservableOnAssemblyScalarCallable extends Observable implements ScalarCallable { +final class ObservableOnAssemblyScalarSupplier extends Observable implements ScalarSupplier { final ObservableSource source; final RxJavaAssemblyException assembled; - ObservableOnAssemblyScalarCallable(ObservableSource source) { + ObservableOnAssemblyScalarSupplier(ObservableSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -43,7 +43,7 @@ protected void subscribeActual(Observer observer) { @SuppressWarnings("unchecked") @Override - public T call() { - return ((ScalarCallable)source).call(); + public T get() { + return ((ScalarSupplier)source).get(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblySupplier.java similarity index 65% rename from src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblySupplier.java index 6a362e6a..bcb89474 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/ObservableOnAssemblyCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/ObservableOnAssemblySupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import java.util.concurrent.Callable; - -import hu.akarnokd.rxjava2.debug.ObservableOnAssembly.OnAssemblyObserver; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; +import hu.akarnokd.rxjava4.debug.ObservableOnAssembly.OnAssemblyObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Wraps a ObservableSource and inject the assembly info. * * @param the value type */ -final class ObservableOnAssemblyCallable extends Observable implements Callable { +final class ObservableOnAssemblySupplier extends Observable implements Supplier { final ObservableSource source; final RxJavaAssemblyException assembled; - ObservableOnAssemblyCallable(ObservableSource source) { + ObservableOnAssemblySupplier(ObservableSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -45,12 +44,12 @@ protected void subscribeActual(Observer observer) { @SuppressWarnings("unchecked") @Override - public T call() throws Exception { + public T get() throws Throwable { try { - return ((Callable)source).call(); - } catch (Exception ex) { + return ((Supplier)source).get(); + } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - throw (Exception)assembled.appendLast(ex); + throw assembled.appendLast(ex); } } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/ParallelFlowableOnAssembly.java b/src/main/java/hu/akarnokd/rxjava4/debug/ParallelFlowableOnAssembly.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/debug/ParallelFlowableOnAssembly.java rename to src/main/java/hu/akarnokd/rxjava4/debug/ParallelFlowableOnAssembly.java index 1d5f9d93..a703aae8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/ParallelFlowableOnAssembly.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/ParallelFlowableOnAssembly.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.debug.FlowableOnAssembly.*; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.parallel.ParallelFlowable; +import hu.akarnokd.rxjava4.debug.FlowableOnAssembly.*; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; +import io.reactivex.rxjava4.parallel.ParallelFlowable; /** * Wrap a Parallel Flowable and inject the assembly info. @@ -53,9 +53,9 @@ public void subscribe(Subscriber[] s) { for (int i = 0; i < n; i++) { Subscriber z = s[i]; if (z instanceof ConditionalSubscriber) { - parents[i] = new OnAssemblyConditionalSubscriber((ConditionalSubscriber)z, assembled); + parents[i] = new OnAssemblyConditionalSubscriber<>((ConditionalSubscriber)z, assembled); } else { - parents[i] = new OnAssemblySubscriber(z, assembled); + parents[i] = new OnAssemblySubscriber<>(z, assembled); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/RxJavaAssemblyException.java b/src/main/java/hu/akarnokd/rxjava4/debug/RxJavaAssemblyException.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/debug/RxJavaAssemblyException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/RxJavaAssemblyException.java index 48063333..9d08d1b7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/RxJavaAssemblyException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/RxJavaAssemblyException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; import java.util.*; @@ -27,20 +27,31 @@ public final class RxJavaAssemblyException extends RuntimeException { final String stacktrace; + /** + * Constructs the exception without message or cause and captures the stacktrace. + */ public RxJavaAssemblyException() { this.stacktrace = buildStackTrace(); } + /** + * Converts the current thread's stacktrace into a String, + * without using {@code printStackTrace()} and all sorts + * of buffers and writers + * @return the String of the stacktrace + */ public static String buildStackTrace() { StringBuilder b = new StringBuilder(); StackTraceElement[] es = Thread.currentThread().getStackTrace(); - b.append("RxJavaAssemblyException: assembled\r\n"); + b.append("RxJavaAssemblyException: assembled"); for (StackTraceElement e : es) { if (filter(e)) { - b.append("at ").append(e).append("\r\n"); + b.append(System.lineSeparator()) + .append("\tat ") + .append(e); } } @@ -116,7 +127,7 @@ public synchronized Throwable fillInStackTrace() { */ public Throwable appendLast(Throwable ex) { Throwable r = ex; - Set memory = new HashSet(); + Set memory = new HashSet<>(); while (ex.getCause() != null) { if (memory.add(ex)) { ex = ex.getCause(); @@ -141,7 +152,7 @@ public Throwable appendLast(Throwable ex) { * @return the RxJavaAssemblyException found or null */ public static RxJavaAssemblyException find(Throwable ex) { - Set memory = new HashSet(); + Set memory = new HashSet<>(); while (ex != null) { if (ex instanceof RxJavaAssemblyException) { return (RxJavaAssemblyException)ex; @@ -155,4 +166,9 @@ public static RxJavaAssemblyException find(Throwable ex) { } return null; } + + @Override + public String getMessage() { + return stacktrace; + } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/RxJavaAssemblyTracking.java b/src/main/java/hu/akarnokd/rxjava4/debug/RxJavaAssemblyTracking.java similarity index 71% rename from src/main/java/hu/akarnokd/rxjava2/debug/RxJavaAssemblyTracking.java rename to src/main/java/hu/akarnokd/rxjava4/debug/RxJavaAssemblyTracking.java index 66c5b075..f5c2bb01 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/RxJavaAssemblyTracking.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/RxJavaAssemblyTracking.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.*; -import io.reactivex.flowables.ConnectableFlowable; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.ResettableConnectable; -import io.reactivex.internal.fuseable.ScalarCallable; -import io.reactivex.observables.ConnectableObservable; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.ScalarSupplier; +import io.reactivex.rxjava4.parallel.ParallelFlowable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Utility class to enable and disable tracking of operator application ({@code source.map().filter()}) @@ -54,11 +50,11 @@ public static void enable() { RxJavaPlugins.setOnFlowableAssembly(new Function() { @Override public Flowable apply(Flowable f) throws Exception { - if (f instanceof Callable) { - if (f instanceof ScalarCallable) { - return new FlowableOnAssemblyScalarCallable(f); + if (f instanceof Supplier) { + if (f instanceof ScalarSupplier) { + return new FlowableOnAssemblyScalarSupplier(f); } - return new FlowableOnAssemblyCallable(f); + return new FlowableOnAssemblySupplier(f); } return new FlowableOnAssembly(f); } @@ -67,9 +63,6 @@ public Flowable apply(Flowable f) throws Exception { RxJavaPlugins.setOnConnectableFlowableAssembly(new Function() { @Override public ConnectableFlowable apply(ConnectableFlowable f) throws Exception { - if (f instanceof ResettableConnectable) { - return new FlowableOnAssemblyConnectableResettable(f); - } return new FlowableOnAssemblyConnectable(f); } }); @@ -77,11 +70,11 @@ public ConnectableFlowable apply(ConnectableFlowable f) throws Exception { RxJavaPlugins.setOnObservableAssembly(new Function() { @Override public Observable apply(Observable f) throws Exception { - if (f instanceof Callable) { - if (f instanceof ScalarCallable) { - return new ObservableOnAssemblyScalarCallable(f); + if (f instanceof Supplier) { + if (f instanceof ScalarSupplier) { + return new ObservableOnAssemblyScalarSupplier(f); } - return new ObservableOnAssemblyCallable(f); + return new ObservableOnAssemblySupplier(f); } return new ObservableOnAssembly(f); } @@ -90,9 +83,6 @@ public Observable apply(Observable f) throws Exception { RxJavaPlugins.setOnConnectableObservableAssembly(new Function() { @Override public ConnectableObservable apply(ConnectableObservable f) throws Exception { - if (f instanceof ResettableConnectable) { - return new ObservableOnAssemblyConnectableResettable(f); - } return new ObservableOnAssemblyConnectable(f); } }); @@ -100,11 +90,11 @@ public ConnectableObservable apply(ConnectableObservable f) throws Exception { RxJavaPlugins.setOnSingleAssembly(new Function() { @Override public Single apply(Single f) throws Exception { - if (f instanceof Callable) { - if (f instanceof ScalarCallable) { - return new SingleOnAssemblyScalarCallable(f); + if (f instanceof Supplier) { + if (f instanceof ScalarSupplier) { + return new SingleOnAssemblyScalarSupplier(f); } - return new SingleOnAssemblyCallable(f); + return new SingleOnAssemblySupplier(f); } return new SingleOnAssembly(f); } @@ -113,11 +103,11 @@ public Single apply(Single f) throws Exception { RxJavaPlugins.setOnCompletableAssembly(new Function() { @Override public Completable apply(Completable f) throws Exception { - if (f instanceof Callable) { - if (f instanceof ScalarCallable) { - return new CompletableOnAssemblyScalarCallable(f); + if (f instanceof Supplier) { + if (f instanceof ScalarSupplier) { + return new CompletableOnAssemblyScalarSupplier(f); } - return new CompletableOnAssemblyCallable(f); + return new CompletableOnAssemblySupplier(f); } return new CompletableOnAssembly(f); } @@ -126,11 +116,11 @@ public Completable apply(Completable f) throws Exception { RxJavaPlugins.setOnMaybeAssembly(new Function() { @Override public Maybe apply(Maybe f) throws Exception { - if (f instanceof Callable) { - if (f instanceof ScalarCallable) { - return new MaybeOnAssemblyScalarCallable(f); + if (f instanceof Supplier) { + if (f instanceof ScalarSupplier) { + return new MaybeOnAssemblyScalarSupplier(f); } - return new MaybeOnAssemblyCallable(f); + return new MaybeOnAssemblySupplier(f); } return new MaybeOnAssembly(f); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/SavedHooks.java b/src/main/java/hu/akarnokd/rxjava4/debug/SavedHooks.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/debug/SavedHooks.java rename to src/main/java/hu/akarnokd/rxjava4/debug/SavedHooks.java index 8ca34645..a754b19b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/SavedHooks.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/SavedHooks.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; /** * Remembers the previous hooks overridden by the debug diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssembly.java b/src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssembly.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssembly.java rename to src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssembly.java index 19262f4e..7c1efdba 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssembly.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssembly.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Wraps a Publisher and inject the assembly info. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssemblyScalarCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssemblyScalarSupplier.java similarity index 70% rename from src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssemblyScalarCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssemblyScalarSupplier.java index 5c14e5d2..e24971ac 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssemblyScalarCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssemblyScalarSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import hu.akarnokd.rxjava2.debug.SingleOnAssembly.OnAssemblySingleObserver; -import io.reactivex.*; -import io.reactivex.internal.fuseable.ScalarCallable; +import hu.akarnokd.rxjava4.debug.SingleOnAssembly.OnAssemblySingleObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.ScalarSupplier; /** * Wraps a Publisher and inject the assembly info. * * @param the value type */ -final class SingleOnAssemblyScalarCallable extends Single implements ScalarCallable { +final class SingleOnAssemblyScalarSupplier extends Single implements ScalarSupplier { final SingleSource source; final RxJavaAssemblyException assembled; - SingleOnAssemblyScalarCallable(SingleSource source) { + SingleOnAssemblyScalarSupplier(SingleSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -43,7 +43,7 @@ protected void subscribeActual(SingleObserver observer) { @SuppressWarnings("unchecked") @Override - public T call() { - return ((ScalarCallable)source).call(); + public T get() { + return ((ScalarSupplier)source).get(); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssemblyCallable.java b/src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssemblySupplier.java similarity index 66% rename from src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssemblyCallable.java rename to src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssemblySupplier.java index e1d2dd75..e83f1fb8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/SingleOnAssemblyCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/SingleOnAssemblySupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import java.util.concurrent.Callable; - -import hu.akarnokd.rxjava2.debug.SingleOnAssembly.OnAssemblySingleObserver; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; +import hu.akarnokd.rxjava4.debug.SingleOnAssembly.OnAssemblySingleObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * Wraps a Publisher and inject the assembly info. * * @param the value type */ -final class SingleOnAssemblyCallable extends Single implements Callable { +final class SingleOnAssemblySupplier extends Single implements Supplier { final SingleSource source; final RxJavaAssemblyException assembled; - SingleOnAssemblyCallable(SingleSource source) { + SingleOnAssemblySupplier(SingleSource source) { this.source = source; this.assembled = new RxJavaAssemblyException(); } @@ -45,12 +44,12 @@ protected void subscribeActual(SingleObserver observer) { @SuppressWarnings("unchecked") @Override - public T call() throws Exception { + public T get() throws Throwable { try { - return ((Callable)source).call(); - } catch (Exception ex) { + return ((Supplier)source).get(); + } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - throw (Exception)assembled.appendLast(ex); + throw assembled.appendLast(ex); } } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/multihook/MultiHandlerManager.java b/src/main/java/hu/akarnokd/rxjava4/debug/multihook/MultiHandlerManager.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/debug/multihook/MultiHandlerManager.java rename to src/main/java/hu/akarnokd/rxjava4/debug/multihook/MultiHandlerManager.java index f3346502..f3190f86 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/multihook/MultiHandlerManager.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/multihook/MultiHandlerManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.multihook; +package hu.akarnokd.rxjava4.debug.multihook; -import java.util.Iterator; +import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.annotations.NonNull; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.annotations.NonNull; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; /** * Manages an array of handlers. @@ -43,7 +42,7 @@ public class MultiHandlerManager { * Constructs an empty handler manager. */ public MultiHandlerManager() { - handlers = new CopyOnWriteArrayList>(); + handlers = new CopyOnWriteArrayList<>(); } /** @@ -58,8 +57,8 @@ public MultiHandlerManager() { */ @NonNull public final Disposable register(@NonNull H handler) { - ObjectHelper.requireNonNull(handler, "handler is null"); - HandlerRegistration hr = new HandlerRegistration(this, handler); + Objects.requireNonNull(handler, "handler is null"); + HandlerRegistration hr = new HandlerRegistration<>(this, handler); handlers.add(hr); return hr; } @@ -79,7 +78,7 @@ final void unregister(HandlerRegistration handler) { * @param consumer the consumer to invoke */ public final void forEach(@NonNull Consumer consumer) { - ObjectHelper.requireNonNull(consumer, "consumer is null"); + Objects.requireNonNull(consumer, "consumer is null"); Iterator> it = handlers.iterator(); while (it.hasNext()) { try { @@ -109,7 +108,7 @@ public final void forEach(@NonNull Consumer consumer) { * @param consumer the consumer to invoke */ public final void forEach(S state, @NonNull BiConsumer consumer) { - ObjectHelper.requireNonNull(consumer, "consumer is null"); + Objects.requireNonNull(consumer, "consumer is null"); Iterator> it = handlers.iterator(); while (it.hasNext()) { try { diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/multihook/OnScheduleMultiHandlerManager.java b/src/main/java/hu/akarnokd/rxjava4/debug/multihook/OnScheduleMultiHandlerManager.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/debug/multihook/OnScheduleMultiHandlerManager.java rename to src/main/java/hu/akarnokd/rxjava4/debug/multihook/OnScheduleMultiHandlerManager.java index 040da0c3..8d0f3d6f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/multihook/OnScheduleMultiHandlerManager.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/multihook/OnScheduleMultiHandlerManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.multihook; +package hu.akarnokd.rxjava4.debug.multihook; -import io.reactivex.functions.*; -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Handles the OnSchedule hooks. @@ -67,7 +67,7 @@ public Runnable apply(Runnable t) throws Exception { @Override public void accept(Runnable[] t1, - Function t2) throws Exception { + Function t2) throws Throwable { t1[0] = t2.apply(t1[0]); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/multihook/package-info.java b/src/main/java/hu/akarnokd/rxjava4/debug/multihook/package-info.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/debug/multihook/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/debug/multihook/package-info.java index 8f0562b4..b58558dc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/multihook/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/multihook/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,9 @@ */ /** - * Proof of concept {@link io.reactivex.plugins.RxJavaPlugins RxJavaPlugins} + * Proof of concept {@link io.reactivex.rxjava4.plugins.RxJavaPlugins RxJavaPlugins} * hook implementation for handling multiple hooks to * the {@code onSchedule} callback via - * {@link hu.akarnokd.rxjava2.debug.multihook.OnScheduleMultiHandlerManager OnScheduleMultiHandlerManager}. + * {@link hu.akarnokd.rxjava4.debug.multihook.OnScheduleMultiHandlerManager OnScheduleMultiHandlerManager}. */ -package hu.akarnokd.rxjava2.debug.multihook; \ No newline at end of file +package hu.akarnokd.rxjava4.debug.multihook; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/package-info.java b/src/main/java/hu/akarnokd/rxjava4/debug/package-info.java similarity index 73% rename from src/main/java/hu/akarnokd/rxjava2/debug/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/debug/package-info.java index 7d4f2d59..f38730ee 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ /** * Debugging support to remember where operators have been created in the - * code via {@link io.reactivex.plugins.RxJavaPlugins RxJavaPlugins}' assembly hooks, enabled via - * {@link hu.akarnokd.rxjava2.debug.RxJavaAssemblyTracking RxJavaAssemblyTracking}. + * code via {@link io.reactivex.rxjava4.plugins.RxJavaPlugins RxJavaPlugins}' assembly hooks, enabled via + * {@link hu.akarnokd.rxjava4.debug.RxJavaAssemblyTracking RxJavaAssemblyTracking}. */ -package hu.akarnokd.rxjava2.debug; \ No newline at end of file +package hu.akarnokd.rxjava4.debug; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/CompletableValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/CompletableValidator.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/CompletableValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/CompletableValidator.java index 08ef3696..b88d87a1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/CompletableValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/CompletableValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Validates a Completable. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ConnectableFlowableValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ConnectableFlowableValidator.java similarity index 76% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/ConnectableFlowableValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/ConnectableFlowableValidator.java index 831a30ca..887e1cee 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ConnectableFlowableValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ConnectableFlowableValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.disposables.Disposable; -import io.reactivex.flowables.ConnectableFlowable; -import io.reactivex.functions.Consumer; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.ConnectableFlowable; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Consumer; /** * Validates a ConnectableFlowable. @@ -48,4 +48,9 @@ protected void subscribeActual(Subscriber s) { public void connect(Consumer connection) { source.connect(connection); } + + @Override + public void reset() { + source.reset(); + } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ConnectableObservableValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ConnectableObservableValidator.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/ConnectableObservableValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/ConnectableObservableValidator.java index 1c608b0c..8f8203f4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ConnectableObservableValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ConnectableObservableValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; -import io.reactivex.observables.ConnectableObservable; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Consumer; /** * Validates a ConnectableObservable. @@ -47,4 +46,9 @@ protected void subscribeActual(Observer observer) { public void connect(Consumer connection) { source.connect(connection); } + + @Override + public void reset() { + source.reset(); + } } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/FlowableValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/FlowableValidator.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/FlowableValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/FlowableValidator.java index 9456b423..c32501dc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/FlowableValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/FlowableValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.*; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.*; /** * Validates a Flowable. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/MaybeValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/MaybeValidator.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/MaybeValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/MaybeValidator.java index 43ac43ed..68508343 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/MaybeValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/MaybeValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Validates a Maybe. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/MultipleOnSubscribeCallsException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/MultipleOnSubscribeCallsException.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/MultipleOnSubscribeCallsException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/MultipleOnSubscribeCallsException.java index c63e52fc..8658b683 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/MultipleOnSubscribeCallsException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/MultipleOnSubscribeCallsException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Indicates there were multiple {@code onSubscribe} calls. @@ -24,6 +24,9 @@ public final class MultipleOnSubscribeCallsException extends ProtocolNonConforma private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public MultipleOnSubscribeCallsException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/MultipleTerminationsException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/MultipleTerminationsException.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/MultipleTerminationsException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/MultipleTerminationsException.java index 102c8ace..99f44d18 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/MultipleTerminationsException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/MultipleTerminationsException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Indicates there were multiple {@code onError} or {@code onComplete} calls. @@ -24,10 +24,17 @@ public final class MultipleTerminationsException extends ProtocolNonConformanceE private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public MultipleTerminationsException() { super(); } + /** + * Constructs the exception with a cause. + * @param cause the cause + */ public MultipleTerminationsException(Throwable cause) { super(cause); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnErrorParameterException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnErrorParameterException.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnErrorParameterException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnErrorParameterException.java index 45bab575..815d32f0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnErrorParameterException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnErrorParameterException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Indicates the {@code onError} was called with a {@code null} {@code Throwable}. @@ -24,6 +24,9 @@ public final class NullOnErrorParameterException extends ProtocolNonConformanceE private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without a message or cause. + */ public NullOnErrorParameterException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnNextParameterException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnNextParameterException.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnNextParameterException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnNextParameterException.java index f852b750..7aa45b36 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnNextParameterException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnNextParameterException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Indicates the {@code onNext} was called with a {@code null} value. @@ -24,6 +24,9 @@ public final class NullOnNextParameterException extends ProtocolNonConformanceEx private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without a message or cause. + */ public NullOnNextParameterException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnSubscribeParameterException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnSubscribeParameterException.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnSubscribeParameterException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnSubscribeParameterException.java index 973f7c4e..4af8176f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnSubscribeParameterException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnSubscribeParameterException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Indicates the {@code onSubscribe} was called with a {@code null} {@code Disposable} or {@code Subscription}. @@ -24,6 +24,9 @@ public final class NullOnSubscribeParameterException extends ProtocolNonConforma private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public NullOnSubscribeParameterException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnSuccessParameterException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnSuccessParameterException.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnSuccessParameterException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnSuccessParameterException.java index 21ffbbf1..fba03e81 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/NullOnSuccessParameterException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/NullOnSuccessParameterException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Indicates the {@code onSuccess} was called with a {@code null} value. @@ -24,6 +24,9 @@ public final class NullOnSuccessParameterException extends ProtocolNonConformanc private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public NullOnSuccessParameterException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ObservableValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ObservableValidator.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/ObservableValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/ObservableValidator.java index b8c4e1c5..0ba1e090 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ObservableValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ObservableValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Validates an Observable. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/OnNextAfterTerminationException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/OnNextAfterTerminationException.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/OnNextAfterTerminationException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/OnNextAfterTerminationException.java index b4744f44..6a4e83aa 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/OnNextAfterTerminationException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/OnNextAfterTerminationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * The {@code onNext} was invoked after an {@code onError} or {@code onComplete} call. @@ -24,6 +24,9 @@ public final class OnNextAfterTerminationException extends ProtocolNonConformanc private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public OnNextAfterTerminationException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/OnSubscribeNotCalledException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/OnSubscribeNotCalledException.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/OnSubscribeNotCalledException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/OnSubscribeNotCalledException.java index 514ef404..0a15577d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/OnSubscribeNotCalledException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/OnSubscribeNotCalledException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * The {@code onSubscribe} was not called before calling {@code onNext}, @@ -24,10 +24,17 @@ public final class OnSubscribeNotCalledException extends ProtocolNonConformanceE private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public OnSubscribeNotCalledException() { super(); } + /** + * Constructs the exception with a cause. + * @param cause the cause + */ public OnSubscribeNotCalledException(Throwable cause) { super(cause); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/OnSuccessAfterTerminationException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/OnSuccessAfterTerminationException.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/OnSuccessAfterTerminationException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/OnSuccessAfterTerminationException.java index c86f346c..01614fec 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/OnSuccessAfterTerminationException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/OnSuccessAfterTerminationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * The {@code onSuccess} was invoked after an {@code onError} or {@code onComplete} call. @@ -24,6 +24,9 @@ public final class OnSuccessAfterTerminationException extends ProtocolNonConform private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs the exception without message or cause. + */ public OnSuccessAfterTerminationException() { super(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ParallelFlowableValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ParallelFlowableValidator.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/ParallelFlowableValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/ParallelFlowableValidator.java index cc85d256..53cc2d99 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ParallelFlowableValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ParallelFlowableValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.parallel.ParallelFlowable; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.parallel.ParallelFlowable; /** * Validates a ParallelFlowable. @@ -44,7 +44,7 @@ public void subscribe(Subscriber[] s) { @SuppressWarnings("unchecked") Subscriber[] actual = new Subscriber[n]; for (int i = 0; i < n; i++) { - actual[i] = new FlowableValidator.ValidatorConsumer(s[i], onViolation); + actual[i] = new FlowableValidator.ValidatorConsumer<>(s[i], onViolation); } source.subscribe(actual); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ProtocolNonConformanceException.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ProtocolNonConformanceException.java similarity index 67% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/ProtocolNonConformanceException.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/ProtocolNonConformanceException.java index dca9ecf6..e0dcf638 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/ProtocolNonConformanceException.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/ProtocolNonConformanceException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; /** * Base exception type indicating a failure in conforming the Reactive-Streams @@ -24,18 +24,34 @@ public abstract class ProtocolNonConformanceException extends IllegalStateExcept private static final long serialVersionUID = -6096755460680899745L; + /** + * Constructs an empty instance. + */ public ProtocolNonConformanceException() { super(); } + /** + * Constructs an instance with a message and cause. + * @param message the message + * @param cause the cause + */ public ProtocolNonConformanceException(String message, Throwable cause) { super(message, cause); } - public ProtocolNonConformanceException(String s) { - super(s); + /** + * Constructs an instance with a message. + * @param message the message + */ + public ProtocolNonConformanceException(String message) { + super(message); } + /** + * Constructs an instance with a cause. + * @param cause the cause + */ public ProtocolNonConformanceException(Throwable cause) { super(cause); } diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/RxJavaProtocolValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/RxJavaProtocolValidator.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/RxJavaProtocolValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/RxJavaProtocolValidator.java index d07bd290..56c5a6b9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/RxJavaProtocolValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/RxJavaProtocolValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import hu.akarnokd.rxjava2.debug.SavedHooks; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.*; -import io.reactivex.annotations.Nullable; -import io.reactivex.flowables.ConnectableFlowable; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.Functions; -import io.reactivex.observables.ConnectableObservable; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.debug.SavedHooks; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.annotations.Nullable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.parallel.ParallelFlowable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Installs assembly hooks that validate the Reactive-Streams and derived @@ -92,7 +90,7 @@ static SavedHooks enable(boolean chain) { RxJavaPlugins.setOnCompletableAssembly(new Function() { @Override - public Completable apply(Completable c) throws Exception { + public Completable apply(Completable c) throws Throwable { return oldC.apply(new CompletableValidator(c, handler)); } }); @@ -109,7 +107,7 @@ public Completable apply(Completable c) throws Exception { RxJavaPlugins.setOnMaybeAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public Maybe apply(Maybe c) throws Exception { + public Maybe apply(Maybe c) throws Throwable { return oldM.apply(new MaybeValidator(c, handler)); } }); @@ -126,7 +124,7 @@ public Maybe apply(Maybe c) throws Exception { RxJavaPlugins.setOnSingleAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public Single apply(Single c) throws Exception { + public Single apply(Single c) throws Throwable { return oldS.apply(new SingleValidator(c, handler)); } }); @@ -143,7 +141,7 @@ public Single apply(Single c) throws Exception { RxJavaPlugins.setOnObservableAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public Observable apply(Observable c) throws Exception { + public Observable apply(Observable c) throws Throwable { return oldO.apply(new ObservableValidator(c, handler)); } }); @@ -160,7 +158,7 @@ public Observable apply(Observable c) throws Exception { RxJavaPlugins.setOnFlowableAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public Flowable apply(Flowable c) throws Exception { + public Flowable apply(Flowable c) throws Throwable { return oldF.apply(new FlowableValidator(c, handler)); } }); @@ -177,7 +175,7 @@ public Flowable apply(Flowable c) throws Exception { RxJavaPlugins.setOnConnectableFlowableAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public ConnectableFlowable apply(ConnectableFlowable c) throws Exception { + public ConnectableFlowable apply(ConnectableFlowable c) throws Throwable { return oldCF.apply(new ConnectableFlowableValidator(c, handler)); } }); @@ -194,7 +192,7 @@ public ConnectableFlowable apply(ConnectableFlowable c) throws Exception { RxJavaPlugins.setOnConnectableObservableAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public ConnectableObservable apply(ConnectableObservable c) throws Exception { + public ConnectableObservable apply(ConnectableObservable c) throws Throwable { return oldCO.apply(new ConnectableObservableValidator(c, handler)); } }); @@ -211,7 +209,7 @@ public ConnectableObservable apply(ConnectableObservable c) throws Exception { RxJavaPlugins.setOnParallelAssembly(new Function() { @SuppressWarnings("unchecked") @Override - public ParallelFlowable apply(ParallelFlowable c) throws Exception { + public ParallelFlowable apply(ParallelFlowable c) throws Throwable { return oldPF.apply(new ParallelFlowableValidator(c, handler)); } }); diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/SingleValidator.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/SingleValidator.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/SingleValidator.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/SingleValidator.java index f206145c..27767e72 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/SingleValidator.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/SingleValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; /** * Validates a Single. diff --git a/src/main/java/hu/akarnokd/rxjava2/debug/validator/package-info.java b/src/main/java/hu/akarnokd/rxjava4/debug/validator/package-info.java similarity index 72% rename from src/main/java/hu/akarnokd/rxjava2/debug/validator/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/debug/validator/package-info.java index 6721432e..8a31bb60 100644 --- a/src/main/java/hu/akarnokd/rxjava2/debug/validator/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/debug/validator/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ /** - * Protocol validation support via {@link io.reactivex.plugins.RxJavaPlugins RxJavaPlugins} + * Protocol validation support via {@link io.reactivex.rxjava4.plugins.RxJavaPlugins RxJavaPlugins} * hook implementations enalbed via - * {@link hu.akarnokd.rxjava2.debug.validator.RxJavaProtocolValidator RxJavaProtocolValidator}. + * {@link hu.akarnokd.rxjava4.debug.validator.RxJavaProtocolValidator RxJavaProtocolValidator}. */ -package hu.akarnokd.rxjava2.debug.validator; \ No newline at end of file +package hu.akarnokd.rxjava4.debug.validator; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/CompletableIfThen.java b/src/main/java/hu/akarnokd/rxjava4/expr/CompletableIfThen.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/expr/CompletableIfThen.java rename to src/main/java/hu/akarnokd/rxjava4/expr/CompletableIfThen.java index f4d20233..d8dad281 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/CompletableIfThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/CompletableIfThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Completable; -import io.reactivex.CompletableObserver; -import io.reactivex.CompletableSource; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.disposables.EmptyDisposable; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * When an Observer subscribes, the condition is evaluated and the appropriate diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/CompletableSwitchCase.java b/src/main/java/hu/akarnokd/rxjava4/expr/CompletableSwitchCase.java similarity index 78% rename from src/main/java/hu/akarnokd/rxjava2/expr/CompletableSwitchCase.java rename to src/main/java/hu/akarnokd/rxjava4/expr/CompletableSwitchCase.java index c479c92d..08f6ef66 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/CompletableSwitchCase.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/CompletableSwitchCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; - -import io.reactivex.Completable; -import io.reactivex.CompletableObserver; -import io.reactivex.CompletableSource; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.disposables.EmptyDisposable; +package hu.akarnokd.rxjava4.expr; import java.util.Map; -import java.util.concurrent.Callable; + +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * For each Observer, it calls a keySelector for a key to lookup in the given Map for a CompletableSource @@ -33,13 +31,13 @@ */ final class CompletableSwitchCase extends Completable { - final Callable caseSelector; + final Supplier caseSelector; final Map mapOfCases; final CompletableSource defaultCase; - CompletableSwitchCase(Callable caseSelector, + CompletableSwitchCase(Supplier caseSelector, Map mapOfCases, CompletableSource defaultCase) { this.caseSelector = caseSelector; @@ -53,7 +51,7 @@ protected void subscribeActual(CompletableObserver observer) { CompletableSource source; try { - key = caseSelector.call(); + key = caseSelector.get(); source = mapOfCases.get(key); } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/FlowableIfThen.java b/src/main/java/hu/akarnokd/rxjava4/expr/FlowableIfThen.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/expr/FlowableIfThen.java rename to src/main/java/hu/akarnokd/rxjava4/expr/FlowableIfThen.java index 99c6a87d..e5c1dd50 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/FlowableIfThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/FlowableIfThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * When an Subscriber subscribes, the condition is evaluated and the appropriate diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/FlowableSwitchCase.java b/src/main/java/hu/akarnokd/rxjava4/expr/FlowableSwitchCase.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/expr/FlowableSwitchCase.java rename to src/main/java/hu/akarnokd/rxjava4/expr/FlowableSwitchCase.java index e76e5a76..a148e0af 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/FlowableSwitchCase.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/FlowableSwitchCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; import java.util.Map; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * For each Subscriber, it calls a keySelector for a key to lookup in the given Map for an Publisher @@ -34,13 +33,13 @@ */ final class FlowableSwitchCase extends Flowable { - final Callable caseSelector; + final Supplier caseSelector; final Map> mapOfCases; final Publisher defaultCase; - FlowableSwitchCase(Callable caseSelector, + FlowableSwitchCase(Supplier caseSelector, Map> mapOfCases, Publisher defaultCase) { this.caseSelector = caseSelector; @@ -54,7 +53,7 @@ protected void subscribeActual(Subscriber s) { Publisher source; try { - key = caseSelector.call(); + key = caseSelector.get(); source = mapOfCases.get(key); } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/FlowableWhileDoWhile.java b/src/main/java/hu/akarnokd/rxjava4/expr/FlowableWhileDoWhile.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/expr/FlowableWhileDoWhile.java rename to src/main/java/hu/akarnokd/rxjava4/expr/FlowableWhileDoWhile.java index e1e573b3..c6cd5d78 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/FlowableWhileDoWhile.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/FlowableWhileDoWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicInteger; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.subscriptions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; final class FlowableWhileDoWhile extends Flowable { @@ -53,7 +52,7 @@ protected void subscribeActual(Subscriber s) { } if (b) { - WhileDoWhileObserver parent = new WhileDoWhileObserver(s, postCondition, source); + WhileDoWhileObserver parent = new WhileDoWhileObserver<>(s, postCondition, source); s.onSubscribe(parent); parent.subscribeNext(); } else { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/MaybeIfThen.java b/src/main/java/hu/akarnokd/rxjava4/expr/MaybeIfThen.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/expr/MaybeIfThen.java rename to src/main/java/hu/akarnokd/rxjava4/expr/MaybeIfThen.java index 8ff9f596..a933f0b2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/MaybeIfThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/MaybeIfThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Maybe; -import io.reactivex.MaybeObserver; -import io.reactivex.MaybeSource; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.disposables.EmptyDisposable; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * When an Observer subscribes, the condition is evaluated and the appropriate diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/MaybeSwitchCase.java b/src/main/java/hu/akarnokd/rxjava4/expr/MaybeSwitchCase.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/expr/MaybeSwitchCase.java rename to src/main/java/hu/akarnokd/rxjava4/expr/MaybeSwitchCase.java index 3d8fa903..1d15cde4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/MaybeSwitchCase.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/MaybeSwitchCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; - -import io.reactivex.Maybe; -import io.reactivex.MaybeObserver; -import io.reactivex.MaybeSource; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.disposables.EmptyDisposable; +package hu.akarnokd.rxjava4.expr; import java.util.Map; -import java.util.concurrent.Callable; + +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * For each Observer, it calls a keySelector for a key to lookup in the given Map for a MaybeSource @@ -34,13 +32,13 @@ */ final class MaybeSwitchCase extends Maybe { - final Callable caseSelector; + final Supplier caseSelector; final Map> mapOfCases; final MaybeSource defaultCase; - MaybeSwitchCase(Callable caseSelector, + MaybeSwitchCase(Supplier caseSelector, Map> mapOfCases, MaybeSource defaultCase) { this.caseSelector = caseSelector; @@ -54,7 +52,7 @@ protected void subscribeActual(MaybeObserver observer) { MaybeSource source; try { - key = caseSelector.call(); + key = caseSelector.get(); source = mapOfCases.get(key); } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/ObservableIfThen.java b/src/main/java/hu/akarnokd/rxjava4/expr/ObservableIfThen.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/expr/ObservableIfThen.java rename to src/main/java/hu/akarnokd/rxjava4/expr/ObservableIfThen.java index 969c0645..0895d5ba 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/ObservableIfThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/ObservableIfThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.disposables.EmptyDisposable; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * When an Observer subscribes, the condition is evaluated and the appropriate diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/ObservableSwitchCase.java b/src/main/java/hu/akarnokd/rxjava4/expr/ObservableSwitchCase.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/expr/ObservableSwitchCase.java rename to src/main/java/hu/akarnokd/rxjava4/expr/ObservableSwitchCase.java index cbccc5d6..634b5db8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/ObservableSwitchCase.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/ObservableSwitchCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; import java.util.Map; -import java.util.concurrent.Callable; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.disposables.EmptyDisposable; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * For each Observer, it calls a keySelector for a key to lookup in the given Map for an ObservableSource @@ -32,13 +32,13 @@ */ final class ObservableSwitchCase extends Observable { - final Callable caseSelector; + final Supplier caseSelector; final Map> mapOfCases; final ObservableSource defaultCase; - ObservableSwitchCase(Callable caseSelector, + ObservableSwitchCase(Supplier caseSelector, Map> mapOfCases, ObservableSource defaultCase) { this.caseSelector = caseSelector; @@ -52,7 +52,7 @@ protected void subscribeActual(Observer observer) { ObservableSource source; try { - key = caseSelector.call(); + key = caseSelector.get(); source = mapOfCases.get(key); } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/ObservableWhileDoWhile.java b/src/main/java/hu/akarnokd/rxjava4/expr/ObservableWhileDoWhile.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/expr/ObservableWhileDoWhile.java rename to src/main/java/hu/akarnokd/rxjava4/expr/ObservableWhileDoWhile.java index eeeafe75..f878081f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/ObservableWhileDoWhile.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/ObservableWhileDoWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.disposables.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; final class ObservableWhileDoWhile extends Observable { @@ -52,7 +52,7 @@ protected void subscribeActual(Observer observer) { } if (b) { - WhileDoWhileObserver parent = new WhileDoWhileObserver(observer, postCondition, source); + WhileDoWhileObserver parent = new WhileDoWhileObserver<>(observer, postCondition, source); observer.onSubscribe(parent); parent.subscribeNext(); } else { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/SingleIfThen.java b/src/main/java/hu/akarnokd/rxjava4/expr/SingleIfThen.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/expr/SingleIfThen.java rename to src/main/java/hu/akarnokd/rxjava4/expr/SingleIfThen.java index 6053521c..78e0b132 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/SingleIfThen.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/SingleIfThen.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Single; -import io.reactivex.SingleObserver; -import io.reactivex.SingleSource; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.disposables.EmptyDisposable; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * When an Observer subscribes, the condition is evaluated and the appropriate diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/SingleSwitchCase.java b/src/main/java/hu/akarnokd/rxjava4/expr/SingleSwitchCase.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/expr/SingleSwitchCase.java rename to src/main/java/hu/akarnokd/rxjava4/expr/SingleSwitchCase.java index c2d4e693..66b73abe 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/SingleSwitchCase.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/SingleSwitchCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; - -import io.reactivex.Single; -import io.reactivex.SingleObserver; -import io.reactivex.SingleSource; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.disposables.EmptyDisposable; +package hu.akarnokd.rxjava4.expr; import java.util.Map; -import java.util.concurrent.Callable; + +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; /** * For each Observer, it calls a keySelector for a key to lookup in the given Map for a SingleSource @@ -34,13 +32,13 @@ */ final class SingleSwitchCase extends Single { - final Callable caseSelector; + final Supplier caseSelector; final Map> mapOfCases; final SingleSource defaultCase; - SingleSwitchCase(Callable caseSelector, + SingleSwitchCase(Supplier caseSelector, Map> mapOfCases, SingleSource defaultCase) { this.caseSelector = caseSelector; @@ -54,7 +52,7 @@ protected void subscribeActual(SingleObserver observer) { SingleSource source; try { - key = caseSelector.call(); + key = caseSelector.get(); source = mapOfCases.get(key); } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/StatementCompletable.java b/src/main/java/hu/akarnokd/rxjava4/expr/StatementCompletable.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/expr/StatementCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/expr/StatementCompletable.java index 2b6873a7..125b5abf 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/StatementCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/StatementCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,22 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Completable; -import io.reactivex.CompletableSource; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import java.util.*; -import java.util.Map; -import java.util.concurrent.Callable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Imperative statements expressed as Completable operators. */ public final class StatementCompletable { + /** Factory class. */ + private StatementCompletable() { throw new IllegalStateException("No instances!"); } + /** * Return a particular one of several possible Completables based on a case * selector, or a default Completable if the case selector does not map to @@ -39,8 +39,6 @@ public final class StatementCompletable { * * @param * the case key type - * @param - * the result value type * @param caseSelector * the function that produces a case key when an * CompletableObserver subscribes @@ -51,12 +49,12 @@ public final class StatementCompletable { * @return a particular Completable chosen by key from the map of * Completables, or the default case if no Completable matches the key */ - public static Completable switchCase(Callable caseSelector, + public static Completable switchCase(Supplier caseSelector, Map mapOfCases, CompletableSource defaultCase) { - ObjectHelper.requireNonNull(caseSelector, "caseSelector is null"); - ObjectHelper.requireNonNull(mapOfCases, "mapOfCases is null"); - ObjectHelper.requireNonNull(defaultCase, "defaultCase is null"); + Objects.requireNonNull(caseSelector, "caseSelector is null"); + Objects.requireNonNull(mapOfCases, "mapOfCases is null"); + Objects.requireNonNull(defaultCase, "defaultCase is null"); return RxJavaPlugins.onAssembly(new CompletableSwitchCase(caseSelector, mapOfCases, defaultCase)); } @@ -67,8 +65,6 @@ public static Completable switchCase(Callable caseSelector, *

* * - * @param - * the result value type * @param condition * the condition that decides which Completable to emit the * emissions from @@ -80,9 +76,9 @@ public static Completable switchCase(Callable caseSelector, */ public static Completable ifThen(BooleanSupplier condition, CompletableSource then, Completable orElse) { - ObjectHelper.requireNonNull(condition, "condition is null"); - ObjectHelper.requireNonNull(then, "then is null"); - ObjectHelper.requireNonNull(orElse, "orElse is null"); + Objects.requireNonNull(condition, "condition is null"); + Objects.requireNonNull(then, "then is null"); + Objects.requireNonNull(orElse, "orElse is null"); return RxJavaPlugins.onAssembly(new CompletableIfThen(condition, then, orElse)); } } \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/StatementFlowable.java b/src/main/java/hu/akarnokd/rxjava4/expr/StatementFlowable.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/expr/StatementFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/expr/StatementFlowable.java index 9927a185..9d68293d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/StatementFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/StatementFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import java.util.Map; -import java.util.concurrent.Callable; +import java.util.*; +import java.util.concurrent.Flow.Publisher; -import org.reactivestreams.Publisher; - -import hu.akarnokd.rxjava2.util.AlwaysTrueBooleanSupplier; -import io.reactivex.*; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.util.AlwaysTrueBooleanSupplier; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Imperative statements expressed as Flowable operators. @@ -53,7 +50,7 @@ public final class StatementFlowable { * Observables, or an empty Flowable if no Flowable matches the * key */ - public static Flowable switchCase(Callable caseSelector, + public static Flowable switchCase(Supplier caseSelector, Map> mapOfCases) { return switchCase(caseSelector, mapOfCases, Flowable. empty()); } @@ -79,7 +76,7 @@ public static Flowable switchCase(Callable caseSelector, * Observables, or an empty Flowable if no Flowable matches the * key, but one that runs on the designated scheduler in either case */ - public static Flowable switchCase(Callable caseSelector, + public static Flowable switchCase(Supplier caseSelector, Map> mapOfCases, Scheduler scheduler) { return switchCase(caseSelector, mapOfCases, Flowable. empty().subscribeOn(scheduler)); } @@ -105,12 +102,12 @@ public static Flowable switchCase(Callable caseSelector, * @return a particular Flowable chosen by key from the map of * Observables, or the default case if no Flowable matches the key */ - public static Flowable switchCase(Callable caseSelector, + public static Flowable switchCase(Supplier caseSelector, Map> mapOfCases, Publisher defaultCase) { - ObjectHelper.requireNonNull(caseSelector, "caseSelector is null"); - ObjectHelper.requireNonNull(mapOfCases, "mapOfCases is null"); - ObjectHelper.requireNonNull(defaultCase, "defaultCase is null"); + Objects.requireNonNull(caseSelector, "caseSelector is null"); + Objects.requireNonNull(mapOfCases, "mapOfCases is null"); + Objects.requireNonNull(defaultCase, "defaultCase is null"); return RxJavaPlugins.onAssembly(new FlowableSwitchCase(caseSelector, mapOfCases, defaultCase)); } @@ -131,8 +128,8 @@ public static Flowable switchCase(Callable caseSelector, * condition is true */ public static Flowable doWhile(Publisher source, BooleanSupplier postCondition) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(postCondition, "postCondition is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(postCondition, "postCondition is null"); return RxJavaPlugins.onAssembly(new FlowableWhileDoWhile(source, AlwaysTrueBooleanSupplier.INSTANCE, postCondition)); } @@ -151,8 +148,8 @@ public static Flowable doWhile(Publisher source, BooleanSupp * Flowable so long as preCondition is true */ public static Flowable whileDo(Publisher source, BooleanSupplier preCondition) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(preCondition, "preCondition is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(preCondition, "preCondition is null"); return RxJavaPlugins.onAssembly(new FlowableWhileDoWhile(source, preCondition, preCondition)); } @@ -220,9 +217,9 @@ public static Flowable ifThen(BooleanSupplier condition, Publisher Flowable ifThen(BooleanSupplier condition, Publisher then, Flowable orElse) { - ObjectHelper.requireNonNull(condition, "condition is null"); - ObjectHelper.requireNonNull(then, "then is null"); - ObjectHelper.requireNonNull(orElse, "orElse is null"); - return RxJavaPlugins.onAssembly(new FlowableIfThen(condition, then, orElse)); + Objects.requireNonNull(condition, "condition is null"); + Objects.requireNonNull(then, "then is null"); + Objects.requireNonNull(orElse, "orElse is null"); + return RxJavaPlugins.onAssembly(new FlowableIfThen<>(condition, then, orElse)); } } \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/StatementMaybe.java b/src/main/java/hu/akarnokd/rxjava4/expr/StatementMaybe.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/expr/StatementMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/expr/StatementMaybe.java index c7f9c733..b8f6686c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/StatementMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/StatementMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Maybe; -import io.reactivex.MaybeSource; -import io.reactivex.Scheduler; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import java.util.*; -import java.util.Map; -import java.util.concurrent.Callable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Imperative statements expressed as Maybe operators. @@ -52,7 +48,7 @@ public final class StatementMaybe { * Maybes, or an empty Maybe if no Maybe matches the * key */ - public static Maybe switchCase(Callable caseSelector, + public static Maybe switchCase(Supplier caseSelector, Map> mapOfCases) { return switchCase(caseSelector, mapOfCases, Maybe. empty()); } @@ -78,7 +74,7 @@ public static Maybe switchCase(Callable caseSelector, * Maybes, or an empty Maybe if no Maybe matches the * key, but one that runs on the designated scheduler in either case */ - public static Maybe switchCase(Callable caseSelector, + public static Maybe switchCase(Supplier caseSelector, Map> mapOfCases, Scheduler scheduler) { return switchCase(caseSelector, mapOfCases, Maybe. empty().subscribeOn(scheduler)); } @@ -104,12 +100,12 @@ public static Maybe switchCase(Callable caseSelector, * @return a particular Maybe chosen by key from the map of * Maybes, or the default case if no Maybe matches the key */ - public static Maybe switchCase(Callable caseSelector, + public static Maybe switchCase(Supplier caseSelector, Map> mapOfCases, MaybeSource defaultCase) { - ObjectHelper.requireNonNull(caseSelector, "caseSelector is null"); - ObjectHelper.requireNonNull(mapOfCases, "mapOfCases is null"); - ObjectHelper.requireNonNull(defaultCase, "defaultCase is null"); + Objects.requireNonNull(caseSelector, "caseSelector is null"); + Objects.requireNonNull(mapOfCases, "mapOfCases is null"); + Objects.requireNonNull(defaultCase, "defaultCase is null"); return RxJavaPlugins.onAssembly(new MaybeSwitchCase(caseSelector, mapOfCases, defaultCase)); } @@ -177,9 +173,9 @@ public static Maybe ifThen(BooleanSupplier condition, MaybeSource Maybe ifThen(BooleanSupplier condition, MaybeSource then, Maybe orElse) { - ObjectHelper.requireNonNull(condition, "condition is null"); - ObjectHelper.requireNonNull(then, "then is null"); - ObjectHelper.requireNonNull(orElse, "orElse is null"); - return RxJavaPlugins.onAssembly(new MaybeIfThen(condition, then, orElse)); + Objects.requireNonNull(condition, "condition is null"); + Objects.requireNonNull(then, "then is null"); + Objects.requireNonNull(orElse, "orElse is null"); + return RxJavaPlugins.onAssembly(new MaybeIfThen<>(condition, then, orElse)); } } \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/StatementObservable.java b/src/main/java/hu/akarnokd/rxjava4/expr/StatementObservable.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/expr/StatementObservable.java rename to src/main/java/hu/akarnokd/rxjava4/expr/StatementObservable.java index 6482a4fe..82a2e2e7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/StatementObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/StatementObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import java.util.Map; -import java.util.concurrent.Callable; +import java.util.*; -import hu.akarnokd.rxjava2.util.AlwaysTrueBooleanSupplier; -import io.reactivex.*; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.functions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.util.AlwaysTrueBooleanSupplier; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Imperative statements expressed as Observable operators. @@ -51,7 +50,7 @@ public final class StatementObservable { * Observables, or an empty Observable if no Observable matches the * key */ - public static Observable switchCase(Callable caseSelector, + public static Observable switchCase(Supplier caseSelector, Map> mapOfCases) { return switchCase(caseSelector, mapOfCases, Observable. empty()); } @@ -77,7 +76,7 @@ public static Observable switchCase(Callable caseSelector * Observables, or an empty Observable if no Observable matches the * key, but one that runs on the designated scheduler in either case */ - public static Observable switchCase(Callable caseSelector, + public static Observable switchCase(Supplier caseSelector, Map> mapOfCases, Scheduler scheduler) { return switchCase(caseSelector, mapOfCases, Observable. empty().subscribeOn(scheduler)); } @@ -103,12 +102,12 @@ public static Observable switchCase(Callable caseSelector * @return a particular Observable chosen by key from the map of * Observables, or the default case if no Observable matches the key */ - public static Observable switchCase(Callable caseSelector, + public static Observable switchCase(Supplier caseSelector, Map> mapOfCases, ObservableSource defaultCase) { - ObjectHelper.requireNonNull(caseSelector, "caseSelector is null"); - ObjectHelper.requireNonNull(mapOfCases, "mapOfCases is null"); - ObjectHelper.requireNonNull(defaultCase, "defaultCase is null"); + Objects.requireNonNull(caseSelector, "caseSelector is null"); + Objects.requireNonNull(mapOfCases, "mapOfCases is null"); + Objects.requireNonNull(defaultCase, "defaultCase is null"); return RxJavaPlugins.onAssembly(new ObservableSwitchCase(caseSelector, mapOfCases, defaultCase)); } @@ -129,8 +128,8 @@ public static Observable switchCase(Callable caseSelector * condition is true */ public static Observable doWhile(ObservableSource source, BooleanSupplier postCondition) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(postCondition, "postCondition is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(postCondition, "postCondition is null"); return RxJavaPlugins.onAssembly(new ObservableWhileDoWhile(source, AlwaysTrueBooleanSupplier.INSTANCE, postCondition)); } @@ -149,8 +148,8 @@ public static Observable doWhile(ObservableSource source, Bo * Observable so long as preCondition is true */ public static Observable whileDo(ObservableSource source, BooleanSupplier preCondition) { - ObjectHelper.requireNonNull(source, "source is null"); - ObjectHelper.requireNonNull(preCondition, "preCondition is null"); + Objects.requireNonNull(source, "source is null"); + Objects.requireNonNull(preCondition, "preCondition is null"); return RxJavaPlugins.onAssembly(new ObservableWhileDoWhile(source, preCondition, preCondition)); } @@ -218,9 +217,9 @@ public static Observable ifThen(BooleanSupplier condition, ObservableSour */ public static Observable ifThen(BooleanSupplier condition, ObservableSource then, Observable orElse) { - ObjectHelper.requireNonNull(condition, "condition is null"); - ObjectHelper.requireNonNull(then, "then is null"); - ObjectHelper.requireNonNull(orElse, "orElse is null"); - return RxJavaPlugins.onAssembly(new ObservableIfThen(condition, then, orElse)); + Objects.requireNonNull(condition, "condition is null"); + Objects.requireNonNull(then, "then is null"); + Objects.requireNonNull(orElse, "orElse is null"); + return RxJavaPlugins.onAssembly(new ObservableIfThen<>(condition, then, orElse)); } } \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/StatementSingle.java b/src/main/java/hu/akarnokd/rxjava4/expr/StatementSingle.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/expr/StatementSingle.java rename to src/main/java/hu/akarnokd/rxjava4/expr/StatementSingle.java index bfa45734..39078fb8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/StatementSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/StatementSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,22 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Single; -import io.reactivex.SingleSource; -import io.reactivex.Scheduler; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import java.util.*; -import java.util.Map; -import java.util.concurrent.Callable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Imperative statements expressed as Single operators. */ public final class StatementSingle { + /** Factory class. */ + private StatementSingle() { throw new IllegalStateException("No instances!"); } + /** * Return a particular one of several possible Singles based on a case * selector, or a default Single if the case selector does not map to @@ -52,12 +51,12 @@ public final class StatementSingle { * @return a particular Single chosen by key from the map of * Singles, or the default case if no Single matches the key */ - public static Single switchCase(Callable caseSelector, + public static Single switchCase(Supplier caseSelector, Map> mapOfCases, SingleSource defaultCase) { - ObjectHelper.requireNonNull(caseSelector, "caseSelector is null"); - ObjectHelper.requireNonNull(mapOfCases, "mapOfCases is null"); - ObjectHelper.requireNonNull(defaultCase, "defaultCase is null"); + Objects.requireNonNull(caseSelector, "caseSelector is null"); + Objects.requireNonNull(mapOfCases, "mapOfCases is null"); + Objects.requireNonNull(defaultCase, "defaultCase is null"); return RxJavaPlugins.onAssembly(new SingleSwitchCase(caseSelector, mapOfCases, defaultCase)); } @@ -81,9 +80,9 @@ public static Single switchCase(Callable caseSelector, */ public static Single ifThen(BooleanSupplier condition, SingleSource then, Single orElse) { - ObjectHelper.requireNonNull(condition, "condition is null"); - ObjectHelper.requireNonNull(then, "then is null"); - ObjectHelper.requireNonNull(orElse, "orElse is null"); - return RxJavaPlugins.onAssembly(new SingleIfThen(condition, then, orElse)); + Objects.requireNonNull(condition, "condition is null"); + Objects.requireNonNull(then, "then is null"); + Objects.requireNonNull(orElse, "orElse is null"); + return RxJavaPlugins.onAssembly(new SingleIfThen<>(condition, then, orElse)); } } \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/expr/package-info.java b/src/main/java/hu/akarnokd/rxjava4/expr/package-info.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/expr/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/expr/package-info.java index 1eb34601..f92ae5f0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/expr/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/expr/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ /** * Utility methods for computational expressions and statements via - * {@link hu.akarnokd.rxjava2.expr.StatementFlowable StatementFlowable} - * and {@link hu.akarnokd.rxjava2.expr.StatementObservable StatementObservable}; + * {@link hu.akarnokd.rxjava4.expr.StatementFlowable StatementFlowable} + * and {@link hu.akarnokd.rxjava4.expr.StatementObservable StatementObservable}; * a port of the * RxJavaComputationExpression * library. */ -package hu.akarnokd.rxjava2.expr; \ No newline at end of file +package hu.akarnokd.rxjava4.expr; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer4.java b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer4.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/functions/Consumer4.java rename to src/main/java/hu/akarnokd/rxjava4/functions/Consumer4.java index a7e62886..917aee59 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer4.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; /** * Functional interface for a callback that consumes multipe values at the same @@ -33,7 +33,7 @@ public interface Consumer4 { * @param t2 the second parameter * @param t3 the third parameter * @param t4 the fourth parameter - * @throws Exception on error + * @throws Throwable on error */ - void accept(T1 t1, T2 t2, T3 t3, T4 t4) throws Exception; + void accept(T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable; } diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer5.java b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer5.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/functions/Consumer5.java rename to src/main/java/hu/akarnokd/rxjava4/functions/Consumer5.java index 143fde6b..5ec021dc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer5.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer5.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; /** * Functional interface for a callback that consumes multipe values at the same @@ -35,7 +35,7 @@ public interface Consumer5 { * @param t3 the third parameter * @param t4 the fourth parameter * @param t5 the fifth parameter - * @throws Exception on error + * @throws Throwable on error */ - void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Exception; + void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable; } diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer6.java b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer6.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/functions/Consumer6.java rename to src/main/java/hu/akarnokd/rxjava4/functions/Consumer6.java index 66989fd7..91adcb81 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer6.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer6.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; /** * Functional interface for a callback that consumes multipe values at the same @@ -37,7 +37,7 @@ public interface Consumer6 { * @param t4 the fourth parameter * @param t5 the fifth parameter * @param t6 the sixth parameter - * @throws Exception on error + * @throws Throwable on error */ - void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) throws Exception; + void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) throws Throwable; } diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer7.java b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer7.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/functions/Consumer7.java rename to src/main/java/hu/akarnokd/rxjava4/functions/Consumer7.java index 86483191..96db9506 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer7.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer7.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; /** * Functional interface for a callback that consumes multipe values at the same @@ -39,7 +39,7 @@ public interface Consumer7 { * @param t5 the fifth parameter * @param t6 the sixth parameter * @param t7 the seventh parameter - * @throws Exception on error + * @throws Throwable on error */ - void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) throws Exception; + void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) throws Throwable; } diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer8.java b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer8.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/functions/Consumer8.java rename to src/main/java/hu/akarnokd/rxjava4/functions/Consumer8.java index 3d08bd6b..4a00b341 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer8.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer8.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; /** * Functional interface for a callback that consumes multipe values at the same @@ -41,7 +41,7 @@ public interface Consumer8 { * @param t6 the sixth parameter * @param t7 the seventh parameter * @param t8 the eighth parameter - * @throws Exception on error + * @throws Throwable on error */ - void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) throws Exception; + void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) throws Throwable; } diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer9.java b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer9.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/functions/Consumer9.java rename to src/main/java/hu/akarnokd/rxjava4/functions/Consumer9.java index e38023ad..f86eacce 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Consumer9.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/Consumer9.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; /** * Functional interface for a callback that consumes multipe values at the same @@ -43,7 +43,7 @@ public interface Consumer9 { * @param t7 the seventh parameter * @param t8 the eighth parameter * @param t9 the ninth parameter - * @throws Exception on error + * @throws Throwable on error */ - void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) throws Exception; + void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) throws Throwable; } diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/FunctionTagging.java b/src/main/java/hu/akarnokd/rxjava4/functions/FunctionTagging.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/functions/FunctionTagging.java rename to src/main/java/hu/akarnokd/rxjava4/functions/FunctionTagging.java index 29a21031..180f18e2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/FunctionTagging.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/FunctionTagging.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; import java.util.*; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Wraps the regular {@code io.reactivex.functions} function types and appends @@ -69,83 +68,193 @@ public static boolean isEnabled() { return enabled; } + /** + * Applies a tag to a functional interface instance. + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static Function tagFunction(Function func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction<>(func, tag); } return func; } + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static BiFunction tagBiFunction(BiFunction func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagBiFunction(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagBiFunction<>(func, tag); } return func; } + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static Function3 tagFunction3(Function3 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction3(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction3<>(func, tag); } return func; } + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static Function4 tagFunction4(Function4 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction4(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction4<>(func, tag); } return func; } + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the input type + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static Function5 tagFunction5(Function5 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction5(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction5<>(func, tag); } return func; } + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the input type + * @param the input type + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static Function6 tagFunction6(Function6 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction6(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction6<>(func, tag); } return func; } + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the input type + * @param the input type + * @param the input type + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ public static Function7 tagFunction7(Function7 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction7(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction7<>(func, tag); } return func; } - public static Function8 tagFunction8(Function8 func, String tag) { + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the input type + * @param the input type + * @param the input type + * @param the input type + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ + public static Function8 tagFunction8( + Function8 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction8(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction8<>(func, tag); } return func; } - public static Function9 tagFunction9(Function9 func, String tag) { + /** + * Applies a tag to a functional interface instance. + * @param an input type + * @param an input type + * @param an input type + * @param the input type + * @param the input type + * @param the input type + * @param the input type + * @param the input type + * @param the input type + * @param the output type + * @param func the functional interface + * @param tag the tag + * @return the new functional interface instance + */ + public static Function9 tagFunction9( + Function9 func, String tag) { if (enabled) { - ObjectHelper.requireNonNull(func, "func is null"); - ObjectHelper.requireNonNull(tag, "tag is null"); - return new TagFunction9(func, tag); + Objects.requireNonNull(func, "func is null"); + Objects.requireNonNull(tag, "tag is null"); + return new TagFunction9<>(func, tag); } return func; } @@ -197,7 +306,7 @@ public synchronized Throwable fillInStackTrace() { */ public Throwable appendLast(Throwable ex) { Throwable r = ex; - Set memory = new HashSet(); + Set memory = new HashSet<>(); while (ex.getCause() != null) { if (memory.add(ex)) { ex = ex.getCause(); diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/FunctionsEx.java b/src/main/java/hu/akarnokd/rxjava4/functions/FunctionsEx.java similarity index 96% rename from src/main/java/hu/akarnokd/rxjava2/functions/FunctionsEx.java rename to src/main/java/hu/akarnokd/rxjava4/functions/FunctionsEx.java index 2f49029b..f5acaa0a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/FunctionsEx.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/FunctionsEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.functions.*; /** * Utility methods to work with functional interfaces of this package. diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainBiConsumer.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainBiConsumer.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainBiConsumer.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainBiConsumer.java index fd98596e..726280a6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainBiConsumer.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainBiConsumer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.BiConsumer; +import io.reactivex.rxjava4.functions.BiConsumer; /** * A {@link BiConsumer} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainBiFunction.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainBiFunction.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainBiFunction.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainBiFunction.java index 82f16668..8dea2f8f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainBiFunction.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainBiFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.functions.BiFunction; /** * A {@link BiFunction} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainConsumer.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainConsumer.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainConsumer.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainConsumer.java index 985dc05e..fbb3a362 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainConsumer.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainConsumer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Consumer; +import io.reactivex.rxjava4.functions.Consumer; /** * A {@link Consumer} with suppressed exception on its {@link #accept(Object)} method. diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction.java index c51888f2..5bce10fa 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Function; +import io.reactivex.rxjava4.functions.Function; /** * A {@link Function} with suppressed exception on its {@link #apply(Object)} method. diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction3.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction3.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction3.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction3.java index fc4c57cd..682cc858 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction3.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction3.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.functions.Function3; /** * A {@link Function3} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction4.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction4.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction4.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction4.java index 7dccd638..08ac7680 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction4.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.functions.Function4; /** * A {@link Function4} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction5.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction5.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction5.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction5.java index 503c5871..600c9332 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction5.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction5.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Function5; +import io.reactivex.rxjava4.functions.Function5; /** * A {@link Function5} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction6.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction6.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction6.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction6.java index 55dadd17..a91b2dac 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction6.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction6.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Function6; +import io.reactivex.rxjava4.functions.Function6; /** * A {@link Function6} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction7.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction7.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction7.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction7.java index 552829f6..4dc3e482 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction7.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction7.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Function7; +import io.reactivex.rxjava4.functions.Function7; /** * A {@link Function7} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction8.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction8.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction8.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction8.java index 2cd12dc2..dc95c65e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction8.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction8.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Function8; +import io.reactivex.rxjava4.functions.Function8; /** * A {@link Function8} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction9.java b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction9.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction9.java rename to src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction9.java index 5e0aa707..ed01a890 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/PlainFunction9.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/PlainFunction9.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import io.reactivex.functions.Function9; +import io.reactivex.rxjava4.functions.Function9; /** * A {@link Function9} with suppressed exception on its diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/Supplier.java b/src/main/java/hu/akarnokd/rxjava4/functions/SimpleCallable.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/functions/Supplier.java rename to src/main/java/hu/akarnokd/rxjava4/functions/SimpleCallable.java index b76a366d..569bbbf1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/Supplier.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/SimpleCallable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; import java.util.concurrent.Callable; @@ -22,7 +22,7 @@ * A {@link Callable} with suppressed exception on its {@link #call()} method. * @param the value type */ -public interface Supplier extends Callable { +public interface SimpleCallable extends Callable { @Override T call(); diff --git a/src/main/java/hu/akarnokd/rxjava2/functions/package-info.java b/src/main/java/hu/akarnokd/rxjava4/functions/package-info.java similarity index 69% rename from src/main/java/hu/akarnokd/rxjava2/functions/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/functions/package-info.java index 5cdfb4a0..e876b1a1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/functions/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/functions/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ /** - * Functional interface definitions for {@link io.reactivex.functions.Consumer Consumer}s with - * 3..9 arguments and {@link io.reactivex.functions.Function Function}s without the + * Functional interface definitions for {@link io.reactivex.rxjava4.functions.Consumer Consumer}s with + * 3..9 arguments and {@link io.reactivex.rxjava4.functions.Function Function}s without the * {@code throws Exception} clause in their definition. */ -package hu.akarnokd.rxjava2.functions; \ No newline at end of file +package hu.akarnokd.rxjava4.functions; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/BasicMergeSubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/operators/BasicMergeSubscription.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/operators/BasicMergeSubscription.java rename to src/main/java/hu/akarnokd/rxjava4/internal/operators/BasicMergeSubscription.java index 62efe94d..7980b36d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/BasicMergeSubscription.java +++ b/src/main/java/hu/akarnokd/rxjava4/internal/operators/BasicMergeSubscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.internal.operators; -import java.util.Arrays; -import java.util.Comparator; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; +import java.util.*; +import java.util.concurrent.Flow.*; +import java.util.concurrent.atomic.*; -import org.reactivestreams.Publisher; -import org.reactivestreams.Subscriber; -import org.reactivestreams.Subscription; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.fuseable.SimpleQueue; -import io.reactivex.internal.subscribers.InnerQueuedSubscriber; -import io.reactivex.internal.subscribers.InnerQueuedSubscriberSupport; -import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.AtomicThrowable; -import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.operators.SimpleQueue; +import io.reactivex.rxjava4.parallel.ParallelFlowable; /** * Subscription coordinator that merges items from a fixed set of source Publishers by @@ -71,7 +60,7 @@ public BasicMergeSubscription(Subscriber downstream, Comparator[] subs = new InnerQueuedSubscriber[n]; for (int i = 0; i < n; i++) { - subs[i] = new InnerQueuedSubscriber(this, prefetch); + subs[i] = new InnerQueuedSubscriber<>(this, prefetch); } this.subscribers = subs; this.requested = new AtomicLong(); @@ -80,22 +69,22 @@ public BasicMergeSubscription(Subscriber downstream, Comparator[] sources, int n) { - InnerQueuedSubscriber[] subs = subscribers; - for (int i = 0; i < n && !cancelled; i++) { - Publisher p = sources[i]; - if (p != null) { - p.subscribe(subs[i]); - } else { - EmptySubscription.error(new NullPointerException("The " + i + "th source is null"), subs[i]); - if (!delayErrors) { - break; - } - } - } + InnerQueuedSubscriber[] subs = subscribers; + for (int i = 0; i < n && !cancelled; i++) { + Publisher p = sources[i]; + if (p != null) { + p.subscribe(subs[i]); + } else { + EmptySubscription.error(new NullPointerException("The " + i + "th source is null"), subs[i]); + if (!delayErrors) { + break; + } + } + } } public void subscribe(ParallelFlowable source) { - source.subscribe(subscribers); + source.subscribe(subscribers); } @Override @@ -138,6 +127,7 @@ public void cancel() { if (!cancelled) { cancelled = true; cancelSources(); + errors.tryTerminateAndReport(); if (getAndIncrement() == 0) { clearSources(); } @@ -152,15 +142,13 @@ public void innerNext(InnerQueuedSubscriber inner, T value) { @Override public void innerError(InnerQueuedSubscriber inner, Throwable e) { - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { if (!delayErrors) { cancelSources(); } else { inner.setDone(); } drain(); - } else { - RxJavaPlugins.onError(e); } } @@ -223,11 +211,11 @@ public void drain() { v = q != null ? q.poll() : null; } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - err.addThrowable(ex); + err.tryAddThrowableOrReport(ex); inner.setDone(); if (!delayErrors) { cancelAndClearSources(); - a.onError(err.terminate()); + err.tryTerminateConsumer(a); return; } v = this; @@ -259,7 +247,7 @@ public void drain() { } } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - err.addThrowable(ex); + err.tryAddThrowableOrReport(ex); cancelAndClearSources(); a.onError(err.terminate()); return; @@ -274,7 +262,7 @@ public void drain() { if (hasValue == n && pick >= 0) { a.onNext(smallest); latest[pick] = null; - subs[pick].requestOne(); + subs[pick].request(1); e++; } else { @@ -318,10 +306,10 @@ public void drain() { o = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - err.addThrowable(ex); + err.tryAddThrowableOrReport(ex); if (!delayErrors) { cancelAndClearSources(); - a.onError(ex); + err.tryTerminateConsumer(a); return; } o = this; diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/AtomicThrowable.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/AtomicThrowable.java new file mode 100644 index 00000000..2c004316 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/AtomicThrowable.java @@ -0,0 +1,193 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicReference; + +import static java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Atomic container for {@link Throwable}s including combining and having a + * terminal state via ExceptionHelper. + *

+ * Watch out for the leaked AtomicReference methods! + */ +public final class AtomicThrowable extends AtomicReference { + + @Serial + private static final long serialVersionUID = 3949248817947090603L; + + /** + * Atomically adds a Throwable to this container (combining with a previous Throwable is necessary). + * @param t the throwable to add + * @return true if successful, false if the container has been terminated + */ + public boolean tryAddThrowable(Throwable t) { + return ExceptionHelper.addThrowable(this, t); + } + + /** + * Atomically adds a Throwable to this container (combining with a previous Throwable is necessary) + * or reports the error the global error handler and no changes are made. + * @param t the throwable to add + * @return true if successful, false if the container has been terminated + */ + public boolean tryAddThrowableOrReport(Throwable t) { + if (tryAddThrowable(t)) { + return true; + } + RxJavaPlugins.onError(t); + return false; + } + + /** + * Atomically terminate the container and return the contents of the last + * non-terminal Throwable of it. + * @return the last Throwable + */ + public Throwable terminate() { + return ExceptionHelper.terminate(this); + } + + public boolean isTerminated() { + return get() == ExceptionHelper.TERMINATED; + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and calls {@link RxJavaPlugins#onError(Throwable)} if there was a non-null, non-indicator + * exception contained within before. + * @since 3.0.0 + */ + public void tryTerminateAndReport() { + Throwable ex = terminate(); + if (ex != null && ex != ExceptionHelper.TERMINATED) { + RxJavaPlugins.onError(ex); + } + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and notifies the consumer if there was no error (onComplete) or there was a + * non-null, non-indicator exception contained before (onError). + * If there was a terminated indicator, the consumer is not signaled. + * @param consumer the consumer to notify + */ + public void tryTerminateConsumer(Subscriber consumer) { + Throwable ex = terminate(); + if (ex == null) { + consumer.onComplete(); + } else if (ex != ExceptionHelper.TERMINATED) { + consumer.onError(ex); + } + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and notifies the consumer if there was no error (onComplete) or there was a + * non-null, non-indicator exception contained before (onError). + * If there was a terminated indicator, the consumer is not signaled. + * @param consumer the consumer to notify + */ + public void tryTerminateConsumer(Observer consumer) { + Throwable ex = terminate(); + if (ex == null) { + consumer.onComplete(); + } else if (ex != ExceptionHelper.TERMINATED) { + consumer.onError(ex); + } + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and notifies the consumer if there was no error (onComplete) or there was a + * non-null, non-indicator exception contained before (onError). + * If there was a terminated indicator, the consumer is not signaled. + * @param consumer the consumer to notify + */ + public void tryTerminateConsumer(MaybeObserver consumer) { + Throwable ex = terminate(); + if (ex == null) { + consumer.onComplete(); + } else if (ex != ExceptionHelper.TERMINATED) { + consumer.onError(ex); + } + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and notifies the consumer if there was a + * non-null, non-indicator exception contained before (onError). + * If there was a terminated indicator, the consumer is not signaled. + * @param consumer the consumer to notify + */ + public void tryTerminateConsumer(SingleObserver consumer) { + Throwable ex = terminate(); + if (ex != null && ex != ExceptionHelper.TERMINATED) { + consumer.onError(ex); + } + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and notifies the consumer if there was no error (onComplete) or there was a + * non-null, non-indicator exception contained before (onError). + * If there was a terminated indicator, the consumer is not signaled. + * @param consumer the consumer to notify + */ + public void tryTerminateConsumer(CompletableObserver consumer) { + Throwable ex = terminate(); + if (ex == null) { + consumer.onComplete(); + } else if (ex != ExceptionHelper.TERMINATED) { + consumer.onError(ex); + } + } + + /** + * Tries to terminate this atomic throwable (by swapping in the TERMINATED indicator) + * and notifies the consumer if there was no error (onComplete) or there was a + * non-null, non-indicator exception contained before (onError). + * If there was a terminated indicator, the consumer is not signaled. + * @param consumer the consumer to notify + */ + public void tryTerminateConsumer(Emitter consumer) { + Throwable ex = terminate(); + if (ex == null) { + consumer.onComplete(); + } else if (ex != ExceptionHelper.TERMINATED) { + consumer.onError(ex); + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BackpressureHelper.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BackpressureHelper.java new file mode 100644 index 00000000..5446358a --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BackpressureHelper.java @@ -0,0 +1,169 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.concurrent.atomic.AtomicLong; + +import io.reactivex.rxjava4.annotations.NonNull; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Utility class to help with backpressure-related operations such as request aggregation. + */ +public final class BackpressureHelper { + /** Utility class. */ + private BackpressureHelper() { + throw new IllegalStateException("No instances!"); + } + + /** + * Adds two long values and caps the sum at {@link Long#MAX_VALUE}. + * @param aValue the first value + * @param bValue the second value + * @return the sum capped at {@link Long#MAX_VALUE} + */ + public static long addCap(long aValue, long bValue) { + long u = aValue + bValue; + if (u < 0L) { + return Long.MAX_VALUE; + } + return u; + } + + /** + * Multiplies two long values and caps the product at {@link Long#MAX_VALUE}. + * @param aValue the first value + * @param bValue the second value + * @return the product capped at {@link Long#MAX_VALUE} + */ + public static long multiplyCap(long aValue, long bValue) { + long u = aValue * bValue; + if (((aValue | bValue) >>> 31) != 0) { + if (u / aValue != bValue) { + return Long.MAX_VALUE; + } + } + return u; + } + + /** + * Atomically adds the positive value n to the requested value in the {@link AtomicLong} and + * caps the result at {@link Long#MAX_VALUE} and returns the previous value. + * @param requested the {@code AtomicLong} holding the current requested value + * @param n the value to add, must be positive (not verified) + * @return the original value before the add + */ + public static long add(@NonNull AtomicLong requested, long n) { + for (;;) { + long r = requested.get(); + if (r == Long.MAX_VALUE) { + return Long.MAX_VALUE; + } + long u = addCap(r, n); + if (requested.compareAndSet(r, u)) { + return r; + } + } + } + + /** + * Atomically adds the positive value n to the requested value in the {@link AtomicLong} and + * caps the result at {@link Long#MAX_VALUE} and returns the previous value and + * considers {@link Long#MIN_VALUE} as a cancel indication (no addition then). + * @param requested the {@code AtomicLong} holding the current requested value + * @param n the value to add, must be positive (not verified) + * @return the original value before the add + */ + public static long addCancel(@NonNull AtomicLong requested, long n) { + for (;;) { + long r = requested.get(); + if (r == Long.MIN_VALUE) { + return Long.MIN_VALUE; + } + if (r == Long.MAX_VALUE) { + return Long.MAX_VALUE; + } + long u = addCap(r, n); + if (requested.compareAndSet(r, u)) { + return r; + } + } + } + + /** + * Atomically subtract the given number (positive, not validated) from the target field unless it contains {@link Long#MAX_VALUE}. + * @param requested the target field holding the current requested amount + * @param n the produced element count, positive (not validated) + * @return the new amount + */ + public static long produced(@NonNull AtomicLong requested, long n) { + for (;;) { + long current = requested.get(); + if (current == Long.MAX_VALUE) { + return Long.MAX_VALUE; + } + long update = current - n; + if (update < 0L) { + RxJavaPlugins.onError(new IllegalStateException("More produced than requested: " + update)); + update = 0L; + } + if (requested.compareAndSet(current, update)) { + return update; + } + } + } + + /** + * Atomically subtract the given number (positive, not validated) from the target field if + * it doesn't contain {@link Long#MIN_VALUE} (indicating some cancelled state) or {@link Long#MAX_VALUE} (unbounded mode). + * @param requested the target field holding the current requested amount + * @param n the produced element count, positive (not validated) + * @return the new amount + */ + public static long producedCancel(@NonNull AtomicLong requested, long n) { + for (;;) { + long current = requested.get(); + if (current == Long.MIN_VALUE) { + return Long.MIN_VALUE; + } + if (current == Long.MAX_VALUE) { + return Long.MAX_VALUE; + } + long update = current - n; + if (update < 0L) { + RxJavaPlugins.onError(new IllegalStateException("More produced than requested: " + update)); + update = 0L; + } + if (requested.compareAndSet(current, update)) { + return update; + } + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableConditionalSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableConditionalSubscriber.java new file mode 100644 index 00000000..136f5930 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableConditionalSubscriber.java @@ -0,0 +1,198 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.concurrent.Flow.Subscription; + +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.operators.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Base class for a fuseable intermediate subscriber. + * @param the upstream value type + * @param the downstream value type + */ +public abstract class BasicFuseableConditionalSubscriber implements ConditionalSubscriber, QueueSubscription { + + /** The downstream subscriber. */ + protected final ConditionalSubscriber downstream; + + /** The upstream subscription. */ + protected Subscription upstream; + + /** The upstream's QueueSubscription if not null. */ + protected QueueSubscription qs; + + /** Flag indicating no further onXXX event should be accepted. */ + protected boolean done; + + /** Holds the established fusion mode of the upstream. */ + protected int sourceMode; + + /** + * Construct a BasicFuseableSubscriber by wrapping the given subscriber. + * @param downstream the subscriber, not null (not verified) + */ + public BasicFuseableConditionalSubscriber(ConditionalSubscriber downstream) { + this.downstream = downstream; + } + + // final: fixed protocol steps to support fuseable and non-fuseable upstream + @SuppressWarnings("unchecked") + @Override + public final void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(this.upstream, s)) { + + this.upstream = s; + if (s instanceof QueueSubscription) { + this.qs = (QueueSubscription)s; + } + + if (beforeDownstream()) { + + downstream.onSubscribe(this); + + afterDownstream(); + } + + } + } + + /** + * Override this to perform actions before the call {@code actual.onSubscribe(this)} happens. + * @return true if onSubscribe should continue with the call + */ + protected boolean beforeDownstream() { + return true; + } + + /** + * Override this to perform actions after the call to {@code actual.onSubscribe(this)} happened. + */ + protected void afterDownstream() { + // default no-op + } + + // ----------------------------------- + // Convenience and state-aware methods + // ----------------------------------- + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + downstream.onError(t); + } + + /** + * Rethrows the throwable if it is a fatal exception or calls {@link #onError(Throwable)}. + * @param t the throwable to rethrow or signal to the actual subscriber + */ + protected final void fail(Throwable t) { + Exceptions.throwIfFatal(t); + upstream.cancel(); + onError(t); + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + downstream.onComplete(); + } + + /** + * Calls the upstream's QueueSubscription.requestFusion with the mode and + * saves the established mode in {@link #sourceMode} if that mode doesn't + * have the {@link QueueSubscription#BOUNDARY} flag set. + *

+ * If the upstream doesn't support fusion ({@link #qs} is null), the method + * returns {@link QueueSubscription#NONE}. + * @param mode the fusion mode requested + * @return the established fusion mode + */ + protected final int transitiveBoundaryFusion(int mode) { + QueueSubscription qs = this.qs; + if (qs != null) { + if ((mode & BOUNDARY) == 0) { + int m = qs.requestFusion(mode); + if (m != NONE) { + sourceMode = m; + } + return m; + } + } + return NONE; + } + + // -------------------------------------------------------------- + // Default implementation of the RS and QS protocol (can be overridden) + // -------------------------------------------------------------- + + @Override + public void request(long n) { + upstream.request(n); + } + + @Override + public void cancel() { + upstream.cancel(); + } + + @Override + public boolean isEmpty() { + return qs.isEmpty(); + } + + @Override + public void clear() { + qs.clear(); + } + + // ----------------------------------------------------------- + // The rest of the Queue interface methods shouldn't be called + // ----------------------------------------------------------- + + @Override + public final boolean offer(R e) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public final boolean offer(R v1, R v2) { + throw new UnsupportedOperationException("Should not be called!"); + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableObserver.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableObserver.java new file mode 100644 index 00000000..afa1af1e --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableObserver.java @@ -0,0 +1,198 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.operators.QueueDisposable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Base class for a fuseable intermediate observer. + * @param the upstream value type + * @param the downstream value type + */ +public abstract class BasicFuseableObserver implements Observer, QueueDisposable { + + /** The downstream subscriber. */ + protected final Observer downstream; + + /** The upstream subscription. */ + protected Disposable upstream; + + /** The upstream's QueueDisposable if not null. */ + protected QueueDisposable qd; + + /** Flag indicating no further onXXX event should be accepted. */ + protected boolean done; + + /** Holds the established fusion mode of the upstream. */ + protected int sourceMode; + + /** + * Construct a BasicFuseableObserver by wrapping the given subscriber. + * @param downstream the subscriber, not null (not verified) + */ + public BasicFuseableObserver(Observer downstream) { + this.downstream = downstream; + } + + // final: fixed protocol steps to support fuseable and non-fuseable upstream + @SuppressWarnings("unchecked") + @Override + public final void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + + this.upstream = d; + if (d instanceof QueueDisposable) { + this.qd = (QueueDisposable)d; + } + + if (beforeDownstream()) { + + downstream.onSubscribe(this); + + afterDownstream(); + } + + } + } + + /** + * Override this to perform actions before the call {@code actual.onSubscribe(this)} happens. + * @return true if onSubscribe should continue with the call + */ + protected boolean beforeDownstream() { + return true; + } + + /** + * Override this to perform actions after the call to {@code actual.onSubscribe(this)} happened. + */ + protected void afterDownstream() { + // default no-op + } + + // ----------------------------------- + // Convenience and state-aware methods + // ----------------------------------- + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + downstream.onError(t); + } + + /** + * Rethrows the throwable if it is a fatal exception or calls {@link #onError(Throwable)}. + * @param t the throwable to rethrow or signal to the actual subscriber + */ + protected final void fail(Throwable t) { + Exceptions.throwIfFatal(t); + upstream.dispose(); + onError(t); + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + downstream.onComplete(); + } + + /** + * Calls the upstream's QueueDisposable.requestFusion with the mode and + * saves the established mode in {@link #sourceMode} if that mode doesn't + * have the {@link QueueDisposable#BOUNDARY} flag set. + *

+ * If the upstream doesn't support fusion ({@link #qd} is null), the method + * returns {@link QueueDisposable#NONE}. + * @param mode the fusion mode requested + * @return the established fusion mode + */ + protected final int transitiveBoundaryFusion(int mode) { + QueueDisposable qd = this.qd; + if (qd != null) { + if ((mode & BOUNDARY) == 0) { + int m = qd.requestFusion(mode); + if (m != NONE) { + sourceMode = m; + } + return m; + } + } + return NONE; + } + + // -------------------------------------------------------------- + // Default implementation of the RS and QS protocol (can be overridden) + // -------------------------------------------------------------- + + @Override + public void dispose() { + upstream.dispose(); + } + + @Override + public boolean isDisposed() { + return upstream.isDisposed(); + } + + @Override + public boolean isEmpty() { + return qd.isEmpty(); + } + + @Override + public void clear() { + qd.clear(); + } + + // ----------------------------------------------------------- + // The rest of the Queue interface methods shouldn't be called + // ----------------------------------------------------------- + + @Override + public final boolean offer(R e) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public final boolean offer(R v1, R v2) { + throw new UnsupportedOperationException("Should not be called!"); + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableSubscriber.java new file mode 100644 index 00000000..1b4ac20a --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicFuseableSubscriber.java @@ -0,0 +1,199 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Base class for a fuseable intermediate subscriber. + * @param the upstream value type + * @param the downstream value type + */ +public abstract class BasicFuseableSubscriber implements FlowableSubscriber, QueueSubscription { + + /** The downstream subscriber. */ + protected final Subscriber downstream; + + /** The upstream subscription. */ + protected Subscription upstream; + + /** The upstream's QueueSubscription if not null. */ + protected QueueSubscription qs; + + /** Flag indicating no further onXXX event should be accepted. */ + protected boolean done; + + /** Holds the established fusion mode of the upstream. */ + protected int sourceMode; + + /** + * Construct a BasicFuseableSubscriber by wrapping the given subscriber. + * @param downstream the subscriber, not null (not verified) + */ + public BasicFuseableSubscriber(Subscriber downstream) { + this.downstream = downstream; + } + + // final: fixed protocol steps to support fuseable and non-fuseable upstream + @SuppressWarnings("unchecked") + @Override + public final void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(this.upstream, s)) { + + this.upstream = s; + if (s instanceof QueueSubscription) { + this.qs = (QueueSubscription)s; + } + + if (beforeDownstream()) { + + downstream.onSubscribe(this); + + afterDownstream(); + } + + } + } + + /** + * Override this to perform actions before the call {@code actual.onSubscribe(this)} happens. + * @return true if onSubscribe should continue with the call + */ + protected boolean beforeDownstream() { + return true; + } + + /** + * Override this to perform actions after the call to {@code actual.onSubscribe(this)} happened. + */ + protected void afterDownstream() { + // default no-op + } + + // ----------------------------------- + // Convenience and state-aware methods + // ----------------------------------- + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + downstream.onError(t); + } + + /** + * Rethrows the throwable if it is a fatal exception or calls {@link #onError(Throwable)}. + * @param t the throwable to rethrow or signal to the actual subscriber + */ + protected final void fail(Throwable t) { + Exceptions.throwIfFatal(t); + upstream.cancel(); + onError(t); + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + downstream.onComplete(); + } + + /** + * Calls the upstream's QueueSubscription.requestFusion with the mode and + * saves the established mode in {@link #sourceMode} if that mode doesn't + * have the {@link QueueSubscription#BOUNDARY} flag set. + *

+ * If the upstream doesn't support fusion ({@link #qs} is null), the method + * returns {@link QueueSubscription#NONE}. + * @param mode the fusion mode requested + * @return the established fusion mode + */ + protected final int transitiveBoundaryFusion(int mode) { + QueueSubscription qs = this.qs; + if (qs != null) { + if ((mode & BOUNDARY) == 0) { + int m = qs.requestFusion(mode); + if (m != NONE) { + sourceMode = m; + } + return m; + } + } + return NONE; + } + + // -------------------------------------------------------------- + // Default implementation of the RS and QS protocol (can be overridden) + // -------------------------------------------------------------- + + @Override + public void request(long n) { + upstream.request(n); + } + + @Override + public void cancel() { + upstream.cancel(); + } + + @Override + public boolean isEmpty() { + return qs.isEmpty(); + } + + @Override + public void clear() { + qs.clear(); + } + + // ----------------------------------------------------------- + // The rest of the Queue interface methods shouldn't be called + // ----------------------------------------------------------- + + @Override + public final boolean offer(R e) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public final boolean offer(R v1, R v2) { + throw new UnsupportedOperationException("Should not be called!"); + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicIntQueueDisposable.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicIntQueueDisposable.java new file mode 100644 index 00000000..e9687c28 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicIntQueueDisposable.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicInteger; + +import io.reactivex.rxjava4.operators.QueueDisposable; + +/** + * An abstract QueueDisposable implementation, extending an AtomicInteger, + * that defaults all unnecessary Queue methods to throw UnsupportedOperationException. + * @param the output value type + */ +public abstract class BasicIntQueueDisposable +extends AtomicInteger +implements QueueDisposable { + + @Serial + private static final long serialVersionUID = -1001730202384742097L; + + @Override + public final boolean offer(T e) { + throw new UnsupportedOperationException("Should not be called"); + } + + @Override + public final boolean offer(T v1, T v2) { + throw new UnsupportedOperationException("Should not be called"); + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicIntQueueSubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicIntQueueSubscription.java new file mode 100644 index 00000000..367ee0ef --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicIntQueueSubscription.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicInteger; + +import io.reactivex.rxjava4.annotations.NonNull; +import io.reactivex.rxjava4.operators.QueueSubscription; + +/** + * Base class extending AtomicInteger (wip or request accounting) and QueueSubscription (fusion). + * + * @param the value type + */ +public abstract class BasicIntQueueSubscription<@NonNull T> extends AtomicInteger implements QueueSubscription { + + @Serial + private static final long serialVersionUID = -6671519529404341862L; + + @Override + public final boolean offer(T e) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public final boolean offer(T v1, T v2) { + throw new UnsupportedOperationException("Should not be called!"); + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicQueueSubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicQueueSubscription.java new file mode 100644 index 00000000..064b7971 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BasicQueueSubscription.java @@ -0,0 +1,56 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicLong; + +import io.reactivex.rxjava4.operators.QueueSubscription; + +/** + * Base class extending AtomicLong (wip or request accounting) and QueueSubscription (fusion). + * + * @param the value type + */ +public abstract class BasicQueueSubscription extends AtomicLong implements QueueSubscription { + + @Serial + private static final long serialVersionUID = -6671519529404341862L; + + @Override + public final boolean offer(T e) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public final boolean offer(T v1, T v2) { + throw new UnsupportedOperationException("Should not be called!"); + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BooleanSubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BooleanSubscription.java new file mode 100644 index 00000000..7e1bfa30 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/BooleanSubscription.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicBoolean; + +import static java.util.concurrent.Flow.*; + +/** + * Subscription implementation that ignores request but remembers the cancellation + * which can be checked via isCancelled. + */ +public final class BooleanSubscription extends AtomicBoolean implements Subscription { + + @Serial + private static final long serialVersionUID = -8127758972444290902L; + + @Override + public void request(long n) { + SubscriptionHelper.validate(n); + } + + @Override + public void cancel() { + lazySet(true); + } + + /** + * Returns true if this BooleanSubscription has been cancelled. + * @return true if this BooleanSubscription has been cancelled + */ + public boolean isCancelled() { + return get(); + } + + @Override + public String toString() { + return "BooleanSubscription(cancelled=" + get() + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/CancellableDisposable.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/CancellableDisposable.java new file mode 100644 index 00000000..9f95acfa --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/CancellableDisposable.java @@ -0,0 +1,74 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Cancellable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * A disposable container that wraps a Cancellable instance. + *

+ * Watch out for the AtomicReference API leak! + */ +public final class CancellableDisposable extends AtomicReference +implements Disposable { + + @Serial + private static final long serialVersionUID = 5718521705281392066L; + + public CancellableDisposable(Cancellable cancellable) { + super(cancellable); + } + + @Override + public boolean isDisposed() { + return get() == null; + } + + @Override + public void dispose() { + if (get() != null) { + Cancellable c = getAndSet(null); + if (c != null) { + try { + c.cancel(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + RxJavaPlugins.onError(ex); + } + } + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarDisposable.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarDisposable.java new file mode 100644 index 00000000..8e1dd3e7 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarDisposable.java @@ -0,0 +1,176 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import io.reactivex.rxjava4.annotations.Nullable; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +import java.io.Serial; + +/** + * Represents a fuseable container for a single value. + * + * @param the value type received and emitted + */ +public class DeferredScalarDisposable extends BasicIntQueueDisposable { + + @Serial + private static final long serialVersionUID = -5502432239815349361L; + + /** The target of the events. */ + protected final Observer downstream; + + /** The value stored temporarily when in fusion mode. */ + protected T value; + + /** Indicates there was a call to complete(T). */ + static final int TERMINATED = 2; + + /** Indicates the Disposable has been disposed. */ + static final int DISPOSED = 4; + + /** Indicates this Disposable is in fusion mode and is currently empty. */ + static final int FUSED_EMPTY = 8; + /** Indicates this Disposable is in fusion mode and has a value. */ + static final int FUSED_READY = 16; + /** Indicates this Disposable is in fusion mode and its value has been consumed. */ + static final int FUSED_CONSUMED = 32; + + /** + * Constructs a DeferredScalarDisposable by wrapping the Observer. + * @param downstream the Observer to wrap, not null (not verified) + */ + public DeferredScalarDisposable(Observer downstream) { + this.downstream = downstream; + } + + @Override + public final int requestFusion(int mode) { + if ((mode & ASYNC) != 0) { + lazySet(FUSED_EMPTY); + return ASYNC; + } + return NONE; + } + + /** + * Complete the target with a single value or indicate there is a value available in + * fusion mode. + * @param value the value to signal, not null (not verified) + */ + public final void complete(T value) { + int state = get(); + if ((state & (FUSED_READY | FUSED_CONSUMED | TERMINATED | DISPOSED)) != 0) { + return; + } + Observer a = downstream; + if (state == FUSED_EMPTY) { + this.value = value; + lazySet(FUSED_READY); + a.onNext(null); + } else { + lazySet(TERMINATED); + a.onNext(value); + } + if (get() != DISPOSED) { + a.onComplete(); + } + } + + /** + * Complete the target with an error signal. + * @param t the Throwable to signal, not null (not verified) + */ + public final void error(Throwable t) { + int state = get(); + if ((state & (FUSED_READY | FUSED_CONSUMED | TERMINATED | DISPOSED)) != 0) { + RxJavaPlugins.onError(t); + return; + } + lazySet(TERMINATED); + downstream.onError(t); + } + + /** + * Complete the target without any value. + */ + public final void complete() { + int state = get(); + if ((state & (FUSED_READY | FUSED_CONSUMED | TERMINATED | DISPOSED)) != 0) { + return; + } + lazySet(TERMINATED); + downstream.onComplete(); + } + + @Nullable + @Override + public final T poll() { + if (get() == FUSED_READY) { + T v = value; + value = null; + lazySet(FUSED_CONSUMED); + return v; + } + return null; + } + + @Override + public final boolean isEmpty() { + return get() != FUSED_READY; + } + + @Override + public final void clear() { + lazySet(FUSED_CONSUMED); + value = null; + } + + @Override + public void dispose() { + set(DISPOSED); + value = null; + } + + /** + * Try disposing this Disposable and return true if the current thread succeeded. + * @return true if the current thread succeeded + */ + public final boolean tryDispose() { + return getAndSet(DISPOSED) != DISPOSED; + } + + @Override + public final boolean isDisposed() { + return get() == DISPOSED; + } + +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarObserver.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarObserver.java new file mode 100644 index 00000000..ff944758 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarObserver.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; + +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; + +/** + * A fuseable Observer that can generate 0 or 1 resulting value. + * @param the input value type + * @param the output value type + */ +public abstract class DeferredScalarObserver +extends DeferredScalarDisposable +implements Observer { + + @Serial + private static final long serialVersionUID = -266195175408988651L; + + /** The upstream disposable. */ + protected Disposable upstream; + + /** + * Creates a DeferredScalarObserver instance and wraps a downstream Observer. + * @param downstream the downstream subscriber, not null (not verified) + */ + public DeferredScalarObserver(Observer downstream) { + super(downstream); + } + + @Override + public void onSubscribe(Disposable d) { + if (DisposableHelper.validate(this.upstream, d)) { + this.upstream = d; + + downstream.onSubscribe(this); + } + } + + @Override + public void onError(Throwable t) { + value = null; + error(t); + } + + @Override + public void onComplete() { + R v = value; + if (v != null) { + value = null; + complete(v); + } else { + complete(); + } + } + + @Override + public void dispose() { + super.dispose(); + upstream.dispose(); + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarSubscriber.java new file mode 100644 index 00000000..cf22aaef --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarSubscriber.java @@ -0,0 +1,94 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.core.FlowableSubscriber; + +/** + * A subscriber, extending a DeferredScalarSubscription, + * that is unbounded-in and can generate 0 or 1 resulting value. + * @param the input value type + * @param the output value type + */ +public abstract class DeferredScalarSubscriber extends DeferredScalarSubscription +implements FlowableSubscriber { + + @Serial + private static final long serialVersionUID = 2984505488220891551L; + + /** The upstream subscription. */ + protected Subscription upstream; + + /** Can indicate if there was at least on onNext call. */ + protected boolean hasValue; + + /** + * Creates a DeferredScalarSubscriber instance and wraps a downstream Subscriber. + * @param downstream the downstream subscriber, not null (not verified) + */ + public DeferredScalarSubscriber(Subscriber downstream) { + super(downstream); + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + + downstream.onSubscribe(this); + + s.request(Long.MAX_VALUE); + } + } + + @Override + public void onError(Throwable t) { + value = null; + downstream.onError(t); + } + + @Override + public void onComplete() { + if (hasValue) { + complete(value); + } else { + downstream.onComplete(); + } + } + + @Override + public void cancel() { + super.cancel(); + upstream.cancel(); + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarSubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarSubscription.java new file mode 100644 index 00000000..96676fab --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DeferredScalarSubscription.java @@ -0,0 +1,223 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.Flow.Subscriber; + +import io.reactivex.rxjava4.annotations.*; + +/** + * A subscription that signals a single value eventually. + *

+ * Note that the class leaks all methods of {@link java.util.concurrent.atomic.AtomicLong}. + * Use {@link #complete(Object)} to signal the single value. + *

+ * This atomic integer stores a bit field:
+ * bit 0: indicates that there is a value available
+ * bit 1: indicates that there was a request made
+ * bit 2: indicates there was a cancellation, exclusively set
+ * bit 3: indicates in fusion mode but no value yet, exclusively set
+ * bit 4: indicates in fusion mode and value is available, exclusively set
+ * bit 5: indicates in fusion mode and value has been consumed, exclusively set
+ * Where exclusively set means any other bits are 0 when that bit is set. + * @param the value type + */ +public class DeferredScalarSubscription<@NonNull T> extends BasicIntQueueSubscription { + + @Serial + private static final long serialVersionUID = -2151279923272604993L; + + /** The Subscriber to emit the value to. */ + protected final Subscriber downstream; + + /** The value is stored here if there is no request yet or in fusion mode. */ + protected T value; + + /** Indicates this Subscription has no value and not requested yet. */ + static final int NO_REQUEST_NO_VALUE = 0; + /** Indicates this Subscription has a value but not requested yet. */ + static final int NO_REQUEST_HAS_VALUE = 1; + /** Indicates this Subscription has been requested but there is no value yet. */ + static final int HAS_REQUEST_NO_VALUE = 2; + /** Indicates this Subscription has both request and value. */ + static final int HAS_REQUEST_HAS_VALUE = 3; + + /** Indicates the Subscription has been cancelled. */ + static final int CANCELLED = 4; + + /** Indicates this Subscription is in fusion mode and is currently empty. */ + static final int FUSED_EMPTY = 8; + /** Indicates this Subscription is in fusion mode and has a value. */ + static final int FUSED_READY = 16; + /** Indicates this Subscription is in fusion mode and its value has been consumed. */ + static final int FUSED_CONSUMED = 32; + + /** + * Creates a DeferredScalarSubscription by wrapping the given Subscriber. + * @param downstream the Subscriber to wrap, not null (not verified) + */ + public DeferredScalarSubscription(Subscriber downstream) { + this.downstream = downstream; + } + + @Override + public final void request(long n) { + if (SubscriptionHelper.validate(n)) { + for (;;) { + int state = get(); + // if any bits 1-31 are set, we are either in fusion mode (FUSED_*) + // or request has been called (HAS_REQUEST_*) + if ((state & ~NO_REQUEST_HAS_VALUE) != 0) { + return; + } + if (state == NO_REQUEST_HAS_VALUE) { + if (compareAndSet(NO_REQUEST_HAS_VALUE, HAS_REQUEST_HAS_VALUE)) { + T v = value; + if (v != null) { + value = null; + Subscriber a = downstream; + a.onNext(v); + if (get() != CANCELLED) { + a.onComplete(); + } + } + } + return; + } + if (compareAndSet(NO_REQUEST_NO_VALUE, HAS_REQUEST_NO_VALUE)) { + return; + } + } + } + } + + /** + * Completes this subscription by indicating the given value should + * be emitted when the first request arrives. + *

Make sure this is called exactly once. + * @param v the value to signal, not null (not validated) + */ + public final void complete(T v) { + int state = get(); + for (;;) { + if (state == FUSED_EMPTY) { + value = v; + lazySet(FUSED_READY); + + Subscriber a = downstream; + a.onNext(null); + if (get() != CANCELLED) { + a.onComplete(); + } + return; + } + + // if state is >= CANCELLED or bit zero is set (*_HAS_VALUE) case, return + if ((state & ~HAS_REQUEST_NO_VALUE) != 0) { + return; + } + + if (state == HAS_REQUEST_NO_VALUE) { + lazySet(HAS_REQUEST_HAS_VALUE); + Subscriber a = downstream; + a.onNext(v); + if (get() != CANCELLED) { + a.onComplete(); + } + return; + } + value = v; + if (compareAndSet(NO_REQUEST_NO_VALUE, NO_REQUEST_HAS_VALUE)) { + return; + } + state = get(); + if (state == CANCELLED) { + value = null; + return; + } + } + } + + @Override + public final int requestFusion(int mode) { + if ((mode & ASYNC) != 0) { + lazySet(FUSED_EMPTY); + return ASYNC; + } + return NONE; + } + + @Nullable + @Override + public final T poll() { + if (get() == FUSED_READY) { + lazySet(FUSED_CONSUMED); + T v = value; + value = null; + return v; + } + return null; + } + + @Override + public final boolean isEmpty() { + return get() != FUSED_READY; + } + + @Override + public final void clear() { + lazySet(FUSED_CONSUMED); + value = null; + } + + @Override + public void cancel() { + set(CANCELLED); + value = null; + } + + /** + * Returns true if this Subscription has been cancelled. + * @return true if this Subscription has been cancelled + */ + public final boolean isCancelled() { + return get() == CANCELLED; + } + + /** + * Atomically sets a cancelled state and returns true if + * the current thread did it successfully. + * @return true if the current thread cancelled + */ + public final boolean tryCancel() { + return getAndSet(CANCELLED) != CANCELLED; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DisposableHelper.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DisposableHelper.java new file mode 100644 index 00000000..ebba995a --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/DisposableHelper.java @@ -0,0 +1,201 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.ProtocolViolationException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Utility methods for working with Disposables atomically. + */ +public enum DisposableHelper implements Disposable { + /** + * The singleton instance representing a terminal, disposed state, don't leak it. + */ + DISPOSED + ; + + /** + * Checks if the given Disposable is the common {@link #DISPOSED} enum value. + * @param d the disposable to check + * @return true if d is {@link #DISPOSED} + */ + public static boolean isDisposed(Disposable d) { + return d == DISPOSED; + } + + /** + * Atomically sets the field and disposes the old contents. + * @param field the target field + * @param d the new Disposable to set + * @return true if successful, false if the field contains the {@link #DISPOSED} instance. + */ + public static boolean set(AtomicReference field, Disposable d) { + for (;;) { + Disposable current = field.get(); + if (current == DISPOSED) { + if (d != null) { + d.dispose(); + } + return false; + } + if (field.compareAndSet(current, d)) { + if (current != null) { + current.dispose(); + } + return true; + } + } + } + + /** + * Atomically sets the field to the given non-null Disposable and returns true + * or returns false if the field is non-null. + * If the target field contains the common DISPOSED instance, the supplied disposable + * is disposed. If the field contains other non-null Disposable, an IllegalStateException + * is signaled to the RxJavaPlugins.onError hook. + * + * @param field the target field + * @param d the disposable to set, not null + * @return true if the operation succeeded, false + */ + public static boolean setOnce(AtomicReference field, Disposable d) { + Objects.requireNonNull(d, "d is null"); + if (!field.compareAndSet(null, d)) { + d.dispose(); + if (field.get() != DISPOSED) { + reportDisposableSet(); + } + return false; + } + return true; + } + + /** + * Atomically replaces the Disposable in the field with the given new Disposable + * but does not dispose the old one. + * @param field the target field to change + * @param d the new disposable, null allowed + * @return true if the operation succeeded, false if the target field contained + * the common DISPOSED instance and the given disposable (if not null) is disposed. + */ + public static boolean replace(AtomicReference field, Disposable d) { + for (;;) { + Disposable current = field.get(); + if (current == DISPOSED) { + if (d != null) { + d.dispose(); + } + return false; + } + if (field.compareAndSet(current, d)) { + return true; + } + } + } + + /** + * Atomically disposes the Disposable in the field if not already disposed. + * @param field the target field + * @return true if the current thread managed to dispose the Disposable + */ + public static boolean dispose(AtomicReference field) { + Disposable current = field.get(); + Disposable d = DISPOSED; + if (current != d) { + current = field.getAndSet(d); + if (current != d) { + if (current != null) { + current.dispose(); + } + return true; + } + } + return false; + } + + /** + * Verifies that current is null, next is not null, otherwise signals errors + * to the RxJavaPlugins and returns false. + * @param current the current Disposable, expected to be null + * @param next the next Disposable, expected to be non-null + * @return true if the validation succeeded + */ + public static boolean validate(Disposable current, Disposable next) { + if (next == null) { + RxJavaPlugins.onError(new NullPointerException("next is null")); + return false; + } + if (current != null) { + next.dispose(); + reportDisposableSet(); + return false; + } + return true; + } + + /** + * Reports that the disposable is already set to the RxJavaPlugins error handler. + */ + public static void reportDisposableSet() { + RxJavaPlugins.onError(new ProtocolViolationException("Disposable already set!")); + } + + /** + * Atomically tries to set the given Disposable on the field if it is null or disposes it if + * the field contains {@link #DISPOSED}. + * @param field the target field + * @param d the disposable to set + * @return true if successful, false otherwise + */ + public static boolean trySet(AtomicReference field, Disposable d) { + if (!field.compareAndSet(null, d)) { + if (field.get() == DISPOSED) { + d.dispose(); + } + return false; + } + return true; + } + + @Override + public void dispose() { + // deliberately no-op + } + + @Override + public boolean isDisposed() { + return true; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/EmptyDisposable.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/EmptyDisposable.java new file mode 100644 index 00000000..011ee005 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/EmptyDisposable.java @@ -0,0 +1,133 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import io.reactivex.rxjava4.annotations.Nullable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.QueueDisposable; + +/** + * Represents a stateless empty Disposable that reports being always + * empty and disposed. + *

It is also async-fuseable but empty all the time. + *

Since EmptyDisposable implements QueueDisposable and is empty, + * don't use it in tests and then signal onNext with it; + * use Disposables.empty() instead. + */ +public enum EmptyDisposable implements QueueDisposable { + /** + * Since EmptyDisposable implements QueueDisposable and is empty, + * don't use it in tests and then signal onNext with it; + * use Disposables.empty() instead. + */ + INSTANCE, + /** + * An empty disposable that returns false for isDisposed. + */ + NEVER + ; + + @Override + public void dispose() { + // no-op + } + + @Override + public boolean isDisposed() { + return this == INSTANCE; + } + + public static void complete(Observer observer) { + observer.onSubscribe(INSTANCE); + observer.onComplete(); + } + + public static void complete(MaybeObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onComplete(); + } + + public static void error(Throwable e, Observer observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); + } + + public static void complete(CompletableObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onComplete(); + } + + public static void error(Throwable e, CompletableObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); + } + + public static void error(Throwable e, SingleObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); + } + + public static void error(Throwable e, MaybeObserver observer) { + observer.onSubscribe(INSTANCE); + observer.onError(e); + } + + @Override + public boolean offer(Object value) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public boolean offer(Object v1, Object v2) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Nullable + @Override + public Object poll() { + return null; // always empty + } + + @Override + public boolean isEmpty() { + return true; // always empty + } + + @Override + public void clear() { + // nothing to do + } + + @Override + public int requestFusion(int mode) { + return mode & ASYNC; + } + +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/EmptySubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/EmptySubscription.java new file mode 100644 index 00000000..87b46326 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/EmptySubscription.java @@ -0,0 +1,118 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import static java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.annotations.Nullable; +import io.reactivex.rxjava4.operators.QueueSubscription; + +/** + * An empty subscription that does nothing other than validates the request amount. + */ +public enum EmptySubscription implements QueueSubscription { + /** A singleton, stateless instance. */ + INSTANCE; + + @Override + public void request(long n) { + SubscriptionHelper.validate(n); + } + + @Override + public void cancel() { + // no-op + } + + @Override + public String toString() { + return "EmptySubscription"; + } + + /** + * Sets the empty subscription instance on the subscriber and then + * calls onError with the supplied error. + * + *

Make sure this is only called if the subscriber hasn't received a + * subscription already (there is no way of telling this). + * + * @param e the error to deliver to the subscriber + * @param s the target subscriber + */ + public static void error(Throwable e, Subscriber s) { + s.onSubscribe(INSTANCE); + s.onError(e); + } + + /** + * Sets the empty subscription instance on the subscriber and then + * calls onComplete. + * + *

Make sure this is only called if the subscriber hasn't received a + * subscription already (there is no way of telling this). + * + * @param s the target subscriber + */ + public static void complete(Subscriber s) { + s.onSubscribe(INSTANCE); + s.onComplete(); + } + + @Nullable + @Override + public Object poll() { + return null; // always empty + } + + @Override + public boolean isEmpty() { + return true; + } + + @Override + public void clear() { + // nothing to do + } + + @Override + public int requestFusion(int mode) { + return mode & ASYNC; // accept async mode: an onComplete or onError will be signaled after anyway + } + + @Override + public boolean offer(Object value) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public boolean offer(Object v1, Object v2) { + throw new UnsupportedOperationException("Should not be called!"); + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ExceptionHelper.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ExceptionHelper.java new file mode 100644 index 00000000..024fb08e --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ExceptionHelper.java @@ -0,0 +1,258 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.annotations.*; +import io.reactivex.rxjava4.exceptions.CompositeException; + +/** + * Terminal atomics for Throwable containers. + */ +public final class ExceptionHelper { + + /** Utility class. */ + private ExceptionHelper() { + throw new IllegalStateException("No instances!"); + } + + /** + * If the provided Throwable is an Error this method + * throws it, otherwise returns a CompletionException wrapping the error + * if that error is a checked exception. + * @param error the error to wrap or throw + * @return the (wrapped) error + */ + @NonNull + public static RuntimeException wrapOrThrow(@NonNull Throwable error) { + if (error instanceof Error err) { + throw err; + } + if (error instanceof RuntimeException rte) { + return rte; + } + return new CompletionException("You forgot to unwrap me!", error); + } + /** + * Unwraps a {@link CompletionException} and rethrows its {@link Error} + * or {@link RuntimeException} inside it, or returns it as is if + * the {@code CompletionException} holds a checked exception. + * @param error the error to unwrap and rethrow its cause if possible + * @return the {@code error} if it has a checked exception cause + * @since 4.0.0 + */ + @NonNull + public static RuntimeException unwrapOrThrow(@NonNull CompletionException error) { + var cause = error.getCause(); + if (cause instanceof Error err) { + throw err; + } + if (cause instanceof RuntimeException rte) { + return rte; + } + return error; + } + + /** + * A singleton instance of a Throwable indicating a terminal state for exceptions, + * don't leak this. + */ + public static final Throwable TERMINATED = new Termination(); + + public static boolean addThrowable(AtomicReference field, Throwable exception) { + for (;;) { + Throwable current = field.get(); + + if (current == TERMINATED) { + return false; + } + + Throwable update; + if (current == null) { + update = exception; + } else { + update = new CompositeException(current, exception); + } + + if (field.compareAndSet(current, update)) { + return true; + } + } + } + + public static Throwable terminate(AtomicReference field) { + Throwable current = field.get(); + if (current != TERMINATED) { + current = field.getAndSet(TERMINATED); + } + return current; + } + + /** + * Returns a flattened list of Throwables from tree-like CompositeException chain. + * @param t the starting throwable + * @return the list of Throwables flattened in a depth-first manner + */ + public static List flatten(Throwable t) { + List list = new ArrayList<>(); + ArrayDeque deque = new ArrayDeque<>(); + deque.offer(t); + + while (!deque.isEmpty()) { + Throwable e = deque.removeFirst(); + if (e instanceof CompositeException ce) { + List exceptions = ce.getExceptions(); + for (int i = exceptions.size() - 1; i >= 0; i--) { + deque.offerFirst(exceptions.get(i)); + } + } else { + list.add(e); + } + } + + return list; + } + + /** + * Workaround for Java 6 not supporting throwing a final Throwable from a catch block. + * @param the generic exception type + * @param e the Throwable error to return or throw + * @return the Throwable e if it is a subclass of Exception + * @throws E the generic exception thrown + */ + @SuppressWarnings("unchecked") + public static Exception throwIfThrowable(Throwable e) throws E { + if (e instanceof Exception) { + return (Exception)e; + } + throw (E)e; + } + + public static String timeoutMessage(long timeout, TimeUnit unit) { + return "The source did not signal an event for " + + timeout + + " " + + unit.toString().toLowerCase() + + " and has been terminated."; + } + + static final class Termination extends Throwable { + + @Serial + private static final long serialVersionUID = -4649703670690200604L; + + Termination() { + super("No further exceptions"); + } + + @Override + public Throwable fillInStackTrace() { + return this; + } + } + + /** + * Composes a String with a null warning message. + * @param prefix the prefix to add to the message. + * @return the composed String + * @since 3.0.0 + */ + public static String nullWarning(String prefix) { + return prefix + " Null values are generally not allowed in 3.x operators and sources."; + } + + /** + * Creates a NullPointerException with a composed message via {@link #nullWarning(String)}. + * @param prefix the prefix to add to the message. + * @return the composed String + * @since 3.0.0 + */ + public static NullPointerException createNullPointerException(String prefix) { + return new NullPointerException(nullWarning(prefix)); + } + + /** + * Similar to Objects.requireNonNull but composes the error message via + * {@link #nullWarning(String)}. + * @param the value type + * @param value the value to check + * @param prefix the prefix to the error message + * @return the value + * @throws NullPointerException if value is null + * @since 3.0.0 + */ + public static T nullCheck(T value, String prefix) { + if (value == null) { + throw createNullPointerException(prefix); + } + return value; + } + + /** + * Unwraps both throwables if they are wrapped into a {@link CompletionException}, + * then if both are present, add {@code b} as suppressed to {@code a} + * and return a; return b otherwise + * @param main the first throwable + * @param secondary the second throwable + * @return the unwrapped and combined throwable or null if both where + */ + @Nullable + public static Throwable unwrapAndCombine(@Nullable Throwable main, @Nullable Throwable secondary) { + if (main instanceof CompletionException) { + main = main.getCause(); + } + if (secondary instanceof CompletionException) { + secondary = secondary.getCause(); + } + if (main != null && secondary != null && main != secondary) { + main.addSuppressed(secondary); + } + if (main != null) { + return main; + } + return secondary; + } + + /** + * Unwraps the given {@link CompletionException}. + * @param t the possible throwable to unwrap + * @return the unwrapped Throwable + */ + public static Throwable unwrap(@Nullable Throwable t) { + if (t instanceof CompletionException) { + t = t.getCause(); + } + return t; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/Functions.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/Functions.java new file mode 100644 index 00000000..1f7c2b0f --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/Functions.java @@ -0,0 +1,691 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.*; +import java.util.concurrent.*; + +import static java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.annotations.NonNull; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.OnErrorNotImplementedException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Timed; + +/** + * Utility methods to convert the BiFunction, Function3 .. Function9 instances to Function of Object array. + */ +public final class Functions { + + /** Utility class. */ + private Functions() { + throw new IllegalStateException("No instances!"); + } + + @NonNull + public static Function toFunction(@NonNull BiFunction f) { + return new Array2Func<>(f); + } + + @NonNull + public static Function toFunction(@NonNull Function3 f) { + return new Array3Func<>(f); + } + + @NonNull + public static Function toFunction(@NonNull Function4 f) { + return new Array4Func<>(f); + } + + @NonNull + public static Function toFunction(@NonNull Function5 f) { + return new Array5Func<>(f); + } + + @NonNull + public static Function toFunction( + @NonNull Function6 f) { + return new Array6Func<>(f); + } + + @NonNull + public static Function toFunction( + @NonNull Function7 f) { + return new Array7Func<>(f); + } + + @NonNull + public static Function toFunction( + @NonNull Function8 f) { + return new Array8Func<>(f); + } + + @NonNull + public static Function toFunction( + @NonNull Function9 f) { + return new Array9Func<>(f); + } + + /** A singleton identity function. */ + static final Function IDENTITY = new Identity(); + + /** + * Returns an identity function that simply returns its argument. + * @param the input and output value type + * @return the identity function + */ + @SuppressWarnings("unchecked") + @NonNull + public static Function identity() { + return (Function)IDENTITY; + } + + public static final Runnable EMPTY_RUNNABLE = new EmptyRunnable(); + + public static final Action EMPTY_ACTION = new EmptyAction(); + + static final Consumer EMPTY_CONSUMER = new EmptyConsumer(); + + /** + * Returns an empty consumer that does nothing. + * @param the consumed value type, the value is ignored + * @return an empty consumer that does nothing. + */ + @SuppressWarnings("unchecked") + public static Consumer emptyConsumer() { + return (Consumer)EMPTY_CONSUMER; + } + + public static final Consumer ERROR_CONSUMER = new ErrorConsumer(); + + /** + * Wraps the consumed Throwable into an OnErrorNotImplementedException and + * signals it to the plugin error handler. + */ + public static final Consumer ON_ERROR_MISSING = new OnErrorMissingConsumer(); + + public static final LongConsumer EMPTY_LONG_CONSUMER = new EmptyLongConsumer(); + + static final Predicate ALWAYS_TRUE = new TruePredicate(); + + static final Predicate ALWAYS_FALSE = new FalsePredicate(); + + static final Supplier NULL_SUPPLIER = new NullProvider(); + + @SuppressWarnings("unchecked") + @NonNull + public static Predicate alwaysTrue() { + return (Predicate)ALWAYS_TRUE; + } + + @SuppressWarnings("unchecked") + @NonNull + public static Predicate alwaysFalse() { + return (Predicate)ALWAYS_FALSE; + } + + @SuppressWarnings("unchecked") + @NonNull + public static Supplier nullSupplier() { + return (Supplier)NULL_SUPPLIER; + } + + record FutureAction(Future future) implements Action { + + @Override + public void run() throws Exception { + future.get(); + } + } + + /** + * Wraps the blocking get call of the Future into an Action. + * @param future the future to call get() on, not null + * @return the new Action instance + */ + @NonNull + public static Action futureAction(@NonNull Future future) { + return new FutureAction(future); + } + + record JustValue(U value) implements Callable, Supplier, Function { + + @Override + public U call() { + return value; + } + + @Override + public U apply(T t) { + return value; + } + + @Override + public U get() { + return value; + } + } + + /** + * Returns a Callable that returns the given value. + * @param the value type + * @param value the value to return + * @return the new Callable instance + */ + @NonNull + public static Callable justCallable(@NonNull T value) { + return new JustValue<>(value); + } + + /** + * Returns a Supplier that returns the given value. + * @param the value type + * @param value the value to return + * @return the new Callable instance + */ + @NonNull + public static Supplier justSupplier(@NonNull T value) { + return new JustValue<>(value); + } + + /** + * Returns a Function that ignores its parameter and returns the given value. + * @param the function's input type + * @param the value and return type of the function + * @param value the value to return + * @return the new Function instance + */ + @NonNull + public static Function justFunction(@NonNull U value) { + return new JustValue<>(value); + } + + record CastToClass(Class clazz) implements Function { + + @Override + public U apply(T t) { + return clazz.cast(t); + } + } + + /** + * Returns a function that cast the incoming values via a Class object. + * @param the input value type + * @param the output and target type + * @param target the target class + * @return the new Function instance + */ + @NonNull + public static Function castFunction(@NonNull Class target) { + return new CastToClass<>(target); + } + + record ArrayListCapacityCallable(int capacity) implements Supplier> { + + @Override + public List get() { + return new ArrayList<>(capacity); + } + } + + public static Supplier> createArrayList(int capacity) { + return new ArrayListCapacityCallable<>(capacity); + } + + record EqualsPredicate(T value) implements Predicate { + + @Override + public boolean test(T t) { + return Objects.equals(t, value); + } + } + + public static Predicate equalsWith(T value) { + return new EqualsPredicate<>(value); + } + + enum HashSetSupplier implements Supplier> { + INSTANCE; + @Override + public Set get() { + return new HashSet<>(); + } + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Supplier> createHashSet() { + return (Supplier)HashSetSupplier.INSTANCE; + } + + record NotificationOnNext(Consumer> onNotification) implements Consumer { + + @Override + public void accept(T v) throws Throwable { + onNotification.accept(Notification.createOnNext(v)); + } + } + + record NotificationOnError(Consumer> onNotification) implements Consumer { + + @Override + public void accept(Throwable v) throws Throwable { + onNotification.accept(Notification.createOnError(v)); + } + } + + record NotificationOnComplete(Consumer> onNotification) implements Action { + + @Override + public void run() throws Throwable { + onNotification.accept(Notification.createOnComplete()); + } + } + + public static Consumer notificationOnNext(Consumer> onNotification) { + return new NotificationOnNext<>(onNotification); + } + + public static Consumer notificationOnError(Consumer> onNotification) { + return new NotificationOnError<>(onNotification); + } + + public static Action notificationOnComplete(Consumer> onNotification) { + return new NotificationOnComplete<>(onNotification); + } + + record ActionConsumer(Action action) implements Consumer { + + @Override + public void accept(T t) throws Throwable { + action.run(); + } + } + + public static Consumer actionConsumer(Action action) { + return new ActionConsumer<>(action); + } + + record ClassFilter(Class clazz) implements Predicate { + + @Override + public boolean test(T t) { + return clazz.isInstance(t); + } + } + + public static Predicate isInstanceOf(Class clazz) { + return new ClassFilter<>(clazz); + } + + record BooleanSupplierPredicateReverse(BooleanSupplier supplier) implements Predicate { + + @Override + public boolean test(T t) throws Throwable { + return !supplier.getAsBoolean(); + } + } + + public static Predicate predicateReverseFor(BooleanSupplier supplier) { + return new BooleanSupplierPredicateReverse<>(supplier); + } + + record TimestampFunction(TimeUnit unit, Scheduler scheduler) implements Function> { + + @Override + public Timed apply(T t) { + return new Timed<>(t, scheduler.now(unit), unit); + } + } + + public static Function> timestampWith(TimeUnit unit, Scheduler scheduler) { + return new TimestampFunction<>(unit, scheduler); + } + + static final class ToMapKeySelector implements BiConsumer, T> { + private final Function keySelector; + + ToMapKeySelector(Function keySelector) { + this.keySelector = keySelector; + } + + @Override + public void accept(Map m, T t) throws Throwable { + K key = keySelector.apply(t); + m.put(key, t); + } + } + + public static BiConsumer, T> toMapKeySelector(final Function keySelector) { + return new ToMapKeySelector<>(keySelector); + } + + static final class ToMapKeyValueSelector implements BiConsumer, T> { + private final Function valueSelector; + private final Function keySelector; + + ToMapKeyValueSelector(Function valueSelector, + Function keySelector) { + this.valueSelector = valueSelector; + this.keySelector = keySelector; + } + + @Override + public void accept(Map m, T t) throws Throwable { + K key = keySelector.apply(t); + V value = valueSelector.apply(t); + m.put(key, value); + } + } + + public static BiConsumer, T> toMapKeyValueSelector(final Function keySelector, + final Function valueSelector) { + return new ToMapKeyValueSelector<>(valueSelector, keySelector); + } + + static final class ToMultimapKeyValueSelector implements BiConsumer>, T> { + private final Function> collectionFactory; + private final Function valueSelector; + private final Function keySelector; + + ToMultimapKeyValueSelector(Function> collectionFactory, + Function valueSelector, Function keySelector) { + this.collectionFactory = collectionFactory; + this.valueSelector = valueSelector; + this.keySelector = keySelector; + } + + @SuppressWarnings("unchecked") + @Override + public void accept(Map> m, T t) throws Throwable { + K key = keySelector.apply(t); + + Collection coll = m.get(key); + if (coll == null) { + coll = (Collection)collectionFactory.apply(key); + m.put(key, coll); + } + + V value = valueSelector.apply(t); + + coll.add(value); + } + } + + public static BiConsumer>, T> toMultimapKeyValueSelector( + final Function keySelector, final Function valueSelector, + final Function> collectionFactory) { + return new ToMultimapKeyValueSelector<>(collectionFactory, valueSelector, keySelector); + } + + enum NaturalComparator implements Comparator { + INSTANCE; + + @SuppressWarnings("unchecked") + @Override + public int compare(Object o1, Object o2) { + return ((Comparable)o1).compareTo(o2); + } + } + + @SuppressWarnings("unchecked") + public static Comparator naturalComparator() { + return (Comparator)NaturalComparator.INSTANCE; + } + + record ListSorter(Comparator comparator) implements Function, List> { + + @Override + public List apply(List v) { + v.sort(comparator); + return v; + } + } + + public static Function, List> listSorter(final Comparator comparator) { + return new ListSorter<>(comparator); + } + + public static final Consumer REQUEST_MAX = new MaxRequestSubscription(); + + record Array2Func(BiFunction f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 2) { + throw new IllegalArgumentException("Array of size 2 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1]); + } + } + + record Array3Func(Function3 f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 3) { + throw new IllegalArgumentException("Array of size 3 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1], (T3) a[2]); + } + } + + record Array4Func(Function4 f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 4) { + throw new IllegalArgumentException("Array of size 4 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3]); + } + } + + static final class Array5Func implements Function { + private final Function5 f; + + Array5Func(Function5 f) { + this.f = f; + } + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 5) { + throw new IllegalArgumentException("Array of size 5 expected but got " + a.length); + } + return f.apply((T1)a[0], (T2)a[1], (T3)a[2], (T4)a[3], (T5)a[4]); + } + } + + record Array6Func( + Function6 f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 6) { + throw new IllegalArgumentException("Array of size 6 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5]); + } + } + + record Array7Func( + Function7 f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 7) { + throw new IllegalArgumentException("Array of size 7 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5], (T7) a[6]); + } + } + + record Array8Func( + Function8 f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 8) { + throw new IllegalArgumentException("Array of size 8 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5], (T7) a[6], (T8) a[7]); + } + } + + record Array9Func( + Function9 f) implements Function { + + @SuppressWarnings("unchecked") + @Override + public R apply(Object[] a) throws Throwable { + if (a.length != 9) { + throw new IllegalArgumentException("Array of size 9 expected but got " + a.length); + } + return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5], (T7) a[6], (T8) a[7], (T9) a[8]); + } + } + + static final class Identity implements Function { + @Override + public Object apply(Object v) { + return v; + } + + @Override + public String toString() { + return "IdentityFunction"; + } + } + + static final class EmptyRunnable implements Runnable { + @Override + public void run() { } + + @Override + public String toString() { + return "EmptyRunnable"; + } + } + + static final class EmptyAction implements Action { + @Override + public void run() { } + + @Override + public String toString() { + return "EmptyAction"; + } + } + + static final class EmptyConsumer implements Consumer { + @Override + public void accept(Object v) { } + + @Override + public String toString() { + return "EmptyConsumer"; + } + } + + static final class ErrorConsumer implements Consumer { + @Override + public void accept(Throwable error) { + RxJavaPlugins.onError(error); + } + } + + static final class OnErrorMissingConsumer implements Consumer { + @Override + public void accept(Throwable error) { + RxJavaPlugins.onError(new OnErrorNotImplementedException(error)); + } + } + + static final class EmptyLongConsumer implements LongConsumer { + @Override + public void accept(long v) { } + } + + static final class TruePredicate implements Predicate { + @Override + public boolean test(Object o) { + return true; + } + } + + static final class FalsePredicate implements Predicate { + @Override + public boolean test(Object o) { + return false; + } + } + + static final class NullProvider implements Supplier { + @Override + public Object get() { + return null; + } + } + + static final class MaxRequestSubscription implements Consumer { + @Override + public void accept(Subscription t) { + t.request(Long.MAX_VALUE); + } + } + + @SuppressWarnings("unchecked") + public static Consumer boundedConsumer(int bufferSize) { + return (Consumer) new BoundedConsumer(bufferSize); + } + + public static class BoundedConsumer implements Consumer { + + final int bufferSize; + + BoundedConsumer(int bufferSize) { + this.bufferSize = bufferSize; + } + + @Override + public void accept(Subscription s) { + s.request(bufferSize); + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/HalfSerializer.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/HalfSerializer.java new file mode 100644 index 00000000..35310a6e --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/HalfSerializer.java @@ -0,0 +1,152 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.concurrent.atomic.AtomicInteger; + +import static java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.core.Observer; + +/** + * Utility methods to perform half-serialization: a form of serialization + * where onNext is guaranteed to be called from a single thread but + * onError or onComplete may be called from any threads. + */ +public final class HalfSerializer { + /** Utility class. */ + private HalfSerializer() { + throw new IllegalStateException("No instances!"); + } + + /** + * Emits the given value if possible and terminates if there was an onComplete or onError + * while emitting, drops the value otherwise. + * @param the value type + * @param subscriber the target Subscriber to emit to + * @param value the value to emit + * @param wip the serialization work-in-progress counter/indicator + * @param errors the holder of Throwables + * @return true if the operation succeeded, false if there sequence completed + */ + public static boolean onNext(Subscriber subscriber, T value, + AtomicInteger wip, AtomicThrowable errors) { + if (wip.get() == 0 && wip.compareAndSet(0, 1)) { + subscriber.onNext(value); + if (wip.decrementAndGet() == 0) { + return true; + } + errors.tryTerminateConsumer(subscriber); + } + return false; + } + + /** + * Emits the given exception if possible or adds it to the given error container to + * be emitted by a concurrent onNext if one is running. + * Undeliverable exceptions are sent to the RxJavaPlugins.onError. + * @param subscriber the target Subscriber to emit to + * @param ex the Throwable to emit + * @param wip the serialization work-in-progress counter/indicator + * @param errors the holder of Throwables + */ + public static void onError(Subscriber subscriber, Throwable ex, + AtomicInteger wip, AtomicThrowable errors) { + if (errors.tryAddThrowableOrReport(ex)) { + if (wip.getAndIncrement() == 0) { + errors.tryTerminateConsumer(subscriber); + } + } + } + + /** + * Emits an onComplete signal or an onError signal with the given error or indicates + * the concurrently running onNext should do that. + * @param subscriber the target Subscriber to emit to + * @param wip the serialization work-in-progress counter/indicator + * @param errors the holder of Throwables + */ + public static void onComplete(Subscriber subscriber, AtomicInteger wip, AtomicThrowable errors) { + if (wip.getAndIncrement() == 0) { + errors.tryTerminateConsumer(subscriber); + } + } + + /** + * Emits the given value if possible and terminates if there was an onComplete or onError + * while emitting, drops the value otherwise. + * @param the value type + * @param observer the target Observer to emit to + * @param value the value to emit + * @param wip the serialization work-in-progress counter/indicator + * @param errors the holder of Throwables + */ + public static void onNext(Observer observer, T value, + AtomicInteger wip, AtomicThrowable errors) { + if (wip.get() == 0 && wip.compareAndSet(0, 1)) { + observer.onNext(value); + if (wip.decrementAndGet() != 0) { + errors.tryTerminateConsumer(observer); + } + } + } + + /** + * Emits the given exception if possible or adds it to the given error container to + * be emitted by a concurrent onNext if one is running. + * Undeliverable exceptions are sent to the RxJavaPlugins.onError. + * @param observer the target Subscriber to emit to + * @param ex the Throwable to emit + * @param wip the serialization work-in-progress counter/indicator + * @param errors the holder of Throwables + */ + public static void onError(Observer observer, Throwable ex, + AtomicInteger wip, AtomicThrowable errors) { + if (errors.tryAddThrowableOrReport(ex)) { + if (wip.getAndIncrement() == 0) { + errors.tryTerminateConsumer(observer); + } + } + } + + /** + * Emits an onComplete signal or an onError signal with the given error or indicates + * the concurrently running onNext should do that. + * @param observer the target Subscriber to emit to + * @param wip the serialization work-in-progress counter/indicator + * @param errors the holder of Throwables + */ + public static void onComplete(Observer observer, AtomicInteger wip, AtomicThrowable errors) { + if (wip.getAndIncrement() == 0) { + errors.tryTerminateConsumer(observer); + } + } + +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/HideSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/HideSubscriber.java new file mode 100644 index 00000000..f70e8c99 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/HideSubscriber.java @@ -0,0 +1,65 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.core.FlowableSubscriber; + +public final class HideSubscriber implements FlowableSubscriber, Subscription { + + final Subscriber downstream; + + Subscription upstream; + + public HideSubscriber(Subscriber downstream) { + this.downstream = downstream; + } + + @Override + public void request(long n) { + upstream.request(n); + } + + @Override + public void cancel() { + upstream.cancel(); + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.validate(this.upstream, s)) { + this.upstream = s; + downstream.onSubscribe(this); + } + } + + @Override + public void onNext(T t) { + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + downstream.onError(t); + } + + @Override + public void onComplete() { + downstream.onComplete(); + } + } \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ImmediateThinScheduler.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ImmediateThinScheduler.java new file mode 100644 index 00000000..008df053 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ImmediateThinScheduler.java @@ -0,0 +1,121 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.concurrent.TimeUnit; + +import io.reactivex.rxjava4.annotations.NonNull; +import io.reactivex.rxjava4.core.Scheduler; +import io.reactivex.rxjava4.disposables.*; + +/** + * A Scheduler partially implementing the API by allowing only non-delayed, non-periodic + * task execution on the current thread immediately. + *

+ * Note that this doesn't support recursive scheduling and disposing the returned Disposable + * has no effect (because when the schedule() method returns, the task has been already run). + */ +public final class ImmediateThinScheduler extends Scheduler { + + /** + * The singleton instance of the immediate (thin) scheduler. + */ + public static final Scheduler INSTANCE = new ImmediateThinScheduler(); + + static final Worker WORKER = new ImmediateThinWorker(); + + static final Disposable DISPOSED; + + static { + DISPOSED = Disposable.empty(); + DISPOSED.dispose(); + } + + private ImmediateThinScheduler() { + // singleton class + } + + @NonNull + @Override + public Disposable scheduleDirect(@NonNull Runnable run) { + run.run(); + return DISPOSED; + } + + @NonNull + @Override + public Disposable scheduleDirect(@NonNull Runnable run, long delay, TimeUnit unit) { + throw new UnsupportedOperationException("This scheduler doesn't support delayed execution"); + } + + @NonNull + @Override + public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, TimeUnit unit) { + throw new UnsupportedOperationException("This scheduler doesn't support periodic execution"); + } + + @NonNull + @Override + public Worker createWorker() { + return WORKER; + } + + static final class ImmediateThinWorker extends Worker { + + @Override + public void dispose() { + // This worker is always stateless and won't track tasks + } + + @Override + public boolean isDisposed() { + return false; // dispose() has no effect + } + + @NonNull + @Override + public Disposable schedule(@NonNull Runnable run) { + run.run(); + return DISPOSED; + } + + @NonNull + @Override + public Disposable schedule(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) { + throw new UnsupportedOperationException("This scheduler doesn't support delayed execution"); + } + + @NonNull + @Override + public Disposable schedulePeriodically(@NonNull Runnable run, long initialDelay, long period, TimeUnit unit) { + throw new UnsupportedOperationException("This scheduler doesn't support periodic execution"); + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/InnerQueuedSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/InnerQueuedSubscriber.java new file mode 100644 index 00000000..8bc68d8c --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/InnerQueuedSubscriber.java @@ -0,0 +1,149 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.Flow.Subscription; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.operators.*; + +/** + * Subscriber that can fuse with the upstream and calls a support interface + * whenever an event is available. + * + * @param the value type + */ +public final class InnerQueuedSubscriber +extends AtomicReference +implements FlowableSubscriber, Subscription { + + @Serial + private static final long serialVersionUID = 22876611072430776L; + + final InnerQueuedSubscriberSupport parent; + + final int prefetch; + + final int limit; + + volatile SimpleQueue queue; + + volatile boolean done; + + long produced; + + int fusionMode; + + public InnerQueuedSubscriber(InnerQueuedSubscriberSupport parent, int prefetch) { + this.parent = parent; + this.prefetch = prefetch; + this.limit = prefetch - (prefetch >> 2); + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.setOnce(this, s)) { + if (s instanceof QueueSubscription) { + @SuppressWarnings("unchecked") + QueueSubscription qs = (QueueSubscription) s; + + int m = qs.requestFusion(QueueSubscription.ANY); + if (m == QueueSubscription.SYNC) { + fusionMode = m; + queue = qs; + done = true; + parent.innerComplete(this); + return; + } + if (m == QueueSubscription.ASYNC) { + fusionMode = m; + queue = qs; + QueueDrainHelper.request(s, prefetch); + return; + } + } + + queue = QueueDrainHelper.createQueue(prefetch); + + QueueDrainHelper.request(s, prefetch); + } + } + + @Override + public void onNext(T t) { + if (fusionMode == QueueSubscription.NONE) { + parent.innerNext(this, t); + } else { + parent.drain(); + } + } + + @Override + public void onError(Throwable t) { + parent.innerError(this, t); + } + + @Override + public void onComplete() { + parent.innerComplete(this); + } + + @Override + public void request(long n) { + if (fusionMode != QueueSubscription.SYNC) { + long p = produced + n; + if (p >= limit) { + produced = 0L; + get().request(p); + } else { + produced = p; + } + } + } + + @Override + public void cancel() { + SubscriptionHelper.cancel(this); + } + + public boolean isDone() { + return done; + } + + public void setDone() { + this.done = true; + } + + public SimpleQueue queue() { + return queue; + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/InnerQueuedSubscriberSupport.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/InnerQueuedSubscriberSupport.java new file mode 100644 index 00000000..e9df5fdf --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/InnerQueuedSubscriberSupport.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +/** + * Interface to allow the InnerQueuedSubscriber to call back a parent + * with signals. + * + * @param the value type + */ +public interface InnerQueuedSubscriberSupport { + + void innerNext(InnerQueuedSubscriber inner, T value); + + void innerError(InnerQueuedSubscriber inner, Throwable e); + + void innerComplete(InnerQueuedSubscriber inner); + + void drain(); +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/LambdaObserver.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/LambdaObserver.java new file mode 100644 index 00000000..904c7e0d --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/LambdaObserver.java @@ -0,0 +1,130 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +public final class LambdaObserver extends AtomicReference + implements Observer, Disposable, LambdaConsumerIntrospection { + + @Serial + private static final long serialVersionUID = -7251123623727029452L; + final Consumer onNext; + final Consumer onError; + final Action onComplete; + final Consumer onSubscribe; + + public LambdaObserver(Consumer onNext, Consumer onError, + Action onComplete, + Consumer onSubscribe) { + super(); + this.onNext = onNext; + this.onError = onError; + this.onComplete = onComplete; + this.onSubscribe = onSubscribe; + } + + @Override + public void onSubscribe(Disposable d) { + if (DisposableHelper.setOnce(this, d)) { + try { + onSubscribe.accept(this); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + d.dispose(); + onError(ex); + } + } + } + + @Override + public void onNext(T t) { + if (!isDisposed()) { + try { + onNext.accept(t); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + get().dispose(); + onError(e); + } + } + } + + @Override + public void onError(Throwable t) { + if (!isDisposed()) { + lazySet(DisposableHelper.DISPOSED); + try { + onError.accept(t); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + RxJavaPlugins.onError(new CompositeException(t, e)); + } + } else { + RxJavaPlugins.onError(t); + } + } + + @Override + public void onComplete() { + if (!isDisposed()) { + lazySet(DisposableHelper.DISPOSED); + try { + onComplete.run(); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + RxJavaPlugins.onError(e); + } + } + } + + @Override + public void dispose() { + DisposableHelper.dispose(this); + } + + @Override + public boolean isDisposed() { + return get() == DisposableHelper.DISPOSED; + } + + @Override + public boolean hasCustomOnError() { + return onError != Functions.ON_ERROR_MISSING; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/LambdaSubscriber.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/LambdaSubscriber.java new file mode 100644 index 00000000..5776a332 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/LambdaSubscriber.java @@ -0,0 +1,141 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.Flow.Subscription; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +public final class LambdaSubscriber extends AtomicReference + implements FlowableSubscriber, Subscription, Disposable, LambdaConsumerIntrospection { + + @Serial + private static final long serialVersionUID = -7251123623727029452L; + final Consumer onNext; + final Consumer onError; + final Action onComplete; + final Consumer onSubscribe; + + public LambdaSubscriber(Consumer onNext, Consumer onError, + Action onComplete, + Consumer onSubscribe) { + super(); + this.onNext = onNext; + this.onError = onError; + this.onComplete = onComplete; + this.onSubscribe = onSubscribe; + } + + @Override + public void onSubscribe(Subscription s) { + if (SubscriptionHelper.setOnce(this, s)) { + try { + onSubscribe.accept(this); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + s.cancel(); + onError(ex); + } + } + } + + @Override + public void onNext(T t) { + if (!isDisposed()) { + try { + onNext.accept(t); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + get().cancel(); + onError(e); + } + } + } + + @Override + public void onError(Throwable t) { + if (get() != SubscriptionHelper.CANCELLED) { + lazySet(SubscriptionHelper.CANCELLED); + try { + onError.accept(t); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + RxJavaPlugins.onError(new CompositeException(t, e)); + } + } else { + RxJavaPlugins.onError(t); + } + } + + @Override + public void onComplete() { + if (get() != SubscriptionHelper.CANCELLED) { + lazySet(SubscriptionHelper.CANCELLED); + try { + onComplete.run(); + } catch (Throwable e) { + Exceptions.throwIfFatal(e); + RxJavaPlugins.onError(e); + } + } + } + + @Override + public void dispose() { + cancel(); + } + + @Override + public boolean isDisposed() { + return get() == SubscriptionHelper.CANCELLED; + } + + @Override + public void request(long n) { + get().request(n); + } + + @Override + public void cancel() { + SubscriptionHelper.cancel(this); + } + + @Override + public boolean hasCustomOnError() { + return onError != Functions.ON_ERROR_MISSING; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ObjectHelper.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ObjectHelper.java new file mode 100644 index 00000000..30b7c8c9 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ObjectHelper.java @@ -0,0 +1,94 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import io.reactivex.rxjava4.functions.BiPredicate; +import java.util.Objects; + +/** + * Utility methods containing the backport of Java 7's Objects utility class. + *

Named as such to avoid clash with java.util.Objects. + */ +public final class ObjectHelper { + + /** Utility class. */ + private ObjectHelper() { + throw new IllegalStateException("No instances!"); + } + + static final BiPredicate EQUALS = new BiObjectPredicate(); + + /** + * Returns a BiPredicate that compares its parameters via Objects.equals(). + * @param the value type + * @return the bi-predicate instance + */ + @SuppressWarnings("unchecked") + public static BiPredicate equalsPredicate() { + return (BiPredicate)EQUALS; + } + + /** + * Validate that the given value is positive or report an IllegalArgumentException with + * the parameter name. + * @param value the value to validate + * @param paramName the parameter name of the value + * @return value + * @throws IllegalArgumentException if bufferSize <= 0 + */ + public static int verifyPositive(int value, String paramName) { + if (value <= 0) { + throw new IllegalArgumentException(paramName + " > 0 required but it was " + value); + } + return value; + } + + /** + * Validate that the given value is positive or report an IllegalArgumentException with + * the parameter name. + * @param value the value to validate + * @param paramName the parameter name of the value + * @return value + * @throws IllegalArgumentException if bufferSize <= 0 + */ + public static long verifyPositive(long value, String paramName) { + if (value <= 0L) { + throw new IllegalArgumentException(paramName + " > 0 required but it was " + value); + } + return value; + } + + static final class BiObjectPredicate implements BiPredicate { + @Override + public boolean test(Object o1, Object o2) { + return Objects.equals(o1, o2); + } + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ObservableQueueDrain.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ObservableQueueDrain.java new file mode 100644 index 00000000..0433fe4e --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ObservableQueueDrain.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import io.reactivex.rxjava4.core.Observer; + +public interface ObservableQueueDrain { + + boolean cancelled(); + + boolean done(); + + Throwable error(); + + boolean enter(); + + /** + * Adds m to the wip counter. + * @param m the value to add + * @return the wip value after adding the value + */ + int leave(int m); + + /** + * Accept the value and return true if forwarded. + * @param observer the subscriber to deliver values to + * @param value the value to deliver + */ + void accept(Observer observer, T value); +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/OpenHashSet.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/OpenHashSet.java new file mode 100644 index 00000000..60696f94 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/OpenHashSet.java @@ -0,0 +1,190 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +/* + * Inspired by fastutils' OpenHashSet implementation at + * https://github.com/vigna/fastutil/blob/master/drv/OpenHashSet.drv + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +/** + * A simple open hash set with add, remove and clear capabilities only. + *

Doesn't support nor checks for {@code null}s. + * + * @param the element type + */ +public final class OpenHashSet { + private static final int INT_PHI = 0x9E3779B9; + + final float loadFactor; + int mask; + int size; + int maxSize; + T[] keys; + + public OpenHashSet() { + this(16, 0.75f); + } + + /** + * Creates an OpenHashSet with the initial capacity and load factor of 0.75f. + * @param capacity the initial capacity + */ + public OpenHashSet(int capacity) { + this(capacity, 0.75f); + } + + @SuppressWarnings("unchecked") + public OpenHashSet(int capacity, float loadFactor) { + this.loadFactor = loadFactor; + int c = Pow2.roundToPowerOfTwo(capacity); + this.mask = c - 1; + this.maxSize = (int)(loadFactor * c); + this.keys = (T[])new Object[c]; + } + + public boolean add(T value) { + final T[] a = keys; + final int m = mask; + + int pos = mix(value.hashCode()) & m; + T curr = a[pos]; + if (curr != null) { + if (curr.equals(value)) { + return false; + } + for (;;) { + pos = (pos + 1) & m; + curr = a[pos]; + if (curr == null) { + break; + } + if (curr.equals(value)) { + return false; + } + } + } + a[pos] = value; + if (++size >= maxSize) { + rehash(); + } + return true; + } + public boolean remove(T value) { + T[] a = keys; + int m = mask; + int pos = mix(value.hashCode()) & m; + T curr = a[pos]; + if (curr == null) { + return false; + } + if (curr.equals(value)) { + return removeEntry(pos, a, m); + } + for (;;) { + pos = (pos + 1) & m; + curr = a[pos]; + if (curr == null) { + return false; + } + if (curr.equals(value)) { + return removeEntry(pos, a, m); + } + } + } + + boolean removeEntry(int pos, T[] a, int m) { + size--; + + int last; + int slot; + T curr; + for (;;) { + last = pos; + pos = (pos + 1) & m; + for (;;) { + curr = a[pos]; + if (curr == null) { + a[last] = null; + return true; + } + slot = mix(curr.hashCode()) & m; + + if (last <= pos ? last >= slot || slot > pos : last >= slot && slot > pos) { + break; + } + + pos = (pos + 1) & m; + } + a[last] = curr; + } + } + + @SuppressWarnings("unchecked") + void rehash() { + T[] a = keys; + int i = a.length; + int newCap = i << 1; + int m = newCap - 1; + + T[] b = (T[])new Object[newCap]; + + for (int j = size; j-- != 0; ) { + while (a[--i] == null) { } // NOPMD + int pos = mix(a[i].hashCode()) & m; + if (b[pos] != null) { + for (;;) { + pos = (pos + 1) & m; + if (b[pos] == null) { + break; + } + } + } + b[pos] = a[i]; + } + + this.mask = m; + this.maxSize = (int)(newCap * loadFactor); + this.keys = b; + } + + static int mix(int x) { + final int h = x * INT_PHI; + return h ^ (h >>> 16); + } + + public Object[] keys() { + return keys; // NOPMD + } + + public int size() { + return size; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/Pow2.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/Pow2.java new file mode 100644 index 00000000..b99e68b0 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/Pow2.java @@ -0,0 +1,62 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +/* + * Original License: https://github.com/JCTools/JCTools/blob/master/LICENSE + * Original location: https://github.com/JCTools/JCTools/blob/master/jctools-core/src/main/java/org/jctools/util/Pow2.java + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +public final class Pow2 { + private Pow2() { + throw new IllegalStateException("No instances!"); + } + + /** + * Find the next larger positive power of two value up from the given value. If value is a power of two then + * this value will be returned. + * + * @param value from which next positive power of two will be found. + * @return the next positive power of 2 or this value if it is a power of 2. + */ + public static int roundToPowerOfTwo(final int value) { + return 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); + } + + /** + * Is this value a power of two. + * + * @param value to be tested to see if it is a power of two. + * @return true if the value is a power of 2 otherwise false. + */ + public static boolean isPowerOfTwo(final int value) { + return (value & (value - 1)) == 0; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/QueueDrain.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/QueueDrain.java new file mode 100644 index 00000000..420f6e76 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/QueueDrain.java @@ -0,0 +1,62 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import static java.util.concurrent.Flow.*; + +public interface QueueDrain { + + boolean cancelled(); + + boolean done(); + + Throwable error(); + + boolean enter(); + + long requested(); + + long produced(long n); + + /** + * Adds m to the wip counter. + * @param m the value to add + * @return the current value after adding m + */ + int leave(int m); + + /** + * Accept the value and return true if forwarded. + * @param subscriber the subscriber + * @param value the value + * @return true if the value was delivered + */ + boolean accept(Subscriber subscriber, T value); +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/QueueDrainHelper.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/QueueDrainHelper.java new file mode 100644 index 00000000..6e0c1069 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/QueueDrainHelper.java @@ -0,0 +1,445 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.Queue; +import java.util.concurrent.Flow.*; +import java.util.concurrent.atomic.AtomicLong; + +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.BooleanSupplier; +import io.reactivex.rxjava4.operators.*; + +/** + * Utility class to help with the queue-drain serialization idiom. + */ +public final class QueueDrainHelper { + /** Utility class. */ + private QueueDrainHelper() { + throw new IllegalStateException("No instances!"); + } + + /** + * Drain the queue but give up with an error if there aren't enough requests. + * @param the queue value type + * @param the emission value type + * @param q the queue + * @param subscriber the subscriber + * @param delayError true if errors should be delayed after all normal items + * @param dispose the disposable to call when termination happens and cleanup is necessary + * @param qd the QueueDrain instance that gives status information to the drain logic + */ + public static void drainMaxLoop(SimplePlainQueue q, Subscriber subscriber, boolean delayError, + Disposable dispose, QueueDrain qd) { + int missed = 1; + + for (;;) { + for (;;) { + boolean d = qd.done(); + + T v = q.poll(); + + boolean empty = v == null; + + if (checkTerminated(d, empty, subscriber, delayError, q, qd)) { + if (dispose != null) { + dispose.dispose(); + } + return; + } + + if (empty) { + break; + } + + long r = qd.requested(); + if (r != 0L) { + if (qd.accept(subscriber, v)) { + if (r != Long.MAX_VALUE) { + qd.produced(1); + } + } + } else { + q.clear(); + if (dispose != null) { + dispose.dispose(); + } + subscriber.onError(MissingBackpressureException.createDefault()); + return; + } + } + + missed = qd.leave(-missed); + if (missed == 0) { + break; + } + } + } + + public static boolean checkTerminated(boolean d, boolean empty, + Subscriber s, boolean delayError, SimpleQueue q, QueueDrain qd) { + if (qd.cancelled()) { + q.clear(); + return true; + } + + if (d) { + if (delayError) { + if (empty) { + Throwable err = qd.error(); + if (err != null) { + s.onError(err); + } else { + s.onComplete(); + } + return true; + } + } else { + Throwable err = qd.error(); + if (err != null) { + q.clear(); + s.onError(err); + return true; + } else + if (empty) { + s.onComplete(); + return true; + } + } + } + + return false; + } + + public static void drainLoop(SimplePlainQueue q, Observer a, boolean delayError, Disposable dispose, ObservableQueueDrain qd) { + + int missed = 1; + + for (;;) { + if (checkTerminated(qd.done(), q.isEmpty(), a, delayError, q, dispose, qd)) { + return; + } + + for (;;) { + boolean d = qd.done(); + T v = q.poll(); + boolean empty = v == null; + + if (checkTerminated(d, empty, a, delayError, q, dispose, qd)) { + return; + } + + if (empty) { + break; + } + + qd.accept(a, v); + } + + missed = qd.leave(-missed); + if (missed == 0) { + break; + } + } + } + + public static boolean checkTerminated(boolean d, boolean empty, + Observer observer, boolean delayError, SimpleQueue q, Disposable disposable, ObservableQueueDrain qd) { + if (qd.cancelled()) { + q.clear(); + disposable.dispose(); + return true; + } + + if (d) { + if (delayError) { + if (empty) { + if (disposable != null) { + disposable.dispose(); + } + Throwable err = qd.error(); + if (err != null) { + observer.onError(err); + } else { + observer.onComplete(); + } + return true; + } + } else { + Throwable err = qd.error(); + if (err != null) { + q.clear(); + if (disposable != null) { + disposable.dispose(); + } + observer.onError(err); + return true; + } else + if (empty) { + if (disposable != null) { + disposable.dispose(); + } + observer.onComplete(); + return true; + } + } + } + + return false; + } + + /** + * Creates a queue: spsc-array if capacityHint is positive and + * spsc-linked-array if capacityHint is negative; in both cases, the + * capacity is the absolute value of prefetch. + * @param the value type of the queue + * @param capacityHint the capacity hint, negative value will create an array-based SPSC queue + * @return the queue instance + */ + public static SimpleQueue createQueue(int capacityHint) { + if (capacityHint < 0) { + return new SpscLinkedArrayQueue<>(-capacityHint); + } + return new SpscArrayQueue<>(capacityHint); + } + + /** + * Requests {@link Long#MAX_VALUE} if prefetch is negative or the exact + * amount if prefetch is positive. + * @param s the Subscription to request from + * @param prefetch the prefetch value + */ + public static void request(Subscription s, int prefetch) { + s.request(prefetch < 0 ? Long.MAX_VALUE : prefetch); + } + + static final long COMPLETED_MASK = 0x8000000000000000L; + static final long REQUESTED_MASK = 0x7FFFFFFFFFFFFFFFL; + + /** + * Accumulates requests (not validated) and handles the completed mode draining of the queue based on the requests. + * + *

+ * Post-completion backpressure handles the case when a source produces values based on + * requests when it is active but more values are available even after its completion. + * In this case, the onComplete() can't just emit the contents of the queue but has to + * coordinate with the requested amounts. This requires two distinct modes: active and + * completed. In active mode, requests flow through and the queue is not accessed but + * in completed mode, requests no-longer reach the upstream but help in draining the queue. + * + * @param the value type emitted + * @param n the request amount, positive (not validated) + * @param downstream the target Subscriber to send events to + * @param queue the queue to drain if in the post-complete state + * @param state holds the request amount and the post-completed flag + * @param isCancelled a supplier that returns true if the drain has been cancelled + * @return true if the state indicates a completion state. + */ + public static boolean postCompleteRequest(long n, + Subscriber downstream, + Queue queue, + AtomicLong state, + BooleanSupplier isCancelled) { + for (; ; ) { + long r = state.get(); + + // extract the current request amount + long r0 = r & REQUESTED_MASK; + + // preserve COMPLETED_MASK and calculate new requested amount + long u = (r & COMPLETED_MASK) | BackpressureHelper.addCap(r0, n); + + if (state.compareAndSet(r, u)) { + // (complete, 0) -> (complete, n) transition then replay + if (r == COMPLETED_MASK) { + + postCompleteDrain(n | COMPLETED_MASK, downstream, queue, state, isCancelled); + + return true; + } + // (active, r) -> (active, r + n) transition then continue with requesting from upstream + return false; + } + } + + } + + static boolean isCancelled(BooleanSupplier cancelled) { + try { + return cancelled.getAsBoolean(); + } catch (Throwable ex) { + Exceptions.throwIfFatal(ex); + return true; + } + } + + /** + * Drains the queue based on the outstanding requests in post-completed mode (only!). + * + * @param the value type + * @param n the current request amount + * @param downstream the target Subscriber to send events to + * @param queue the queue to drain if in the post-complete state + * @param state holds the request amount and the post-completed flag + * @param isCancelled a supplier that returns true if the drain has been cancelled + * @return true if the queue was completely drained or the drain process was cancelled + */ + static boolean postCompleteDrain(long n, + Subscriber downstream, + Queue queue, + AtomicLong state, + BooleanSupplier isCancelled) { + +// TODO enable fast-path +// if (n == -1 || n == Long.MAX_VALUE) { +// for (;;) { +// if (isCancelled.getAsBoolean()) { +// break; +// } +// +// T v = queue.poll(); +// +// if (v == null) { +// actual.onComplete(); +// break; +// } +// +// actual.onNext(v); +// } +// +// return true; +// } + + long e = n & COMPLETED_MASK; + + for (; ; ) { + + while (e != n) { + if (isCancelled(isCancelled)) { + return true; + } + + T t = queue.poll(); + + if (t == null) { + downstream.onComplete(); + return true; + } + + downstream.onNext(t); + e++; + } + + if (isCancelled(isCancelled)) { + return true; + } + + if (queue.isEmpty()) { + downstream.onComplete(); + return true; + } + + n = state.get(); + + if (n == e) { + + n = state.addAndGet(-(e & REQUESTED_MASK)); + + if ((n & REQUESTED_MASK) == 0L) { + return false; + } + + e = n & COMPLETED_MASK; + } + } + + } + + /** + * Signals the completion of the main sequence and switches to post-completion replay mode. + * + *

+ * Don't modify the queue after calling this method! + * + *

+ * Post-completion backpressure handles the case when a source produces values based on + * requests when it is active but more values are available even after its completion. + * In this case, the onComplete() can't just emit the contents of the queue but has to + * coordinate with the requested amounts. This requires two distinct modes: active and + * completed. In active mode, requests flow through and the queue is not accessed but + * in completed mode, requests no-longer reach the upstream but help in draining the queue. + *

+ * The algorithm utilizes the most significant bit (bit 63) of a long value (AtomicLong) since + * request amount only goes up to {@link Long#MAX_VALUE} (bits 0-62) and negative values aren't + * allowed. + * + * @param the value type emitted + * @param downstream the target Subscriber to send events to + * @param queue the queue to drain if in the post-complete state + * @param state holds the request amount and the post-completed flag + * @param isCancelled a supplier that returns true if the drain has been cancelled + */ + public static void postComplete(Subscriber downstream, + Queue queue, + AtomicLong state, + BooleanSupplier isCancelled) { + + if (queue.isEmpty()) { + downstream.onComplete(); + return; + } + + if (postCompleteDrain(state.get(), downstream, queue, state, isCancelled)) { + return; + } + + for (; ; ) { + long r = state.get(); + + if ((r & COMPLETED_MASK) != 0L) { + return; + } + + long u = r | COMPLETED_MASK; + // (active, r) -> (complete, r) transition + if (state.compareAndSet(r, u)) { + // if the requested amount was non-zero, drain the queue + if (r != 0L) { + postCompleteDrain(u, downstream, queue, state, isCancelled); + } + + return; + } + } + + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ScalarSubscription.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ScalarSubscription.java new file mode 100644 index 00000000..84a5b995 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/ScalarSubscription.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicInteger; + +import static java.util.concurrent.Flow.*; + +import io.reactivex.rxjava4.annotations.Nullable; +import io.reactivex.rxjava4.operators.QueueSubscription; + +/** + * A Subscription that holds a constant value and emits it only when requested. + * @param the value type + */ +public final class ScalarSubscription extends AtomicInteger implements QueueSubscription { + + @Serial + private static final long serialVersionUID = -3830916580126663321L; + /** The single value to emit, set to null. */ + final T value; + /** The actual subscriber. */ + final Subscriber subscriber; + + /** No request has been issued yet. */ + static final int NO_REQUEST = 0; + /** Request has been called.*/ + static final int REQUESTED = 1; + /** Cancel has been called. */ + static final int CANCELLED = 2; + + public ScalarSubscription(Subscriber subscriber, T value) { + this.subscriber = subscriber; + this.value = value; + } + + @Override + public void request(long n) { + if (!SubscriptionHelper.validate(n)) { + return; + } + if (compareAndSet(NO_REQUEST, REQUESTED)) { + Subscriber s = subscriber; + + s.onNext(value); + if (get() != CANCELLED) { + s.onComplete(); + } + } + + } + + @Override + public void cancel() { + lazySet(CANCELLED); + } + + /** + * Returns true if this Subscription was cancelled. + * @return true if this Subscription was cancelled + */ + public boolean isCancelled() { + return get() == CANCELLED; + } + + @Override + public boolean offer(T e) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Override + public boolean offer(T v1, T v2) { + throw new UnsupportedOperationException("Should not be called!"); + } + + @Nullable + @Override + public T poll() { + if (get() == NO_REQUEST) { + lazySet(REQUESTED); + return value; + } + return null; + } + + @Override + public boolean isEmpty() { + return get() != NO_REQUEST; + } + + @Override + public void clear() { + lazySet(1); + } + + @Override + public int requestFusion(int mode) { + return mode & SYNC; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SequentialDisposable.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SequentialDisposable.java new file mode 100644 index 00000000..379db346 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SequentialDisposable.java @@ -0,0 +1,97 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.rxjava4.disposables.Disposable; + +/** + * A Disposable container that allows updating/replacing a Disposable + * atomically and with respect of disposing the container itself. + *

+ * The class extends AtomicReference directly so watch out for the API leak! + * @since 2.0 + */ +public final class SequentialDisposable +extends AtomicReference +implements Disposable { + + @Serial + private static final long serialVersionUID = -754898800686245608L; + + /** + * Constructs an empty SequentialDisposable. + */ + public SequentialDisposable() { + // nothing to do + } + + /** + * Construct a SequentialDisposable with the initial Disposable provided. + * @param initial the initial disposable, null allowed + */ + public SequentialDisposable(Disposable initial) { + lazySet(initial); + } + + /** + * Atomically: set the next disposable on this container and dispose the previous + * one (if any) or dispose next if the container has been disposed. + * @param next the Disposable to set, may be null + * @return true if the operation succeeded, false if the container has been disposed + * @see #replace(Disposable) + */ + public boolean update(Disposable next) { + return DisposableHelper.set(this, next); + } + + /** + * Atomically: set the next disposable on this container but don't dispose the previous + * one (if any) or dispose next if the container has been disposed. + * @param next the Disposable to set, may be null + * @return true if the operation succeeded, false if the container has been disposed + * @see #update(Disposable) + */ + public boolean replace(Disposable next) { + return DisposableHelper.replace(this, next); + } + + @Override + public void dispose() { + DisposableHelper.dispose(this); + } + + @Override + public boolean isDisposed() { + return DisposableHelper.isDisposed(get()); + } +} diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SubscriptionArbiter.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SubscriptionArbiter.java new file mode 100644 index 00000000..3af429cd --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SubscriptionArbiter.java @@ -0,0 +1,288 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.io.Serial; +import java.util.Objects; +import java.util.concurrent.Flow.Subscription; +import java.util.concurrent.atomic.*; + +/** + * Arbitrates requests and cancellation between Subscriptions. + */ +public class SubscriptionArbiter extends AtomicInteger implements Subscription { + + @Serial + private static final long serialVersionUID = -2189523197179400958L; + + /** + * The current subscription which may null if no Subscriptions have been set. + */ + Subscription actual; + + /** + * The current outstanding request amount. + */ + long requested; + + final AtomicReference missedSubscription; + + final AtomicLong missedRequested; + + final AtomicLong missedProduced; + + final boolean cancelOnReplace; + + volatile boolean cancelled; + + protected boolean unbounded; + + public SubscriptionArbiter(boolean cancelOnReplace) { + this.cancelOnReplace = cancelOnReplace; + missedSubscription = new AtomicReference<>(); + missedRequested = new AtomicLong(); + missedProduced = new AtomicLong(); + } + + /** + * Atomically sets a new subscription. + * @param s the subscription to set, not null (verified) + */ + public final void setSubscription(Subscription s) { + if (cancelled) { + s.cancel(); + return; + } + + Objects.requireNonNull(s, "s is null"); + + if (get() == 0 && compareAndSet(0, 1)) { + Subscription a = actual; + + if (a != null && cancelOnReplace) { + a.cancel(); + } + + actual = s; + + long r = requested; + + if (decrementAndGet() != 0) { + drainLoop(); + } + + if (r != 0L) { + s.request(r); + } + + return; + } + + Subscription a = missedSubscription.getAndSet(s); + if (a != null && cancelOnReplace) { + a.cancel(); + } + drain(); + } + + @Override + public final void request(long n) { + if (SubscriptionHelper.validate(n)) { + if (unbounded) { + return; + } + if (get() == 0 && compareAndSet(0, 1)) { + long r = requested; + + if (r != Long.MAX_VALUE) { + r = BackpressureHelper.addCap(r, n); + requested = r; + if (r == Long.MAX_VALUE) { + unbounded = true; + } + } + Subscription a = actual; + + if (decrementAndGet() != 0) { + drainLoop(); + } + + if (a != null) { + a.request(n); + } + + return; + } + + BackpressureHelper.add(missedRequested, n); + + drain(); + } + } + + public final void produced(long n) { + if (unbounded) { + return; + } + if (get() == 0 && compareAndSet(0, 1)) { + long r = requested; + + if (r != Long.MAX_VALUE) { + long u = r - n; + if (u < 0L) { + SubscriptionHelper.reportMoreProduced(u); + u = 0; + } + requested = u; + } + + if (decrementAndGet() == 0) { + return; + } + + drainLoop(); + + return; + } + + BackpressureHelper.add(missedProduced, n); + + drain(); + } + + @Override + public void cancel() { + if (!cancelled) { + cancelled = true; + + drain(); + } + } + + final void drain() { + if (getAndIncrement() != 0) { + return; + } + drainLoop(); + } + + final void drainLoop() { + int missed = 1; + + long requestAmount = 0L; + Subscription requestTarget = null; + + for (; ; ) { + + Subscription ms = missedSubscription.get(); + + if (ms != null) { + ms = missedSubscription.getAndSet(null); + } + + long mr = missedRequested.get(); + if (mr != 0L) { + mr = missedRequested.getAndSet(0L); + } + + long mp = missedProduced.get(); + if (mp != 0L) { + mp = missedProduced.getAndSet(0L); + } + + Subscription a = actual; + + if (cancelled) { + if (a != null) { + a.cancel(); + actual = null; + } + if (ms != null) { + ms.cancel(); + } + } else { + long r = requested; + if (r != Long.MAX_VALUE) { + long u = BackpressureHelper.addCap(r, mr); + + if (u != Long.MAX_VALUE) { + long v = u - mp; + if (v < 0L) { + SubscriptionHelper.reportMoreProduced(v); + v = 0; + } + r = v; + } else { + r = u; + } + requested = r; + } + + if (ms != null) { + if (a != null && cancelOnReplace) { + a.cancel(); + } + actual = ms; + if (r != 0L) { + requestAmount = BackpressureHelper.addCap(requestAmount, r); + requestTarget = ms; + } + } else if (a != null && mr != 0L) { + requestAmount = BackpressureHelper.addCap(requestAmount, mr); + requestTarget = a; + } + } + + missed = addAndGet(-missed); + if (missed == 0) { + if (requestAmount != 0L) { + requestTarget.request(requestAmount); + } + return; + } + } + } + + /** + * Returns true if the arbiter runs in unbounded mode. + * @return true if the arbiter runs in unbounded mode + */ + public final boolean isUnbounded() { + return unbounded; + } + + /** + * Returns true if the arbiter has been cancelled. + * @return true if the arbiter has been cancelled + */ + public final boolean isCancelled() { + return cancelled; + } +} \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SubscriptionHelper.java b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SubscriptionHelper.java new file mode 100644 index 00000000..9c9aeabd --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/internal/rxcopy/SubscriptionHelper.java @@ -0,0 +1,268 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package hu.akarnokd.rxjava4.internal.rxcopy; + +import java.util.Objects; +import java.util.concurrent.Flow.Subscription; +import java.util.concurrent.atomic.*; + +import io.reactivex.rxjava4.exceptions.ProtocolViolationException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Utility methods to validate Subscriptions in the various onSubscribe calls. + */ +public enum SubscriptionHelper implements Subscription { + /** + * Represents a cancelled Subscription. + *

Don't leak this instance! + */ + CANCELLED + ; + + @Override + public void request(long n) { + // deliberately ignored + } + + @Override + public void cancel() { + // deliberately ignored + } + + /** + * Verifies that current is null, next is not null, otherwise signals errors + * to the RxJavaPlugins and returns false. + * @param current the current Subscription, expected to be null + * @param next the next Subscription, expected to be non-null + * @return true if the validation succeeded + */ + public static boolean validate(Subscription current, Subscription next) { + if (next == null) { + RxJavaPlugins.onError(new NullPointerException("next is null")); + return false; + } + if (current != null) { + next.cancel(); + reportSubscriptionSet(); + return false; + } + return true; + } + + /** + * Reports that the subscription is already set to the RxJavaPlugins error handler, + * which is an indication of a onSubscribe management bug. + */ + public static void reportSubscriptionSet() { + RxJavaPlugins.onError(new ProtocolViolationException("Subscription already set!")); + } + + /** + * Validates that the n is positive. + * @param n the request amount + * @return false if n is non-positive. + */ + public static boolean validate(long n) { + if (n <= 0) { + RxJavaPlugins.onError(new IllegalArgumentException("n > 0 required but it was " + n)); + return false; + } + return true; + } + + /** + * Reports to the plugin error handler that there were more values produced than requested, which + * is a sign of internal backpressure handling bug. + * @param n the overproduction amount + */ + public static void reportMoreProduced(long n) { + RxJavaPlugins.onError(new ProtocolViolationException("More produced than requested: " + n)); + } + + /** + * Atomically sets the subscription on the field and cancels the + * previous subscription if any. + * @param field the target field to set the new subscription on + * @param s the new subscription + * @return true if the operation succeeded, false if the target field + * holds the {@link #CANCELLED} instance. + * @see #replace(AtomicReference, Subscription) + */ + public static boolean set(AtomicReference field, Subscription s) { + for (;;) { + Subscription current = field.get(); + if (current == CANCELLED) { + if (s != null) { + s.cancel(); + } + return false; + } + if (field.compareAndSet(current, s)) { + if (current != null) { + current.cancel(); + } + return true; + } + } + } + + /** + * Atomically sets the subscription on the field if it is still null. + *

If the field is not null and doesn't contain the {@link #CANCELLED} + * instance, the {@link #reportSubscriptionSet()} is called. + * @param field the target field + * @param s the new subscription to set + * @return true if the operation succeeded, false if the target field was not null. + */ + public static boolean setOnce(AtomicReference field, Subscription s) { + Objects.requireNonNull(s, "s is null"); + if (!field.compareAndSet(null, s)) { + s.cancel(); + if (field.get() != CANCELLED) { + reportSubscriptionSet(); + } + return false; + } + return true; + } + + /** + * Atomically sets the subscription on the field but does not + * cancel the previous subscription. + * @param field the target field to set the new subscription on + * @param s the new subscription + * @return true if the operation succeeded, false if the target field + * holds the {@link #CANCELLED} instance. + * @see #set(AtomicReference, Subscription) + */ + public static boolean replace(AtomicReference field, Subscription s) { + for (;;) { + Subscription current = field.get(); + if (current == CANCELLED) { + if (s != null) { + s.cancel(); + } + return false; + } + if (field.compareAndSet(current, s)) { + return true; + } + } + } + + /** + * Atomically swaps in the common cancelled subscription instance + * and cancels the previous subscription if any. + * @param field the target field to dispose the contents of + * @return true if the swap from the non-cancelled instance to the + * common cancelled instance happened in the caller's thread (allows + * further one-time actions). + */ + public static boolean cancel(AtomicReference field) { + Subscription current = field.get(); + if (current != CANCELLED) { + current = field.getAndSet(CANCELLED); + if (current != CANCELLED) { + if (current != null) { + current.cancel(); + } + return true; + } + } + return false; + } + + /** + * Atomically sets the new Subscription on the field and requests any accumulated amount + * from the requested field. + * @param field the target field for the new Subscription + * @param requested the current requested amount + * @param s the new Subscription, not null (verified) + * @return true if the Subscription was set the first time + */ + public static boolean deferredSetOnce(AtomicReference field, AtomicLong requested, + Subscription s) { + if (SubscriptionHelper.setOnce(field, s)) { + long r = requested.getAndSet(0L); + if (r != 0L) { + s.request(r); + } + return true; + } + return false; + } + + /** + * Atomically requests from the Subscription in the field if not null, otherwise accumulates + * the request amount in the requested field to be requested once the field is set to non-null. + * @param field the target field that may already contain a Subscription + * @param requested the current requested amount + * @param n the request amount, positive (verified) + */ + public static void deferredRequest(AtomicReference field, AtomicLong requested, long n) { + Subscription s = field.get(); + if (s != null) { + s.request(n); + } else { + if (SubscriptionHelper.validate(n)) { + BackpressureHelper.add(requested, n); + + s = field.get(); + if (s != null) { + long r = requested.getAndSet(0L); + if (r != 0L) { + s.request(r); + } + } + } + } + } + + /** + * Atomically sets the subscription on the field if it is still null and issues a positive request + * to the given {@link Subscription}. + *

+ * If the field is not null and doesn't contain the {@link #CANCELLED} + * instance, the {@link #reportSubscriptionSet()} is called. + * @param field the target field + * @param s the new subscription to set + * @param request the amount to request, positive (not verified) + * @return true if the operation succeeded, false if the target field was not null. + * @since 2.1.11 + */ + public static boolean setOnce(AtomicReference field, Subscription s, long request) { + if (setOnce(field, s)) { + s.request(request); + return true; + } + return false; + } +} diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan0.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan0.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan0.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan0.java index bfaba70d..ed1593ca 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan0.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan0.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Represents an activated plan. */ abstract class ActivePlan0 { - protected final Map joinObservers = new HashMap(); + protected final Map joinObservers = new HashMap<>(); - protected abstract void match() throws Exception; + protected abstract void match() throws Throwable; protected void addJoinObserver(JoinObserver joinObserver) { joinObservers.put(joinObserver, joinObserver); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan1.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan1.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan1.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan1.java index 8f1c0db0..7bcab1a9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan1.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan1.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Notification; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.*; /** * Represents an active plan. @@ -36,7 +36,7 @@ final class ActivePlan1 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty()) { Notification n1 = jo1.queue().peek(); if (n1.isOnComplete()) { diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan2.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan2.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan2.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan2.java index f137324d..591cd04d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan2.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan2.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Notification; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.*; /** * Represents an active plan. @@ -40,7 +40,7 @@ final class ActivePlan2 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty()) { Notification n1 = jo1.queue().peek(); Notification n2 = jo2.queue().peek(); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan3.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan3.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan3.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan3.java index 8930a168..f68d785c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan3.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan3.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer3; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.*; /** * Represents an active plan. @@ -49,7 +48,7 @@ final class ActivePlan3 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!first.queue().isEmpty() && !second.queue().isEmpty() && !third.queue().isEmpty()) { diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan4.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan4.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan4.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan4.java index b0e2b3ab..fffd3c90 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan4.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer4; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import hu.akarnokd.rxjava4.functions.Consumer4; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.Action; /** * Represents an active plan. @@ -55,7 +55,7 @@ final class ActivePlan4 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty() && !jo3.queue().isEmpty() diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan5.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan5.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan5.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan5.java index 3a657e45..8ced9d2c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan5.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan5.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer5; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import hu.akarnokd.rxjava4.functions.Consumer5; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.Action; /** * Represents an active plan. @@ -60,7 +60,7 @@ final class ActivePlan5 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty() && !jo3.queue().isEmpty() diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan6.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan6.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan6.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan6.java index 319fb1e3..85fceaa3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan6.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan6.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer6; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import hu.akarnokd.rxjava4.functions.Consumer6; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.Action; /** * Represents an active plan. @@ -65,7 +65,7 @@ final class ActivePlan6 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty() && !jo3.queue().isEmpty() diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan7.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan7.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan7.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan7.java index 2081aea7..e5260c6f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan7.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan7.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer7; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import hu.akarnokd.rxjava4.functions.Consumer7; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.Action; /** * Represents an active plan. @@ -70,7 +70,7 @@ final class ActivePlan7 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty() && !jo3.queue().isEmpty() diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan8.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan8.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan8.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan8.java index 4d574406..d3c5cb14 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan8.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan8.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer8; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import hu.akarnokd.rxjava4.functions.Consumer8; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.Action; /** * Represents an active plan. @@ -75,7 +75,7 @@ final class ActivePlan8 extends ActivePlan0 { } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty() && !jo3.queue().isEmpty() diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan9.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan9.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan9.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan9.java index 75953106..38013b8d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlan9.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlan9.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import hu.akarnokd.rxjava2.functions.Consumer9; -import io.reactivex.Notification; -import io.reactivex.functions.Action; +import hu.akarnokd.rxjava4.functions.Consumer9; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.Action; /** * Represents an active plan. @@ -80,7 +80,7 @@ final class ActivePlan9 extends ActivePlan0 } @Override - protected void match() throws Exception { + protected void match() throws Throwable { if (!jo1.queue().isEmpty() && !jo2.queue().isEmpty() && !jo3.queue().isEmpty() diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlanN.java b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlanN.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/joins/ActivePlanN.java rename to src/main/java/hu/akarnokd/rxjava4/joins/ActivePlanN.java index 381ebb0c..b9bd8417 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/ActivePlanN.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/ActivePlanN.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.*; -import io.reactivex.Notification; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.functions.*; /** * Represents an active plan. @@ -34,14 +34,14 @@ final class ActivePlanN extends ActivePlan0 { Action onCompleted) { this.onNext = onNext; this.onCompleted = onCompleted; - this.observers = new ArrayList>(observers); + this.observers = new ArrayList<>(observers); for (JoinObserver1 jo : this.observers) { addJoinObserver(jo); } } @Override - protected void match() throws Exception { + protected void match() throws Throwable { Object[] notifications = new Object[this.observers.size()]; int j = 0; int completedCount = 0; diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/JoinObservable.java b/src/main/java/hu/akarnokd/rxjava4/joins/JoinObservable.java similarity index 96% rename from src/main/java/hu/akarnokd/rxjava2/joins/JoinObservable.java rename to src/main/java/hu/akarnokd/rxjava4/joins/JoinObservable.java index b3928f0e..f09832f9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/JoinObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/JoinObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function; -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Represents an observable that supports join operations. @@ -40,7 +40,7 @@ private JoinObservable(Observable o) { * @return the created JoinObservable instance */ public static JoinObservable from(Observable o) { - return new JoinObservable(RxJavaPlugins.onAssembly(o)); + return new JoinObservable<>(RxJavaPlugins.onAssembly(o)); } /** @@ -96,6 +96,7 @@ public static JoinObservable when(Iterable> plans) { * @see RxJava Wiki: when() * @see MSDN: Observable.When */ + @SafeVarargs public static JoinObservable when(Plan... plans) { return from(JoinPatterns.when(plans)); } @@ -112,7 +113,6 @@ public static JoinObservable when(Plan... plans) { * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1) { return from(JoinPatterns.when(p1)); } @@ -131,7 +131,6 @@ public static JoinObservable when(Plan p1) { * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2) { return from(JoinPatterns.when(p1, p2)); } @@ -152,7 +151,6 @@ public static JoinObservable when(Plan p1, Plan p2) { * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3) { return from(JoinPatterns.when(p1, p2, p3)); } @@ -175,7 +173,6 @@ public static JoinObservable when(Plan p1, Plan p2, Plan p3) { * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4) { return from(JoinPatterns.when(p1, p2, p3, p4)); } @@ -200,7 +197,6 @@ public static JoinObservable when(Plan p1, Plan p2, Plan p3, Pla * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5) { return from(JoinPatterns.when(p1, p2, p3, p4, p5)); } @@ -227,7 +223,6 @@ public static JoinObservable when(Plan p1, Plan p2, Plan p3, Pla * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6)); } @@ -256,7 +251,6 @@ public static JoinObservable when(Plan p1, Plan p2, Plan p3, Pla * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6, Plan p7) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6, p7)); } @@ -287,7 +281,6 @@ public static JoinObservable when(Plan p1, Plan p2, Plan p3, Pla * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6, Plan p7, Plan p8) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8)); } @@ -320,7 +313,6 @@ public static JoinObservable when(Plan p1, Plan p2, Plan p3, Pla * @see RxJava Wiki: when() * @see MSDN: Observable.When */ - @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6, Plan p7, Plan p8, Plan p9) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8, p9)); } @@ -344,6 +336,10 @@ public Plan then(Function selector) { return JoinPatterns.then(o, selector); } + /** + * Returns the internal {@code Observable}. + * @return the internal {@code Observable}. + */ public Observable toObservable() { return o; } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/JoinObserver.java b/src/main/java/hu/akarnokd/rxjava4/joins/JoinObserver.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/joins/JoinObserver.java rename to src/main/java/hu/akarnokd/rxjava4/joins/JoinObserver.java index 42931760..1b2d6db3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/JoinObserver.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/JoinObserver.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.disposables.Disposable; +import io.reactivex.rxjava4.disposables.Disposable; /** * Base interface to manage joined observations. diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/JoinObserver1.java b/src/main/java/hu/akarnokd/rxjava4/joins/JoinObserver1.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/joins/JoinObserver1.java rename to src/main/java/hu/akarnokd/rxjava4/joins/JoinObserver1.java index aa0d85fb..54733df6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/JoinObserver1.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/JoinObserver1.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.*; import java.util.concurrent.atomic.*; -import io.reactivex.Notification; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.*; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.Notification; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Default implementation of a join observer. @@ -44,8 +44,8 @@ final class JoinObserver1 implements Observer>, JoinObserver JoinObserver1(Observable source, Consumer onError) { this.source = source; this.onError = onError; - queue = new LinkedList>(); - activePlans = new ArrayList(); + queue = new LinkedList<>(); + activePlans = new ArrayList<>(); safeObserver = new InnerObserver(); // add this subscription so it gets unsubscribed when the parent does // add(safeObserver); @@ -138,7 +138,7 @@ public void onNext(Notification args) { queue.add(args); // remark: activePlans might change while iterating - for (ActivePlan0 a : new ArrayList(activePlans)) { + for (ActivePlan0 a : new ArrayList<>(activePlans)) { try { a.match(); } catch (Throwable ex) { diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/JoinPatterns.java b/src/main/java/hu/akarnokd/rxjava4/joins/JoinPatterns.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/joins/JoinPatterns.java rename to src/main/java/hu/akarnokd/rxjava4/joins/JoinPatterns.java index 5fb076e4..c47c9287 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/JoinPatterns.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/JoinPatterns.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.*; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.disposables.*; -import io.reactivex.functions.*; -import io.reactivex.observers.SafeObserver; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.SafeObserver; /** * Join patterns And, Then and When. @@ -45,7 +45,7 @@ public static Pattern2 and(/* this */Observable left, Obser if (right == null) { throw new NullPointerException("right"); } - return new Pattern2(left, right); + return new Pattern2<>(left, right); } /** @@ -63,7 +63,7 @@ public static Plan then(/* this */Observable source, Function(source).then(selector); + return new Pattern1<>(source).then(selector); } /** @@ -72,6 +72,7 @@ public static Plan then(/* this */Observable source, Function the result type * @return the Observable coining the plans */ + @SafeVarargs public static Observable when(Plan... plans) { if (plans == null) { throw new NullPointerException("plans"); @@ -92,11 +93,11 @@ public static Observable when(final Iterable> plans) { return new Observable() { @Override protected void subscribeActual(final Observer t1) { - final Map externalSubscriptions = new HashMap(); + final Map externalSubscriptions = new HashMap<>(); final Object gate = new Object(); - final List activePlans = new ArrayList(); + final List activePlans = new ArrayList<>(); - final Observer out = new SafeObserver(new Observer() { + final Observer out = new SafeObserver<>(new Observer() { @Override public void onSubscribe(Disposable d) { @@ -121,7 +122,7 @@ public void onComplete() { } }); - out.onSubscribe(Disposables.empty()); + out.onSubscribe(Disposable.empty()); try { for (Plan plan : plans) { diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern1.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern1.java similarity index 73% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern1.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern1.java index a581da20..abc6908d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern1.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern1.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function; /** - * Represents a join pattern over Observable sequences. + * Represents a join pattern over {@link Observable} sequences. * @param the first value type + * @param o1 the first {@code Observable} */ -public final class Pattern1 { - private final Observable o1; - - public Pattern1(Observable o1) { - this.o1 = o1; - } - - Observable o1() { - return o1; - } +public record Pattern1(Observable o1) { /** * Matches when all observable sequences have an available @@ -49,6 +41,6 @@ public Plan then(Function selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan1(this, selector); + return new Plan1<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern2.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern2.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern2.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern2.java index ff49be66..574cb20c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern2.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern2.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,32 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.BiFunction; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.BiFunction; /** * Represents a join pattern over observable sequences. * @param the first value type * @param the second value type + * @param o1 the first source + * @param o2 the second source */ -public final class Pattern2 { - private final Observable o1; - private final Observable o2; - - public Pattern2(Observable o1, Observable o2) { - this.o1 = o1; - this.o2 = o2; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } +public record Pattern2(Observable o1, Observable o2) { /** * Creates a pattern that matches when all three observable sequences have an available element. @@ -53,7 +40,7 @@ public Pattern3 and(Observable other) { if (other == null) { throw new NullPointerException(); } - return new Pattern3(o1, o2, other); + return new Pattern3<>(o1, o2, other); } /** @@ -71,6 +58,6 @@ public Plan then(BiFunction selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan2(this, selector); + return new Plan2<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern3.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern3.java similarity index 71% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern3.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern3.java index d13aa2e7..796fb4f8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern3.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern3.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,40 +14,22 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function3; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function3; /** * Represents a join pattern over observable sequences. * @param the first value type * @param the second value type * @param the third value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source */ -public final class Pattern3 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - - public Pattern3(Observable o1, Observable o2, - Observable o3) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } +public record Pattern3(Observable o1, Observable o2, + Observable o3) { /** * Creates a pattern that matches when all three observable sequences have an available element. @@ -61,7 +43,7 @@ public Pattern4 and(Observable other) { if (other == null) { throw new NullPointerException(); } - return new Pattern4(o1, o2, o3, other); + return new Pattern4<>(o1, o2, o3, other); } /** @@ -79,6 +61,6 @@ public Plan then(Function3 selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan3(this, selector); + return new Plan3<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern4.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern4.java similarity index 67% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern4.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern4.java index 4f56936e..e065264e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern4.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function4; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function4; /** * Represents a join pattern over observable sequences. @@ -25,40 +25,17 @@ * @param the second value type * @param the third value type * @param the fourth value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source + * @param o4 the fourth source */ -public final class Pattern4 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - private final Observable o4; - - public Pattern4( - Observable o1, - Observable o2, - Observable o3, - Observable o4 - ) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - this.o4 = o4; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } - - Observable o4() { - return o4; - } +public record Pattern4( + Observable o1, + Observable o2, + Observable o3, + Observable o4 + ) { /** * Creates a pattern that matches when all four observable sequences have an available element. @@ -72,7 +49,7 @@ public Pattern5 and(Observable other) { if (other == null) { throw new NullPointerException(); } - return new Pattern5(o1, o2, o3, o4, other); + return new Pattern5<>(o1, o2, o3, o4, other); } /** * Matches when all observable sequences have an available @@ -89,6 +66,6 @@ public Plan then(Function4 selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan4(this, selector); + return new Plan4<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern5.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern5.java similarity index 64% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern5.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern5.java index 8d4c5711..72059c48 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern5.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern5.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function5; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function5; /** * Represents a join pattern over observable sequences. @@ -26,47 +26,19 @@ * @param the third value type * @param the fourth value type * @param the fifth value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source + * @param o4 the fourth source + * @param o5 the fifth source */ -public final class Pattern5 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - private final Observable o4; - private final Observable o5; - - public Pattern5( - Observable o1, - Observable o2, - Observable o3, - Observable o4, - Observable o5 - ) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - this.o4 = o4; - this.o5 = o5; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } - - Observable o4() { - return o4; - } - - Observable o5() { - return o5; - } +public record Pattern5( + Observable o1, + Observable o2, + Observable o3, + Observable o4, + Observable o5 + ) { /** * Creates a pattern that matches when all five observable sequences have an available element. @@ -80,7 +52,7 @@ public Pattern6 and(Observable other) { if (other == null) { throw new NullPointerException(); } - return new Pattern6(o1, o2, o3, o4, o5, other); + return new Pattern6<>(o1, o2, o3, o4, o5, other); } /** * Matches when all observable sequences have an available @@ -97,6 +69,6 @@ public Plan then(Function5 selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan5(this, selector); + return new Plan5<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern6.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern6.java similarity index 61% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern6.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern6.java index 8bd8e57c..ae0d0f12 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern6.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern6.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function6; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function6; /** * Represents a join pattern over observable sequences. @@ -27,54 +27,21 @@ * @param the fourth value type * @param the fifth value type * @param the sixth value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source + * @param o4 the fourth source + * @param o5 the fifth source + * @param o6 the sixth source */ -public final class Pattern6 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - private final Observable o4; - private final Observable o5; - private final Observable o6; - - public Pattern6( - Observable o1, - Observable o2, - Observable o3, - Observable o4, - Observable o5, - Observable o6 - ) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - this.o4 = o4; - this.o5 = o5; - this.o6 = o6; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } - - Observable o4() { - return o4; - } - - Observable o5() { - return o5; - } - - Observable o6() { - return o6; - } +public record Pattern6( + Observable o1, + Observable o2, + Observable o3, + Observable o4, + Observable o5, + Observable o6 + ) { /** * Creates a pattern that matches when all six observable sequences have an available element. @@ -88,7 +55,7 @@ public Pattern7 and(Observable other) { if (other == null) { throw new NullPointerException(); } - return new Pattern7(o1, o2, o3, o4, o5, o6, other); + return new Pattern7<>(o1, o2, o3, o4, o5, o6, other); } /** * Matches when all observable sequences have an available @@ -105,6 +72,6 @@ public Plan then(Function6 selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan6(this, selector); + return new Plan6<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern7.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern7.java similarity index 58% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern7.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern7.java index f7210e8b..554e1c05 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern7.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern7.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function7; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function7; /** * Represents a join pattern over observable sequences. @@ -27,62 +27,24 @@ * @param the fourth value type * @param the fifth value type * @param the sixth value type - * @param the sevent value type + * @param the seventh value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source + * @param o4 the fourth source + * @param o5 the fifth source + * @param o6 the sixth source + * @param o7 the seventh source */ -public final class Pattern7 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - private final Observable o4; - private final Observable o5; - private final Observable o6; - private final Observable o7; - - public Pattern7( - Observable o1, - Observable o2, - Observable o3, - Observable o4, - Observable o5, - Observable o6, - Observable o7 - ) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - this.o4 = o4; - this.o5 = o5; - this.o6 = o6; - this.o7 = o7; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } - - Observable o4() { - return o4; - } - - Observable o5() { - return o5; - } - - Observable o6() { - return o6; - } - - Observable o7() { - return o7; - } +public record Pattern7( + Observable o1, + Observable o2, + Observable o3, + Observable o4, + Observable o5, + Observable o6, + Observable o7 + ) { /** * Creates a pattern that matches when all seven observable sequences have an available element. @@ -96,7 +58,7 @@ public Pattern8 and(Observable other) { if (other == null) { throw new NullPointerException(); } - return new Pattern8(o1, o2, o3, o4, o5, o6, o7, other); + return new Pattern8<>(o1, o2, o3, o4, o5, o6, o7, other); } /** * Matches when all observable sequences have an available @@ -113,6 +75,6 @@ public Plan then(Function7 selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan7(this, selector); + return new Plan7<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern8.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern8.java similarity index 56% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern8.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern8.java index fe752f36..86aea83d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern8.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern8.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import io.reactivex.Observable; -import io.reactivex.functions.Function8; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function8; /** * Represents a join pattern over observable sequences. @@ -27,70 +27,27 @@ * @param the fourth value type * @param the fifth value type * @param the sixth value type - * @param the sevent value type + * @param the seventh value type * @param the eighth value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source + * @param o4 the fourth source + * @param o5 the fifth source + * @param o6 the sixth source + * @param o7 the seventh source + * @param o8 the eight source */ -public final class Pattern8 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - private final Observable o4; - private final Observable o5; - private final Observable o6; - private final Observable o7; - private final Observable o8; - - public Pattern8( - Observable o1, - Observable o2, - Observable o3, - Observable o4, - Observable o5, - Observable o6, - Observable o7, - Observable o8 - ) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - this.o4 = o4; - this.o5 = o5; - this.o6 = o6; - this.o7 = o7; - this.o8 = o8; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } - - Observable o4() { - return o4; - } - - Observable o5() { - return o5; - } - - Observable o6() { - return o6; - } - - Observable o7() { - return o7; - } - - Observable o8() { - return o8; - } +public record Pattern8( + Observable o1, + Observable o2, + Observable o3, + Observable o4, + Observable o5, + Observable o6, + Observable o7, + Observable o8 + ) { /** * Creates a pattern that matches when all eight observable sequences have an available element. @@ -103,7 +60,7 @@ public Pattern9 and(Observable othe if (other == null) { throw new NullPointerException(); } - return new Pattern9(o1, o2, o3, o4, o5, o6, o7, o8, other); + return new Pattern9<>(o1, o2, o3, o4, o5, o6, o7, o8, other); } /** * Matches when all observable sequences have an available @@ -120,6 +77,6 @@ public Plan then(Function8 selector) { if (selector == null) { throw new NullPointerException(); } - return new Plan8(this, selector); + return new Plan8<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern9.java b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern9.java similarity index 55% rename from src/main/java/hu/akarnokd/rxjava2/joins/Pattern9.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Pattern9.java index b8aac139..52c20c93 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Pattern9.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Pattern9.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.*; -import io.reactivex.Observable; -import io.reactivex.functions.Function9; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function9; /** * Represents a join pattern over observable sequences. @@ -30,78 +29,30 @@ * @param the fourth value type * @param the fifth value type * @param the sixth value type - * @param the sevent value type + * @param the seventh value type * @param the eighth value type * @param the ninth value type + * @param o1 the first source + * @param o2 the second source + * @param o3 the third source + * @param o4 the fourth source + * @param o5 the fifth source + * @param o6 the sixth source + * @param o7 the seventh source + * @param o8 the eight source + * @param o9 the ninth source */ -public final class Pattern9 { - private final Observable o1; - private final Observable o2; - private final Observable o3; - private final Observable o4; - private final Observable o5; - private final Observable o6; - private final Observable o7; - private final Observable o8; - private final Observable o9; - - public Pattern9( - Observable o1, - Observable o2, - Observable o3, - Observable o4, - Observable o5, - Observable o6, - Observable o7, - Observable o8, - Observable o9 - ) { - this.o1 = o1; - this.o2 = o2; - this.o3 = o3; - this.o4 = o4; - this.o5 = o5; - this.o6 = o6; - this.o7 = o7; - this.o8 = o8; - this.o9 = o9; - } - - Observable o1() { - return o1; - } - - Observable o2() { - return o2; - } - - Observable o3() { - return o3; - } - - Observable o4() { - return o4; - } - - Observable o5() { - return o5; - } - - Observable o6() { - return o6; - } - - Observable o7() { - return o7; - } - - Observable o8() { - return o8; - } - - Observable o9() { - return o9; - } +public record Pattern9( + Observable o1, + Observable o2, + Observable o3, + Observable o4, + Observable o5, + Observable o6, + Observable o7, + Observable o8, + Observable o9 + ) { /** * Creates a pattern that matches when all nine observable sequences have an available element. @@ -114,7 +65,7 @@ public PatternN and(Observable other) { if (other == null) { throw new NullPointerException(); } - List> list = new ArrayList>(); + List> list = new ArrayList<>(); list.add(o1); list.add(o2); list.add(o3); @@ -139,7 +90,7 @@ public PatternN and(Observable other) { * if selector is null */ public Plan then(Function9 selector) { - ObjectHelper.requireNonNull(selector, "selector is null"); - return new Plan9(this, selector); + Objects.requireNonNull(selector, "selector is null"); + return new Plan9<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/PatternN.java b/src/main/java/hu/akarnokd/rxjava4/joins/PatternN.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/joins/PatternN.java rename to src/main/java/hu/akarnokd/rxjava4/joins/PatternN.java index f1a61de2..95ea6649 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/PatternN.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/PatternN.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.*; -import io.reactivex.Observable; -import io.reactivex.functions.Function; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function; /** * Represents a join pattern over observable sequences. @@ -27,12 +27,21 @@ public final class PatternN { private final List> observables; + /** + * Constructs a multi-valued pattern from the list of {@link Observable}s. + * @param observables the list of {@code Observable}s to work with + */ public PatternN(List> observables) { this.observables = observables; } + /** + * Constructs a multi-valued pattern from the list of {@link Observable}s. + * @param observables the list of {@code Observable}s to work with + * @param other the extra {@code Observable} to work with + */ public PatternN(List> observables, Observable other) { - this.observables = new ArrayList>(observables); + this.observables = new ArrayList<>(observables); this.observables.add(other); } @@ -81,6 +90,6 @@ public Plan then(Function selector) { if (selector == null) { throw new NullPointerException(); } - return new PlanN(this, selector); + return new PlanN<>(this, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan.java index 0a2eecd6..46f675c3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; -import io.reactivex.*; -import io.reactivex.functions.Consumer; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Consumer; /** * Represents an execution plan for join patterns. @@ -38,7 +38,7 @@ static final JoinObserver1 createObserver( JoinObserver1 observer; JoinObserver nonGeneric = externalSubscriptions.get(observable); if (nonGeneric == null) { - observer = new JoinObserver1(observable, onError); + observer = new JoinObserver1<>(observable, onError); externalSubscriptions.put(observable, observer); } else { observer = (JoinObserver1) nonGeneric; diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan1.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan1.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan1.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan1.java index d4e53f8d..a8e389fe 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan1.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan1.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -42,9 +42,9 @@ public ActivePlan0 activate(Map externalSubscriptions, fin final JoinObserver1 firstJoinObserver = createObserver(externalSubscriptions, expression.o1(), onError); - final AtomicReference> self = new AtomicReference>(); + final AtomicReference> self = new AtomicReference<>(); - ActivePlan1 activePlan = new ActivePlan1(firstJoinObserver, new Consumer() { + ActivePlan1 activePlan = new ActivePlan1<>(firstJoinObserver, new Consumer() { @Override public void accept(T1 t1) { R result; @@ -59,7 +59,7 @@ public void accept(T1 t1) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); firstJoinObserver.removeActivePlan(ap); deactivate.accept(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan2.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan2.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan2.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan2.java index 770a564d..b4176894 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan2.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan2.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -45,9 +45,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo1 = createObserver(externalSubscriptions, expression.o1(), onError); final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); - final AtomicReference> self = new AtomicReference>(); + final AtomicReference> self = new AtomicReference<>(); - ActivePlan2 activePlan = new ActivePlan2(jo1, jo2, new BiConsumer() { + ActivePlan2 activePlan = new ActivePlan2<>(jo1, jo2, new BiConsumer() { @Override public void accept(T1 t1, T2 t2) { R result; @@ -62,7 +62,7 @@ public void accept(T1 t1, T2 t2) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan3.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan3.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan3.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan3.java index 3a7ec86e..86c099af 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan3.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan3.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer3; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -48,9 +47,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo2 = createObserver(externalSubscriptions, expression.o2(), onError); final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); - final AtomicReference> self = new AtomicReference>(); + final AtomicReference> self = new AtomicReference<>(); - ActivePlan3 activePlan = new ActivePlan3( + ActivePlan3 activePlan = new ActivePlan3<>( jo1, jo2, jo3, new Consumer3() { @Override @@ -67,7 +66,7 @@ public void accept(T1 t1, T2 t2, T3 t3) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan4.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan4.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan4.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan4.java index 8b670d1b..65a76dfc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan4.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer4; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import hu.akarnokd.rxjava4.functions.Consumer4; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -50,9 +50,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo3 = createObserver(externalSubscriptions, expression.o3(), onError); final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); - ActivePlan0 activePlan = new ActivePlan4( + ActivePlan0 activePlan = new ActivePlan4<>( jo1, jo2, jo3, jo4, new Consumer4() { @Override @@ -69,7 +69,7 @@ public void accept(T1 t1, T2 t2, T3 t3, T4 t4) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan5.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan5.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan5.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan5.java index 1d759281..f513ff54 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan5.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan5.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer5; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import hu.akarnokd.rxjava4.functions.Consumer5; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -52,9 +52,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo4 = createObserver(externalSubscriptions, expression.o4(), onError); final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); - ActivePlan0 activePlan = new ActivePlan5( + ActivePlan0 activePlan = new ActivePlan5<>( jo1, jo2, jo3, jo4, jo5, new Consumer5() { @Override @@ -71,7 +71,7 @@ public void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan6.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan6.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan6.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan6.java index 371ce1de..e47052db 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan6.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan6.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer6; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import hu.akarnokd.rxjava4.functions.Consumer6; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -54,9 +54,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo5 = createObserver(externalSubscriptions, expression.o5(), onError); final JoinObserver1 jo6 = createObserver(externalSubscriptions, expression.o6(), onError); - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); - ActivePlan0 activePlan = new ActivePlan6( + ActivePlan0 activePlan = new ActivePlan6<>( jo1, jo2, jo3, jo4, jo5, jo6, new Consumer6() { @Override @@ -73,7 +73,7 @@ public void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan7.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan7.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan7.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan7.java index a03abf82..e220d243 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan7.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan7.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer7; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import hu.akarnokd.rxjava4.functions.Consumer7; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -56,9 +56,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo6 = createObserver(externalSubscriptions, expression.o6(), onError); final JoinObserver1 jo7 = createObserver(externalSubscriptions, expression.o7(), onError); - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); - ActivePlan0 activePlan = new ActivePlan7( + ActivePlan0 activePlan = new ActivePlan7<>( jo1, jo2, jo3, jo4, jo5, jo6, jo7, new Consumer7() { @Override @@ -75,7 +75,7 @@ public void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan8.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan8.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan8.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan8.java index 018123cc..c066b3c6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan8.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan8.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer8; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import hu.akarnokd.rxjava4.functions.Consumer8; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -58,9 +58,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo7 = createObserver(externalSubscriptions, expression.o7(), onError); final JoinObserver1 jo8 = createObserver(externalSubscriptions, expression.o8(), onError); - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); - ActivePlan0 activePlan = new ActivePlan8( + ActivePlan0 activePlan = new ActivePlan8<>( jo1, jo2, jo3, jo4, jo5, jo6, jo7, jo8, new Consumer8() { @Override @@ -77,7 +77,7 @@ public void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/Plan9.java b/src/main/java/hu/akarnokd/rxjava4/joins/Plan9.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/joins/Plan9.java rename to src/main/java/hu/akarnokd/rxjava4/joins/Plan9.java index d0452cea..dcc2ba6d 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/Plan9.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/Plan9.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import hu.akarnokd.rxjava2.functions.Consumer9; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import hu.akarnokd.rxjava4.functions.Consumer9; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -60,9 +60,9 @@ public ActivePlan0 activate(Map externalSubscriptions, final JoinObserver1 jo8 = createObserver(externalSubscriptions, expression.o8(), onError); final JoinObserver1 jo9 = createObserver(externalSubscriptions, expression.o9(), onError); - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); - ActivePlan0 activePlan = new ActivePlan9( + ActivePlan0 activePlan = new ActivePlan9<>( jo1, jo2, jo3, jo4, jo5, jo6, jo7, jo8, jo9, new Consumer9() { @Override @@ -79,7 +79,7 @@ public void accept(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9 }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { ActivePlan0 ap = self.get(); jo1.removeActivePlan(ap); jo2.removeActivePlan(ap); diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/PlanN.java b/src/main/java/hu/akarnokd/rxjava4/joins/PlanN.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/joins/PlanN.java rename to src/main/java/hu/akarnokd/rxjava4/joins/PlanN.java index 913c4578..49e86637 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/PlanN.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/PlanN.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; import java.util.*; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.Observer; -import io.reactivex.functions.*; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.functions.*; /** * Represents an execution plan for join patterns. @@ -40,11 +40,11 @@ public ActivePlan0 activate(Map externalSubscriptions, final Observer observer, final Consumer deactivate) { Consumer onError = onErrorFrom(observer); - final List> observers = new ArrayList>(); + final List> observers = new ArrayList<>(); for (int i = 0; i < expression.size(); i++) { observers.add(createObserver(externalSubscriptions, expression.get(i), onError)); } - final AtomicReference self = new AtomicReference(); + final AtomicReference self = new AtomicReference<>(); ActivePlanN activePlan = new ActivePlanN(observers, new Consumer() { @Override @@ -61,7 +61,7 @@ public void accept(Object[]args) { }, new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { for (JoinObserver1 jo : observers) { jo.removeActivePlan(self.get()); } diff --git a/src/main/java/hu/akarnokd/rxjava2/joins/package-info.java b/src/main/java/hu/akarnokd/rxjava4/joins/package-info.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/joins/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/joins/package-info.java index 6bc12ec9..ce186144 100644 --- a/src/main/java/hu/akarnokd/rxjava2/joins/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/joins/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ /** * Utility methods for join patterns (more generic way than {@code combineLatest}) via - * {@link hu.akarnokd.rxjava2.joins.JoinObservable JoinObservable} wrapper and the {@code and/then/when} + * {@link hu.akarnokd.rxjava4.joins.JoinObservable JoinObservable} wrapper and the {@code and/then/when} * vocabulary; * a port of the * RxJavaJoins * library. */ -package hu.akarnokd.rxjava2.joins; \ No newline at end of file +package hu.akarnokd.rxjava4.joins; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableAverageDouble.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableAverageDouble.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableAverageDouble.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableAverageDouble.java index daeb4276..66de4815 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableAverageDouble.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableAverageDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; final class FlowableAverageDouble extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableAverageFloat.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableAverageFloat.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableAverageFloat.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableAverageFloat.java index d2b6d78f..2908e44a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableAverageFloat.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableAverageFloat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; final class FlowableAverageFloat extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableMinMax.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableMinMax.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableMinMax.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableMinMax.java index 7c9f3a6d..b62977b4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableMinMax.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableMinMax.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; import java.util.Comparator; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; +import io.reactivex.rxjava4.exceptions.Exceptions; final class FlowableMinMax extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSource.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSource.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableSource.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableSource.java index fa54fa33..5a95f7e3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSource.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.Publisher; +import java.util.concurrent.Flow.Publisher; -import io.reactivex.Flowable; +import io.reactivex.rxjava4.core.Flowable; abstract class FlowableSource extends Flowable { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumDouble.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumDouble.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableSumDouble.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableSumDouble.java index 274e3a25..b8736684 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumDouble.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; final class FlowableSumDouble extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumFloat.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumFloat.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableSumFloat.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableSumFloat.java index c86f7cce..34dc22f1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumFloat.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumFloat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; final class FlowableSumFloat extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumInt.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumInt.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableSumInt.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableSumInt.java index b70361d1..eff0343a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumInt.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumInt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; final class FlowableSumInt extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumLong.java b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumLong.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/math/FlowableSumLong.java rename to src/main/java/hu/akarnokd/rxjava4/math/FlowableSumLong.java index f43b9c8f..31d503e0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/FlowableSumLong.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/FlowableSumLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; final class FlowableSumLong extends FlowableSource { diff --git a/src/main/java/hu/akarnokd/rxjava4/math/MathFlowable.java b/src/main/java/hu/akarnokd/rxjava4/math/MathFlowable.java new file mode 100644 index 00000000..92cc6a66 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/math/MathFlowable.java @@ -0,0 +1,134 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.math; + +import java.util.Comparator; +import java.util.concurrent.Flow.Publisher; + +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Utility methods to work with numerical Flowable sources: sum, min, max and average. + */ +public final class MathFlowable { + /** Utility class. */ + private MathFlowable() { + throw new IllegalStateException("No instances!"); + } + + /** + * Returns a {@code Flowable} that will emit the sum of integers of the upstream. + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + public static Flowable sumInt(Publisher source) { + return RxJavaPlugins.onAssembly(new FlowableSumInt(source)); + } + + /** + * Returns a {@code Flowable} that will emit the sum of longs of the upstream. + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + public static Flowable sumLong(Publisher source) { + return RxJavaPlugins.onAssembly(new FlowableSumLong(source)); + } + + /** + * Returns a {@code Flowable} that will emit the sum of floats of the upstream. + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + public static Flowable sumFloat(Publisher source) { + return RxJavaPlugins.onAssembly(new FlowableSumFloat(source)); + } + + /** + * Returns a {@code Flowable} that will emit the sum of doubles of the upstream. + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + public static Flowable sumDouble(Publisher source) { + return RxJavaPlugins.onAssembly(new FlowableSumDouble(source)); + } + + /** + * Returns a {@code Flowable} that will find the largest comparable value in the upstream. + * @param the element type + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + public static > Flowable max(Publisher source) { + return max(source, Comparator.naturalOrder()); + } + + /** + * Returns a {@code Flowable} that will find the largest value via a comparator in the upstream. + * @param the element type + * @param source the source sequence + * @param comparator the comparator to compare items with + * @return the new {@code Flowable} instance + */ + public static Flowable max(Publisher source, Comparator comparator) { + return RxJavaPlugins.onAssembly(new FlowableMinMax<>(source, comparator, -1)); + } + + /** + * Returns a {@code Flowable} that will find the smallest comparable value in the upstream. + * @param the element type + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + public static > Flowable min(Publisher source) { + return min(source, Comparator.naturalOrder()); + } + + /** + * Returns a {@code Flowable} that will find the smallest value via a comparator in the upstream. + * @param the element type + * @param source the source sequence + * @param comparator the comparator to compare items with + * @return the new {@code Flowable} instance + */ + public static Flowable min(Publisher source, Comparator comparator) { + return RxJavaPlugins.onAssembly(new FlowableMinMax<>(source, comparator, 1)); + } + + /** + * Returns a {@code Flowable} that calculates the average of the numeric values in the upstream + * as a float. + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + @SuppressWarnings("unchecked") + public static Flowable averageFloat(Publisher source) { + return RxJavaPlugins.onAssembly(new FlowableAverageFloat((Publisher)source)); + } + + /** + * Returns a {@code Flowable} that calculates the average of the numeric values in the upstream + * as a double. + * @param source the source sequence + * @return the new {@code Flowable} instance + */ + @SuppressWarnings("unchecked") + public static Flowable averageDouble(Publisher source) { + return RxJavaPlugins.onAssembly(new FlowableAverageDouble((Publisher)source)); + } + +} diff --git a/src/main/java/hu/akarnokd/rxjava4/math/MathObservable.java b/src/main/java/hu/akarnokd/rxjava4/math/MathObservable.java new file mode 100644 index 00000000..2b9fd458 --- /dev/null +++ b/src/main/java/hu/akarnokd/rxjava4/math/MathObservable.java @@ -0,0 +1,133 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.math; + +import java.util.Comparator; + +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; + +/** + * Utility methods to work with numerical Observable sources: sum, min, max and average. + */ +public final class MathObservable { + /** Utility class. */ + private MathObservable() { + throw new IllegalStateException("No instances!"); + } + + /** + * Returns a {@code Observable} that will emit the sum of integers of the upstream. + * @param source the source sequence + * @return the new {@code Observable} instance + */ + public static Observable sumInt(ObservableSource source) { + return RxJavaPlugins.onAssembly(new ObservableSumInt(source)); + } + + /** + * Returns a {@code Observable} that will emit the sum of longs of the upstream. + * @param source the source sequence + * @return the new {@code Observable} instance + */ + public static Observable sumLong(ObservableSource source) { + return RxJavaPlugins.onAssembly(new ObservableSumLong(source)); + } + + /** + * Returns a {@code Observable} that will emit the sum of floats of the upstream. + * @param source the source sequence + * @return the new {@code Observable} instance + */ + public static Observable sumFloat(ObservableSource source) { + return RxJavaPlugins.onAssembly(new ObservableSumFloat(source)); + } + + /** + * Returns a {@code Observable} that will emit the sum of doubles of the upstream. + * @param source the source sequence + * @return the new {@code Observable} instance + */ + public static Observable sumDouble(ObservableSource source) { + return RxJavaPlugins.onAssembly(new ObservableSumDouble(source)); + } + + /** + * Returns a {@code Observable} that will find the largest comparable value in the upstream. + * @param the element type + * @param source the source sequence + * @return the new {@code Observable} instance + */ + public static > Observable max(ObservableSource source) { + return max(source, Comparator.naturalOrder()); + } + + /** + * Returns a {@code Observable} that will find the largest value via a comparator in the upstream. + * @param the element type + * @param source the source sequence + * @param comparator the comparator to compare items with + * @return the new {@code Observable} instance + */ + public static Observable max(ObservableSource source, Comparator comparator) { + return RxJavaPlugins.onAssembly(new ObservableMinMax<>(source, comparator, -1)); + } + + /** + * Returns a {@code Observable} that will find the smallest comparable value in the upstream. + * @param the element type + * @param source the source sequence + * @return the new {@code Observable} instance + */ + public static > Observable min(ObservableSource source) { + return min(source, Comparator.naturalOrder()); + } + + /** + * Returns a {@code Observable} that will find the smallest value via a comparator in the upstream. + * @param the element type + * @param source the source sequence + * @param comparator the comparator to compare items with + * @return the new {@code Observable} instance + */ + public static Observable min(ObservableSource source, Comparator comparator) { + return RxJavaPlugins.onAssembly(new ObservableMinMax<>(source, comparator, 1)); + } + + /** + * Returns a {@code Observable} that calculates the average of the numeric values in the upstream + * as a float. + * @param source the source sequence + * @return the new {@code Observable} instance + */ + @SuppressWarnings("unchecked") + public static Observable averageFloat(ObservableSource source) { + return RxJavaPlugins.onAssembly(new ObservableAverageFloat((ObservableSource)source)); + } + + /** + * Returns a {@code Observable} that calculates the average of the numeric values in the upstream + * as a double. + * @param source the source sequence + * @return the new {@code Observable} instance + */ + @SuppressWarnings("unchecked") + public static Observable averageDouble(ObservableSource source) { + return RxJavaPlugins.onAssembly(new ObservableAverageDouble((ObservableSource)source)); + } + +} diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableAverageDouble.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableAverageDouble.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableAverageDouble.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableAverageDouble.java index 0bf39b73..746aeeeb 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableAverageDouble.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableAverageDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.*; -import io.reactivex.internal.observers.DeferredScalarObserver; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; -public class ObservableAverageDouble extends ObservableWithSource { +final class ObservableAverageDouble extends ObservableWithSource { - public ObservableAverageDouble(ObservableSource source) { + ObservableAverageDouble(ObservableSource source) { super(source); } diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableAverageFloat.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableAverageFloat.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableAverageFloat.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableAverageFloat.java index 3bdb2ebd..0b1d0a05 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableAverageFloat.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableAverageFloat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.internal.observers.DeferredScalarObserver; -import io.reactivex.*; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; -public class ObservableAverageFloat extends ObservableWithSource { +final class ObservableAverageFloat extends ObservableWithSource { - public ObservableAverageFloat(ObservableSource source) { + ObservableAverageFloat(ObservableSource source) { super(source); } diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableMinMax.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableMinMax.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableMinMax.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableMinMax.java index 04c44f99..87d1ac7a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableMinMax.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableMinMax.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; import java.util.Comparator; -import io.reactivex.internal.observers.DeferredScalarObserver; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; final class ObservableMinMax extends ObservableWithSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumDouble.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumDouble.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableSumDouble.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableSumDouble.java index 9ff3f19e..d96ffe96 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumDouble.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.internal.observers.DeferredScalarObserver; -import io.reactivex.*; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; -public class ObservableSumDouble extends ObservableWithSource { +final class ObservableSumDouble extends ObservableWithSource { - public ObservableSumDouble(ObservableSource source) { + ObservableSumDouble(ObservableSource source) { super(source); } diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumFloat.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumFloat.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableSumFloat.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableSumFloat.java index f5ca0005..7d92322c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumFloat.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumFloat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.internal.observers.DeferredScalarObserver; -import io.reactivex.*; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; -public class ObservableSumFloat extends ObservableWithSource { +final class ObservableSumFloat extends ObservableWithSource { - public ObservableSumFloat(ObservableSource source) { + ObservableSumFloat(ObservableSource source) { super(source); } diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumInt.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumInt.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableSumInt.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableSumInt.java index 3651e415..dc533342 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumInt.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumInt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.internal.observers.DeferredScalarObserver; -import io.reactivex.*; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; final class ObservableSumInt extends ObservableWithSource { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumLong.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumLong.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableSumLong.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableSumLong.java index 7096ffa1..fe7528bd 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSumLong.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableSumLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.internal.observers.DeferredScalarObserver; -import io.reactivex.*; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; -public class ObservableSumLong extends ObservableWithSource { +final class ObservableSumLong extends ObservableWithSource { - public ObservableSumLong(ObservableSource source) { + ObservableSumLong(ObservableSource source) { super(source); } diff --git a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSource.java b/src/main/java/hu/akarnokd/rxjava4/math/ObservableWithSource.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/math/ObservableSource.java rename to src/main/java/hu/akarnokd/rxjava4/math/ObservableWithSource.java index 31ec9df2..b77ec246 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/ObservableSource.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/ObservableWithSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import io.reactivex.*; +import io.reactivex.rxjava4.core.*; abstract class ObservableWithSource extends Observable { diff --git a/src/main/java/hu/akarnokd/rxjava2/math/package-info.java b/src/main/java/hu/akarnokd/rxjava4/math/package-info.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/math/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/math/package-info.java index d24a6897..c43c83c3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/math/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/math/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ /** * Utility methods for aggregating and reducing flows with numeric content via - * {@link hu.akarnokd.rxjava2.math.MathFlowable MathFlowable} - * and {@link hu.akarnokd.rxjava2.math.MathObservable MathObservable}; + * {@link hu.akarnokd.rxjava4.math.MathFlowable MathFlowable} + * and {@link hu.akarnokd.rxjava4.math.MathObservable MathObservable}; * a port of the * RxJavaMath * library. */ -package hu.akarnokd.rxjava2.math; \ No newline at end of file +package hu.akarnokd.rxjava4.math; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/BasicEmitter.java b/src/main/java/hu/akarnokd/rxjava4/operators/BasicEmitter.java similarity index 74% rename from src/main/java/hu/akarnokd/rxjava2/operators/BasicEmitter.java rename to src/main/java/hu/akarnokd/rxjava4/operators/BasicEmitter.java index 5479b94d..91b38ea7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/BasicEmitter.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/BasicEmitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; /** * Abstraction over a Subscriber. @@ -23,9 +23,20 @@ */ public interface BasicEmitter { + /** + * Handle an item. + * @param t the item + */ void doNext(T t); + /** + * Handle a throwable. + * @param t the throwable + */ void doError(Throwable t); + /** + * Handle completion. + */ void doComplete(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalCompletable.java b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalCompletable.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalCompletable.java index fdfe5779..a6df3835 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the terminal signals of the upstream into CompletableSources and consumes them. @@ -35,12 +34,12 @@ final class CompletableFlatMapSignalCompletable extends Completable final Completable source; - final Callable onCompleteHandler; + final Supplier onCompleteHandler; final Function onErrorHandler; CompletableFlatMapSignalCompletable(Completable source, - Callable onCompleteHandler, + Supplier onCompleteHandler, Function onErrorHandler) { this.source = source; this.onCompleteHandler = onCompleteHandler; @@ -62,12 +61,12 @@ static final class FlatMapSignalConsumer final SignalConsumer consumer; - final Callable onCompleteHandler; + final Supplier onCompleteHandler; final Function onErrorHandler; FlatMapSignalConsumer(CompletableObserver downstream, - Callable onCompleteHandler, + Supplier onCompleteHandler, Function onErrorHandler) { this.consumer = new SignalConsumer(downstream); this.onCompleteHandler = onCompleteHandler; @@ -97,7 +96,7 @@ public void onComplete() { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +111,7 @@ public void onError(Throwable e) { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalFlowable.java b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalFlowable.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalFlowable.java index feff70eb..a7433ce5 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the terminal signals of the upstream into ObservableSources and consumes them. @@ -38,12 +35,12 @@ final class CompletableFlatMapSignalFlowable extends Flowable final Completable source; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; CompletableFlatMapSignalFlowable(Completable source, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { this.source = source; this.onCompleteHandler = onCompleteHandler; @@ -52,12 +49,12 @@ final class CompletableFlatMapSignalFlowable extends Flowable @Override public Flowable apply(Completable t) { - return new CompletableFlatMapSignalFlowable(t, onCompleteHandler, onErrorHandler); + return new CompletableFlatMapSignalFlowable<>(t, onCompleteHandler, onErrorHandler); } @Override protected void subscribeActual(Subscriber subscriber) { - source.subscribe(new FlatMapSignalConsumer(subscriber, onCompleteHandler, onErrorHandler)); + source.subscribe(new FlatMapSignalConsumer<>(subscriber, onCompleteHandler, onErrorHandler)); } static final class FlatMapSignalConsumer @@ -65,16 +62,16 @@ static final class FlatMapSignalConsumer final SignalConsumer consumer; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; Disposable upstream; FlatMapSignalConsumer(Subscriber downstream, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onCompleteHandler = onCompleteHandler; this.onErrorHandler = onErrorHandler; } @@ -103,7 +100,7 @@ public void onComplete() { Publisher next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null Publisher"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -118,7 +115,7 @@ public void onError(Throwable e) { Publisher next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null Publisher"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalMaybe.java b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalMaybe.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalMaybe.java index ac30e05a..13355bb1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the terminal signals of the upstream into MaybeSources and consumes them. @@ -35,12 +34,12 @@ final class CompletableFlatMapSignalMaybe extends Maybe final Completable source; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; CompletableFlatMapSignalMaybe(Completable source, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { this.source = source; this.onCompleteHandler = onCompleteHandler; @@ -49,12 +48,12 @@ final class CompletableFlatMapSignalMaybe extends Maybe @Override public Maybe apply(Completable t) { - return new CompletableFlatMapSignalMaybe(t, onCompleteHandler, onErrorHandler); + return new CompletableFlatMapSignalMaybe<>(t, onCompleteHandler, onErrorHandler); } @Override protected void subscribeActual(MaybeObserver observer) { - source.subscribe(new FlatMapSignalConsumer(observer, onCompleteHandler, onErrorHandler)); + source.subscribe(new FlatMapSignalConsumer<>(observer, onCompleteHandler, onErrorHandler)); } static final class FlatMapSignalConsumer @@ -62,14 +61,14 @@ static final class FlatMapSignalConsumer final SignalConsumer consumer; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; FlatMapSignalConsumer(MaybeObserver downstream, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onCompleteHandler = onCompleteHandler; this.onErrorHandler = onErrorHandler; } @@ -97,7 +96,7 @@ public void onComplete() { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +111,7 @@ public void onError(Throwable e) { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalObservable.java b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalObservable.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalObservable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalObservable.java index 45234424..dde14b4a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the terminal signals of the upstream into ObservableSources and consumes them. @@ -35,12 +34,12 @@ final class CompletableFlatMapSignalObservable extends Observable final Completable source; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; CompletableFlatMapSignalObservable(Completable source, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { this.source = source; this.onCompleteHandler = onCompleteHandler; @@ -49,12 +48,12 @@ final class CompletableFlatMapSignalObservable extends Observable @Override public Observable apply(Completable t) { - return new CompletableFlatMapSignalObservable(t, onCompleteHandler, onErrorHandler); + return new CompletableFlatMapSignalObservable<>(t, onCompleteHandler, onErrorHandler); } @Override protected void subscribeActual(Observer observer) { - source.subscribe(new FlatMapSignalConsumer(observer, onCompleteHandler, onErrorHandler)); + source.subscribe(new FlatMapSignalConsumer<>(observer, onCompleteHandler, onErrorHandler)); } static final class FlatMapSignalConsumer @@ -62,14 +61,14 @@ static final class FlatMapSignalConsumer final SignalConsumer consumer; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; FlatMapSignalConsumer(Observer downstream, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onCompleteHandler = onCompleteHandler; this.onErrorHandler = onErrorHandler; } @@ -97,7 +96,7 @@ public void onComplete() { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +111,7 @@ public void onError(Throwable e) { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalSingle.java b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalSingle.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalSingle.java rename to src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalSingle.java index 45da9f7e..b7114281 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the terminal signals of the upstream into SingleSources and consumes them. @@ -35,12 +34,12 @@ final class CompletableFlatMapSignalSingle extends Single final Completable source; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; CompletableFlatMapSignalSingle(Completable source, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { this.source = source; this.onCompleteHandler = onCompleteHandler; @@ -49,12 +48,12 @@ final class CompletableFlatMapSignalSingle extends Single @Override public Single apply(Completable t) { - return new CompletableFlatMapSignalSingle(t, onCompleteHandler, onErrorHandler); + return new CompletableFlatMapSignalSingle<>(t, onCompleteHandler, onErrorHandler); } @Override protected void subscribeActual(SingleObserver observer) { - source.subscribe(new FlatMapSignalConsumer(observer, onCompleteHandler, onErrorHandler)); + source.subscribe(new FlatMapSignalConsumer<>(observer, onCompleteHandler, onErrorHandler)); } static final class FlatMapSignalConsumer @@ -62,14 +61,14 @@ static final class FlatMapSignalConsumer final SignalConsumer consumer; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; final Function> onErrorHandler; FlatMapSignalConsumer(SingleObserver downstream, - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onCompleteHandler = onCompleteHandler; this.onErrorHandler = onErrorHandler; } @@ -97,7 +96,7 @@ public void onComplete() { SingleSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null SingleSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +111,7 @@ public void onError(Throwable e) { SingleSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null SingleSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableTransformers.java b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableTransformers.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/operators/CompletableTransformers.java rename to src/main/java/hu/akarnokd/rxjava4/operators/CompletableTransformers.java index fe54201e..e05241bc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/CompletableTransformers.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/CompletableTransformers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; /** * Additional operators in the form of {@link CompletableTransformer}, @@ -48,10 +47,10 @@ private CompletableTransformers() { * @since 0.20.2 */ public static CompletableTransformer flatMap( - Callable onCompleteHandler, + Supplier onCompleteHandler, Function onErrorHandler) { - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); return new CompletableFlatMapSignalCompletable(null, onCompleteHandler, onErrorHandler); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/Completables.java b/src/main/java/hu/akarnokd/rxjava4/operators/Completables.java similarity index 71% rename from src/main/java/hu/akarnokd/rxjava2/operators/Completables.java rename to src/main/java/hu/akarnokd/rxjava4/operators/Completables.java index db1a2bbd..e83b72cd 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/Completables.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/Completables.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Publisher; -import org.reactivestreams.Publisher; - -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; /** * Additional operators in the form of {@link CompletableConverter}s, - * use {@link Completable#as(CompletableConverter)} + * use {@link Completable#to(CompletableConverter)} * to apply the operators to an existing sequence. * * @see CompletableTransformers @@ -51,11 +49,11 @@ private Completables() { * @since 0.20.2 */ public static CompletableConverter> flatMapMaybe( - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new CompletableFlatMapSignalMaybe(null, onCompleteHandler, onErrorHandler); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new CompletableFlatMapSignalMaybe<>(null, onCompleteHandler, onErrorHandler); } /** @@ -70,11 +68,11 @@ public static CompletableConverter> flatMapMaybe( * @since 0.20.2 */ public static CompletableConverter> flatMapSingle( - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new CompletableFlatMapSignalSingle(null, onCompleteHandler, onErrorHandler); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new CompletableFlatMapSignalSingle<>(null, onCompleteHandler, onErrorHandler); } /** @@ -89,11 +87,11 @@ public static CompletableConverter> flatMapSingle( * @since 0.20.2 */ public static CompletableConverter> flatMapObservable( - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new CompletableFlatMapSignalObservable(null, onCompleteHandler, onErrorHandler); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new CompletableFlatMapSignalObservable<>(null, onCompleteHandler, onErrorHandler); } /** @@ -108,10 +106,10 @@ public static CompletableConverter> flatMapObservable( * @since 0.20.2 */ public static CompletableConverter> flatMapFlowable( - Callable> onCompleteHandler, + Supplier> onCompleteHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new CompletableFlatMapSignalFlowable(null, onCompleteHandler, onErrorHandler); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new CompletableFlatMapSignalFlowable<>(null, onCompleteHandler, onErrorHandler); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ExpandStrategy.java b/src/main/java/hu/akarnokd/rxjava4/operators/ExpandStrategy.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/operators/ExpandStrategy.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ExpandStrategy.java index da8d7595..fa90c8b4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ExpandStrategy.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ExpandStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; /** * Represents the strategies for recursive expansion with the {@code expand()} operator. diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableAsyncEmitter.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableAsyncEmitter.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableAsyncEmitter.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableAsyncEmitter.java index 9b18ec9d..581a6904 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableAsyncEmitter.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableAsyncEmitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import io.reactivex.Emitter; -import io.reactivex.annotations.Experimental; -import io.reactivex.functions.Cancellable; +import io.reactivex.rxjava4.annotations.Experimental; +import io.reactivex.rxjava4.core.Emitter; +import io.reactivex.rxjava4.functions.Cancellable; /** * Provides an API on top of the {@link Emitter} signals that allow diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableBufferPredicate.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableBufferPredicate.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableBufferPredicate.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableBufferPredicate.java index 7cb68fea..3393f555 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableBufferPredicate.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableBufferPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.Collection; -import java.util.concurrent.Callable; +import java.util.*; +import java.util.concurrent.Flow.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Buffer into the same buffer while the predicate returns true or @@ -55,10 +52,10 @@ enum Mode { final Mode mode; - final Callable bufferSupplier; + final Supplier bufferSupplier; FlowableBufferPredicate(Publisher source, Predicate predicate, Mode mode, - Callable bufferSupplier) { + Supplier bufferSupplier) { this.source = source; this.predicate = predicate; this.mode = mode; @@ -70,19 +67,19 @@ protected void subscribeActual(Subscriber s) { C buffer; try { - buffer = ObjectHelper.requireNonNull(bufferSupplier.call(), "The bufferSupplier returned a null buffer"); + buffer = Objects.requireNonNull(bufferSupplier.get(), "The bufferSupplier returned a null buffer"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); return; } - source.subscribe(new BufferPredicateSubscriber(s, buffer, predicate, mode, bufferSupplier)); + source.subscribe(new BufferPredicateSubscriber<>(s, buffer, predicate, mode, bufferSupplier)); } @Override public Publisher apply(Flowable upstream) { - return new FlowableBufferPredicate(upstream, predicate, mode, bufferSupplier); + return new FlowableBufferPredicate<>(upstream, predicate, mode, bufferSupplier); } static final class BufferPredicateSubscriber> @@ -94,7 +91,7 @@ static final class BufferPredicateSubscriber> final Mode mode; - final Callable bufferSupplier; + final Supplier bufferSupplier; C buffer; @@ -105,7 +102,7 @@ static final class BufferPredicateSubscriber> BufferPredicateSubscriber(Subscriber downstream, C buffer, Predicate predicate, Mode mode, - Callable bufferSupplier) { + Supplier bufferSupplier) { this.downstream = downstream; this.predicate = predicate; this.mode = mode; @@ -152,7 +149,7 @@ public boolean tryOnNext(T t) { downstream.onNext(buf); try { - buffer = bufferSupplier.call(); + buffer = bufferSupplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.cancel(); @@ -175,7 +172,7 @@ public boolean tryOnNext(T t) { } else { downstream.onNext(buf); try { - buf = bufferSupplier.call(); + buf = bufferSupplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.cancel(); @@ -194,7 +191,7 @@ public boolean tryOnNext(T t) { downstream.onNext(buf); try { - buffer = bufferSupplier.call(); + buffer = bufferSupplier.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.cancel(); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableCacheLast.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableCacheLast.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableCacheLast.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableCacheLast.java index 82d42ff4..d90914f8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableCacheLast.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableCacheLast.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicBoolean; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.processors.AsyncProcessor; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.processors.AsyncProcessor; /** * Cache only the very last value and relay/replay it to Subscribers. @@ -46,7 +45,7 @@ final class FlowableCacheLast extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableCacheLast(upstream); + return new FlowableCacheLast<>(upstream); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableCoalesce.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableCoalesce.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableCoalesce.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableCoalesce.java index b2417917..d43271bb 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableCoalesce.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableCoalesce.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.BiConsumer; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.*; /** * Coalesces items into a container if the downstream is not ready to receive items. @@ -41,13 +37,13 @@ final class FlowableCoalesce extends Flowable implements FlowableTransf final Publisher source; - final Callable containerSupplier; + final Supplier containerSupplier; final BiConsumer coalescer; final int bufferSize; - FlowableCoalesce(Publisher source, Callable containerSupplier, BiConsumer coalescer, int bufferSize) { + FlowableCoalesce(Publisher source, Supplier containerSupplier, BiConsumer coalescer, int bufferSize) { this.source = source; this.containerSupplier = containerSupplier; this.coalescer = coalescer; @@ -56,12 +52,12 @@ final class FlowableCoalesce extends Flowable implements FlowableTransf @Override public Publisher apply(Flowable upstream) { - return new FlowableCoalesce(upstream, containerSupplier, coalescer, bufferSize); + return new FlowableCoalesce<>(upstream, containerSupplier, coalescer, bufferSize); } @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new CoalesceSubscriber(s, containerSupplier, coalescer, bufferSize)); + source.subscribe(new CoalesceSubscriber<>(s, containerSupplier, coalescer, bufferSize)); } static final class CoalesceSubscriber extends AtomicInteger @@ -71,7 +67,7 @@ static final class CoalesceSubscriber extends AtomicInteger final Subscriber downstream; - final Callable containerSupplier; + final Supplier containerSupplier; final BiConsumer coalescer; @@ -93,7 +89,7 @@ static final class CoalesceSubscriber extends AtomicInteger long emitted; - CoalesceSubscriber(Subscriber downstream, Callable containerSupplier, + CoalesceSubscriber(Subscriber downstream, Supplier containerSupplier, BiConsumer coalescer, int bufferSize) { this.downstream = downstream; this.containerSupplier = containerSupplier; @@ -120,7 +116,7 @@ public void onNext(T t) { R c = container; try { if (c == null) { - c = containerSupplier.call(); + c = containerSupplier.get(); container = c; } coalescer.accept(c, t); @@ -145,7 +141,7 @@ public void onNext(T t) { } else { SimplePlainQueue q = queue; if (q == null) { - q = new SpscLinkedArrayQueue(bufferSize); + q = new SpscLinkedArrayQueue<>(bufferSize); queue = q; } q.offer(t); @@ -212,7 +208,7 @@ void drainLoop() { if (!empty) { try { if (c == null) { - c = containerSupplier.call(); + c = containerSupplier.get(); container = c; } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableDebounceFirst.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableDebounceFirst.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableDebounceFirst.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableDebounceFirst.java index beeb2bd7..ee463d9c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableDebounceFirst.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableDebounceFirst.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; -import org.reactivestreams.*; +import java.util.concurrent.TimeUnit; -import io.reactivex.*; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; /** * Debounce the upstream by taking an item and then blocking out subsequent @@ -52,7 +53,7 @@ final class FlowableDebounceFirst extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableDebounceFirst(upstream, timeout, unit, scheduler); + return new FlowableDebounceFirst<>(upstream, timeout, unit, scheduler); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableErrorJump.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableErrorJump.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableErrorJump.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableErrorJump.java index 0e7c2455..2557b9f9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableErrorJump.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableErrorJump.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.*; /** * Makes sure an upstream error skips the flow created with a @@ -49,18 +48,18 @@ final class FlowableErrorJump extends Flowable implements FlowableTrans @Override public Publisher apply(Flowable upstream) { - return new FlowableErrorJump(upstream, transformer); + return new FlowableErrorJump<>(upstream, transformer); } @Override protected void subscribeActual(Subscriber s) { - ErrorJumpFront front = new ErrorJumpFront(source, s); + ErrorJumpFront front = new ErrorJumpFront<>(source, s); Publisher downstream; try { - downstream = ObjectHelper.requireNonNull( + downstream = Objects.requireNonNull( transformer.apply(front), "The transformer returned a null Publisher"); } catch (Throwable ex) { @@ -84,7 +83,7 @@ static final class ErrorJumpFront extends Flowable implements FlowableS ErrorJumpFront(Flowable source, Subscriber downstream) { this.source = source; - this.middle = new AtomicReference>(); + this.middle = new AtomicReference<>(); this.end = new EndSubscriber(downstream); } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableEvery.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableEvery.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableEvery.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableEvery.java index 1ebe5d53..1117ad12 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableEvery.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableEvery.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; /** * Emits only every Nth item. @@ -47,7 +46,7 @@ protected void subscribeActual(Subscriber s) { @Override public Publisher apply(Flowable upstream) { - return new FlowableEvery(upstream, keep); + return new FlowableEvery<>(upstream, keep); } static final class EverySubscriber implements Subscriber, Subscription { diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableExpand.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableExpand.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableExpand.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableExpand.java index 30370d7f..cbdc6399 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableExpand.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableExpand.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.ArrayDeque; +import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.operators.*; /** * Emit and recursively expand elements from upstream. @@ -59,12 +55,12 @@ final class FlowableExpand extends Flowable implements FlowableTransformer @Override protected void subscribeActual(Subscriber s) { if (strategy != ExpandStrategy.DEPTH_FIRST) { - ExpandBreadthSubscriber parent = new ExpandBreadthSubscriber(s, expander, capacityHint, delayErrors); + ExpandBreadthSubscriber parent = new ExpandBreadthSubscriber<>(s, expander, capacityHint, delayErrors); parent.queue.offer(source); s.onSubscribe(parent); parent.drainQueue(); } else { - ExpandDepthSubscription parent = new ExpandDepthSubscription(s, expander, capacityHint, delayErrors); + ExpandDepthSubscription parent = new ExpandDepthSubscription<>(s, expander, capacityHint, delayErrors); parent.source = source; s.onSubscribe(parent); } @@ -72,7 +68,7 @@ protected void subscribeActual(Subscriber s) { @Override public Publisher apply(Flowable upstream) { - return new FlowableExpand(upstream, expander, strategy, capacityHint, delayErrors); + return new FlowableExpand<>(upstream, expander, strategy, capacityHint, delayErrors); } static final class ExpandBreadthSubscriber extends SubscriptionArbiter implements FlowableSubscriber { @@ -101,7 +97,7 @@ static final class ExpandBreadthSubscriber extends SubscriptionArbiter implem this.downstream = downstream; this.expander = expander; this.wip = new AtomicInteger(); - this.queue = new SpscLinkedArrayQueue>(capacityHint); + this.queue = new SpscLinkedArrayQueue<>(capacityHint); this.errors = new AtomicThrowable(); this.delayErrors = delayErrors; } @@ -118,7 +114,7 @@ public void onNext(T t) { Publisher p; try { - p = ObjectHelper.requireNonNull(expander.apply(t), "The expander returned a null Publisher"); + p = Objects.requireNonNull(expander.apply(t), "The expander returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); super.cancel(); @@ -134,7 +130,7 @@ public void onNext(T t) { public void onError(Throwable t) { setSubscription(SubscriptionHelper.CANCELLED); if (delayErrors) { - errors.addThrowable(t); + errors.tryAddThrowableOrReport(t); active = false; } else { super.cancel(); @@ -152,6 +148,7 @@ public void onComplete() { @Override public void cancel() { super.cancel(); + errors.tryTerminateAndReport(); drainQueue(); } @@ -166,12 +163,7 @@ void drainQueue() { if (q.isEmpty()) { setSubscription(SubscriptionHelper.CANCELLED); super.cancel(); - Throwable ex = errors.terminate(); - if (ex == null) { - downstream.onComplete(); - } else { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); } else { Publisher p = q.poll(); long c = produced; @@ -222,11 +214,11 @@ static final class ExpandDepthSubscription int capacityHint, boolean delayErrors) { this.downstream = downstream; this.expander = expander; - this.subscriptionStack = new ArrayDeque(); + this.subscriptionStack = new ArrayDeque<>(); this.error = new AtomicThrowable(); this.active = new AtomicInteger(); this.requested = new AtomicLong(); - this.current = new AtomicReference(); + this.current = new AtomicReference<>(); this.delayErrors = delayErrors; } @@ -333,7 +325,7 @@ void drainQueue() { if (!delayErrors && error.get() != null) { cancel(); - a.onError(error.terminate()); + error.tryTerminateConsumer(a); return; } @@ -346,7 +338,7 @@ void drainQueue() { e++; try { - p = ObjectHelper.requireNonNull(expander.apply(v), "The expander returned a null Publisher"); + p = Objects.requireNonNull(expander.apply(v), "The expander returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); p = null; @@ -354,7 +346,7 @@ void drainQueue() { curr.done = true; currentDone = true; v = null; - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); } if (p != null) { @@ -374,12 +366,7 @@ void drainQueue() { if (!newSource) { if (currentDone && v == null) { if (n.decrementAndGet() == 0) { - Throwable ex = error.terminate(); - if (ex != null) { - a.onError(ex); - } else { - a.onComplete(); - } + error.tryTerminateConsumer(a); return; } curr = pop(); @@ -410,7 +397,7 @@ void innerNext(ExpandDepthSubscriber inner, T t) { } void innerError(ExpandDepthSubscriber inner, Throwable t) { - error.addThrowable(t); + error.tryAddThrowableOrReport(t); inner.done = true; drainQueue(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableFilterAsync.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableFilterAsync.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableFilterAsync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableFilterAsync.java index 54108636..642cde5c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableFilterAsync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableFilterAsync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.operators.FlowableMapAsync.AsyncSupport; -import hu.akarnokd.rxjava2.operators.FlowableMapAsync.MapAsyncSubscriber.InnerSubscriber; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.operators.FlowableMapAsync.AsyncSupport; +import hu.akarnokd.rxjava4.operators.FlowableMapAsync.MapAsyncSubscriber.InnerSubscriber; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps each upstream value into a single {@code true} or {@code false} value provided by a generated Publisher for that @@ -56,7 +53,7 @@ final class FlowableFilterAsync extends Flowable implements FlowableTransf @Override public Publisher apply(Flowable upstream) { - return new FlowableFilterAsync(upstream, asyncPredicate, bufferSize); + return new FlowableFilterAsync<>(upstream, asyncPredicate, bufferSize); } @Override @@ -76,7 +73,7 @@ static final class FilterAsyncSubscriber final int bufferSize; - final AtomicThrowable error; + final AtomicThrowable errors; final AtomicLong requested; @@ -115,10 +112,10 @@ static final class FilterAsyncSubscriber this.downstream = downstream; this.asyncPredicate = asyncPredicate; this.bufferSize = bufferSize; - this.error = new AtomicThrowable(); + this.errors = new AtomicThrowable(); this.requested = new AtomicLong(); this.wip = new AtomicInteger(); - this.current = new AtomicReference>(); + this.current = new AtomicReference<>(); } @Override @@ -134,7 +131,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - error.addThrowable(t); + errors.tryAddThrowableOrReport(t); done = true; drain(); } @@ -158,6 +155,7 @@ public void cancel() { if (!cancelled) { cancelled = true; upstream.cancel(); + errors.tryTerminateAndReport(); cancelInner(); if (wip.getAndIncrement() == 0) { clear(); @@ -225,7 +223,7 @@ void drain() { boolean empty = t == null; if (d && empty) { - Throwable ex = error.terminate(); + Throwable ex = errors.terminate(); if (ex == null) { a.onComplete(); } else { @@ -243,22 +241,22 @@ void drain() { Publisher p; try { - p = ObjectHelper.requireNonNull(asyncPredicate.apply(t), "The asyncPredicate returned a null value"); + p = Objects.requireNonNull(asyncPredicate.apply(t), "The asyncPredicate returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); p = null; } if (p != null) { - if (p instanceof Callable) { + if (p instanceof Supplier) { Boolean u; try { - u = ((Callable)p).call(); + u = ((Supplier)p).get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); u = null; } @@ -267,7 +265,7 @@ void drain() { e++; } } else { - InnerSubscriber inner = new InnerSubscriber(this); + InnerSubscriber inner = new InnerSubscriber<>(this); if (current.compareAndSet(null, inner)) { state = STATE_RUNNING; p.subscribe(inner); @@ -317,7 +315,7 @@ void drain() { boolean empty = t == null; if (d && empty) { - Throwable ex = error.terminate(); + Throwable ex = errors.terminate(); if (ex == null) { a.onComplete(); } else { @@ -359,7 +357,7 @@ public void innerResult(Boolean item) { @Override public void innerError(Throwable ex) { - error.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); state = STATE_RESULT; clearCurrent(); drain(); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapAsync.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapAsync.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapAsync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapAsync.java index 34cba435..40753ec6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapAsync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapAsync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import hu.akarnokd.rxjava2.operators.FlowableFlatMapSync.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.fuseable.SimpleQueue; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.operators.FlowableFlatMapSync.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.operators.SimpleQueue; /** * FlatMap a bounded number of inner, non-trivial flows (unbound not supported). @@ -63,7 +62,7 @@ protected void subscribeActual(Subscriber s) { @Override public Publisher apply(Flowable upstream) { - return new FlowableFlatMapAsync(upstream, mapper, maxConcurrency, bufferSize, depthFirst, scheduler); + return new FlowableFlatMapAsync<>(upstream, mapper, maxConcurrency, bufferSize, depthFirst, scheduler); } static final class FlatMapOuterSubscriber extends BaseFlatMapOuterSubscriber implements Runnable { @@ -109,14 +108,12 @@ public void innerNext(FlatMapInnerSubscriber inner, R item) { @Override public void innerError(FlatMapInnerSubscriber inner, Throwable ex) { remove(inner); - if (error.addThrowable(ex)) { + if (error.tryAddThrowableOrReport(ex)) { inner.done = true; done = true; upstream.cancel(); cancelInners(); drain(); - } else { - RxJavaPlugins.onError(ex); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapSync.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapSync.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapSync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapSync.java index 2930ed42..570cbdf9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapSync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapSync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.queue.SpscArrayQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.operators.*; /** * FlatMap a bounded number of inner, non-trivial flows (unbound not supported). @@ -66,7 +62,7 @@ protected void subscribeActual(Subscriber s) { @Override public Publisher apply(Flowable upstream) { - return new FlowableFlatMapSync(upstream, mapper, maxConcurrency, bufferSize, depthFirst); + return new FlowableFlatMapSync<>(upstream, mapper, maxConcurrency, bufferSize, depthFirst); } interface FlatMapInnerSubscriberSupport { @@ -132,7 +128,7 @@ abstract static class BaseFlatMapOuterSubscriber extends AtomicInteger this.active = new AtomicLong(); int c = Pow2.roundToPowerOfTwo(maxConcurrency); - this.subscribers = new AtomicReferenceArray>(c); + this.subscribers = new AtomicReferenceArray<>(c); this.freelist = new AtomicIntegerArray(c + CONSUMER_INDEX + 16); } @@ -153,16 +149,14 @@ public final void onNext(T t) { Publisher p; try { - p = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null value"); + p = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.cancel(); cancelInners(); - if (error.addThrowable(ex)) { + if (error.tryAddThrowableOrReport(ex)) { done = true; drain(); - } else { - RxJavaPlugins.onError(ex); } return; } @@ -178,7 +172,7 @@ public final void onNext(T t) { idx = ci + 1; } - FlatMapInnerSubscriber inner = new FlatMapInnerSubscriber(this, bufferSize, idx); + FlatMapInnerSubscriber inner = new FlatMapInnerSubscriber<>(this, bufferSize, idx); s.lazySet(idx - 1, inner); fl.lazySet(m + CONSUMER_INDEX, (ci + 1) & (m - 1)); @@ -195,11 +189,9 @@ public final void onNext(T t) { @Override public final void onError(Throwable t) { - if (error.addThrowable(t)) { + if (error.tryAddThrowableOrReport(t)) { done = true; drain(); - } else { - RxJavaPlugins.onError(t); } } @@ -222,6 +214,7 @@ public final void cancel() { if (!cancelled) { cancelled = true; upstream.cancel(); + error.tryTerminateAndReport(); cancelInners(); cleanupAfter(); } @@ -283,7 +276,7 @@ final void depthFirst() { if (d) { Throwable ex = error.get(); if (ex != null) { - a.onError(error.terminate()); + error.tryTerminateConsumer(a); cleanupAfter(); return; } @@ -295,10 +288,10 @@ final void depthFirst() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); upstream.cancel(); cancelInners(); - a.onError(error.terminate()); + error.tryTerminateConsumer(a); cleanupAfter(); return; } @@ -356,7 +349,7 @@ final void depthFirst() { Throwable ex = error.get(); if (ex != null) { - a.onError(error.terminate()); + error.tryTerminateConsumer(a); cleanupAfter(); return; } @@ -409,7 +402,7 @@ final void breadthFirst() { if (done) { Throwable ex = error.get(); if (ex != null) { - a.onError(error.terminate()); + error.tryTerminateConsumer(a); cleanupAfter(); return; } @@ -435,10 +428,10 @@ final void breadthFirst() { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); upstream.cancel(); cancelInners(); - a.onError(error.terminate()); + error.tryTerminateConsumer(a); cleanupAfter(); return; } @@ -465,7 +458,7 @@ final void breadthFirst() { if (done) { Throwable ex = error.get(); if (ex != null) { - a.onError(error.terminate()); + error.tryTerminateConsumer(a); cleanupAfter(); return; } @@ -587,14 +580,12 @@ public void innerNext(FlatMapInnerSubscriber inner, R item) { @Override public void innerError(FlatMapInnerSubscriber inner, Throwable ex) { remove(inner); - if (error.addThrowable(ex)) { + if (error.tryAddThrowableOrReport(ex)) { inner.done = true; done = true; upstream.cancel(); cancelInners(); drain(); - } else { - RxJavaPlugins.onError(ex); } } @@ -698,7 +689,7 @@ void producedOne() { SimpleQueue queue() { SimpleQueue q = queue; if (q == null) { - q = new SpscArrayQueue(bufferSize); + q = new SpscArrayQueue<>(bufferSize); queue = q; } return q; diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableGenerateAsync.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableGenerateAsync.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableGenerateAsync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableGenerateAsync.java index 5ab5b630..297171eb 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableGenerateAsync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableGenerateAsync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Generates items by invoking a callback, for each downstream request one by one, that sets up an @@ -40,13 +37,13 @@ */ final class FlowableGenerateAsync extends Flowable { - final Callable initialState; + final Supplier initialState; final BiFunction, ? extends S> asyncGenerator; final Consumer stateCleanup; - FlowableGenerateAsync(Callable initialState, + FlowableGenerateAsync(Supplier initialState, BiFunction, ? extends S> asyncGenerator, Consumer stateCleanup) { this.initialState = initialState; @@ -59,14 +56,14 @@ protected void subscribeActual(Subscriber s) { S state; try { - state = initialState.call(); + state = initialState.get(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); return; } - GenerateAsyncSubscription parent = new GenerateAsyncSubscription(s, state, asyncGenerator, stateCleanup); + GenerateAsyncSubscription parent = new GenerateAsyncSubscription<>(s, state, asyncGenerator, stateCleanup); s.onSubscribe(parent); parent.moveNext(); } @@ -132,6 +129,7 @@ public void request(long n) { @Override public void cancel() { cancelled = true; + errors.tryTerminateAndReport(); resource.cancel(); if (getAndIncrement() == 0) { cleanup(); @@ -163,12 +161,10 @@ public void onError(Throwable error) { if (error == null) { error = new NullPointerException("error is null"); } - if (errors.addThrowable(error)) { + if (errors.tryAddThrowableOrReport(error)) { itemState |= ITEM_STATE_DONE; done = true; drain(); - } else { - RxJavaPlugins.onError(error); } } @@ -240,12 +236,7 @@ void drain() { int s = itemState; if (d && s == ITEM_STATE_DONE) { - Throwable ex = errors.terminate(); - if (ex != null) { - downstream.onError(ex); - } else { - downstream.onComplete(); - } + errors.tryTerminateConsumer(downstream); resource.cancel(); cleanup(); return; diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableIndexOf.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableIndexOf.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableIndexOf.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableIndexOf.java index 27c89541..cc860f59 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableIndexOf.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableIndexOf.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscribers.DeferredScalarSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarSubscriber; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Predicate; /** * Returns the first index of an element that matches a predicate or -1L if no elements match. @@ -43,7 +43,7 @@ final class FlowableIndexOf extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableIndexOf(upstream, predicate); + return new FlowableIndexOf<>(upstream, predicate); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableIntervalBackpressure.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableIntervalBackpressure.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableIntervalBackpressure.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableIntervalBackpressure.java index fdfa5e56..d7637459 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableIntervalBackpressure.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableIntervalBackpressure.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; /** * Periodically try to emit an ever increasing long value (starting from 0L) diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableMapAsync.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableMapAsync.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableMapAsync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableMapAsync.java index a7816de1..ad4f0aa3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableMapAsync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableMapAsync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Maps each upstream value into a single value provided by a generated Publisher for that @@ -61,7 +58,7 @@ final class FlowableMapAsync extends Flowable implements FlowableTra @Override public Publisher apply(Flowable upstream) { - return new FlowableMapAsync(upstream, mapper, combiner, bufferSize); + return new FlowableMapAsync<>(upstream, mapper, combiner, bufferSize); } @Override @@ -135,7 +132,7 @@ static final class MapAsyncSubscriber this.error = new AtomicThrowable(); this.requested = new AtomicLong(); this.wip = new AtomicInteger(); - this.current = new AtomicReference>(); + this.current = new AtomicReference<>(); } @Override @@ -151,7 +148,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - error.addThrowable(t); + error.tryAddThrowableOrReport(t); done = true; drain(); } @@ -175,6 +172,7 @@ public void cancel() { if (!cancelled) { cancelled = true; upstream.cancel(); + error.tryTerminateAndReport(); cancelInner(); if (wip.getAndIncrement() == 0) { clear(); @@ -259,28 +257,28 @@ void drain() { Publisher p; try { - p = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null value"); + p = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); p = null; } if (p != null) { - if (p instanceof Callable) { + if (p instanceof Supplier) { R v; try { @SuppressWarnings("unchecked") - U u = ((Callable)p).call(); + U u = ((Supplier)p).get(); if (u != null) { - v = ObjectHelper.requireNonNull(combiner.apply(t, u), "The combiner returned a null value"); + v = Objects.requireNonNull(combiner.apply(t, u), "The combiner returned a null value"); } else { v = null; } } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); v = null; } @@ -289,7 +287,7 @@ void drain() { e++; } } else { - InnerSubscriber inner = new InnerSubscriber(this); + InnerSubscriber inner = new InnerSubscriber<>(this); if (current.compareAndSet(null, inner)) { state = STATE_RUNNING; p.subscribe(inner); @@ -313,10 +311,10 @@ void drain() { R v; try { - v = ObjectHelper.requireNonNull(combiner.apply(t, u), "The combiner returned a null value"); + v = Objects.requireNonNull(combiner.apply(t, u), "The combiner returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); v = null; } @@ -351,12 +349,7 @@ void drain() { boolean empty = t == null; if (d && empty) { - Throwable ex = error.terminate(); - if (ex == null) { - a.onComplete(); - } else { - a.onError(ex); - } + error.tryTerminateConsumer(a); return; } } @@ -393,7 +386,7 @@ public void innerResult(U item) { @Override public void innerError(Throwable ex) { - error.addThrowable(ex); + error.tryAddThrowableOrReport(ex); state = STATE_RESULT; clearCurrent(); drain(); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableMapFilter.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableMapFilter.java similarity index 95% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableMapFilter.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableMapFilter.java index 1e5f6bcb..3023f3c4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableMapFilter.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableMapFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.BiConsumer; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.internal.subscribers.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.BiConsumer; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Filters and/or maps source values via a callback and emitter. @@ -44,7 +44,7 @@ final class FlowableMapFilter extends Flowable implements FlowableTrans @Override public Publisher apply(Flowable upstream) { - return new FlowableMapFilter(upstream, consumer); + return new FlowableMapFilter<>(upstream, consumer); } @Override @@ -180,7 +180,7 @@ public void doComplete() { } @Override - public R poll() throws Exception { + public R poll() throws Throwable { for (;;) { T v = qs.poll(); @@ -355,7 +355,7 @@ public void doComplete() { } @Override - public R poll() throws Exception { + public R poll() throws Throwable { for (;;) { T v = qs.poll(); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeout.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableOnBackpressureTimeout.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeout.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableOnBackpressureTimeout.java index 359da15e..2cc4d1ed 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeout.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableOnBackpressureTimeout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.ArrayDeque; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * If the downstream doesn't request, it buffers events and times out @@ -62,7 +60,7 @@ final class FlowableOnBackpressureTimeout extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableOnBackpressureTimeout(upstream, maxSize, timeout, unit, scheduler, onEvict); + return new FlowableOnBackpressureTimeout<>(upstream, maxSize, timeout, unit, scheduler, onEvict); } @Override @@ -108,7 +106,7 @@ static final class OnBackpressureTimeoutSubscriber this.worker = worker; this.onEvict = onEvict; this.requested = new AtomicLong(); - this.queue = new ArrayDeque(); + this.queue = new ArrayDeque<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableOrderedMerge.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableOrderedMerge.java similarity index 82% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableOrderedMerge.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableOrderedMerge.java index f506ad86..1b9eb79e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableOrderedMerge.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableOrderedMerge.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.Arrays; -import java.util.Comparator; +import java.util.*; +import java.util.concurrent.Flow.*; -import org.reactivestreams.Publisher; -import org.reactivestreams.Subscriber; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.EmptySubscription; +import hu.akarnokd.rxjava4.internal.operators.BasicMergeSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptySubscription; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; /** * Merges a fixed set of sources by picking the next smallest @@ -71,7 +68,7 @@ protected void subscribeActual(Subscriber s) { if (n == array.length) { array = Arrays.copyOf(array, n << 1); } - array[n++] = ObjectHelper.requireNonNull(p, "a source is null"); + array[n++] = Objects.requireNonNull(p, "a source is null"); } } catch (Throwable ex) { Exceptions.throwIfFatal(ex); @@ -92,7 +89,7 @@ protected void subscribeActual(Subscriber s) { return; } - BasicMergeSubscription parent = new BasicMergeSubscription(s, comparator, n, prefetch, delayErrors); + BasicMergeSubscription parent = new BasicMergeSubscription<>(s, comparator, n, prefetch, delayErrors); s.onSubscribe(parent); parent.subscribe(array, n); } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowablePartialCollect.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowablePartialCollect.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowablePartialCollect.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowablePartialCollect.java index 856036f1..440469e1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowablePartialCollect.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowablePartialCollect.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Allows converting upstream items into output objects where an upstream item @@ -65,12 +63,12 @@ final class FlowablePartialCollect extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowablePartialCollect(upstream, handler, cleaner, prefetch); + return new FlowablePartialCollect<>(upstream, handler, cleaner, prefetch); } @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new PartialCollectSubscriber(s, handler, cleaner, prefetch)); + source.subscribe(new PartialCollectSubscriber<>(s, handler, cleaner, prefetch)); } static final class PartialCollectSubscriber @@ -124,7 +122,7 @@ static final class PartialCollectSubscriber this.cleaner = cleaner; this.prefetch = prefetch; this.errors = new AtomicThrowable(); - this.queue = new AtomicReferenceArray(Pow2.roundToPowerOfTwo(prefetch)); + this.queue = new AtomicReferenceArray<>(Pow2.roundToPowerOfTwo(prefetch)); this.producerIndex = new AtomicLong(); this.requested = new AtomicLong(); this.limit = prefetch - (prefetch >> 2); @@ -152,11 +150,9 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - if (errors.addThrowable(t)) { + if (errors.tryAddThrowableOrReport(t)) { done = true; drain(); - } else { - RxJavaPlugins.onError(t); } } @@ -170,6 +166,7 @@ public void onComplete() { public void cancel() { cancelled = true; upstream.cancel(); + errors.tryTerminateAndReport(); drain(); } @@ -317,20 +314,14 @@ void drain() { boolean d = this.done; if (d && errors.get() != null) { - Throwable ex = errors.terminate(); - downstream.onError(ex); + errors.tryTerminateConsumer(downstream); cleanup(); cancelled = true; break; } if (this.handlerDone) { - Throwable ex = errors.terminate(); - if (ex == null) { - downstream.onComplete(); - } else { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); cleanup(); cancelled = true; break; @@ -344,7 +335,7 @@ void drain() { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.cancel(); - errors.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); this.handlerDone = true; continue; } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRepeatScalar.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRepeatScalar.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableRepeatScalar.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableRepeatScalar.java index 7ae6bd8a..2ccff654 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRepeatScalar.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRepeatScalar.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.Flowable; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; /** * Repeats a scalar value indefinitely. @@ -41,9 +40,9 @@ final class FlowableRepeatScalar extends Flowable { @Override protected void subscribeActual(Subscriber s) { if (s instanceof ConditionalSubscriber) { - s.onSubscribe(new RepeatScalarConditionalSubscription((ConditionalSubscriber)s, value)); + s.onSubscribe(new RepeatScalarConditionalSubscription<>((ConditionalSubscriber)s, value)); } else { - s.onSubscribe(new RepeatScalarSubscription(s, value)); + s.onSubscribe(new RepeatScalarSubscription<>(s, value)); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRepeatCallable.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRepeatSupplier.java similarity index 76% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableRepeatCallable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableRepeatSupplier.java index 9fb9e4aa..0451fff7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRepeatCallable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRepeatSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,40 +14,38 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import io.reactivex.Flowable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Supplier; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; /** - * Repeatedly calls a Callable indefinitely. + * Repeatedly calls a Supplier indefinitely. * * @param the value type * * @since 0.14.2 */ -final class FlowableRepeatCallable extends Flowable { +final class FlowableRepeatSupplier extends Flowable { - final Callable callable; + final Supplier supplier; - FlowableRepeatCallable(Callable callable) { - this.callable = callable; + FlowableRepeatSupplier(Supplier supplier) { + this.supplier = supplier; } @Override protected void subscribeActual(Subscriber s) { if (s instanceof ConditionalSubscriber) { - s.onSubscribe(new RepeatCallableConditionalSubscription((ConditionalSubscriber)s, callable)); + s.onSubscribe(new RepeatCallableConditionalSubscription<>((ConditionalSubscriber)s, supplier)); } else { - s.onSubscribe(new RepeatCallableSubscription(s, callable)); + s.onSubscribe(new RepeatCallableSubscription<>(s, supplier)); } } @@ -57,13 +55,13 @@ static final class RepeatCallableSubscription extends BasicQueueSubscription< final Subscriber downstream; - final Callable callable; + final Supplier supplier; volatile boolean cancelled; - RepeatCallableSubscription(Subscriber downstream, Callable callable) { + RepeatCallableSubscription(Subscriber downstream, Supplier supplier) { this.downstream = downstream; - this.callable = callable; + this.supplier = supplier; } @Override @@ -80,7 +78,7 @@ public void request(long n) { } void fastpath() { - Callable c = callable; + Supplier c = supplier; for (;;) { if (cancelled) { break; @@ -89,7 +87,7 @@ void fastpath() { T v; try { - v = ObjectHelper.requireNonNull(c.call(), "The callable returned a null value"); + v = Objects.requireNonNull(c.get(), "The supplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -101,7 +99,7 @@ void fastpath() { } void slowpath(long r) { - Callable c = callable; + Supplier c = supplier; long e = 0L; @@ -115,7 +113,7 @@ void slowpath(long r) { T v; try { - v = ObjectHelper.requireNonNull(c.call(), "The callable returned a null value"); + v = Objects.requireNonNull(c.get(), "The supplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -156,8 +154,8 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { - return ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value"); + public T poll() throws Throwable { + return Objects.requireNonNull(supplier.get(), "The supplier returned a null value"); } @Override @@ -177,13 +175,13 @@ static final class RepeatCallableConditionalSubscription extends BasicQueueSu final ConditionalSubscriber downstream; - final Callable callable; + final Supplier supplier; volatile boolean cancelled; - RepeatCallableConditionalSubscription(ConditionalSubscriber downstream, Callable callable) { + RepeatCallableConditionalSubscription(ConditionalSubscriber downstream, Supplier supplier) { this.downstream = downstream; - this.callable = callable; + this.supplier = supplier; } @Override @@ -200,7 +198,7 @@ public void request(long n) { } void fastpath() { - Callable c = callable; + Supplier c = supplier; for (;;) { if (cancelled) { break; @@ -209,7 +207,7 @@ void fastpath() { T v; try { - v = ObjectHelper.requireNonNull(c.call(), "The callable returned a null value"); + v = Objects.requireNonNull(c.get(), "The supplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -221,7 +219,7 @@ void fastpath() { } void slowpath(long r) { - Callable c = callable; + Supplier c = supplier; long e = 0L; @@ -235,7 +233,7 @@ void slowpath(long r) { T v; try { - v = ObjectHelper.requireNonNull(c.call(), "The callable returned a null value"); + v = Objects.requireNonNull(c.get(), "The supplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); @@ -276,8 +274,8 @@ public int requestFusion(int mode) { } @Override - public T poll() throws Exception { - return ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value"); + public T poll() throws Throwable { + return Objects.requireNonNull(supplier.get(), "The supplier returned a null value"); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestObserveOn.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestObserveOn.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestObserveOn.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestObserveOn.java index 9515997e..b760d934 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestObserveOn.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestObserveOn.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicLong; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.BackpressureHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; /** * Requests one-by-one and emits those items on the given {@link Scheduler}, allowing an @@ -44,7 +43,7 @@ final class FlowableRequestObserveOn extends Flowable implements FlowableT @Override public Publisher apply(Flowable upstream) { - return new FlowableRequestObserveOn(upstream, scheduler); + return new FlowableRequestObserveOn<>(upstream, scheduler); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestSample.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestSample.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestSample.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestSample.java index fa58a2e1..6162f3e0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestSample.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.MissingBackpressureException; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.MissingBackpressureException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Issues {@link Subscription#request(long)}(1) when the other source Publisher signals an onNext item. @@ -45,12 +43,12 @@ final class FlowableRequestSample extends Flowable implements FlowableTran @Override public Publisher apply(Flowable upstream) { - return new FlowableRequestSample(upstream, other); + return new FlowableRequestSample<>(upstream, other); } @Override protected void subscribeActual(Subscriber s) { - RequestSample parent = new RequestSample(s); + RequestSample parent = new RequestSample<>(s); s.onSubscribe(parent); other.subscribe(parent.otherConsumer); source.subscribe(parent); @@ -81,7 +79,7 @@ static final class RequestSample this.downstream = downstream; this.downstreamRequests = new AtomicLong(); this.upstreamRequests = new AtomicLong(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); this.otherConsumer = new OtherConsumer(this); this.error = new AtomicThrowable(); this.wip = new AtomicInteger(); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTime.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTime.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTime.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTime.java index b80d0d23..7be89bac 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTime.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTime.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.MissingBackpressureException; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.MissingBackpressureException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Issues {@link Subscription#request(long)}(1) after the initial delay and then at each period. @@ -59,12 +56,12 @@ final class FlowableRequestSampleTime extends Flowable implements Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableRequestSampleTime(upstream, initialDelay, period, unit, scheduler); + return new FlowableRequestSampleTime<>(upstream, initialDelay, period, unit, scheduler); } @Override protected void subscribeActual(Subscriber s) { - RequestSample parent = new RequestSample(s); + RequestSample parent = new RequestSample<>(s); s.onSubscribe(parent); DisposableHelper.setOnce(parent.timer, scheduler.schedulePeriodicallyDirect(parent, initialDelay, period, unit)); source.subscribe(parent); @@ -91,8 +88,8 @@ static final class RequestSample this.downstream = downstream; this.downstreamRequests = new AtomicLong(); this.upstreamRequests = new AtomicLong(); - this.upstream = new AtomicReference(); - this.timer = new AtomicReference(); + this.upstream = new AtomicReference<>(); + this.timer = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSpanout.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSpanout.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableSpanout.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableSpanout.java index 4ec0b56d..ac6ddd79 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSpanout.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSpanout.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.Flow.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; -import org.reactivestreams.*; +import java.util.concurrent.TimeUnit; -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.operators.*; /** * Makes sure there is at least the given amount of time between emissions of the upstream elements. @@ -64,7 +64,7 @@ final class FlowableSpanout extends Flowable implements FlowableTransforme @Override public Publisher apply(Flowable upstream) { - return new FlowableSpanout(upstream, initialSpan, betweenSpan, TimeUnit.NANOSECONDS, scheduler, delayError, bufferSize); + return new FlowableSpanout<>(upstream, initialSpan, betweenSpan, TimeUnit.NANOSECONDS, scheduler, delayError, bufferSize); } @Override @@ -101,7 +101,7 @@ static final class SpanoutSubscriber implements Subscriber, Subscription, this.worker = worker; this.delayError = delayError; this.lastEvent = -1L; - this.queue = new SpscLinkedArrayQueue(bufferSize); + this.queue = new SpscLinkedArrayQueue<>(bufferSize); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchFlatMap.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchFlatMap.java similarity index 93% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchFlatMap.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchFlatMap.java index 5fa0917c..ff2b0478 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchFlatMap.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchFlatMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscArrayQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.operators.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; final class FlowableSwitchFlatMap extends Flowable implements FlowableTransformer { @@ -53,7 +49,7 @@ final class FlowableSwitchFlatMap extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableSwitchFlatMap(upstream, mapper, maxActive, bufferSize); + return new FlowableSwitchFlatMap<>(upstream, mapper, maxActive, bufferSize); } @Override @@ -100,7 +96,7 @@ static final class SwitchFlatMapSubscriber this.mapper = mapper; this.maxActive = maxActive; this.bufferSize = bufferSize; - this.active = new ArrayDeque>(); + this.active = new ArrayDeque<>(); this.requested = new AtomicLong(); this.error = new AtomicThrowable(); this.activeCache = new SfmInnerSubscriber[maxActive]; @@ -121,7 +117,7 @@ public void onSubscribe(Subscription s) { public void onNext(T t) { Publisher p; try { - p = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); + p = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.cancel(); @@ -129,7 +125,7 @@ public void onNext(T t) { return; } - SfmInnerSubscriber inner = new SfmInnerSubscriber(this, bufferSize); + SfmInnerSubscriber inner = new SfmInnerSubscriber<>(this, bufferSize); if (add(inner)) { p.subscribe(inner); } @@ -204,7 +200,7 @@ void clearCache() { } void cancelInners() { - List> subscribers = new ArrayList>(); + List> subscribers = new ArrayList<>(); synchronized (this) { subscribers.addAll(active); active.clear(); @@ -398,7 +394,7 @@ static final class SfmInnerSubscriber extends AtomicReference> 2); - this.queue = new SpscArrayQueue(bufferSize); + this.queue = new SpscArrayQueue<>(bufferSize); } void cancel() { diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyMany.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyMany.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyMany.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyMany.java index 3cd68f9f..7c2c656b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyMany.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyMany.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.Iterator; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; final class FlowableSwitchIfEmptyMany extends Flowable implements FlowableTransformer { @@ -48,14 +46,14 @@ protected void subscribeActual(Subscriber s) { EmptySubscription.error(ex, s); return; } - SwitchManySubscriber parent = new SwitchManySubscriber(s, it); + SwitchManySubscriber parent = new SwitchManySubscriber<>(s, it); s.onSubscribe(parent); parent.drain(source); } @Override public Publisher apply(Flowable upstream) { - return new FlowableSwitchIfEmptyMany(upstream, alternatives); + return new FlowableSwitchIfEmptyMany<>(upstream, alternatives); } static final class SwitchManySubscriber @@ -80,7 +78,7 @@ static final class SwitchManySubscriber this.downstream = downstream; this.alternatives = alternatives; this.requested = new AtomicLong(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyArray.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyArray.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyArray.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyArray.java index 237ec5c8..3b3fd7a4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyArray.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; final class FlowableSwitchIfEmptyManyArray extends Flowable implements FlowableTransformer { @@ -38,14 +36,14 @@ final class FlowableSwitchIfEmptyManyArray extends Flowable @Override protected void subscribeActual(Subscriber s) { - SwitchManySubscriber parent = new SwitchManySubscriber(s, alternatives); + SwitchManySubscriber parent = new SwitchManySubscriber<>(s, alternatives); s.onSubscribe(parent); parent.drain(source); } @Override public Publisher apply(Flowable upstream) { - return new FlowableSwitchIfEmptyManyArray(upstream, alternatives); + return new FlowableSwitchIfEmptyManyArray<>(upstream, alternatives); } static final class SwitchManySubscriber @@ -72,7 +70,7 @@ static final class SwitchManySubscriber this.downstream = downstream; this.alternatives = alternatives; this.requested = new AtomicLong(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchOnFirst.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchOnFirst.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchOnFirst.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchOnFirst.java index fb1d7226..a2d3837a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableSwitchOnFirst.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableSwitchOnFirst.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Wait for the very first item and if it matches a predicate, switch to @@ -51,12 +50,12 @@ final class FlowableSwitchOnFirst extends Flowable implements FlowableTran @Override protected void subscribeActual(Subscriber s) { - source.subscribe(new SwitchOnFirstSubscriber(s, predicate, selector)); + source.subscribe(new SwitchOnFirstSubscriber<>(s, predicate, selector)); } @Override public Publisher apply(Flowable upstream) { - return new FlowableSwitchOnFirst(upstream, predicate, selector); + return new FlowableSwitchOnFirst<>(upstream, predicate, selector); } static final class SwitchOnFirstSubscriber extends AtomicBoolean @@ -83,7 +82,7 @@ static final class SwitchOnFirstSubscriber extends AtomicBoolean this.downstream = downstream; this.predicate = predicate; this.selector = selector; - this.secondary = new SwitchOnSecondarySubscriber(downstream); + this.secondary = new SwitchOnSecondarySubscriber<>(downstream); } @Override @@ -103,7 +102,7 @@ public void onNext(T t) { try { if (predicate.test(t)) { - resume = ObjectHelper.requireNonNull(selector.apply(t), "The selector returned a null Publisher"); + resume = Objects.requireNonNull(selector.apply(t), "The selector returned a null Publisher"); } } catch (Throwable ex) { upstream.cancel(); @@ -176,7 +175,7 @@ static final class SwitchOnSecondarySubscriber extends AtomicLong SwitchOnSecondarySubscriber(Subscriber downstream) { this.downstream = downstream; - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableTimeoutLast.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableTimeoutLast.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableTimeoutLast.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableTimeoutLast.java index b3086884..456b9e0a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableTimeoutLast.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableTimeoutLast.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.SequentialDisposable; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.subscribers.SerializedSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.subscribers.SerializedSubscriber; /** * Emit the very last item if the source ends or the timeout @@ -58,16 +56,16 @@ final class FlowableTimeoutLast extends Flowable @Override public Publisher apply(Flowable upstream) { - return new FlowableTimeoutLast(upstream, timeout, unit, scheduler, fromStart); + return new FlowableTimeoutLast<>(upstream, timeout, unit, scheduler, fromStart); } @Override protected void subscribeActual(Subscriber s) { - SerializedSubscriber serial = new SerializedSubscriber(s); + SerializedSubscriber serial = new SerializedSubscriber<>(s); if (fromStart) { - source.subscribe(new TimeoutStartLast(serial, timeout, unit, scheduler)); + source.subscribe(new TimeoutStartLast<>(serial, timeout, unit, scheduler)); } else { - source.subscribe(new TimeoutLast(serial, timeout, unit, scheduler.createWorker())); + source.subscribe(new TimeoutLast<>(serial, timeout, unit, scheduler.createWorker())); } } @@ -98,7 +96,7 @@ static final class TimeoutLast this.worker = worker; this.task = new SequentialDisposable(); this.index = new AtomicLong(); - this.value = new AtomicReference(); + this.value = new AtomicReference<>(); } @Override @@ -205,7 +203,7 @@ static final class TimeoutStartLast this.scheduler = scheduler; this.task = new SequentialDisposable(); this.once = new AtomicBoolean(); - this.value = new AtomicReference(); + this.value = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableTransformers.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableTransformers.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableTransformers.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableTransformers.java index e372e064..0b187caa 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableTransformers.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableTransformers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.TimeUnit; -import org.reactivestreams.Publisher; - -import hu.akarnokd.rxjava2.util.BiFunctionSecondIdentity; -import io.reactivex.*; -import io.reactivex.annotations.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.util.BiFunctionSecondIdentity; +import io.reactivex.rxjava4.annotations.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.Schedulers; /** * Additional operators in the form of {@link FlowableTransformer}, @@ -49,7 +48,7 @@ private FlowableTransformers() { *
    *
  • The operator starts with an open valve.
  • *
  • If the other Publisher completes, the sequence terminates with an {@code IllegalStateException}.
  • - *
  • The operator doesn't run on any particular {@link io.reactivex.Scheduler Scheduler}.
  • + *
  • The operator doesn't run on any particular {@link io.reactivex.rxjava4.core.Scheduler Scheduler}.
  • *
  • The operator is a pass-through for backpressure and uses an internal unbounded buffer * of size {@link Flowable#bufferSize()} to hold onto values if the valve is closed.
  • *
@@ -73,7 +72,7 @@ public static FlowableTransformer valve(Publisher other) { *

Properties: *

    *
  • If the other Publisher completes, the sequence terminates with an {@code IllegalStateException}.
  • - *
  • The operator doesn't run on any particular {@link io.reactivex.Scheduler Scheduler}.
  • + *
  • The operator doesn't run on any particular {@link io.reactivex.rxjava4.core.Scheduler Scheduler}.
  • *
  • The operator is a pass-through for backpressure and uses an internal unbounded buffer * of size {@link Flowable#bufferSize()} to hold onto values if the valve is closed.
  • *
@@ -99,7 +98,7 @@ public static FlowableTransformer valve(Publisher other, bool *

Properties: *

    *
  • If the other Publisher completes, the sequence terminates with an {@code IllegalStateException}.
  • - *
  • The operator doesn't run on any particular {@link io.reactivex.Scheduler Scheduler}.
  • + *
  • The operator doesn't run on any particular {@link io.reactivex.rxjava4.core.Scheduler Scheduler}.
  • *
* @param the value type of the main source * @param other the other source @@ -113,9 +112,9 @@ public static FlowableTransformer valve(Publisher other, bool @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.PASS_THROUGH) public static FlowableTransformer valve(Publisher other, boolean defaultOpen, int bufferSize) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); - return new FlowableValve(null, other, defaultOpen, bufferSize); + return new FlowableValve<>(null, other, defaultOpen, bufferSize); } /** @@ -141,15 +140,15 @@ public static FlowableTransformer> bufferWhile(Predicate the collection type * @param predicate the predicate receiving the current value and if returns false, * a new collection is created with the specified item - * @param bufferSupplier the callable that returns a fresh collection + * @param bufferSupplier the supplier that returns a fresh collection * @return the new FlowableTransformer instance * * @since 0.8.0 */ @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) - public static > FlowableTransformer bufferWhile(Predicate predicate, Callable bufferSupplier) { - return new FlowableBufferPredicate(null, predicate, FlowableBufferPredicate.Mode.BEFORE, bufferSupplier); + public static > FlowableTransformer bufferWhile(Predicate predicate, Supplier bufferSupplier) { + return new FlowableBufferPredicate<>(null, predicate, FlowableBufferPredicate.Mode.BEFORE, bufferSupplier); } /** @@ -175,15 +174,15 @@ public static FlowableTransformer> bufferUntil(Predicate the collection type * @param predicate the predicate receiving the current item and if returns true, * the current collection is emitted and a fresh empty collection is created - * @param bufferSupplier the callable that returns a fresh collection + * @param bufferSupplier the supplier that returns a fresh collection * @return the new Flowable instance * * @since 0.8.0 */ @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) - public static > FlowableTransformer bufferUntil(Predicate predicate, Callable bufferSupplier) { - return new FlowableBufferPredicate(null, predicate, FlowableBufferPredicate.Mode.AFTER, bufferSupplier); + public static > FlowableTransformer bufferUntil(Predicate predicate, Supplier bufferSupplier) { + return new FlowableBufferPredicate<>(null, predicate, FlowableBufferPredicate.Mode.AFTER, bufferSupplier); } /** @@ -209,15 +208,15 @@ public static FlowableTransformer> bufferSplit(Predicate the collection type * @param predicate the predicate receiving the current item and if returns true, * the current collection is emitted and a fresh empty collection is created - * @param bufferSupplier the callable that returns a fresh collection + * @param bufferSupplier the Supplier that returns a fresh collection * @return the new Flowable instance * * @since 0.14.3 */ @SchedulerSupport(SchedulerSupport.NONE) @BackpressureSupport(BackpressureKind.FULL) - public static > FlowableTransformer bufferSplit(Predicate predicate, Callable bufferSupplier) { - return new FlowableBufferPredicate(null, predicate, FlowableBufferPredicate.Mode.SPLIT, bufferSupplier); + public static > FlowableTransformer bufferSplit(Predicate predicate, Supplier bufferSupplier) { + return new FlowableBufferPredicate<>(null, predicate, FlowableBufferPredicate.Mode.SPLIT, bufferSupplier); } /** @@ -405,9 +404,9 @@ public static FlowableTransformer spanout(long initialDelay, long betw @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.CUSTOM) public static FlowableTransformer spanout(long initialDelay, long betweenDelay, TimeUnit unit, Scheduler scheduler, boolean delayError) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return new FlowableSpanout(null, initialDelay, betweenDelay, unit, scheduler, delayError, Flowable.bufferSize()); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return new FlowableSpanout<>(null, initialDelay, betweenDelay, unit, scheduler, delayError, Flowable.bufferSize()); } /** @@ -423,8 +422,8 @@ public static FlowableTransformer spanout(long initialDelay, long betw @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.NONE) public static FlowableTransformer mapFilter(BiConsumer> consumer) { - ObjectHelper.requireNonNull(consumer, "consumer is null"); - return new FlowableMapFilter(null, consumer); + Objects.requireNonNull(consumer, "consumer is null"); + return new FlowableMapFilter<>(null, consumer); } /** @@ -459,11 +458,11 @@ public static FlowableTransformer onBackpressureTimeout(long timeout, @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) public static FlowableTransformer onBackpressureTimeout(long timeout, TimeUnit unit, Scheduler scheduler, Consumer onEvict) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - ObjectHelper.requireNonNull(onEvict, "onEvict is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(onEvict, "onEvict is null"); - return new FlowableOnBackpressureTimeout(null, Integer.MAX_VALUE, timeout, unit, scheduler, onEvict); + return new FlowableOnBackpressureTimeout<>(null, Integer.MAX_VALUE, timeout, unit, scheduler, onEvict); } /** @@ -502,11 +501,11 @@ public static FlowableTransformer onBackpressureTimeout(long timeout, @SchedulerSupport(SchedulerSupport.CUSTOM) public static FlowableTransformer onBackpressureTimeout(int maxSize, long timeout, TimeUnit unit, Scheduler scheduler, Consumer onEvict) { ObjectHelper.verifyPositive(maxSize, "maxSize"); - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - ObjectHelper.requireNonNull(onEvict, "onEvict is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(onEvict, "onEvict is null"); - return new FlowableOnBackpressureTimeout(null, maxSize, timeout, unit, scheduler, onEvict); + return new FlowableOnBackpressureTimeout<>(null, maxSize, timeout, unit, scheduler, onEvict); } /** @@ -528,7 +527,7 @@ public static FlowableTransformer onBackpressureTimeout(int maxSize, l @SchedulerSupport(SchedulerSupport.NONE) public static FlowableTransformer every(long keep) { ObjectHelper.verifyPositive(keep, "keep"); - return new FlowableEvery(null, keep); + return new FlowableEvery<>(null, keep); } /** @@ -549,7 +548,7 @@ public static FlowableTransformer every(long keep) { @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) public static FlowableTransformer cacheLast() { - return new FlowableCacheLast(null); + return new FlowableCacheLast<>(null); } /** @@ -584,9 +583,9 @@ public static FlowableTransformer timeoutLast(long timeout, TimeUnit u @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) public static FlowableTransformer timeoutLast(long timeout, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return new FlowableTimeoutLast(null, timeout, unit, scheduler, false); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return new FlowableTimeoutLast<>(null, timeout, unit, scheduler, false); } /** @@ -621,9 +620,9 @@ public static FlowableTransformer timeoutLastAbsolute(long timeout, Ti @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) public static FlowableTransformer timeoutLastAbsolute(long timeout, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return new FlowableTimeoutLast(null, timeout, unit, scheduler, true); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return new FlowableTimeoutLast<>(null, timeout, unit, scheduler, true); } /** @@ -669,9 +668,9 @@ public static FlowableTransformer debounceFirst(long timeout, TimeUnit @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerSupport.CUSTOM) public static FlowableTransformer debounceFirst(long timeout, TimeUnit unit, Scheduler scheduler) { - ObjectHelper.requireNonNull(unit, "unit is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return new FlowableDebounceFirst(null, timeout, unit, scheduler); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return new FlowableDebounceFirst<>(null, timeout, unit, scheduler); } /** @@ -710,10 +709,10 @@ public static FlowableTransformer switchFlatMap(Function FlowableTransformer switchFlatMap(Function> mapper, int maxActive, int bufferSize) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(mapper, "mapper is null"); ObjectHelper.verifyPositive(maxActive, "maxActive"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); - return new FlowableSwitchFlatMap(null, mapper, maxActive, bufferSize); + return new FlowableSwitchFlatMap<>(null, mapper, maxActive, bufferSize); } /** @@ -760,8 +759,9 @@ public static FlowableTransformer flatMapSync(Function FlowableTransformer flatMapSync(Function> mapper, int maxConcurrency, int bufferSize, boolean depthFirst) { - return new FlowableFlatMapSync(null, mapper, maxConcurrency, bufferSize, depthFirst); + public static FlowableTransformer flatMapSync(Function> mapper, + int maxConcurrency, int bufferSize, boolean depthFirst) { + return new FlowableFlatMapSync<>(null, mapper, maxConcurrency, bufferSize, depthFirst); } /** @@ -817,8 +817,9 @@ public static FlowableTransformer flatMapAsync(Function FlowableTransformer flatMapAsync(Function> mapper, Scheduler scheduler, int maxConcurrency, int bufferSize, boolean depthFirst) { - return new FlowableFlatMapAsync(null, mapper, maxConcurrency, bufferSize, depthFirst, scheduler); + public static FlowableTransformer flatMapAsync(Function> mapper, + Scheduler scheduler, int maxConcurrency, int bufferSize, boolean depthFirst) { + return new FlowableFlatMapAsync<>(null, mapper, maxConcurrency, bufferSize, depthFirst, scheduler); } /** @@ -830,8 +831,9 @@ public static FlowableTransformer flatMapAsync(Function FlowableTransformer switchIfEmptyArray(Publisher... alternatives) { - return new FlowableSwitchIfEmptyManyArray(null, alternatives); + return new FlowableSwitchIfEmptyManyArray<>(null, alternatives); } /** @@ -844,7 +846,7 @@ public static FlowableTransformer switchIfEmptyArray(Publisher FlowableTransformer switchIfEmpty(Iterable> alternatives) { - return new FlowableSwitchIfEmptyMany(null, alternatives); + return new FlowableSwitchIfEmptyMany<>(null, alternatives); } /** @@ -892,10 +894,10 @@ public static FlowableTransformer expand(Function FlowableTransformer expand(Function> expander, ExpandStrategy strategy, int capacityHint) { - ObjectHelper.requireNonNull(expander, "expander is null"); - ObjectHelper.requireNonNull(strategy, "strategy is null"); + Objects.requireNonNull(expander, "expander is null"); + Objects.requireNonNull(strategy, "strategy is null"); ObjectHelper.verifyPositive(capacityHint, "capacityHint"); - return new FlowableExpand(null, expander, strategy, capacityHint, false); + return new FlowableExpand<>(null, expander, strategy, capacityHint, false); } /** @@ -946,10 +948,10 @@ public static FlowableTransformer expandDelayError(Function FlowableTransformer expandDelayError(Function> expander, ExpandStrategy strategy, int capacityHint) { - ObjectHelper.requireNonNull(expander, "expander is null"); - ObjectHelper.requireNonNull(strategy, "strategy is null"); + Objects.requireNonNull(expander, "expander is null"); + Objects.requireNonNull(strategy, "strategy is null"); ObjectHelper.verifyPositive(capacityHint, "capacityHint"); - return new FlowableExpand(null, expander, strategy, capacityHint, true); + return new FlowableExpand<>(null, expander, strategy, capacityHint, true); } /** @@ -1006,7 +1008,8 @@ public static FlowableTransformer mapAsync(Function FlowableTransformer mapAsync(Function> mapper, BiFunction combiner) { + public static FlowableTransformer mapAsync(Function> mapper, + BiFunction combiner) { return mapAsync(mapper, combiner, Flowable.bufferSize()); } @@ -1030,11 +1033,12 @@ public static FlowableTransformer mapAsync(Function FlowableTransformer mapAsync(Function> mapper, BiFunction combiner, int bufferSize) { - ObjectHelper.requireNonNull("mapper", "mapper is null"); - ObjectHelper.requireNonNull("combiner", "combiner is null"); + public static FlowableTransformer mapAsync(Function> mapper, + BiFunction combiner, int bufferSize) { + Objects.requireNonNull("mapper", "mapper is null"); + Objects.requireNonNull("combiner", "combiner is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); - return new FlowableMapAsync(null, mapper, combiner, bufferSize); + return new FlowableMapAsync<>(null, mapper, combiner, bufferSize); } /** @@ -1068,9 +1072,9 @@ public static FlowableTransformer filterAsync(Function FlowableTransformer filterAsync(Function> asyncPredicate, int bufferSize) { - ObjectHelper.requireNonNull("asyncPredicate", "asyncPredicate is null"); + Objects.requireNonNull("asyncPredicate", "asyncPredicate is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); - return new FlowableFilterAsync(null, asyncPredicate, bufferSize); + return new FlowableFilterAsync<>(null, asyncPredicate, bufferSize); } /** @@ -1083,7 +1087,7 @@ public static FlowableTransformer filterAsync(Function FlowableTransformer coalesce(Callable containerSupplier, BiConsumer coalescer) { + public static FlowableTransformer coalesce(Supplier containerSupplier, BiConsumer coalescer) { return coalesce(containerSupplier, coalescer, Flowable.bufferSize()); } @@ -1098,11 +1102,11 @@ public static FlowableTransformer coalesce(Callable containerSup * @return the new FlowableTransformer instance * @since 0.17.3 */ - public static FlowableTransformer coalesce(Callable containerSupplier, BiConsumer coalescer, int bufferSize) { - ObjectHelper.requireNonNull(containerSupplier, "containerSupplier is null"); - ObjectHelper.requireNonNull(coalescer, "coalescer is null"); + public static FlowableTransformer coalesce(Supplier containerSupplier, BiConsumer coalescer, int bufferSize) { + Objects.requireNonNull(containerSupplier, "containerSupplier is null"); + Objects.requireNonNull(coalescer, "coalescer is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); - return new FlowableCoalesce(null, containerSupplier, coalescer, bufferSize); + return new FlowableCoalesce<>(null, containerSupplier, coalescer, bufferSize); } /** @@ -1135,7 +1139,7 @@ public static FlowableTransformer> windowWhile(Predicate FlowableTransformer> windowWhile(final Predicate predicate, int bufferSize) { - return new FlowableWindowPredicate(null, predicate, FlowableWindowPredicate.Mode.BEFORE, bufferSize); + return new FlowableWindowPredicate<>(null, predicate, FlowableWindowPredicate.Mode.BEFORE, bufferSize); } /** @@ -1168,7 +1172,7 @@ public static FlowableTransformer> windowUntil(Predicate FlowableTransformer> windowUntil(Predicate predicate, int bufferSize) { - return new FlowableWindowPredicate(null, predicate, FlowableWindowPredicate.Mode.AFTER, bufferSize); + return new FlowableWindowPredicate<>(null, predicate, FlowableWindowPredicate.Mode.AFTER, bufferSize); } /** @@ -1201,7 +1205,7 @@ public static FlowableTransformer> windowSplit(Predicate FlowableTransformer> windowSplit(Predicate predicate, int bufferSize) { - return new FlowableWindowPredicate(null, predicate, FlowableWindowPredicate.Mode.SPLIT, bufferSize); + return new FlowableWindowPredicate<>(null, predicate, FlowableWindowPredicate.Mode.SPLIT, bufferSize); } /** @@ -1216,7 +1220,7 @@ public static FlowableTransformer> windowSplit(Predicate FlowableTransformer indexOf(Predicate predicate) { - return new FlowableIndexOf(null, predicate); + return new FlowableIndexOf<>(null, predicate); } /** @@ -1229,7 +1233,7 @@ public static FlowableTransformer indexOf(Predicate pred * as an individual {@code Runnable} task. Each item received from the upstream will * also run on the given {@code Scheduler} as individual {@code Runnable} tasks which * should maximize the possibility of work interleaved on a threadpool-backed {@code Scheduler} - * such as {@link io.reactivex.schedulers.Schedulers#computation()}. + * such as {@link io.reactivex.rxjava4.schedulers.Schedulers#computation()}. *
*
Backpressure:
*
The operator requests one item at a time and requests the next item once the downstream @@ -1247,7 +1251,7 @@ public static FlowableTransformer indexOf(Predicate pred @SchedulerSupport(SchedulerSupport.CUSTOM) @BackpressureSupport(BackpressureKind.FULL) public static FlowableTransformer requestObserveOn(Scheduler scheduler) { - return new FlowableRequestObserveOn(null, ObjectHelper.requireNonNull(scheduler, "scheduler == null")); + return new FlowableRequestObserveOn<>(null, Objects.requireNonNull(scheduler, "scheduler == null")); } /** @@ -1257,7 +1261,7 @@ public static FlowableTransformer requestObserveOn(Scheduler scheduler *
Backpressure:
*
The operator issues {@code request(1)} to its upstream periodically and expects the downstream * to be ready to consume the items. If the downstream is not ready at that moment, - * a {@link io.reactivex.exceptions.MissingBackpressureException MissingBackpressureException} is signalled + * a {@link io.reactivex.rxjava4.exceptions.MissingBackpressureException MissingBackpressureException} is signalled * and the flow is cancelled.
*
Scheduler:
*
You specify the {@link Scheduler} this operator should use for issuing each {@code request(1)} call. @@ -1282,7 +1286,7 @@ public static FlowableTransformer requestSample(long period, TimeUnit *
Backpressure:
*
The operator issues {@code request(1)} to its upstream after an initial delay, then periodically and expects the downstream * to be ready to consume the items. If the downstream is not ready at that moment, - * a {@link io.reactivex.exceptions.MissingBackpressureException MissingBackpressureException} is signalled + * a {@link io.reactivex.rxjava4.exceptions.MissingBackpressureException MissingBackpressureException} is signalled * and the flow is cancelled.
*
Scheduler:
*
You specify the {@link Scheduler} this operator should use for issuing each {@code request(1)} call. @@ -1297,7 +1301,7 @@ public static FlowableTransformer requestSample(long period, TimeUnit * @since 0.18.6 */ public static FlowableTransformer requestSample(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { - return new FlowableRequestSampleTime(null, initialDelay, period, unit, scheduler); + return new FlowableRequestSampleTime<>(null, initialDelay, period, unit, scheduler); } /** @@ -1309,7 +1313,7 @@ public static FlowableTransformer requestSample(long initialDelay, lon *
Backpressure:
*
The operator issues {@code request(1)} when the other {@code Publisher} signals an {@code onNext} and expects the downstream * to be ready to consume the items. If the downstream is not ready at that moment, - * a {@link io.reactivex.exceptions.MissingBackpressureException MissingBackpressureException} is signalled + * a {@link io.reactivex.rxjava4.exceptions.MissingBackpressureException MissingBackpressureException} is signalled * and the flow is cancelled. The other {@code Publisher} is consumed in an unbounded manner.
*
Scheduler:
*
This operator doesn't run on any particular {@link Scheduler}.
@@ -1322,7 +1326,7 @@ public static FlowableTransformer requestSample(long initialDelay, lon * @since 0.18.6 */ public static FlowableTransformer requestSample(Publisher other) { - return new FlowableRequestSample(null, other); + return new FlowableRequestSample<>(null, other); } /** @@ -1354,10 +1358,10 @@ public static FlowableTransformer partialCollect( Consumer cleaner, int prefetch ) { - ObjectHelper.requireNonNull(handler, "handler is null"); - ObjectHelper.requireNonNull(cleaner, "cleaner is null"); + Objects.requireNonNull(handler, "handler is null"); + Objects.requireNonNull(cleaner, "cleaner is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); - return new FlowablePartialCollect(null, handler, cleaner, prefetch); + return new FlowablePartialCollect<>(null, handler, cleaner, prefetch); } /** @@ -1370,8 +1374,8 @@ public static FlowableTransformer partialCollect( * @since 0.19.1 */ public static FlowableTransformer errorJump(FlowableTransformer transformer) { - ObjectHelper.requireNonNull(transformer, "transformer"); - return new FlowableErrorJump(null, transformer); + Objects.requireNonNull(transformer, "transformer"); + return new FlowableErrorJump<>(null, transformer); } /** @@ -1379,8 +1383,9 @@ public static FlowableTransformer errorJump(FlowableTransformer * Note that the very first item is not included in the follow-up sequence if the switch happens. - * Use {@link Flowable#startWith(Object)} to add it back if necessary. + * Use {@link Flowable#startWithItem(Object)} to add it back if necessary. * + * @param the element type of the selected flow * @param predicate a predicate that receives the very first item and should return true * to indicate to switch streams. If the predicate returns false, the main sequence is streamed * till its end. @@ -1391,8 +1396,8 @@ public static FlowableTransformer errorJump(FlowableTransformer FlowableTransformer switchOnFirst(Predicate predicate, Function> selector) { - ObjectHelper.requireNonNull(predicate, "predicate"); - ObjectHelper.requireNonNull(selector, "selector"); - return new FlowableSwitchOnFirst(null, predicate, selector); + Objects.requireNonNull(predicate, "predicate"); + Objects.requireNonNull(selector, "selector"); + return new FlowableSwitchOnFirst<>(null, predicate, selector); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableValve.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableValve.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableValve.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableValve.java index c126f013..41f15f88 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableValve.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableValve.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.AtomicThrowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.operators.*; /** * Allows stopping and resuming the flow of the main source when a secondary flow @@ -59,7 +55,7 @@ protected void subscribeActual(Subscriber s) { @Override public Subscriber apply(Subscriber subscriber) { - ValveMainSubscriber parent = new ValveMainSubscriber(subscriber, bufferSize, defaultOpen); + ValveMainSubscriber parent = new ValveMainSubscriber<>(subscriber, bufferSize, defaultOpen); subscriber.onSubscribe(parent); other.subscribe(parent.other); return parent; @@ -67,7 +63,7 @@ public Subscriber apply(Subscriber subscriber) { @Override public Publisher apply(Flowable upstream) { - return new FlowableValve(upstream, other, defaultOpen, bufferSize); + return new FlowableValve<>(upstream, other, defaultOpen, bufferSize); } static final class ValveMainSubscriber @@ -96,12 +92,12 @@ static final class ValveMainSubscriber ValveMainSubscriber(Subscriber downstream, int bufferSize, boolean defaultOpen) { this.downstream = downstream; - this.queue = new SpscLinkedArrayQueue(bufferSize); + this.queue = new SpscLinkedArrayQueue<>(bufferSize); this.gate = defaultOpen; this.other = new OtherSubscriber(); this.requested = new AtomicLong(); this.error = new AtomicThrowable(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override @@ -117,10 +113,8 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - if (error.addThrowable(t)) { + if (error.tryAddThrowableOrReport(t)) { drain(); - } else { - RxJavaPlugins.onError(t); } } @@ -140,6 +134,7 @@ public void cancel() { cancelled = true; SubscriptionHelper.cancel(upstream); SubscriptionHelper.cancel(other); + error.tryTerminateAndReport(); } void drain() { @@ -161,11 +156,10 @@ void drain() { } if (error.get() != null) { - Throwable ex = error.terminate(); q.clear(); SubscriptionHelper.cancel(upstream); SubscriptionHelper.cancel(other); - a.onError(ex); + error.tryTerminateConsumer(a); return; } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableWindowPredicate.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableWindowPredicate.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableWindowPredicate.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableWindowPredicate.java index ebf66939..ff8f2cb4 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableWindowPredicate.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableWindowPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.fuseable.ConditionalSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.processors.UnicastProcessor; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Predicate; +import io.reactivex.rxjava4.operators.ConditionalSubscriber; +import io.reactivex.rxjava4.processors.UnicastProcessor; /** * Emit into the same window while the predicate returns true or @@ -65,12 +63,12 @@ enum Mode { @Override protected void subscribeActual(Subscriber> s) { - source.subscribe(new WindowPredicateSubscriber(s, predicate, mode, bufferSize)); + source.subscribe(new WindowPredicateSubscriber<>(s, predicate, mode, bufferSize)); } @Override public Publisher> apply(Flowable upstream) { - return new FlowableWindowPredicate(upstream, predicate, mode, bufferSize); + return new FlowableWindowPredicate<>(upstream, predicate, mode, bufferSize); } static final class WindowPredicateSubscriber @@ -108,7 +106,7 @@ static final class WindowPredicateSubscriber // In Mode.BEFORE windows are opened earlier and added to the 1-element drain "queue" if (mode == Mode.BEFORE) { requestedWindows = new AtomicLong(); - pending = new AtomicReference>(); + pending = new AtomicReference<>(); } else { requestedWindows = null; pending = null; diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableZipLatest.java b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableZipLatest.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/FlowableZipLatest.java rename to src/main/java/hu/akarnokd/rxjava4/operators/FlowableZipLatest.java index 0c636be4..516d6207 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/FlowableZipLatest.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/FlowableZipLatest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.Arrays; +import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Takes only the latest value from the sources in each zip round and applies a transformer function @@ -84,7 +80,7 @@ protected void subscribeActual(Subscriber s) { if (n == 0) { Flowable.empty().observeOn(scheduler).subscribe(s); } else { - ZipLatestCoordinator zc = new ZipLatestCoordinator(s, n, scheduler.createWorker(), combiner); + ZipLatestCoordinator zc = new ZipLatestCoordinator<>(s, n, scheduler.createWorker(), combiner); s.onSubscribe(zc); zc.subscribe(srcs, n); @@ -123,7 +119,7 @@ static final class ZipLatestCoordinator extends AtomicReferenceArray im this.errors = new AtomicThrowable(); this.worker = worker; for (int i = 0; i < n; i++) { - subscribers[i] = new InnerSubscriber(this, i); + subscribers[i] = new InnerSubscriber<>(this, i); } this.combiner = combiner; } @@ -140,6 +136,7 @@ public void request(long n) { public void cancel() { cancelled = true; cancelAll(); + errors.tryTerminateAndReport(); if (wip.getAndIncrement() == 0) { clear(); } @@ -189,12 +186,7 @@ public void run() { cancelled = true; cancelAll(); clear(); - Throwable ex = errors.terminate(); - if (ex == null) { - a.onComplete(); - } else { - a.onError(ex); - } + errors.tryTerminateConsumer(a); worker.dispose(); return; } @@ -214,14 +206,14 @@ public void run() { R v; try { - v = ObjectHelper.requireNonNull(combiner.apply(array), "The combiner returned a null value"); + v = Objects.requireNonNull(combiner.apply(array), "The combiner returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - errors.addThrowable(ex); + errors.tryAddThrowableOrReport(ex); cancelled = true; cancelAll(); clear(); - a.onError(errors.terminate()); + errors.tryTerminateConsumer(a); worker.dispose(); return; } @@ -242,12 +234,7 @@ public void run() { cancelled = true; cancelAll(); clear(); - Throwable ex = errors.terminate(); - if (ex == null) { - a.onComplete(); - } else { - a.onError(ex); - } + errors.tryTerminateConsumer(a); worker.dispose(); return; } @@ -303,12 +290,10 @@ public void onNext(T t) { @Override public void onError(Throwable t) { ZipLatestCoordinator p = parent; - if (p.errors.addThrowable(t)) { + if (p.errors.tryAddThrowableOrReport(t)) { lazySet(SubscriptionHelper.CANCELLED); done = true; p.drain(); - } else { - RxJavaPlugins.onError(t); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/Flowables.java b/src/main/java/hu/akarnokd/rxjava4/operators/Flowables.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/Flowables.java rename to src/main/java/hu/akarnokd/rxjava4/operators/Flowables.java index dafd9a74..ea6ddd4a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/Flowables.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/Flowables.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.Comparator; -import java.util.concurrent.*; +import java.util.*; +import java.util.concurrent.Flow.*; +import java.util.concurrent.TimeUnit; -import org.reactivestreams.Publisher; - -import io.reactivex.*; -import io.reactivex.annotations.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; -import io.reactivex.internal.schedulers.ImmediateThinScheduler; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.annotations.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; /** * Utility class to create Flowable sources. @@ -49,8 +47,9 @@ private Flowables() { */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static > Flowable orderedMerge(Publisher... sources) { - return orderedMerge(Functions.naturalOrder(), false, Flowable.bufferSize(), sources); + return orderedMerge(Comparator.naturalOrder(), false, Flowable.bufferSize(), sources); } /** @@ -65,8 +64,9 @@ public static > Flowable orderedMerge(Publish */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static > Flowable orderedMerge(boolean delayErrors, Publisher... sources) { - return orderedMerge(Functions.naturalOrder(), delayErrors, Flowable.bufferSize(), sources); + return orderedMerge(Comparator.naturalOrder(), delayErrors, Flowable.bufferSize(), sources); } /** @@ -83,8 +83,9 @@ public static > Flowable orderedMerge(boolean */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static > Flowable orderedMerge(boolean delayErrors, int prefetch, Publisher... sources) { - return orderedMerge(Functions.naturalOrder(), delayErrors, prefetch, sources); + return orderedMerge(Comparator.naturalOrder(), delayErrors, prefetch, sources); } /** @@ -100,6 +101,7 @@ public static > Flowable orderedMerge(boolean */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static Flowable orderedMerge(Comparator comparator, Publisher... sources) { return orderedMerge(comparator, false, Flowable.bufferSize(), sources); } @@ -118,6 +120,7 @@ public static Flowable orderedMerge(Comparator comparator, Pub */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static Flowable orderedMerge(Comparator comparator, boolean delayErrors, Publisher... sources) { return orderedMerge(comparator, delayErrors, Flowable.bufferSize(), sources); } @@ -138,11 +141,12 @@ public static Flowable orderedMerge(Comparator comparator, boo */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static Flowable orderedMerge(Comparator comparator, boolean delayErrors, int prefetch, Publisher... sources) { - ObjectHelper.requireNonNull(comparator, "comparator is null"); - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(comparator, "comparator is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); - return RxJavaPlugins.onAssembly(new FlowableOrderedMerge(sources, null, comparator, delayErrors, prefetch)); + return RxJavaPlugins.onAssembly(new FlowableOrderedMerge<>(sources, null, comparator, delayErrors, prefetch)); } /** @@ -197,10 +201,10 @@ public static Flowable orderedMerge(Iterable> sour @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable orderedMerge(Iterable> sources, Comparator comparator, boolean delayErrors, int prefetch) { - ObjectHelper.requireNonNull(comparator, "comparator is null"); - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(comparator, "comparator is null"); + Objects.requireNonNull(sources, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); - return RxJavaPlugins.onAssembly(new FlowableOrderedMerge(null, sources, comparator, delayErrors, prefetch)); + return RxJavaPlugins.onAssembly(new FlowableOrderedMerge<>(null, sources, comparator, delayErrors, prefetch)); } /** @@ -215,7 +219,7 @@ public static Flowable orderedMerge(Iterable> sour @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static > Flowable orderedMerge(Iterable> sources) { - return orderedMerge(sources, Functions.naturalOrder(), false, Flowable.bufferSize()); + return orderedMerge(sources, Comparator.naturalOrder(), false, Flowable.bufferSize()); } /** @@ -231,7 +235,7 @@ public static > Flowable orderedMerge(Iterabl @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static > Flowable orderedMerge(Iterable> sources, boolean delayErrors) { - return orderedMerge(sources, Functions.naturalOrder(), delayErrors, Flowable.bufferSize()); + return orderedMerge(sources, Comparator.naturalOrder(), delayErrors, Flowable.bufferSize()); } /** @@ -249,7 +253,7 @@ public static > Flowable orderedMerge(Iterabl @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static > Flowable orderedMerge(Iterable> sources, boolean delayErrors, int prefetch) { - return orderedMerge(sources, Functions.naturalOrder(), delayErrors, prefetch); + return orderedMerge(sources, Comparator.naturalOrder(), delayErrors, prefetch); } /** @@ -263,23 +267,23 @@ public static > Flowable orderedMerge(Iterabl @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static Flowable repeat(T item) { - ObjectHelper.requireNonNull(item, "item is null"); - return RxJavaPlugins.onAssembly(new FlowableRepeatScalar(item)); + Objects.requireNonNull(item, "item is null"); + return RxJavaPlugins.onAssembly(new FlowableRepeatScalar<>(item)); } /** - * Repeatedly calls the given Callable to produce items indefinitely. + * Repeatedly calls the given Supplier to produce items indefinitely. * @param the value type - * @param callable the Callable to call + * @param supplier the Supplier to call * @return the new Flowable instance * * @since 0.14.2 */ @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - public static Flowable repeatCallable(Callable callable) { - ObjectHelper.requireNonNull(callable, "callable is null"); - return RxJavaPlugins.onAssembly(new FlowableRepeatCallable(callable)); + public static Flowable repeatSupplier(Supplier supplier) { + Objects.requireNonNull(supplier, "supplier is null"); + return RxJavaPlugins.onAssembly(new FlowableRepeatSupplier<>(supplier)); } /** @@ -418,6 +422,7 @@ public static Flowable intervalBackpressure(long initialDelay, long period */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.NONE) + @SafeVarargs public static Flowable zipLatest(Function combiner, Publisher... sources) { return zipLatest(combiner, ImmediateThinScheduler.INSTANCE, sources); } @@ -454,10 +459,11 @@ public static Flowable zipLatest(Function Flowable zipLatest(Function combiner, Scheduler scheduler, Publisher... sources) { - ObjectHelper.requireNonNull(combiner, "combiner is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - ObjectHelper.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(combiner, "combiner is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(sources, "sources is null"); return RxJavaPlugins.onAssembly(new FlowableZipLatest(sources, null, combiner, scheduler)); } @@ -530,9 +536,9 @@ public static Flowable zipLatest(Iterable Flowable zipLatest(Iterable> sources, Function combiner, Scheduler scheduler) { - ObjectHelper.requireNonNull(sources, "sources is null"); - ObjectHelper.requireNonNull(combiner, "combiner is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(combiner, "combiner is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new FlowableZipLatest(null, sources, combiner, scheduler)); } @@ -608,12 +614,12 @@ public static Flowable zipLatest(Publisher source1, Publisher */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) - @SuppressWarnings("unchecked") - public static Flowable zipLatest(Publisher source1, Publisher source2, BiFunction combiner, Scheduler scheduler) { - ObjectHelper.requireNonNull(source1, "source1 is null"); - ObjectHelper.requireNonNull(source2, "source2 is null"); - ObjectHelper.requireNonNull(combiner, "combiner is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + public static Flowable zipLatest(Publisher source1, Publisher source2, + BiFunction combiner, Scheduler scheduler) { + Objects.requireNonNull(source1, "source1 is null"); + Objects.requireNonNull(source2, "source2 is null"); + Objects.requireNonNull(combiner, "combiner is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new FlowableZipLatest( new Publisher[] { source1, source2 }, null, Functions.toFunction(combiner), scheduler)); @@ -696,15 +702,14 @@ public static Flowable zipLatest(Publisher source1, Publi */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) - @SuppressWarnings("unchecked") public static Flowable zipLatest(Publisher source1, Publisher source2, Publisher source3, Function3 combiner, Scheduler scheduler) { - ObjectHelper.requireNonNull(source1, "source1 is null"); - ObjectHelper.requireNonNull(source2, "source2 is null"); - ObjectHelper.requireNonNull(source3, "source3 is null"); - ObjectHelper.requireNonNull(combiner, "combiner is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(source1, "source1 is null"); + Objects.requireNonNull(source2, "source2 is null"); + Objects.requireNonNull(source3, "source3 is null"); + Objects.requireNonNull(combiner, "combiner is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new FlowableZipLatest( new Publisher[] { source1, source2, source3 }, null, Functions.toFunction(combiner), scheduler)); @@ -792,17 +797,16 @@ public static Flowable zipLatest(Publisher source1, P */ @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerSupport.CUSTOM) - @SuppressWarnings("unchecked") public static Flowable zipLatest(Publisher source1, Publisher source2, Publisher source3, Publisher source4, Function4 combiner, Scheduler scheduler) { - ObjectHelper.requireNonNull(source1, "source1 is null"); - ObjectHelper.requireNonNull(source2, "source2 is null"); - ObjectHelper.requireNonNull(source3, "source3 is null"); - ObjectHelper.requireNonNull(source4, "source4 is null"); - ObjectHelper.requireNonNull(combiner, "combiner is null"); - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(source1, "source1 is null"); + Objects.requireNonNull(source2, "source2 is null"); + Objects.requireNonNull(source3, "source3 is null"); + Objects.requireNonNull(source4, "source4 is null"); + Objects.requireNonNull(combiner, "combiner is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly(new FlowableZipLatest( new Publisher[] { source1, source2, source3, source4 }, null, Functions.toFunction(combiner), scheduler)); @@ -913,8 +917,8 @@ public static Flowable zipLatest(Publisher source1, P *
* @param the generated item type * @param the state associated with an individual subscription. - * @param initialState the {@link Callable} that returns a state object for each individual - * {@link org.reactivestreams.Subscriber Subscriber} to the returned {@code Flowable}. + * @param initialState the {@link Supplier} that returns a state object for each individual + * {@link Subscriber Subscriber} to the returned {@code Flowable}. * @param asyncGenerator the {@link BiFunction} called with the current state value and the * {@link FlowableAsyncEmitter} object and should return a new state value * as well as prepare and issue the async API call in a way that @@ -926,17 +930,17 @@ public static Flowable zipLatest(Publisher source1, P * the flow is cancelled or terminates via {@link FlowableAsyncEmitter#onError(Throwable)} * or {@link FlowableAsyncEmitter#onComplete()}. * @return the new Flowable instance - * @see Flowable#generate(Callable, BiFunction, Consumer) + * @see Flowable#generate(Supplier, BiFunction, Consumer) * @see FlowableAsyncEmitter * @since 0.18.9 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) - public static Flowable generateAsync(Callable initialState, BiFunction, S> asyncGenerator, Consumer stateCleanup) { - ObjectHelper.requireNonNull(initialState, "initialState is null"); - ObjectHelper.requireNonNull(asyncGenerator, "asyncGenerator is null"); - ObjectHelper.requireNonNull(stateCleanup, "stateCleanup is null"); - return RxJavaPlugins.onAssembly(new FlowableGenerateAsync(initialState, asyncGenerator, stateCleanup)); + public static Flowable generateAsync(Supplier initialState, BiFunction, S> asyncGenerator, Consumer stateCleanup) { + Objects.requireNonNull(initialState, "initialState is null"); + Objects.requireNonNull(asyncGenerator, "asyncGenerator is null"); + Objects.requireNonNull(stateCleanup, "stateCleanup is null"); + return RxJavaPlugins.onAssembly(new FlowableGenerateAsync<>(initialState, asyncGenerator, stateCleanup)); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalCompletable.java b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalCompletable.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalCompletable.java index e1c955a9..70add210 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the signals of the upstream into CompletableSources and consumes them. @@ -39,12 +38,12 @@ final class MaybeFlatMapSignalCompletable extends Completable final Function onErrorHandler; - final Callable onCompleteHandler; + final Supplier onCompleteHandler; MaybeFlatMapSignalCompletable(Maybe source, Function onSuccessHandler, Function onErrorHandler, - Callable onCompleteHandler) { + Supplier onCompleteHandler) { this.source = source; this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; @@ -53,7 +52,7 @@ final class MaybeFlatMapSignalCompletable extends Completable @Override public Completable apply(Maybe t) { - return new MaybeFlatMapSignalCompletable(t, onSuccessHandler, onErrorHandler, onCompleteHandler); + return new MaybeFlatMapSignalCompletable<>(t, onSuccessHandler, onErrorHandler, onCompleteHandler); } @Override @@ -70,13 +69,13 @@ static final class FlatMapSignalConsumer final Function onErrorHandler; - final Callable onCompleteHandler; + final Supplier onCompleteHandler; FlatMapSignalConsumer( CompletableObserver downstream, Function onSuccessHandler, Function onErrorHandler, - Callable onCompleteHandler) { + Supplier onCompleteHandler) { this.consumer = new SignalConsumer(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; @@ -106,7 +105,7 @@ public void onSuccess(T t) { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -121,7 +120,7 @@ public void onComplete() { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -136,7 +135,7 @@ public void onError(Throwable e) { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalFlowable.java b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalFlowable.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalFlowable.java index 96121d61..27ab4674 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the signals of the upstream into Publishers and consumes them. @@ -42,12 +39,12 @@ final class MaybeFlatMapSignalFlowable extends Flowable final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; MaybeFlatMapSignalFlowable(Maybe source, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { + Supplier> onCompleteHandler) { this.source = source; this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; @@ -56,7 +53,7 @@ final class MaybeFlatMapSignalFlowable extends Flowable @Override public Flowable apply(Maybe t) { - return new MaybeFlatMapSignalFlowable(t, onSuccessHandler, onErrorHandler, onCompleteHandler); + return new MaybeFlatMapSignalFlowable<>(t, onSuccessHandler, onErrorHandler, onCompleteHandler); } @Override @@ -73,7 +70,7 @@ static final class FlatMapSignalConsumer final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; Disposable upstream; @@ -81,8 +78,8 @@ static final class FlatMapSignalConsumer Subscriber downstream, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - this.consumer = new SignalConsumer(downstream); + Supplier> onCompleteHandler) { + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; this.onCompleteHandler = onCompleteHandler; @@ -112,7 +109,7 @@ public void onSuccess(T t) { Publisher next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null Publisher"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -127,7 +124,7 @@ public void onComplete() { Publisher next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null Publisher"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -142,7 +139,7 @@ public void onError(Throwable e) { Publisher next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null Publisher"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalMaybe.java b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalMaybe.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalMaybe.java index 8c057138..73155a88 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the signals of the upstream into MaybeSources and consumes them. @@ -39,12 +38,12 @@ final class MaybeFlatMapSignalMaybe extends Maybe final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; MaybeFlatMapSignalMaybe(Maybe source, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { + Supplier> onCompleteHandler) { this.source = source; this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; @@ -53,7 +52,7 @@ final class MaybeFlatMapSignalMaybe extends Maybe @Override public Maybe apply(Maybe t) { - return new MaybeFlatMapSignalMaybe(t, onSuccessHandler, onErrorHandler, onCompleteHandler); + return new MaybeFlatMapSignalMaybe<>(t, onSuccessHandler, onErrorHandler, onCompleteHandler); } @Override @@ -70,14 +69,14 @@ static final class FlatMapSignalConsumer final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; FlatMapSignalConsumer( MaybeObserver downstream, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - this.consumer = new SignalConsumer(downstream); + Supplier> onCompleteHandler) { + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; this.onCompleteHandler = onCompleteHandler; @@ -106,7 +105,7 @@ public void onSuccess(T t) { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -121,7 +120,7 @@ public void onComplete() { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -136,7 +135,7 @@ public void onError(Throwable e) { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalObservable.java b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalObservable.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalObservable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalObservable.java index 2b6a14cf..a8b383c0 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the signals of the upstream into ObservableSources and consumes them. @@ -39,12 +38,12 @@ final class MaybeFlatMapSignalObservable extends Observable final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; MaybeFlatMapSignalObservable(Maybe source, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { + Supplier> onCompleteHandler) { this.source = source; this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; @@ -53,7 +52,7 @@ final class MaybeFlatMapSignalObservable extends Observable @Override public Observable apply(Maybe t) { - return new MaybeFlatMapSignalObservable(t, onSuccessHandler, onErrorHandler, onCompleteHandler); + return new MaybeFlatMapSignalObservable<>(t, onSuccessHandler, onErrorHandler, onCompleteHandler); } @Override @@ -70,14 +69,14 @@ static final class FlatMapSignalConsumer final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; FlatMapSignalConsumer( Observer downstream, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - this.consumer = new SignalConsumer(downstream); + Supplier> onCompleteHandler) { + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; this.onCompleteHandler = onCompleteHandler; @@ -106,7 +105,7 @@ public void onSuccess(T t) { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -121,7 +120,7 @@ public void onComplete() { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -136,7 +135,7 @@ public void onError(Throwable e) { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalSingle.java b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalSingle.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalSingle.java rename to src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalSingle.java index 8fab67c1..986bb558 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; /** * Maps the signals of the upstream into SingleSources and consumes them. @@ -39,12 +38,12 @@ final class MaybeFlatMapSignalSingle extends Single final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; MaybeFlatMapSignalSingle(Maybe source, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { + Supplier> onCompleteHandler) { this.source = source; this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; @@ -53,7 +52,7 @@ final class MaybeFlatMapSignalSingle extends Single @Override public Single apply(Maybe t) { - return new MaybeFlatMapSignalSingle(t, onSuccessHandler, onErrorHandler, onCompleteHandler); + return new MaybeFlatMapSignalSingle<>(t, onSuccessHandler, onErrorHandler, onCompleteHandler); } @Override @@ -70,14 +69,14 @@ static final class FlatMapSignalConsumer final Function> onErrorHandler; - final Callable> onCompleteHandler; + final Supplier> onCompleteHandler; FlatMapSignalConsumer( SingleObserver downstream, Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - this.consumer = new SignalConsumer(downstream); + Supplier> onCompleteHandler) { + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; this.onCompleteHandler = onCompleteHandler; @@ -106,7 +105,7 @@ public void onSuccess(T t) { SingleSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null SingleSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -121,7 +120,7 @@ public void onComplete() { SingleSource next; try { - next = ObjectHelper.requireNonNull(onCompleteHandler.call(), "The onCompleteHandler returned a null SingleSource"); + next = Objects.requireNonNull(onCompleteHandler.get(), "The onCompleteHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -136,7 +135,7 @@ public void onError(Throwable e) { SingleSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null SingleSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeTransformers.java b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeTransformers.java similarity index 74% rename from src/main/java/hu/akarnokd/rxjava2/operators/MaybeTransformers.java rename to src/main/java/hu/akarnokd/rxjava4/operators/MaybeTransformers.java index 43117a2d..464280b7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/MaybeTransformers.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/MaybeTransformers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; /** * Additional operators in the form of {@link MaybeTransformer}, @@ -54,10 +53,10 @@ private MaybeTransformers() { public static MaybeTransformer flatMap( Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - return new MaybeFlatMapSignalMaybe(null, onSuccessHandler, onErrorHandler, onCompleteHandler); + Supplier> onCompleteHandler) { + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + return new MaybeFlatMapSignalMaybe<>(null, onSuccessHandler, onErrorHandler, onCompleteHandler); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/Maybes.java b/src/main/java/hu/akarnokd/rxjava4/operators/Maybes.java similarity index 71% rename from src/main/java/hu/akarnokd/rxjava2/operators/Maybes.java rename to src/main/java/hu/akarnokd/rxjava4/operators/Maybes.java index 0a5003d5..d1cda3ef 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/Maybes.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/Maybes.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import java.util.concurrent.Callable; +import java.util.Objects; +import java.util.concurrent.Flow.Publisher; -import org.reactivestreams.Publisher; - -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; /** * Additional operators in the form of {@link MaybeConverter}s, - * use {@link Maybe#as(MaybeConverter)} + * use {@link Maybe#to(MaybeConverter)} * to apply the operators to an existing sequence. * * @see MaybeTransformers @@ -55,11 +53,11 @@ private Maybes() { public static MaybeConverter flatMapCompletable( Function onSuccessHandler, Function onErrorHandler, - Callable onCompleteHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - return new MaybeFlatMapSignalCompletable(null, onSuccessHandler, onErrorHandler, onCompleteHandler); + Supplier onCompleteHandler) { + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + return new MaybeFlatMapSignalCompletable<>(null, onSuccessHandler, onErrorHandler, onCompleteHandler); } /** @@ -79,11 +77,11 @@ public static MaybeConverter flatMapCompletable( public static MaybeConverter> flatMapSingle( Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - return new MaybeFlatMapSignalSingle(null, onSuccessHandler, onErrorHandler, onCompleteHandler); + Supplier> onCompleteHandler) { + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + return new MaybeFlatMapSignalSingle<>(null, onSuccessHandler, onErrorHandler, onCompleteHandler); } /** @@ -103,11 +101,11 @@ public static MaybeConverter> flatMapSingle( public static MaybeConverter> flatMapObservable( Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - return new MaybeFlatMapSignalObservable(null, onSuccessHandler, onErrorHandler, onCompleteHandler); + Supplier> onCompleteHandler) { + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + return new MaybeFlatMapSignalObservable<>(null, onSuccessHandler, onErrorHandler, onCompleteHandler); } /** @@ -127,10 +125,10 @@ public static MaybeConverter> flatMapObservable( public static MaybeConverter> flatMapFlowable( Function> onSuccessHandler, Function> onErrorHandler, - Callable> onCompleteHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - ObjectHelper.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); - return new MaybeFlatMapSignalFlowable(null, onSuccessHandler, onErrorHandler, onCompleteHandler); + Supplier> onCompleteHandler) { + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + Objects.requireNonNull(onCompleteHandler, "onCompleteHandler is null"); + return new MaybeFlatMapSignalFlowable<>(null, onSuccessHandler, onErrorHandler, onCompleteHandler); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableErrorJump.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableErrorJump.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableErrorJump.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableErrorJump.java index 68a97863..9d537f55 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableErrorJump.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableErrorJump.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.*; -import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.EmptyDisposable; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; /** * Makes sure an upstream error skips the flow created with a @@ -48,18 +48,18 @@ final class ObservableErrorJump extends Observable implements Observabl @Override public ObservableSource apply(Observable upstream) { - return new ObservableErrorJump(upstream, transformer); + return new ObservableErrorJump<>(upstream, transformer); } @Override protected void subscribeActual(Observer observer) { - ErrorJumpFront front = new ErrorJumpFront(source, observer); + ErrorJumpFront front = new ErrorJumpFront<>(source, observer); ObservableSource downstream; try { - downstream = ObjectHelper.requireNonNull( + downstream = Objects.requireNonNull( transformer.apply(front), "The transformer returned a null Publisher"); } catch (Throwable ex) { @@ -83,7 +83,7 @@ static final class ErrorJumpFront extends Observable implements Observe ErrorJumpFront(Observable source, Observer downstream) { this.source = source; - this.middle = new AtomicReference>(); + this.middle = new AtomicReference<>(); this.end = new EndSubscriber(downstream); } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableFilterAsync.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableFilterAsync.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableFilterAsync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableFilterAsync.java index 5a8dfa3e..fc689cfc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableFilterAsync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableFilterAsync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.operators.SpscLinkedArrayQueue; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Filters elements of the upstream by mapping each of them, one after the other, onto a @@ -34,8 +33,6 @@ * should be passed to the downstream. * * @param the upstream value type - * @param the inner Observable's element type - * @param the result element type * @since 0.20.4 */ final class ObservableFilterAsync extends Observable @@ -58,7 +55,7 @@ final class ObservableFilterAsync extends Observable @Override public ObservableSource apply(Observable upstream) { - return new ObservableFilterAsync(upstream, asyncPredicate, capacityHint); + return new ObservableFilterAsync<>(upstream, asyncPredicate, capacityHint); } @Override @@ -100,9 +97,9 @@ static final class FilterAsyncObserver extends AtomicInteger implements Obser int capacityHint) { this.downstream = downstream; this.asyncPredicate = asyncPredicate; - this.queue = new SpscLinkedArrayQueue(capacityHint); + this.queue = new SpscLinkedArrayQueue<>(capacityHint); this.errors = new AtomicThrowable(); - this.innerDisposable = new AtomicReference(); + this.innerDisposable = new AtomicReference<>(); } @Override @@ -110,6 +107,7 @@ public void dispose() { disposed = true; upstream.dispose(); DisposableHelper.dispose(innerDisposable); + errors.tryTerminateAndReport(); drain(); } @@ -135,11 +133,9 @@ public void onNext(T t) { @Override public void onError(Throwable e) { DisposableHelper.dispose(innerDisposable); - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { done = true; drain(); - } else { - RxJavaPlugins.onError(e); } } @@ -162,9 +158,8 @@ public void drain() { queue.clear(); } else { if (errors.get() != null) { - Throwable ex = errors.terminate(); disposed = true; - downstream.onError(ex); + errors.tryTerminateConsumer(downstream); continue; } int s = state; @@ -182,14 +177,13 @@ public void drain() { ObservableSource innerSource; try { - innerSource = ObjectHelper.requireNonNull(asyncPredicate.apply(item), "The mapper returned a null ObservableSource"); + innerSource = Objects.requireNonNull(asyncPredicate.apply(item), "The mapper returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - upstream.dispose(); - errors.addThrowable(ex); - ex = errors.terminate(); disposed = true; - downstream.onError(ex); + upstream.dispose(); + errors.tryAddThrowableOrReport(ex); + errors.tryTerminateConsumer(downstream); continue; } @@ -226,13 +220,11 @@ void innerSuccess(boolean value) { } void innerError(Throwable ex) { - if (errors.addThrowable(ex)) { + if (errors.tryAddThrowableOrReport(ex)) { state = STATE_FALSE; DisposableHelper.replace(innerDisposable, null); upstream.dispose(); drain(); - } else { - RxJavaPlugins.onError(ex); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapDrop.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapDrop.java similarity index 78% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapDrop.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapDrop.java index e61186e4..c8d569d3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapDrop.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapDrop.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.util.AtomicThrowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * FlatMap only one {@link ObservableSource} at a time and ignore upstream values until it terminates. @@ -47,7 +45,7 @@ final class ObservableFlatMapDrop extends Observable implements Observa @Override public ObservableSource apply(Observable upstream) { - return new ObservableFlatMapDrop(upstream, mapper); + return new ObservableFlatMapDrop<>(upstream, mapper); } @Override @@ -96,7 +94,7 @@ public void onNext(T t) { ObservableSource o; try { - o = ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null ObservableSource"); + o = Objects.requireNonNull(mapper.apply(t), "The mapper returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.dispose(); @@ -112,22 +110,15 @@ public void onNext(T t) { @Override public void onError(Throwable e) { - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { onComplete(); - } else { - RxJavaPlugins.onError(e); } } @Override public void onComplete() { if (done.decrementAndGet() == 0) { - Throwable ex = errors.terminate(); - if (ex == null) { - downstream.onComplete(); - } else { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); } } @@ -135,6 +126,7 @@ public void onComplete() { public void dispose() { upstream.dispose(); DisposableHelper.dispose(innerObserver); + errors.tryTerminateAndReport(); } @Override @@ -147,22 +139,15 @@ void innerNext(R item) { } void innerError(Throwable e) { - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { innerComplete(); - } else { - RxJavaPlugins.onError(e); } } void innerComplete() { active = false; if (done.decrementAndGet() == 0) { - Throwable ex = errors.terminate(); - if (ex == null) { - downstream.onComplete(); - } else { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapLatest.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapLatest.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapLatest.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapLatest.java index 6978e012..7bf534dc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapLatest.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapLatest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.util.AtomicThrowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * FlatMap only one {@link ObservableSource} at a time and keep the latest upstream value until it terminates @@ -48,7 +46,7 @@ final class ObservableFlatMapLatest extends Observable implements Obser @Override public ObservableSource apply(Observable upstream) { - return new ObservableFlatMapLatest(upstream, mapper); + return new ObservableFlatMapLatest<>(upstream, mapper); } @Override @@ -86,7 +84,7 @@ static final class FlatMapLatestObserver this.mapper = mapper; this.innerObserver = new FlatMapLatestInnerObserver(); this.errors = new AtomicThrowable(); - this.latest = new AtomicReference(); + this.latest = new AtomicReference<>(); } @Override @@ -105,10 +103,8 @@ public void onNext(T t) { @Override public void onError(Throwable e) { - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { onComplete(); - } else { - RxJavaPlugins.onError(e); } } @@ -123,6 +119,7 @@ public void dispose() { disposed = true; upstream.dispose(); DisposableHelper.dispose(innerObserver); + errors.tryTerminateAndReport(); if (getAndIncrement() == 0) { latest.lazySet(null); } @@ -138,10 +135,8 @@ void innerNext(R item) { } void innerError(Throwable e) { - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { innerComplete(); - } else { - RxJavaPlugins.onError(e); } } @@ -164,25 +159,19 @@ void drain() { boolean d = done; T v = latest.getAndSet(null); if (d && v == null) { - Throwable ex = errors.terminate(); - if (ex == null) { - downstream.onComplete(); - } else { - downstream.onError(ex); - } + errors.tryTerminateConsumer(downstream); return; } if (v != null) { ObservableSource o; try { - o = ObjectHelper.requireNonNull(mapper.apply(v), "The mapper returned a null ObservableSource"); + o = Objects.requireNonNull(mapper.apply(v), "The mapper returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.dispose(); - errors.addThrowable(ex); - ex = errors.terminate(); - downstream.onError(ex); + errors.tryAddThrowableOrReport(ex); + errors.tryTerminateConsumer(downstream); return; } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableIndexOf.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableIndexOf.java similarity index 87% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableIndexOf.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableIndexOf.java index f9e05c0f..bff4c5db 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableIndexOf.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableIndexOf.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.observers.DeferredScalarObserver; +import hu.akarnokd.rxjava4.internal.rxcopy.DeferredScalarObserver; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Predicate; /** * Returns the first index of an element that matches a predicate or -1L if no elements match. @@ -41,7 +41,7 @@ final class ObservableIndexOf extends Observable @Override public ObservableSource apply(Observable upstream) { - return new ObservableIndexOf(upstream, predicate); + return new ObservableIndexOf<>(upstream, predicate); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableMapAsync.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableMapAsync.java similarity index 83% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableMapAsync.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableMapAsync.java index 3d17531a..2db3c575 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableMapAsync.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableMapAsync.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.SpscLinkedArrayQueue; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Maps each upstream element into the single result of an inner Observable while @@ -62,7 +61,7 @@ final class ObservableMapAsync extends Observable @Override public ObservableSource apply(Observable upstream) { - return new ObservableMapAsync(upstream, mapper, combiner, capacityHint); + return new ObservableMapAsync<>(upstream, mapper, combiner, capacityHint); } @Override @@ -109,9 +108,9 @@ static final class MapAsyncObserver extends AtomicInteger implements Ob this.downstream = downstream; this.mapper = mapper; this.combiner = combiner; - this.queue = new SpscLinkedArrayQueue(capacityHint); + this.queue = new SpscLinkedArrayQueue<>(capacityHint); this.errors = new AtomicThrowable(); - this.innerDisposable = new AtomicReference(); + this.innerDisposable = new AtomicReference<>(); } @Override @@ -119,6 +118,7 @@ public void dispose() { disposed = true; upstream.dispose(); DisposableHelper.dispose(innerDisposable); + errors.tryTerminateAndReport(); drain(); } @@ -144,11 +144,9 @@ public void onNext(T t) { @Override public void onError(Throwable e) { DisposableHelper.dispose(innerDisposable); - if (errors.addThrowable(e)) { + if (errors.tryAddThrowableOrReport(e)) { done = true; drain(); - } else { - RxJavaPlugins.onError(e); } } @@ -172,9 +170,8 @@ public void drain() { queue.clear(); } else { if (errors.get() != null) { - Throwable ex = errors.terminate(); disposed = true; - downstream.onError(ex); + errors.tryTerminateConsumer(downstream); continue; } int s = state; @@ -192,14 +189,13 @@ public void drain() { ObservableSource innerSource; try { - innerSource = ObjectHelper.requireNonNull(mapper.apply(item), "The mapper returned a null ObservableSource"); + innerSource = Objects.requireNonNull(mapper.apply(item), "The mapper returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - upstream.dispose(); - errors.addThrowable(ex); - ex = errors.terminate(); disposed = true; - downstream.onError(ex); + upstream.dispose(); + errors.tryAddThrowableOrReport(ex); + errors.tryTerminateConsumer(downstream); continue; } @@ -215,14 +211,13 @@ public void drain() { R result; try { - result = ObjectHelper.requireNonNull(combiner.apply(mainItem, innerItem), "The combiner returned a null value"); + result = Objects.requireNonNull(combiner.apply(mainItem, innerItem), "The combiner returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - upstream.dispose(); - errors.addThrowable(ex); - ex = errors.terminate(); disposed = true; - downstream.onError(ex); + upstream.dispose(); + errors.tryAddThrowableOrReport(ex); + errors.tryTerminateConsumer(downstream); continue; } @@ -252,13 +247,11 @@ void innerSuccess(U item) { } void innerError(Throwable ex) { - if (errors.addThrowable(ex)) { + if (errors.tryAddThrowableOrReport(ex)) { state = STATE_EMPTY; DisposableHelper.replace(innerDisposable, null); upstream.dispose(); drain(); - } else { - RxJavaPlugins.onError(ex); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnDrop.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnDrop.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnDrop.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnDrop.java index 8c13f2df..23450bcc 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnDrop.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnDrop.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.disposables.Disposable; /** * Schedules the event emission on a Scheduler and drops upstream values while @@ -43,7 +43,7 @@ final class ObservableObserveOnDrop extends Observable implements Observab @Override public ObservableSource apply(Observable upstream) { - return new ObservableObserveOnDrop(upstream, scheduler); + return new ObservableObserveOnDrop<>(upstream, scheduler); } @Override @@ -75,7 +75,7 @@ static final class ObserveOnDropObserver extends AtomicInteger ObserveOnDropObserver(Observer downstream, Worker worker) { this.downstream = downstream; this.worker = worker; - this.item = new AtomicReference(); + this.item = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnLatest.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnLatest.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnLatest.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnLatest.java index c5ddcda7..aab28d7e 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnLatest.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnLatest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.disposables.Disposable; /** * Schedules the event emission on a Scheduler and keeps the latest upstream item @@ -44,7 +44,7 @@ final class ObservableObserveOnLatest extends Observable implements Observ @Override public ObservableSource apply(Observable upstream) { - return new ObservableObserveOnLatest(upstream, scheduler); + return new ObservableObserveOnLatest<>(upstream, scheduler); } @Override @@ -74,7 +74,7 @@ static final class ObserveOnDropObserver extends AtomicInteger ObserveOnDropObserver(Observer downstream, Worker worker) { this.downstream = downstream; this.worker = worker; - this.item = new AtomicReference(); + this.item = new AtomicReference<>(); } @Override diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableTransformers.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableTransformers.java similarity index 88% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableTransformers.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableTransformers.java index eac631cc..606fe9e8 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableTransformers.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableTransformers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import hu.akarnokd.rxjava2.util.BiFunctionSecondIdentity; -import io.reactivex.*; -import io.reactivex.annotations.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; +import java.util.Objects; + +import hu.akarnokd.rxjava4.internal.rxcopy.ObjectHelper; +import hu.akarnokd.rxjava4.util.BiFunctionSecondIdentity; +import io.reactivex.rxjava4.annotations.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; /** * Additional operators in the form of {@link ObservableTransformer}, @@ -52,8 +54,8 @@ private ObservableTransformers() { @CheckReturnValue @NonNull public static ObservableTransformer indexOf(@NonNull Predicate predicate) { - ObjectHelper.requireNonNull(predicate, "predicate is null"); - return new ObservableIndexOf(null, predicate); + Objects.requireNonNull(predicate, "predicate is null"); + return new ObservableIndexOf<>(null, predicate); } /** @@ -70,8 +72,8 @@ public static ObservableTransformer indexOf(@NonNull Predicate ObservableTransformer observeOnDrop(@NonNull Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return new ObservableObserveOnDrop(null, scheduler); + Objects.requireNonNull(scheduler, "scheduler is null"); + return new ObservableObserveOnDrop<>(null, scheduler); } /** @@ -89,8 +91,8 @@ public static ObservableTransformer observeOnDrop(@NonNull Scheduler s @CheckReturnValue @NonNull public static ObservableTransformer observeOnLatest(@NonNull Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "scheduler is null"); - return new ObservableObserveOnLatest(null, scheduler); + Objects.requireNonNull(scheduler, "scheduler is null"); + return new ObservableObserveOnLatest<>(null, scheduler); } /** @@ -108,8 +110,8 @@ public static ObservableTransformer observeOnLatest(@NonNull Scheduler @CheckReturnValue @NonNull public static ObservableTransformer flatMapDrop(Function> mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - return new ObservableFlatMapDrop(null, mapper); + Objects.requireNonNull(mapper, "mapper is null"); + return new ObservableFlatMapDrop<>(null, mapper); } /** @@ -128,8 +130,8 @@ public static ObservableTransformer flatMapDrop(Function ObservableTransformer flatMapLatest(Function> mapper) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - return new ObservableFlatMapLatest(null, mapper); + Objects.requireNonNull(mapper, "mapper is null"); + return new ObservableFlatMapLatest<>(null, mapper); } /** @@ -142,8 +144,8 @@ public static ObservableTransformer flatMapLatest(Function ObservableTransformer errorJump(ObservableTransformer transformer) { - ObjectHelper.requireNonNull(transformer, "transformer"); - return new ObservableErrorJump(null, transformer); + Objects.requireNonNull(transformer, "transformer"); + return new ObservableErrorJump<>(null, transformer); } /** @@ -154,7 +156,7 @@ public static ObservableTransformer errorJump(ObservableTransformer *
    *
  • The operator starts with an open valve.
  • *
  • If the other ObservableSource completes, the sequence terminates with an {@code IllegalStateException}.
  • - *
  • The operator doesn't run on any particular {@link io.reactivex.Scheduler Scheduler}.
  • + *
  • The operator doesn't run on any particular {@link io.reactivex.rxjava4.core.Scheduler Scheduler}.
  • *
  • The operator uses an internal unbounded buffer * of size {@link Flowable#bufferSize()} to hold onto values if the valve is closed.
  • *
@@ -177,7 +179,7 @@ public static ObservableTransformer valve(ObservableSource ot *

Properties: *

    *
  • If the other ObservableSource completes, the sequence terminates with an {@code IllegalStateException}.
  • - *
  • The operator doesn't run on any particular {@link io.reactivex.Scheduler Scheduler}.
  • + *
  • The operator doesn't run on any particular {@link io.reactivex.rxjava4.core.Scheduler Scheduler}.
  • *
  • The operator uses an internal unbounded buffer * of size {@link Flowable#bufferSize()} to hold onto values if the valve is closed.
  • *
@@ -202,7 +204,7 @@ public static ObservableTransformer valve(ObservableSource ot *

Properties: *

    *
  • If the other ObservableSource completes, the sequence terminates with an {@code IllegalStateException}.
  • - *
  • The operator doesn't run on any particular {@link io.reactivex.Scheduler Scheduler}.
  • + *
  • The operator doesn't run on any particular {@link io.reactivex.rxjava4.core.Scheduler Scheduler}.
  • *
* @param the value type of the main source * @param other the other source @@ -215,9 +217,9 @@ public static ObservableTransformer valve(ObservableSource ot */ @SchedulerSupport(SchedulerSupport.NONE) public static ObservableTransformer valve(ObservableSource other, boolean defaultOpen, int bufferSize) { - ObjectHelper.requireNonNull(other, "other is null"); + Objects.requireNonNull(other, "other is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); - return new ObservableValve(null, other, defaultOpen, bufferSize); + return new ObservableValve<>(null, other, defaultOpen, bufferSize); } /** @@ -272,7 +274,8 @@ public static ObservableTransformer mapAsync(Function ObservableTransformer mapAsync(Function> mapper, BiFunction combiner) { + public static ObservableTransformer mapAsync( + Function> mapper, BiFunction combiner) { return mapAsync(mapper, combiner, Flowable.bufferSize()); } @@ -296,11 +299,12 @@ public static ObservableTransformer mapAsync(Function ObservableTransformer mapAsync(Function> mapper, BiFunction combiner, int capacityHint) { - ObjectHelper.requireNonNull(mapper, "mapper is null"); - ObjectHelper.requireNonNull(combiner, "combiner is null"); + public static ObservableTransformer mapAsync(Function> mapper, + BiFunction combiner, int capacityHint) { + Objects.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(combiner, "combiner is null"); ObjectHelper.verifyPositive(capacityHint, "capacityHint"); - return new ObservableMapAsync(null, mapper, combiner, capacityHint); + return new ObservableMapAsync<>(null, mapper, combiner, capacityHint); } /** @@ -334,8 +338,8 @@ public static ObservableTransformer filterAsync(Function ObservableTransformer filterAsync(Function> asyncPredicate, int bufferSize) { - ObjectHelper.requireNonNull("asyncPredicate", "asyncPredicate is null"); + Objects.requireNonNull("asyncPredicate", "asyncPredicate is null"); ObjectHelper.verifyPositive(bufferSize, "capacityHint"); - return new ObservableFilterAsync(null, asyncPredicate, bufferSize); + return new ObservableFilterAsync<>(null, asyncPredicate, bufferSize); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableValve.java b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableValve.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/ObservableValve.java rename to src/main/java/hu/akarnokd/rxjava4/operators/ObservableValve.java index 1484cd9d..3bc870e6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/ObservableValve.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/ObservableValve.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.util.AtomicThrowable; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.operators.*; /** * Allows stopping and resuming the flow of the main source when a secondary flow @@ -53,7 +50,7 @@ final class ObservableValve extends Observable implements ObservableTransf @Override protected void subscribeActual(Observer observer) { - ValveMainObserver parent = new ValveMainObserver(observer, bufferSize, defaultOpen); + ValveMainObserver parent = new ValveMainObserver<>(observer, bufferSize, defaultOpen); observer.onSubscribe(parent); other.subscribe(parent.other); source.subscribe(parent); @@ -61,7 +58,7 @@ protected void subscribeActual(Observer observer) { @Override public Observable apply(Observable upstream) { - return new ObservableValve(upstream, other, defaultOpen, bufferSize); + return new ObservableValve<>(upstream, other, defaultOpen, bufferSize); } static final class ValveMainObserver @@ -88,11 +85,11 @@ static final class ValveMainObserver ValveMainObserver(Observer downstream, int bufferSize, boolean defaultOpen) { this.downstream = downstream; - this.queue = new SpscLinkedArrayQueue(bufferSize); + this.queue = new SpscLinkedArrayQueue<>(bufferSize); this.gate = defaultOpen; this.other = new OtherSubscriber(); this.error = new AtomicThrowable(); - this.upstream = new AtomicReference(); + this.upstream = new AtomicReference<>(); } @Override @@ -108,10 +105,8 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - if (error.addThrowable(t)) { + if (error.tryAddThrowableOrReport(t)) { drain(); - } else { - RxJavaPlugins.onError(t); } } @@ -131,6 +126,7 @@ public void dispose() { cancelled = true; DisposableHelper.dispose(upstream); DisposableHelper.dispose(other); + error.tryTerminateAndReport(); } void drain() { @@ -152,11 +148,10 @@ void drain() { } if (error.get() != null) { - Throwable ex = error.terminate(); q.clear(); DisposableHelper.dispose(upstream); DisposableHelper.dispose(other); - a.onError(ex); + error.tryTerminateConsumer(a); return; } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/Observables.java b/src/main/java/hu/akarnokd/rxjava4/operators/Observables.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/operators/Observables.java rename to src/main/java/hu/akarnokd/rxjava4/operators/Observables.java index a53b96c9..52821347 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/Observables.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/Observables.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; /** * Utility class to create Observable sources. diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/PartialCollectEmitter.java b/src/main/java/hu/akarnokd/rxjava4/operators/PartialCollectEmitter.java similarity index 97% rename from src/main/java/hu/akarnokd/rxjava2/operators/PartialCollectEmitter.java rename to src/main/java/hu/akarnokd/rxjava4/operators/PartialCollectEmitter.java index 2452496f..ab25b152 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/PartialCollectEmitter.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/PartialCollectEmitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; /** * Provides callbacks and methods to support the partial collect operator: diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalCompletable.java b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalCompletable.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalCompletable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalCompletable.java index 233b42fc..94a9568b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalCompletable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalCompletable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the signals of the upstream into CompletableSources and consumes them. @@ -48,7 +48,7 @@ final class SingleFlatMapSignalCompletable extends Completable @Override public Completable apply(Single t) { - return new SingleFlatMapSignalCompletable(t, onSuccessHandler, onErrorHandler); + return new SingleFlatMapSignalCompletable<>(t, onSuccessHandler, onErrorHandler); } @Override @@ -97,7 +97,7 @@ public void onSuccess(T t) { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +112,7 @@ public void onError(Throwable e) { CompletableSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null CompletableSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null CompletableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalFlowable.java b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalFlowable.java similarity index 84% rename from src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalFlowable.java index 42eecd0e..421ef165 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.subscriptions.SubscriptionHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the signals of the upstream into Publishers and consumes them. @@ -51,7 +49,7 @@ final class SingleFlatMapSignalFlowable extends Flowable @Override public Flowable apply(Single t) { - return new SingleFlatMapSignalFlowable(t, onSuccessHandler, onErrorHandler); + return new SingleFlatMapSignalFlowable<>(t, onSuccessHandler, onErrorHandler); } @Override @@ -74,7 +72,7 @@ static final class FlatMapSignalConsumer Subscriber downstream, Function> onSuccessHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; } @@ -103,7 +101,7 @@ public void onSuccess(T t) { Publisher next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null Publisher"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -118,7 +116,7 @@ public void onError(Throwable e) { Publisher next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null Publisher"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null Publisher"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalMaybe.java b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalMaybe.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalMaybe.java rename to src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalMaybe.java index c9ebbba2..342a9c80 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalMaybe.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalMaybe.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the signals of the upstream into MaybeSources and consumes them. @@ -48,7 +48,7 @@ final class SingleFlatMapSignalMaybe extends Maybe @Override public Maybe apply(Single t) { - return new SingleFlatMapSignalMaybe(t, onSuccessHandler, onErrorHandler); + return new SingleFlatMapSignalMaybe<>(t, onSuccessHandler, onErrorHandler); } @Override @@ -69,7 +69,7 @@ static final class FlatMapSignalConsumer MaybeObserver downstream, Function> onSuccessHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; } @@ -97,7 +97,7 @@ public void onSuccess(T t) { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +112,7 @@ public void onError(Throwable e) { MaybeSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null MaybeSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null MaybeSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalObservable.java b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalObservable.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalObservable.java rename to src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalObservable.java index 80a4a624..c72ae89c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the signals of the upstream into ObservableSources and consumes them. @@ -48,7 +48,7 @@ final class SingleFlatMapSignalObservable extends Observable @Override public Observable apply(Single t) { - return new SingleFlatMapSignalObservable(t, onSuccessHandler, onErrorHandler); + return new SingleFlatMapSignalObservable<>(t, onSuccessHandler, onErrorHandler); } @Override @@ -69,7 +69,7 @@ static final class FlatMapSignalConsumer Observer downstream, Function> onSuccessHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; } @@ -97,7 +97,7 @@ public void onSuccess(T t) { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +112,7 @@ public void onError(Throwable e) { ObservableSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null ObservableSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null ObservableSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalSingle.java b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalSingle.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalSingle.java rename to src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalSingle.java index 1f362894..ed2aa226 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalSingle.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalSingle.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.functions.Function; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.functions.Function; /** * Maps the signals of the upstream into SingleSources and consumes them. @@ -48,7 +48,7 @@ final class SingleFlatMapSignalSingle extends Single @Override public Single apply(Single t) { - return new SingleFlatMapSignalSingle(t, onSuccessHandler, onErrorHandler); + return new SingleFlatMapSignalSingle<>(t, onSuccessHandler, onErrorHandler); } @Override @@ -69,7 +69,7 @@ static final class FlatMapSignalConsumer SingleObserver downstream, Function> onSuccessHandler, Function> onErrorHandler) { - this.consumer = new SignalConsumer(downstream); + this.consumer = new SignalConsumer<>(downstream); this.onSuccessHandler = onSuccessHandler; this.onErrorHandler = onErrorHandler; } @@ -97,7 +97,7 @@ public void onSuccess(T t) { SingleSource next; try { - next = ObjectHelper.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null SingleSource"); + next = Objects.requireNonNull(onSuccessHandler.apply(t), "The onSuccessHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); @@ -112,7 +112,7 @@ public void onError(Throwable e) { SingleSource next; try { - next = ObjectHelper.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null SingleSource"); + next = Objects.requireNonNull(onErrorHandler.apply(e), "The onErrorHandler returned a null SingleSource"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); consumer.onError(ex); diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/SingleTransformers.java b/src/main/java/hu/akarnokd/rxjava4/operators/SingleTransformers.java similarity index 80% rename from src/main/java/hu/akarnokd/rxjava2/operators/SingleTransformers.java rename to src/main/java/hu/akarnokd/rxjava4/operators/SingleTransformers.java index 3b13ddac..1fa50bed 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/SingleTransformers.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/SingleTransformers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import java.util.Objects; + +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; /** * Additional operators in the form of {@link SingleTransformer}, @@ -50,8 +51,8 @@ private SingleTransformers() { public static SingleTransformer flatMap( Function> onSuccessHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new SingleFlatMapSignalSingle(null, onSuccessHandler, onErrorHandler); + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new SingleFlatMapSignalSingle<>(null, onSuccessHandler, onErrorHandler); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/Singles.java b/src/main/java/hu/akarnokd/rxjava4/operators/Singles.java similarity index 77% rename from src/main/java/hu/akarnokd/rxjava2/operators/Singles.java rename to src/main/java/hu/akarnokd/rxjava4/operators/Singles.java index dffaeed1..ef239b2b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/Singles.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/Singles.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.reactivestreams.Publisher; +import java.util.Objects; +import java.util.concurrent.Flow.Publisher; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; /** * Additional operators in the form of {@link SingleConverter}s, - * use {@link Single#as(SingleConverter)} + * use {@link Single#to(SingleConverter)} * to apply the operators to an existing sequence. * * @see SingleTransformers @@ -51,9 +51,9 @@ private Singles() { public static SingleConverter flatMapCompletable( Function onSuccessHandler, Function onErrorHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new SingleFlatMapSignalCompletable(null, onSuccessHandler, onErrorHandler); + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new SingleFlatMapSignalCompletable<>(null, onSuccessHandler, onErrorHandler); } /** @@ -71,9 +71,9 @@ public static SingleConverter flatMapCompletable( public static SingleConverter> flatMapMaybe( Function> onSuccessHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new SingleFlatMapSignalMaybe(null, onSuccessHandler, onErrorHandler); + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new SingleFlatMapSignalMaybe<>(null, onSuccessHandler, onErrorHandler); } /** @@ -91,9 +91,9 @@ public static SingleConverter> flatMapMaybe( public static SingleConverter> flatMapObservable( Function> onSuccessHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new SingleFlatMapSignalObservable(null, onSuccessHandler, onErrorHandler); + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new SingleFlatMapSignalObservable<>(null, onSuccessHandler, onErrorHandler); } /** @@ -111,8 +111,8 @@ public static SingleConverter> flatMapObservable( public static SingleConverter> flatMapFlowable( Function> onSuccessHandler, Function> onErrorHandler) { - ObjectHelper.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); - ObjectHelper.requireNonNull(onErrorHandler, "onErrorHandler is null"); - return new SingleFlatMapSignalFlowable(null, onSuccessHandler, onErrorHandler); + Objects.requireNonNull(onSuccessHandler, "onSuccessHandler is null"); + Objects.requireNonNull(onErrorHandler, "onErrorHandler is null"); + return new SingleFlatMapSignalFlowable<>(null, onSuccessHandler, onErrorHandler); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/operators/package-info.java b/src/main/java/hu/akarnokd/rxjava4/operators/package-info.java similarity index 51% rename from src/main/java/hu/akarnokd/rxjava2/operators/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/operators/package-info.java index 9a428e3d..257d90db 100644 --- a/src/main/java/hu/akarnokd/rxjava2/operators/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/operators/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,18 @@ /** * Utility methods for uncommon, custom, special and exotic operators for RxJava flows - * in the form of transformers and converters: + * in the form of transformers and converters. *
    - *
  • {@link hu.akarnokd.rxjava2.operators.FlowableTransformers FlowableTransformers}, - * {@link hu.akarnokd.rxjava2.operators.Flowables Flowables},
  • - *
  • {@link hu.akarnokd.rxjava2.operators.ObservableTransformers ObservableTransformers}, - * {@link hu.akarnokd.rxjava2.operators.Observables Observables},
  • - *
  • {@link hu.akarnokd.rxjava2.operators.MaybeTransformers MaybeTransformers}, - * {@link hu.akarnokd.rxjava2.operators.Maybes Maybes},
  • - *
  • {@link hu.akarnokd.rxjava2.operators.SingleTransformers SingleTransformers}, - * {@link hu.akarnokd.rxjava2.operators.Singles Singles},
  • - *
  • {@link hu.akarnokd.rxjava2.operators.CompletableTransformers CompletableTransformers} and - * {@link hu.akarnokd.rxjava2.operators.Completables Completables}.
  • + *
  • {@link hu.akarnokd.rxjava4.operators.FlowableTransformers FlowableTransformers}, + * {@link hu.akarnokd.rxjava4.operators.Flowables Flowables},
  • + *
  • {@link hu.akarnokd.rxjava4.operators.ObservableTransformers ObservableTransformers}, + * {@link hu.akarnokd.rxjava4.operators.Observables Observables},
  • + *
  • {@link hu.akarnokd.rxjava4.operators.MaybeTransformers MaybeTransformers}, + * {@link hu.akarnokd.rxjava4.operators.Maybes Maybes},
  • + *
  • {@link hu.akarnokd.rxjava4.operators.SingleTransformers SingleTransformers}, + * {@link hu.akarnokd.rxjava4.operators.Singles Singles},
  • + *
  • {@link hu.akarnokd.rxjava4.operators.CompletableTransformers CompletableTransformers} and + * {@link hu.akarnokd.rxjava4.operators.Completables Completables}.
  • *
*/ -package hu.akarnokd.rxjava2.operators; \ No newline at end of file +package hu.akarnokd.rxjava4.operators; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelOrderedMerge.java b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelOrderedMerge.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/parallel/ParallelOrderedMerge.java rename to src/main/java/hu/akarnokd/rxjava4/parallel/ParallelOrderedMerge.java index eaf80b12..2b070255 100644 --- a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelOrderedMerge.java +++ b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelOrderedMerge.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.parallel; +package hu.akarnokd.rxjava4.parallel; import java.util.Comparator; +import java.util.concurrent.Flow.Subscriber; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.operators.BasicMergeSubscription; -import io.reactivex.Flowable; -import io.reactivex.parallel.ParallelFlowable; +import hu.akarnokd.rxjava4.internal.operators.BasicMergeSubscription; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.parallel.ParallelFlowable; /** * Merges the individual 'rails' of the source ParallelFlowable by picking @@ -54,7 +53,7 @@ final class ParallelOrderedMerge extends Flowable { @Override protected void subscribeActual(Subscriber s) { - final BasicMergeSubscription parent = new BasicMergeSubscription(s, comparator, this.source.parallelism(), prefetch, delayErrors); + final BasicMergeSubscription parent = new BasicMergeSubscription<>(s, comparator, this.source.parallelism(), prefetch, delayErrors); s.onSubscribe(parent); parent.subscribe(this.source); } diff --git a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumDouble.java b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumDouble.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumDouble.java rename to src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumDouble.java index 8acabccf..a45bbce9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumDouble.java +++ b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.parallel; +package hu.akarnokd.rxjava4.parallel; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.FlowableSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.parallel.ParallelTransformer; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.parallel.*; /** * Sums numbers as longs on each parallel rail, or empty if the rail doesn't produce any data. diff --git a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumInteger.java b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumInteger.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumInteger.java rename to src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumInteger.java index a802e031..0e873fa2 100644 --- a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumInteger.java +++ b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumInteger.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.parallel; +package hu.akarnokd.rxjava4.parallel; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.FlowableSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.parallel.ParallelTransformer; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.parallel.*; /** * Sums numbers as integers on each parallel rail, or empty if the rail doesn't produce any data. diff --git a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumLong.java b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumLong.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumLong.java rename to src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumLong.java index e548d8e5..8aae5dff 100644 --- a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelSumLong.java +++ b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelSumLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.parallel; +package hu.akarnokd.rxjava4.parallel; -import org.reactivestreams.*; +import java.util.concurrent.Flow.*; -import io.reactivex.FlowableSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.parallel.ParallelTransformer; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.parallel.*; /** * Sums numbers as longs on each parallel rail, or empty if the rail doesn't produce any data. diff --git a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelTransformers.java b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelTransformers.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/parallel/ParallelTransformers.java rename to src/main/java/hu/akarnokd/rxjava4/parallel/ParallelTransformers.java index 7eed9b0c..065fed37 100644 --- a/src/main/java/hu/akarnokd/rxjava2/parallel/ParallelTransformers.java +++ b/src/main/java/hu/akarnokd/rxjava4/parallel/ParallelTransformers.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.parallel; +package hu.akarnokd.rxjava4.parallel; -import java.util.Comparator; +import java.util.*; -import io.reactivex.Flowable; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.parallel.ParallelTransformer; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.ObjectHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.parallel.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Transformers for RxJava 2 ParallelFlowable sequences. @@ -44,7 +42,7 @@ private ParallelTransformers() { * @since 0.17.9 */ public static > Flowable orderedMerge(ParallelFlowable source) { - return orderedMerge(source, Functions.naturalOrder(), false, Flowable.bufferSize()); + return orderedMerge(source, Comparator.naturalOrder(), false, Flowable.bufferSize()); } /** @@ -57,7 +55,7 @@ public static > Flowable orderedMerge(Paralle * @since 0.17.9 */ public static > Flowable orderedMerge(ParallelFlowable source, boolean delayErrors) { - return orderedMerge(source, Functions.naturalOrder(), delayErrors, Flowable.bufferSize()); + return orderedMerge(source, Comparator.naturalOrder(), delayErrors, Flowable.bufferSize()); } /** @@ -72,7 +70,7 @@ public static > Flowable orderedMerge(Paralle * @since 0.17.9 */ public static > Flowable orderedMerge(ParallelFlowable source, boolean delayErrors, int prefetch) { - return orderedMerge(source, Functions.naturalOrder(), delayErrors, prefetch); + return orderedMerge(source, Comparator.naturalOrder(), delayErrors, prefetch); } /** @@ -118,10 +116,10 @@ public static Flowable orderedMerge(ParallelFlowable source, Comparato * @since 0.17.9 */ public static Flowable orderedMerge(ParallelFlowable source, Comparator comparator, boolean delayErrors, int prefetch) { - ObjectHelper.requireNonNull(comparator, "comparator is null"); - ObjectHelper.requireNonNull(source, "sources is null"); + Objects.requireNonNull(comparator, "comparator is null"); + Objects.requireNonNull(source, "sources is null"); ObjectHelper.verifyPositive(prefetch, "prefetch"); - return RxJavaPlugins.onAssembly(new ParallelOrderedMerge(source, comparator, delayErrors, prefetch)); + return RxJavaPlugins.onAssembly(new ParallelOrderedMerge<>(source, comparator, delayErrors, prefetch)); } /** @@ -131,7 +129,7 @@ public static Flowable orderedMerge(ParallelFlowable source, Comparato * @since 0.16.3 */ public static ParallelTransformer sumInteger() { - return new ParallelSumInteger(null); + return new ParallelSumInteger<>(null); } /** @@ -141,7 +139,7 @@ public static ParallelTransformer sumInteger() { * @since 0.16.3 */ public static ParallelTransformer sumLong() { - return new ParallelSumLong(null); + return new ParallelSumLong<>(null); } /** @@ -151,6 +149,6 @@ public static ParallelTransformer sumLong() { * @since 0.16.3 */ public static ParallelTransformer sumDouble() { - return new ParallelSumDouble(null); + return new ParallelSumDouble<>(null); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/parallel/package-info.java b/src/main/java/hu/akarnokd/rxjava4/parallel/package-info.java similarity index 75% rename from src/main/java/hu/akarnokd/rxjava2/parallel/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/parallel/package-info.java index 3bcb97c3..cc5c51e6 100644 --- a/src/main/java/hu/akarnokd/rxjava2/parallel/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/parallel/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * Utility methods for parallel aggregation and reduction for {@link io.reactivex.parallel.ParallelFlowable ParallelFlowable}s via - * {@link hu.akarnokd.rxjava2.parallel.ParallelTransformers ParallelTransformers}. + * Utility methods for parallel aggregation and reduction for {@link io.reactivex.rxjava4.parallel.ParallelFlowable ParallelFlowable}s via + * {@link hu.akarnokd.rxjava4.parallel.ParallelTransformers ParallelTransformers}. */ -package hu.akarnokd.rxjava2.parallel; \ No newline at end of file +package hu.akarnokd.rxjava4.parallel; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/processors/DispatchWorkProcessor.java b/src/main/java/hu/akarnokd/rxjava4/processors/DispatchWorkProcessor.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/processors/DispatchWorkProcessor.java rename to src/main/java/hu/akarnokd/rxjava4/processors/DispatchWorkProcessor.java index a9e1aa0d..0def1533 100644 --- a/src/main/java/hu/akarnokd/rxjava2/processors/DispatchWorkProcessor.java +++ b/src/main/java/hu/akarnokd/rxjava4/processors/DispatchWorkProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; +import java.util.Objects; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.util.SpmcLinkedArrayQueue; -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.FlowableProcessor; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.util.SpmcLinkedArrayQueue; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.operators.SimplePlainQueue; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.FlowableProcessor; /** * A {@link FlowableProcessor} variant that queues up items and dispatches them asynchronously @@ -102,7 +100,7 @@ public static DispatchWorkProcessor create(Scheduler scheduler, boolean d * @return the new DispatchWorkSubject instance */ public static DispatchWorkProcessor create(Scheduler scheduler, int capacityHint, boolean delayErrors) { - return new DispatchWorkProcessor(capacityHint, delayErrors, scheduler, false); + return new DispatchWorkProcessor<>(capacityHint, delayErrors, scheduler, false); } /** @@ -116,7 +114,7 @@ public static DispatchWorkProcessor create(Scheduler scheduler, int capac * @return the new DispatchWorkSubject instance */ public static DispatchWorkProcessor createUnbounded(Scheduler scheduler, int capacityHint, boolean delayErrors) { - return new DispatchWorkProcessor(capacityHint, delayErrors, scheduler, true); + return new DispatchWorkProcessor<>(capacityHint, delayErrors, scheduler, true); } final SimplePlainQueue queue; @@ -146,12 +144,12 @@ public static DispatchWorkProcessor createUnbounded(Scheduler scheduler, @SuppressWarnings("unchecked") DispatchWorkProcessor(int capacityHint, boolean delayErrors, Scheduler scheduler, boolean unbounded) { - this.queue = new SpmcLinkedArrayQueue(capacityHint); + this.queue = new SpmcLinkedArrayQueue<>(capacityHint); this.delayErrors = delayErrors; this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); - this.error = new AtomicReference(); - this.observers = new AtomicReference[]>(EMPTY); + this.upstream = new AtomicReference<>(); + this.error = new AtomicReference<>(); + this.observers = new AtomicReference<>(EMPTY); this.scheduler = scheduler; this.prefetch = unbounded ? Long.MAX_VALUE : capacityHint; this.requestedUpstream = new AtomicLong(); @@ -178,7 +176,7 @@ public void onNext(T t) { @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { - ObjectHelper.requireNonNull(e, "e is null"); + Objects.requireNonNull(e, "e is null"); if (error.compareAndSet(null, e)) { for (WorkDisposable wd : observers.getAndSet(TERMINATED)) { wd.drain(); @@ -200,7 +198,7 @@ public void onComplete() { @Override protected void subscribeActual(Subscriber subscriber) { - WorkDisposable wd = new WorkDisposable(subscriber, this, scheduler.createWorker(), delayErrors); + WorkDisposable wd = new WorkDisposable<>(subscriber, this, scheduler.createWorker(), delayErrors); subscriber.onSubscribe(wd); if (add(wd)) { if (wd.isCancelled()) { diff --git a/src/main/java/hu/akarnokd/rxjava2/processors/FlowableProcessorWrap.java b/src/main/java/hu/akarnokd/rxjava4/processors/FlowableProcessorWrap.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/processors/FlowableProcessorWrap.java rename to src/main/java/hu/akarnokd/rxjava4/processors/FlowableProcessorWrap.java index 0db08f52..f386854f 100644 --- a/src/main/java/hu/akarnokd/rxjava2/processors/FlowableProcessorWrap.java +++ b/src/main/java/hu/akarnokd/rxjava4/processors/FlowableProcessorWrap.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; -import java.util.concurrent.atomic.*; +import java.util.concurrent.Flow.*; +import java.util.concurrent.atomic.AtomicBoolean; -import org.reactivestreams.*; - -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.processors.FlowableProcessor; +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.processors.FlowableProcessor; final class FlowableProcessorWrap extends FlowableProcessor { diff --git a/src/main/java/hu/akarnokd/rxjava2/processors/FlowableProcessors.java b/src/main/java/hu/akarnokd/rxjava4/processors/FlowableProcessors.java similarity index 81% rename from src/main/java/hu/akarnokd/rxjava2/processors/FlowableProcessors.java rename to src/main/java/hu/akarnokd/rxjava4/processors/FlowableProcessors.java index 6396ae52..9017bfe7 100644 --- a/src/main/java/hu/akarnokd/rxjava2/processors/FlowableProcessors.java +++ b/src/main/java/hu/akarnokd/rxjava4/processors/FlowableProcessors.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; -import org.reactivestreams.Processor; +import java.util.Objects; +import java.util.concurrent.Flow.Processor; -import io.reactivex.annotations.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.processors.*; +import io.reactivex.rxjava4.annotations.*; +import io.reactivex.rxjava4.processors.FlowableProcessor; /** * Utility methods to work with Reactive-Streams Processors and RxJava 2 FlowableProcessors. @@ -44,14 +44,14 @@ public static FlowableProcessor wrap(Processor processor) { if (processor instanceof FlowableProcessor) { return (FlowableProcessor)processor; } - return new FlowableProcessorWrap(ObjectHelper.requireNonNull(processor, "processor is null")); + return new FlowableProcessorWrap<>(Objects.requireNonNull(processor, "processor is null")); } /** * Wraps a FlowableProcessor and makes sure if all subscribers cancel * their subscriptions, the upstream's Subscription gets cancelled as well. *

- * This operator is similar to {@link io.reactivex.flowables.ConnectableFlowable#refCount()} + * This operator is similar to {@link io.reactivex.rxjava4.core.ConnectableFlowable#refCount()} * except the first Subscriber doesn't trigger any sort of connection; that happens * when the resulting FlowableProcessor is subscribed to a Publisher manually. * @param the input and output value type @@ -65,6 +65,6 @@ public static FlowableProcessor refCount(FlowableProcessor processor) if (processor instanceof RefCountProcessor) { return processor; } - return new RefCountProcessor(ObjectHelper.requireNonNull(processor, "processor is null")); + return new RefCountProcessor<>(Objects.requireNonNull(processor, "processor is null")); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/processors/RefCountProcessor.java b/src/main/java/hu/akarnokd/rxjava4/processors/RefCountProcessor.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/processors/RefCountProcessor.java rename to src/main/java/hu/akarnokd/rxjava4/processors/RefCountProcessor.java index 424122a4..e632e374 100644 --- a/src/main/java/hu/akarnokd/rxjava2/processors/RefCountProcessor.java +++ b/src/main/java/hu/akarnokd/rxjava4/processors/RefCountProcessor.java @@ -1,25 +1,27 @@ -/** - * Copyright (c) 2016-present, RxJava Contributors. +/* + * Copyright 2016-present David Karnok * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - -import io.reactivex.FlowableSubscriber; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.processors.FlowableProcessor; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.processors.FlowableProcessor; /** * A FlowableProcessor wrapper that disposes the Subscription set via @@ -45,8 +47,8 @@ @SuppressWarnings("unchecked") RefCountProcessor(FlowableProcessor actual) { this.actual = actual; - this.upstream = new AtomicReference(); - this.subscribers = new AtomicReference[]>(EMPTY); + this.upstream = new AtomicReference<>(); + this.subscribers = new AtomicReference<>(EMPTY); } @Override @@ -75,7 +77,7 @@ public void onComplete() { @Override protected void subscribeActual(Subscriber s) { - RefCountSubscriber rcs = new RefCountSubscriber(s, this); + RefCountSubscriber rcs = new RefCountSubscriber<>(s, this); if (!add(rcs)) { EmptySubscription.error(new IllegalStateException("RefCountProcessor terminated"), s); return; diff --git a/src/main/java/hu/akarnokd/rxjava2/processors/package-info.java b/src/main/java/hu/akarnokd/rxjava4/processors/package-info.java similarity index 67% rename from src/main/java/hu/akarnokd/rxjava2/processors/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/processors/package-info.java index abe8766b..ec51dea3 100644 --- a/src/main/java/hu/akarnokd/rxjava2/processors/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/processors/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ /** * Special processors such as - * {@link hu.akarnokd.rxjava2.processors.DispatchWorkProcessor DispatchWorkProcessor} - * and generic utilities for {@link io.reactivex.processors.FlowableProcessor FlowableProcessor}s - * via {@link hu.akarnokd.rxjava2.processors.FlowableProcessors} methods. + * {@link hu.akarnokd.rxjava4.processors.DispatchWorkProcessor DispatchWorkProcessor} + * and generic utilities for {@link io.reactivex.rxjava4.processors.FlowableProcessor FlowableProcessor}s + * via {@link hu.akarnokd.rxjava4.processors.FlowableProcessors} methods. */ -package hu.akarnokd.rxjava2.processors; \ No newline at end of file +package hu.akarnokd.rxjava4.processors; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/string/FlowableCharSequence.java b/src/main/java/hu/akarnokd/rxjava4/string/FlowableCharSequence.java similarity index 92% rename from src/main/java/hu/akarnokd/rxjava2/string/FlowableCharSequence.java rename to src/main/java/hu/akarnokd/rxjava4/string/FlowableCharSequence.java index 6433d3f9..25410751 100644 --- a/src/main/java/hu/akarnokd/rxjava2/string/FlowableCharSequence.java +++ b/src/main/java/hu/akarnokd/rxjava4/string/FlowableCharSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; -import org.reactivestreams.Subscriber; +import java.util.concurrent.Flow.Subscriber; -import io.reactivex.Flowable; -import io.reactivex.internal.fuseable.QueueFuseable; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.BackpressureHelper; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.operators.QueueFuseable; /** * Streams the characters of a string. diff --git a/src/main/java/hu/akarnokd/rxjava2/string/FlowableSplit.java b/src/main/java/hu/akarnokd/rxjava4/string/FlowableSplit.java similarity index 94% rename from src/main/java/hu/akarnokd/rxjava2/string/FlowableSplit.java rename to src/main/java/hu/akarnokd/rxjava4/string/FlowableSplit.java index 703f4575..55071eba 100644 --- a/src/main/java/hu/akarnokd/rxjava2/string/FlowableSplit.java +++ b/src/main/java/hu/akarnokd/rxjava4/string/FlowableSplit.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.*; import java.util.regex.Pattern; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.exceptions.Exceptions; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.queue.SpscArrayQueue; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.Exceptions; +import io.reactivex.rxjava4.operators.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Consider a sequence of CharSequence as one and split it based on @@ -101,7 +98,7 @@ static final class SplitSubscriber this.pattern = pattern; this.bufferSize = bufferSize; this.limit = bufferSize - (bufferSize >> 2); - this.queue = new SpscArrayQueue(bufferSize); + this.queue = new SpscArrayQueue<>(bufferSize); this.requested = new AtomicLong(); } diff --git a/src/main/java/hu/akarnokd/rxjava2/string/ObservableCharSequence.java b/src/main/java/hu/akarnokd/rxjava4/string/ObservableCharSequence.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/string/ObservableCharSequence.java rename to src/main/java/hu/akarnokd/rxjava4/string/ObservableCharSequence.java index 0f57c501..c7466315 100644 --- a/src/main/java/hu/akarnokd/rxjava2/string/ObservableCharSequence.java +++ b/src/main/java/hu/akarnokd/rxjava4/string/ObservableCharSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.*; -import io.reactivex.disposables.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; final class ObservableCharSequence extends Observable { diff --git a/src/main/java/hu/akarnokd/rxjava2/string/StringFlowable.java b/src/main/java/hu/akarnokd/rxjava4/string/StringFlowable.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/string/StringFlowable.java rename to src/main/java/hu/akarnokd/rxjava4/string/StringFlowable.java index df39a664..208487fd 100644 --- a/src/main/java/hu/akarnokd/rxjava2/string/StringFlowable.java +++ b/src/main/java/hu/akarnokd/rxjava4/string/StringFlowable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; +import java.util.Objects; import java.util.regex.Pattern; -import io.reactivex.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.ObjectHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Utility class for String operations with {@link Flowable}s. @@ -37,7 +38,7 @@ private StringFlowable() { * @return the new Flowable instance */ public static Flowable characters(CharSequence string) { - ObjectHelper.requireNonNull(string, "string is null"); + Objects.requireNonNull(string, "string is null"); return RxJavaPlugins.onAssembly(new FlowableCharSequence(string)); } @@ -63,7 +64,7 @@ public static FlowableTransformer split(Pattern pattern) { * @since 0.13.0 */ public static FlowableTransformer split(Pattern pattern, int bufferSize) { - ObjectHelper.requireNonNull(pattern, "pattern is null"); + Objects.requireNonNull(pattern, "pattern is null"); ObjectHelper.verifyPositive(bufferSize, "bufferSize"); return new FlowableSplit(null, pattern, bufferSize); } diff --git a/src/main/java/hu/akarnokd/rxjava2/string/StringObservable.java b/src/main/java/hu/akarnokd/rxjava4/string/StringObservable.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/string/StringObservable.java rename to src/main/java/hu/akarnokd/rxjava4/string/StringObservable.java index cc80f3c5..a54b377b 100644 --- a/src/main/java/hu/akarnokd/rxjava2/string/StringObservable.java +++ b/src/main/java/hu/akarnokd/rxjava4/string/StringObservable.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; -import io.reactivex.*; -import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; /** * Utility class for String operations with {@link Observable}s. diff --git a/src/main/java/hu/akarnokd/rxjava2/string/package-info.java b/src/main/java/hu/akarnokd/rxjava4/string/package-info.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/string/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/string/package-info.java index 5086d0fe..06c29a26 100644 --- a/src/main/java/hu/akarnokd/rxjava2/string/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/string/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ /** * Utility methods working with strings and character sequences via - * {@link hu.akarnokd.rxjava2.string.StringFlowable} and - * {@link hu.akarnokd.rxjava2.string.StringObservable StringObservable}; + * {@link hu.akarnokd.rxjava4.string.StringFlowable} and + * {@link hu.akarnokd.rxjava4.string.StringObservable StringObservable}; * a partial port of the * RxJavaString * library. */ -package hu.akarnokd.rxjava2.string; \ No newline at end of file +package hu.akarnokd.rxjava4.string; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubject.java b/src/main/java/hu/akarnokd/rxjava4/subjects/DispatchWorkSubject.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubject.java rename to src/main/java/hu/akarnokd/rxjava4/subjects/DispatchWorkSubject.java index 157e1bc6..efddf9c9 100644 --- a/src/main/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubject.java +++ b/src/main/java/hu/akarnokd/rxjava4/subjects/DispatchWorkSubject.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; +import java.util.Objects; import java.util.concurrent.atomic.*; -import hu.akarnokd.rxjava2.util.SpmcLinkedArrayQueue; -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.Subject; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.util.SpmcLinkedArrayQueue; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Scheduler.Worker; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.operators.SimplePlainQueue; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.Subject; /** * A {@link Subject} variant that queues up items and dispatches them asynchronously @@ -88,7 +87,7 @@ public static DispatchWorkSubject create(Scheduler scheduler, boolean del * @return the new DispatchWorkSubject instance */ public static DispatchWorkSubject create(Scheduler scheduler, int capacityHint, boolean delayErrors) { - return new DispatchWorkSubject(capacityHint, delayErrors, scheduler); + return new DispatchWorkSubject<>(capacityHint, delayErrors, scheduler); } final SimplePlainQueue queue; @@ -112,12 +111,12 @@ public static DispatchWorkSubject create(Scheduler scheduler, int capacit @SuppressWarnings("unchecked") DispatchWorkSubject(int capacityHint, boolean delayErrors, Scheduler scheduler) { - this.queue = new SpmcLinkedArrayQueue(capacityHint); + this.queue = new SpmcLinkedArrayQueue<>(capacityHint); this.delayErrors = delayErrors; this.wip = new AtomicInteger(); - this.upstream = new AtomicReference(); - this.error = new AtomicReference(); - this.observers = new AtomicReference[]>(EMPTY); + this.upstream = new AtomicReference<>(); + this.error = new AtomicReference<>(); + this.observers = new AtomicReference<>(EMPTY); this.scheduler = scheduler; } @@ -139,7 +138,7 @@ public void onNext(T t) { @SuppressWarnings("unchecked") @Override public void onError(Throwable e) { - ObjectHelper.requireNonNull(e, "e is null"); + Objects.requireNonNull(e, "e is null"); if (error.compareAndSet(null, e)) { for (WorkDisposable wd : observers.getAndSet(TERMINATED)) { wd.drain(); @@ -161,7 +160,7 @@ public void onComplete() { @Override protected void subscribeActual(Observer observer) { - WorkDisposable wd = new WorkDisposable(observer, this, scheduler.createWorker(), delayErrors); + WorkDisposable wd = new WorkDisposable<>(observer, this, scheduler.createWorker(), delayErrors); observer.onSubscribe(wd); if (add(wd)) { if (wd.isDisposed()) { diff --git a/src/main/java/hu/akarnokd/rxjava2/subjects/RefCountSubject.java b/src/main/java/hu/akarnokd/rxjava4/subjects/RefCountSubject.java similarity index 85% rename from src/main/java/hu/akarnokd/rxjava2/subjects/RefCountSubject.java rename to src/main/java/hu/akarnokd/rxjava4/subjects/RefCountSubject.java index 5a3889b7..e62adfec 100644 --- a/src/main/java/hu/akarnokd/rxjava2/subjects/RefCountSubject.java +++ b/src/main/java/hu/akarnokd/rxjava4/subjects/RefCountSubject.java @@ -1,24 +1,27 @@ -/** - * Copyright (c) 2016-present, RxJava Contributors. +/* + * Copyright 2016-present David Karnok * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; import java.util.concurrent.atomic.*; -import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.*; -import io.reactivex.subjects.Subject; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.subjects.Subject; /** * A Subject wrapper that disposes the Disposable set via @@ -44,8 +47,8 @@ @SuppressWarnings("unchecked") RefCountSubject(Subject actual) { this.actual = actual; - this.upstream = new AtomicReference(); - this.observers = new AtomicReference[]>(EMPTY); + this.upstream = new AtomicReference<>(); + this.observers = new AtomicReference<>(EMPTY); } @Override @@ -74,7 +77,7 @@ public void onComplete() { @Override protected void subscribeActual(Observer observer) { - RefCountObserver rcs = new RefCountObserver(observer, this); + RefCountObserver rcs = new RefCountObserver<>(observer, this); if (!add(rcs)) { EmptyDisposable.error(new IllegalStateException("RefCountSubject terminated"), observer); return; diff --git a/src/main/java/hu/akarnokd/rxjava2/subjects/Subjects.java b/src/main/java/hu/akarnokd/rxjava4/subjects/Subjects.java similarity index 79% rename from src/main/java/hu/akarnokd/rxjava2/subjects/Subjects.java rename to src/main/java/hu/akarnokd/rxjava4/subjects/Subjects.java index ff5f9e18..259bd647 100644 --- a/src/main/java/hu/akarnokd/rxjava2/subjects/Subjects.java +++ b/src/main/java/hu/akarnokd/rxjava4/subjects/Subjects.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; -import io.reactivex.annotations.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.subjects.Subject; +import java.util.Objects; + +import io.reactivex.rxjava4.annotations.*; +import io.reactivex.rxjava4.subjects.Subject; /** * Utility methods to work with RxJava 2 Subjects. @@ -34,7 +35,7 @@ private Subjects() { * Wraps a Subject and makes sure if all observers dispose * their disposables, the upstream's Disposable gets disposed as well. *

- * This operator is similar to {@link io.reactivex.observables.ConnectableObservable#refCount()} + * This operator is similar to {@link io.reactivex.rxjava4.core.ConnectableObservable#refCount()} * except the first Observer doesn't trigger any sort of connection; that happens * when the resulting Subject is subscribed to an Observable manually. * @param the input and output value type @@ -48,6 +49,6 @@ public static Subject refCount(Subject subject) { if (subject instanceof RefCountSubject) { return subject; } - return new RefCountSubject(ObjectHelper.requireNonNull(subject, "subject is null")); + return new RefCountSubject<>(Objects.requireNonNull(subject, "subject is null")); } } diff --git a/src/main/java/hu/akarnokd/rxjava2/subjects/UnicastWorkSubject.java b/src/main/java/hu/akarnokd/rxjava4/subjects/UnicastWorkSubject.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/subjects/UnicastWorkSubject.java rename to src/main/java/hu/akarnokd/rxjava4/subjects/UnicastWorkSubject.java index 1bf64a2c..5834b41a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/subjects/UnicastWorkSubject.java +++ b/src/main/java/hu/akarnokd/rxjava4/subjects/UnicastWorkSubject.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; +import java.util.Objects; import java.util.concurrent.atomic.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; -import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.Subject; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.operators.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.Subject; /** * A {@link Subject} that holds an unbounded queue of items and relays/replays it to @@ -90,7 +88,7 @@ public static UnicastWorkSubject create(boolean delayErrors) { * @return the new UnicastWorkSubject instance */ public static UnicastWorkSubject create(int capacityHint, boolean delayErrors) { - return new UnicastWorkSubject(capacityHint, delayErrors); + return new UnicastWorkSubject<>(capacityHint, delayErrors); } final SimplePlainQueue queue; @@ -108,12 +106,12 @@ public static UnicastWorkSubject create(int capacityHint, boolean delayEr T item; UnicastWorkSubject(int capacityHint, boolean delayErrors) { - this.queue = new SpscLinkedArrayQueue(capacityHint); + this.queue = new SpscLinkedArrayQueue<>(capacityHint); this.delayErrors = delayErrors; - this.consumer = new AtomicReference(); - this.upstream = new AtomicReference(); + this.consumer = new AtomicReference<>(); + this.upstream = new AtomicReference<>(); this.wip = new AtomicInteger(); - this.error = new AtomicReference(); + this.error = new AtomicReference<>(); } @Override @@ -123,7 +121,7 @@ public void onSubscribe(Disposable d) { @Override public void onNext(T t) { - ObjectHelper.requireNonNull(t, "t is null"); + Objects.requireNonNull(t, "t is null"); if (error.get() == null) { queue.offer(t); drain(); @@ -132,7 +130,7 @@ public void onNext(T t) { @Override public void onError(Throwable e) { - ObjectHelper.requireNonNull(e, "e is null"); + Objects.requireNonNull(e, "e is null"); if (error.compareAndSet(null, e)) { drain(); } else { diff --git a/src/main/java/hu/akarnokd/rxjava2/subjects/package-info.java b/src/main/java/hu/akarnokd/rxjava4/subjects/package-info.java similarity index 64% rename from src/main/java/hu/akarnokd/rxjava2/subjects/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/subjects/package-info.java index 865891f1..bfd4915c 100644 --- a/src/main/java/hu/akarnokd/rxjava2/subjects/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/subjects/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ /** * Special subjects such as - * {@link hu.akarnokd.rxjava2.subjects.UnicastWorkSubject UnicastWorkSubject}, - * {@link hu.akarnokd.rxjava2.subjects.DispatchWorkSubject DispatchWorkSubject} - * and generic utilities for {@link io.reactivex.subjects.Subject Subject}s - * via {@link hu.akarnokd.rxjava2.subjects.Subjects} methods. + * {@link hu.akarnokd.rxjava4.subjects.UnicastWorkSubject UnicastWorkSubject}, + * {@link hu.akarnokd.rxjava4.subjects.DispatchWorkSubject DispatchWorkSubject} + * and generic utilities for {@link io.reactivex.rxjava4.subjects.Subject Subject}s + * via {@link hu.akarnokd.rxjava4.subjects.Subjects} methods. */ -package hu.akarnokd.rxjava2.subjects; \ No newline at end of file +package hu.akarnokd.rxjava4.subjects; \ No newline at end of file diff --git a/src/main/java/hu/akarnokd/rxjava2/util/AlwaysFalseBooleanSupplier.java b/src/main/java/hu/akarnokd/rxjava4/util/AlwaysFalseBooleanSupplier.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/util/AlwaysFalseBooleanSupplier.java rename to src/main/java/hu/akarnokd/rxjava4/util/AlwaysFalseBooleanSupplier.java index cae3a219..c899a839 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/AlwaysFalseBooleanSupplier.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/AlwaysFalseBooleanSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; -import io.reactivex.functions.BooleanSupplier; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * A {@link BooleanSupplier} implementation that is always false. diff --git a/src/main/java/hu/akarnokd/rxjava2/util/AlwaysTrueBooleanSupplier.java b/src/main/java/hu/akarnokd/rxjava4/util/AlwaysTrueBooleanSupplier.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/util/AlwaysTrueBooleanSupplier.java rename to src/main/java/hu/akarnokd/rxjava4/util/AlwaysTrueBooleanSupplier.java index 4f62d478..d3985144 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/AlwaysTrueBooleanSupplier.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/AlwaysTrueBooleanSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; -import io.reactivex.functions.BooleanSupplier; +import io.reactivex.rxjava4.functions.BooleanSupplier; /** * A {@link BooleanSupplier} implementation that is always true. diff --git a/src/main/java/hu/akarnokd/rxjava2/util/BiFunctionSecondIdentity.java b/src/main/java/hu/akarnokd/rxjava4/util/BiFunctionSecondIdentity.java similarity index 91% rename from src/main/java/hu/akarnokd/rxjava2/util/BiFunctionSecondIdentity.java rename to src/main/java/hu/akarnokd/rxjava4/util/BiFunctionSecondIdentity.java index 82698cf9..dcddf46a 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/BiFunctionSecondIdentity.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/BiFunctionSecondIdentity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; -import io.reactivex.functions.BiFunction; +import io.reactivex.rxjava4.functions.BiFunction; /** * A BiFunction that returns its second parameter; use {@link #instance()} to diff --git a/src/main/java/hu/akarnokd/rxjava2/util/SneakyThrows.java b/src/main/java/hu/akarnokd/rxjava4/util/SneakyThrows.java similarity index 66% rename from src/main/java/hu/akarnokd/rxjava2/util/SneakyThrows.java rename to src/main/java/hu/akarnokd/rxjava4/util/SneakyThrows.java index 1c50ffb7..6307b2fb 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/SneakyThrows.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/SneakyThrows.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; /** - * Utility class to throw arbitrary Throwables. + * Utility class to throw arbitrary {@link Throwable}s. */ public final class SneakyThrows { @@ -25,8 +25,15 @@ private SneakyThrows() { throw new IllegalStateException("No instances!"); } + /** + * Sneakily throw. + * @param the throwable subclass + * @param error the error to throw + * @return never + * @throws E the exception type + */ @SuppressWarnings("unchecked") - public static E justThrow(Throwable error) throws E { + public static E justThrowX(Throwable error) throws E { throw (E)error; } diff --git a/src/main/java/hu/akarnokd/rxjava2/util/SpmcLinkedArrayQueue.java b/src/main/java/hu/akarnokd/rxjava4/util/SpmcLinkedArrayQueue.java similarity index 89% rename from src/main/java/hu/akarnokd/rxjava2/util/SpmcLinkedArrayQueue.java rename to src/main/java/hu/akarnokd/rxjava4/util/SpmcLinkedArrayQueue.java index beab4aca..e41d1d17 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/SpmcLinkedArrayQueue.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/SpmcLinkedArrayQueue.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; +import java.util.Objects; import java.util.concurrent.atomic.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; +import io.reactivex.rxjava4.operators.SimplePlainQueue; /** * A single-producer multiple-conumer queue implementation with array islands. @@ -35,15 +35,19 @@ public final class SpmcLinkedArrayQueue implements SimplePlainQueue { final AtomicReference consumerArray; + /** + * Constructs an instance with the specified capacity. + * @param capacity the capacity to use + */ public SpmcLinkedArrayQueue(int capacity) { ARA a = new ARA(Math.max(2, capacity) + 1); this.producerArray = a; - this.consumerArray = new AtomicReference(a); + this.consumerArray = new AtomicReference<>(a); } @Override public boolean offer(T value) { - ObjectHelper.requireNonNull(value, "value is null"); + Objects.requireNonNull(value, "value is null"); ARA pa = producerArray; int pi = producerIndex; @@ -63,8 +67,8 @@ public boolean offer(T value) { @Override public boolean offer(T v1, T v2) { - ObjectHelper.requireNonNull(v1, "v1 is null"); - ObjectHelper.requireNonNull(v2, "v2 is null"); + Objects.requireNonNull(v1, "v1 is null"); + Objects.requireNonNull(v2, "v2 is null"); ARA pa = producerArray; int pi = producerIndex; diff --git a/src/main/java/hu/akarnokd/rxjava2/util/SpscOneQueue.java b/src/main/java/hu/akarnokd/rxjava4/util/SpscOneQueue.java similarity index 86% rename from src/main/java/hu/akarnokd/rxjava2/util/SpscOneQueue.java rename to src/main/java/hu/akarnokd/rxjava4/util/SpscOneQueue.java index acbb2b53..106591d1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/SpscOneQueue.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/SpscOneQueue.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.SimplePlainQueue; +import io.reactivex.rxjava4.operators.SimplePlainQueue; /** * A single-producer single-consumer queue with exactly one slot of value. @@ -33,7 +33,7 @@ public final class SpscOneQueue extends AtomicReference @Override public boolean offer(T value) { - ObjectHelper.requireNonNull(value, "value is null"); + Objects.requireNonNull(value, "value is null"); if (get() == null) { lazySet(value); return true; diff --git a/src/main/java/hu/akarnokd/rxjava2/util/package-info.java b/src/main/java/hu/akarnokd/rxjava4/util/package-info.java similarity index 90% rename from src/main/java/hu/akarnokd/rxjava2/util/package-info.java rename to src/main/java/hu/akarnokd/rxjava4/util/package-info.java index edde44da..e438aee1 100644 --- a/src/main/java/hu/akarnokd/rxjava2/util/package-info.java +++ b/src/main/java/hu/akarnokd/rxjava4/util/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,4 +17,4 @@ /** * Utility classes and methods supporting the other utilities in this library. */ -package hu.akarnokd.rxjava2.util; \ No newline at end of file +package hu.akarnokd.rxjava4.util; \ No newline at end of file diff --git a/src/main/module/module-info.java b/src/main/module/module-info.java new file mode 100644 index 00000000..4b94d5c2 --- /dev/null +++ b/src/main/module/module-info.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +module hu.akarnokd.rxjava4 { + exports hu.akarnokd.rxjava4.async; + exports hu.akarnokd.rxjava4.basetypes; + exports hu.akarnokd.rxjava4.consumers; + exports hu.akarnokd.rxjava4.debug; + exports hu.akarnokd.rxjava4.debug.multihook; + exports hu.akarnokd.rxjava4.debug.validator; + exports hu.akarnokd.rxjava4.expr; + exports hu.akarnokd.rxjava4.functions; + exports hu.akarnokd.rxjava4.joins; + exports hu.akarnokd.rxjava4.math; + exports hu.akarnokd.rxjava4.operators; + exports hu.akarnokd.rxjava4.parallel; + exports hu.akarnokd.rxjava4.processors; + exports hu.akarnokd.rxjava4.string; + exports hu.akarnokd.rxjava4.subjects; + exports hu.akarnokd.rxjava4.util; + + requires java.management; + requires transitive io.reactivex.rxjava4; + + requires static org.junit.jupiter.api; + requires static org.mockito; + requires static org.junit.platform.commons; +} \ No newline at end of file diff --git a/src/test/java/hu/akarnokd/rxjava2/parallel/ParallelOrderedMergeTest.java b/src/test/java/hu/akarnokd/rxjava2/parallel/ParallelOrderedMergeTest.java deleted file mode 100644 index fbe162d1..00000000 --- a/src/test/java/hu/akarnokd/rxjava2/parallel/ParallelOrderedMergeTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.parallel; - -import java.util.Random; - -import org.junit.Test; - -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; - -public class ParallelOrderedMergeTest { - @Test - public void testBasicOrder() throws InterruptedException { - final Random rnd = new Random(); - ParallelTransformers.orderedMerge(Flowable.range(1, 5).parallel(4).runOn(Schedulers.computation()).map(new Function() { - @Override - public Integer apply(Integer t) throws Exception { - Thread.sleep(0, 50 + rnd.nextInt(1000)); - return t; - } - })).test().await().assertResult(1, 2, 3, 4, 5); - } -} diff --git a/src/test/java/hu/akarnokd/rxjava2/schedulers/BlockingSchedulerTest.java b/src/test/java/hu/akarnokd/rxjava2/schedulers/BlockingSchedulerTest.java deleted file mode 100644 index c78cdf06..00000000 --- a/src/test/java/hu/akarnokd/rxjava2/schedulers/BlockingSchedulerTest.java +++ /dev/null @@ -1,611 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.schedulers; - -import static org.junit.Assert.*; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; - -public class BlockingSchedulerTest { - - TestSubscriber ts = new TestSubscriber(); - - @Test(timeout = 10000) - public void workerUntimed() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - Flowable.range(1, 5) - .subscribeOn(scheduler) - .doAfterTerminate(new Action() { - @Override - public void run() throws Exception { - scheduler.shutdown(); - } - }) - .subscribe(ts); - - ts.assertEmpty(); - } - }); - - ts.assertResult(1, 2, 3, 4, 5); - - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void workerTimed() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - Flowable.range(1, 5) - .subscribeOn(scheduler) - .delay(100, TimeUnit.MILLISECONDS, scheduler) - .doAfterTerminate(new Action() { - @Override - public void run() throws Exception { - scheduler.shutdown(); - } - }) - .subscribe(ts); - - ts.assertEmpty(); - } - }); - - ts.assertResult(1, 2, 3, 4, 5); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void directCrash() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.shutdown(); - throw new IllegalArgumentException(); - } - }); - } - }); - - TestHelper.assertError(errors, 0, IllegalArgumentException.class); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void workerCrash() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - final Worker worker = scheduler.createWorker(); - worker.schedule(new Runnable() { - @Override - public void run() { - worker.dispose(); - scheduler.shutdown(); - throw new IllegalArgumentException(); - } - }); - } - }); - - TestHelper.assertError(errors, 0, IllegalArgumentException.class); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void directUntimed() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - ts.onSubscribe(new BooleanSubscription()); - - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - ts.onNext(1); - ts.onNext(2); - ts.onNext(3); - ts.onNext(4); - ts.onNext(5); - ts.onComplete(); - - scheduler.shutdown(); - } - }); - - ts.assertEmpty(); - } - }); - - ts.assertResult(1, 2, 3, 4, 5); - for (Throwable t : errors) { - t.printStackTrace(); - } - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void directTimed() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - ts.onSubscribe(new BooleanSubscription()); - - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - ts.onNext(1); - ts.onNext(2); - ts.onNext(3); - ts.onNext(4); - ts.onNext(5); - ts.onComplete(); - - scheduler.shutdown(); - } - }, 100, TimeUnit.MILLISECONDS); - - ts.assertEmpty(); - } - }); - - ts.assertResult(1, 2, 3, 4, 5); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void cancelDirect() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - ts.onSubscribe(new BooleanSubscription()); - - Disposable d = scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - ts.onNext(1); - ts.onNext(2); - ts.onNext(3); - ts.onNext(4); - ts.onNext(5); - ts.onComplete(); - } - }, 100, TimeUnit.MILLISECONDS); - - assertFalse(d.isDisposed()); - d.dispose(); - assertTrue(d.isDisposed()); - - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.shutdown(); - } - }); - - ts.assertEmpty(); - } - }); - - ts.assertEmpty(); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void cancelDirectUntimed() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - ts.onSubscribe(new BooleanSubscription()); - - Disposable d = scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - ts.onNext(1); - ts.onNext(2); - ts.onNext(3); - ts.onNext(4); - ts.onNext(5); - ts.onComplete(); - } - }); - - assertFalse(d.isDisposed()); - d.dispose(); - assertTrue(d.isDisposed()); - - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.shutdown(); - } - }); - - ts.assertEmpty(); - } - }); - - ts.assertEmpty(); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void cancelWorker() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - - ts.onSubscribe(new BooleanSubscription()); - - final Worker w = scheduler.createWorker(); - - Disposable d = w.schedule(new Runnable() { - @Override - public void run() { - ts.onNext(1); - ts.onNext(2); - ts.onNext(3); - ts.onNext(4); - ts.onNext(5); - ts.onComplete(); - } - }, 100, TimeUnit.MILLISECONDS); - - assertFalse(d.isDisposed()); - d.dispose(); - assertTrue(d.isDisposed()); - - w.schedule(new Runnable() { - @Override - public void run() { - w.dispose(); - scheduler.shutdown(); - } - }); - - ts.assertEmpty(); - } - }); - - ts.assertEmpty(); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void cancelWorkerUntimed() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - - ts.onSubscribe(new BooleanSubscription()); - - final Worker w = scheduler.createWorker(); - - Disposable d = w.schedule(new Runnable() { - @Override - public void run() { - ts.onNext(1); - ts.onNext(2); - ts.onNext(3); - ts.onNext(4); - ts.onNext(5); - ts.onComplete(); - } - }); - - assertFalse(d.isDisposed()); - d.dispose(); - assertTrue(d.isDisposed()); - - w.schedule(new Runnable() { - @Override - public void run() { - w.dispose(); - scheduler.shutdown(); - - assertTrue(w.isDisposed()); - } - }); - - ts.assertEmpty(); - } - }); - - ts.assertEmpty(); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void asyncShutdown() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - - Schedulers.single().scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.scheduleDirect(Functions.EMPTY_RUNNABLE); - scheduler.shutdown(); - scheduler.shutdown(); - assertTrue(scheduler.scheduleDirect(Functions.EMPTY_RUNNABLE).isDisposed()); - } - }, 500, TimeUnit.MILLISECONDS); - - scheduler.execute(); - - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void asyncInterrupt() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - - Schedulers.single().scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.shutdown.set(true); - scheduler.thread.interrupt(); - } - }, 500, TimeUnit.MILLISECONDS); - - scheduler.execute(); - - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void asyncDispose() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - - final Disposable d = scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(2000); - } catch (InterruptedException ex) { - // ignored - Thread.currentThread().interrupt(); - } - scheduler.shutdown(); - } - }); - - Schedulers.single().scheduleDirect(new Runnable() { - @Override - public void run() { - d.dispose(); - d.dispose(); - } - }, 500, TimeUnit.MILLISECONDS); - } - }); - - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void asyncFeedInto() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - - final int n = 10000; - - final int[] counter = { 0 }; - - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - Schedulers.single().scheduleDirect(new Runnable() { - @Override - public void run() { - for (int i = 0; i < n; i++) { - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - counter[0]++; - } - }); - } - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.shutdown(); - } - }); - } - }); - } - }); - - assertEquals(n, counter[0]); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void asyncFeedInto2() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - - final int n = 1000; - - final int[] counter = { 0 }; - - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - for (int i = 0; i < n; i++) { - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - counter[0]++; - } - }, i, TimeUnit.MILLISECONDS); - } - scheduler.scheduleDirect(new Runnable() { - @Override - public void run() { - scheduler.shutdown(); - } - }, n + 10, TimeUnit.MILLISECONDS); - } - }); - - assertEquals(n, counter[0]); - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } - - @Test(timeout = 10000) - public void backtoSameThread() { - List errors = TestHelper.trackPluginErrors(); - try { - final BlockingScheduler scheduler = new BlockingScheduler(); - - final Thread t0 = Thread.currentThread(); - final Thread[] t1 = { null }; - - scheduler.execute(new Action() { - @Override - public void run() throws Exception { - Flowable.just(1) - .subscribeOn(Schedulers.io()) - .observeOn(scheduler) - .doAfterTerminate(new Action() { - @Override - public void run() throws Exception { - scheduler.shutdown(); - } - }) - .subscribe(new Consumer() { - @Override - public void accept(Integer v) throws Exception { - t1[0] = Thread.currentThread(); - } - }); - } - }); - - assertSame(t0, t1[0]); - - assertTrue(errors.toString(), errors.isEmpty()); - } finally { - RxJavaPlugins.reset(); - } - } -} diff --git a/src/test/java/hu/akarnokd/rxjava2/schedulers/ParallelSchedulerTest.java b/src/test/java/hu/akarnokd/rxjava2/schedulers/ParallelSchedulerTest.java deleted file mode 100644 index 904fd363..00000000 --- a/src/test/java/hu/akarnokd/rxjava2/schedulers/ParallelSchedulerTest.java +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.schedulers; - -import static org.junit.Assert.*; - -import java.util.List; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import hu.akarnokd.rxjava2.schedulers.ParallelScheduler.TrackingParallelWorker.TrackedAction; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.schedulers.RxThreadFactory; -import io.reactivex.schedulers.Schedulers; - -public class ParallelSchedulerTest implements Runnable { - - final AtomicInteger calls = new AtomicInteger(); - - @Override - public void run() { - calls.getAndIncrement(); - } - - @Test - public void normalNonTracking() { - Scheduler s = new ParallelScheduler(2, false); - - for (int i = 0; i < 100; i++) { - Flowable.range(1, 10).hide() - .observeOn(s, false, 4) - .test() - .awaitDone(5, TimeUnit.SECONDS) - .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - } - } - - @Test - public void delayedNonTracking() { - Scheduler s = new ParallelScheduler(2, false); - - try { - for (int i = 0; i < 100; i++) { - Flowable.range(1, 10).hide() - .delay(50, TimeUnit.MILLISECONDS, s) - .test() - .awaitDone(5, TimeUnit.SECONDS) - .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - } - } finally { - s.shutdown(); - } - } - - @Test - public void normalTracking() { - Scheduler s = new ParallelScheduler(2, true); - - try { - for (int i = 0; i < 100; i++) { - Flowable.range(1, 10).hide() - .observeOn(s, false, 4) - .test() - .awaitDone(5, TimeUnit.SECONDS) - .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - } - } finally { - s.shutdown(); - } - } - - @Test - public void delayedTracking() { - Scheduler s = new ParallelScheduler(2, true); - - try { - for (int i = 0; i < 100; i++) { - Flowable.range(1, 10).hide() - .delay(50, TimeUnit.MILLISECONDS, s) - .test() - .awaitDone(5, TimeUnit.SECONDS) - .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - } - } finally { - s.shutdown(); - } - } - - @Test - public void shutdownNonTracking() throws Exception { - Scheduler s = new ParallelScheduler(2, false); - - shutdown(s); - } - - @Test - public void shutdownTracking() throws Exception { - Scheduler s = new ParallelScheduler(2, true); - - shutdown(s); - } - - protected void shutdown(Scheduler s) throws InterruptedException { - try { - Worker w = s.createWorker(); - - w.dispose(); - - assertSame(Disposables.disposed(), w.schedule(this)); - - assertSame(Disposables.disposed(), w.schedule(this, 100, TimeUnit.MILLISECONDS)); - - assertSame(Disposables.disposed(), w.schedulePeriodically(this, 100, 100, TimeUnit.MILLISECONDS)); - - s.shutdown(); - - assertSame(Disposables.disposed(), s.scheduleDirect(this)); - - assertSame(Disposables.disposed(), s.scheduleDirect(this, 100, TimeUnit.MILLISECONDS)); - - assertSame(Disposables.disposed(), s.schedulePeriodicallyDirect(this, 100, 100, TimeUnit.MILLISECONDS)); - - w = s.createWorker(); - - assertSame(Disposables.disposed(), w.schedule(this)); - - assertSame(Disposables.disposed(), w.schedule(this, 100, TimeUnit.MILLISECONDS)); - - assertSame(Disposables.disposed(), w.schedulePeriodically(this, 100, 100, TimeUnit.MILLISECONDS)); - - assertEquals(0, calls.get()); - - s.start(); - - s.scheduleDirect(this); - - s.scheduleDirect(this, 100, TimeUnit.MILLISECONDS); - - s.schedulePeriodicallyDirect(this, 100, 100, TimeUnit.MILLISECONDS); - - w = s.createWorker(); - - w.schedule(this); - - w.schedule(this, 100, TimeUnit.MILLISECONDS); - - w.schedulePeriodically(this, 100, 100, TimeUnit.MILLISECONDS); - - Thread.sleep(1000); - - int c = calls.get(); - assertTrue("" + c, c > 6); - } finally { - s.shutdown(); - } - } - - @Test(timeout = 5000) - public void taskThrowsNonTracking() throws Exception { - Scheduler s = new ParallelScheduler(2, false); - taskThrows(s); - } - - @Test(timeout = 5000) - public void taskThrowsTracking() throws Exception { - Scheduler s = new ParallelScheduler(2, true); - taskThrows(s); - } - - protected void taskThrows(Scheduler s) throws InterruptedException { - try { - List errors = TestHelper.trackPluginErrors(); - - Worker w = s.createWorker(); - - w.schedule(new Runnable() { - @Override - public void run() { - calls.getAndIncrement(); - throw new IllegalStateException(); - } - }); - - while (errors.isEmpty()) { - Thread.sleep(20); - } - - TestHelper.assertError(errors, 0, IllegalStateException.class); - } finally { - s.shutdown(); - } - } - - @Test - public void cancelledTaskNotTracking() throws Exception { - Scheduler s = new ParallelScheduler(2, false); - cancelledTask(s); - } - - @Test - public void cancelledTaskTracking() throws Exception { - Scheduler s = new ParallelScheduler(2, true); - cancelledTask(s); - } - - void cancelledTask(Scheduler s) throws InterruptedException { - try { - Worker w = s.createWorker(); - - try { - assertFalse(w.isDisposed()); - - Disposable d = w.schedule(this, 200, TimeUnit.MILLISECONDS); - - assertFalse(d.isDisposed()); - - d.dispose(); - - assertTrue(d.isDisposed()); - - Thread.sleep(300); - - assertEquals(0, calls.get()); - w.dispose(); - - assertTrue(w.isDisposed()); - } finally { - w.dispose(); - } - } finally { - s.shutdown(); - } - } - - @Test - public void constructors() { - startStop(new ParallelScheduler()); - startStop(new ParallelScheduler(1)); - startStop(new ParallelScheduler(1, new RxThreadFactory("Test"))); - startStop(new ParallelScheduler("Test")); - } - - private void startStop(Scheduler s) { - s.start(); - s.shutdown(); - s.shutdown(); - } - - @Test - public void shutdownBackingTracking() { - ParallelScheduler s = new ParallelScheduler(2, true); - - shutdownBacking(s); - } - - @Test - public void shutdownBackingNonTracking() { - ParallelScheduler s = new ParallelScheduler(2, false); - - shutdownBacking(s); - } - - private void shutdownBacking(ParallelScheduler s) { - for (ScheduledExecutorService exec : s.pool.get()) { - exec.shutdown(); - } - - assertSame(Disposables.disposed(), s.scheduleDirect(this)); - - assertSame(Disposables.disposed(), s.scheduleDirect(this, 100, TimeUnit.MILLISECONDS)); - - assertSame(Disposables.disposed(), s.schedulePeriodicallyDirect(this, 100, 100, TimeUnit.MILLISECONDS)); - - Worker w = s.createWorker(); - - assertSame(Disposables.disposed(), w.schedule(this)); - - assertSame(Disposables.disposed(), w.schedule(this, 100, TimeUnit.MILLISECONDS)); - - assertSame(Disposables.disposed(), w.schedulePeriodically(this, 100, 100, TimeUnit.MILLISECONDS)); - - assertEquals(0, calls.get()); - } - - @Test - public void startRace() { - for (int i = 0; i < 1000; i++) { - final Scheduler s = new ParallelScheduler(2); - s.shutdown(); - - Runnable r = new Runnable() { - @Override - public void run() { - s.start(); - } - }; - - TestHelper.race(r, r, Schedulers.single()); - } - } - - @Test - public void setFutureRace() { - final Scheduler s = new ParallelScheduler(2, true); - try { - for (int i = 0; i < 1000; i++) { - final Worker w = s.createWorker(); - - Runnable r1 = new Runnable() { - @Override - public void run() { - w.schedule(ParallelSchedulerTest.this); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - w.dispose(); - } - }; - TestHelper.race(r1, r2, Schedulers.single()); - } - } finally { - s.shutdown(); - } - } - - @Test - public void setFutureRace2() { - final Scheduler s = new ParallelScheduler(2, true); - try { - for (int i = 0; i < 1000; i++) { - final CompositeDisposable cd = new CompositeDisposable(); - final TrackedAction tt = new TrackedAction(this, cd); - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, null); - - Runnable r1 = new Runnable() { - @Override - public void run() { - tt.setFuture(ft); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - tt.future.set(TrackedAction.FINISHED); - } - }; - TestHelper.race(r1, r2, Schedulers.single()); - } - } finally { - s.shutdown(); - } - } - - @Test - public void setFutureRace3() { - final Scheduler s = new ParallelScheduler(2, true); - try { - for (int i = 0; i < 1000; i++) { - final CompositeDisposable cd = new CompositeDisposable(); - final TrackedAction tt = new TrackedAction(this, cd); - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, null); - - Runnable r1 = new Runnable() { - @Override - public void run() { - tt.setFuture(ft); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - tt.future.set(TrackedAction.DISPOSED); - } - }; - TestHelper.race(r1, r2, Schedulers.single()); - } - } finally { - s.shutdown(); - } - } - - @Test(expected = IllegalArgumentException.class) - public void illegalParallelism() { - new ParallelScheduler(0); - } - - @Test(expected = IllegalArgumentException.class) - public void illegalPriority() { - new ParallelScheduler(2, true, -1); - } -} diff --git a/src/test/java/hu/akarnokd/rxjava2/schedulers/SharedSchedulerTest.java b/src/test/java/hu/akarnokd/rxjava2/schedulers/SharedSchedulerTest.java deleted file mode 100644 index f6d5f70b..00000000 --- a/src/test/java/hu/akarnokd/rxjava2/schedulers/SharedSchedulerTest.java +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright 2016-2019 David Karnok - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package hu.akarnokd.rxjava2.schedulers; - -import static org.junit.Assert.*; - -import java.lang.management.ManagementFactory; -import java.util.*; -import java.util.concurrent.TimeUnit; - -import org.junit.Test; - -import hu.akarnokd.rxjava2.schedulers.SharedScheduler.SharedWorker.SharedAction; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.Scheduler.Worker; -import io.reactivex.disposables.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.Functions; -import io.reactivex.schedulers.*; - -public class SharedSchedulerTest implements Runnable { - - volatile int calls; - - @Override - public void run() { - calls++; - } - - @Test(timeout = 5000) - public void normal() { - SharedScheduler scheduler = new SharedScheduler(Schedulers.io()); - try { - final Set threads = new HashSet(); - - for (int i = 0; i < 100; i++) { - Flowable.just(1).subscribeOn(scheduler) - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { - return threads.add(Thread.currentThread().getName()); - } - }) - .blockingLast(); - } - - assertEquals(1, threads.size()); - } finally { - scheduler.shutdown(); - } - } - - @Test(timeout = 5000) - public void delay() { - SharedScheduler scheduler = new SharedScheduler(Schedulers.io()); - try { - final Set threads = new HashSet(); - - for (int i = 0; i < 100; i++) { - Flowable.just(1).delay(1, TimeUnit.MILLISECONDS, scheduler) - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { - return threads.add(Thread.currentThread().getName()); - } - }) - .blockingLast(); - } - - assertEquals(1, threads.size()); - } finally { - scheduler.shutdown(); - } - } - - long memoryUsage() { - return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); - } - - @Test - public void noleak() throws Exception { - SharedScheduler scheduler = new SharedScheduler(Schedulers.io()); - try { - Worker worker = scheduler.createWorker(); - - worker.schedule(Functions.EMPTY_RUNNABLE); - - System.gc(); - Thread.sleep(500); - - long before = memoryUsage(); - System.out.printf("Start: %.1f%n", before / 1024.0 / 1024.0); - - for (int i = 0; i < 200 * 1000; i++) { - worker.schedule(Functions.EMPTY_RUNNABLE, 1, TimeUnit.DAYS); - } - - long middle = memoryUsage(); - - System.out.printf("Middle: %.1f -> %.1f%n", before / 1024.0 / 1024.0, middle / 1024.0 / 1024.0); - - worker.dispose(); - - System.gc(); - - Thread.sleep(100); - - int wait = 400; - - long after = memoryUsage(); - - while (wait-- > 0) { - System.out.printf("Usage: %.1f -> %.1f -> %.1f%n", before / 1024.0 / 1024.0, middle / 1024.0 / 1024.0, after / 1024.0 / 1024.0); - - if (middle > after * 2) { - return; - } - - Thread.sleep(100); - - System.gc(); - - Thread.sleep(100); - - after = memoryUsage(); - } - - fail(String.format("Looks like there is a memory leak: %.1f -> %.1f -> %.1f", before / 1024.0 / 1024.0, middle / 1024.0 / 1024.0, after / 1024.0 / 1024.0)); - - } finally { - scheduler.shutdown(); - } - } - - @Test - public void now() { - TestScheduler test = new TestScheduler(); - - SharedScheduler scheduler = new SharedScheduler(test); - - assertEquals(0L, scheduler.now(TimeUnit.MILLISECONDS)); - - assertEquals(0L, scheduler.createWorker().now(TimeUnit.MILLISECONDS)); - } - - @Test - public void direct() { - TestScheduler test = new TestScheduler(); - - SharedScheduler scheduler = new SharedScheduler(test); - - scheduler.scheduleDirect(this); - - test.advanceTimeBy(1, TimeUnit.MILLISECONDS); - - assertEquals(1, calls); - - scheduler.scheduleDirect(this, 1, TimeUnit.MILLISECONDS); - - test.advanceTimeBy(1, TimeUnit.MILLISECONDS); - - assertEquals(2, calls); - - scheduler.schedulePeriodicallyDirect(this, 1, 1, TimeUnit.MILLISECONDS); - - test.advanceTimeBy(10, TimeUnit.MILLISECONDS); - - assertEquals(12, calls); - - Worker worker = scheduler.createWorker(); - worker.dispose(); - - assertSame(Disposables.disposed(), worker.schedule(this)); - - assertSame(Disposables.disposed(), worker.schedule(this, 1, TimeUnit.MILLISECONDS)); - } - - @Test - public void taskCrash() { - TestScheduler test = new TestScheduler(); - - SharedScheduler scheduler = new SharedScheduler(test); - - Disposable d = scheduler.createWorker().schedule(new Runnable() { - @Override - public void run() { - throw new IllegalArgumentException(); - } - }); - - assertFalse(d.isDisposed()); - - try { - test.triggerActions(); - } catch (IllegalArgumentException ex) { - // expected - } - - assertTrue(d.isDisposed()); - } - - @Test(timeout = 5000) - public void futureDisposeRace() throws Exception { - SharedScheduler scheduler = new SharedScheduler(Schedulers.computation()); - try { - Worker w = scheduler.createWorker(); - for (int i = 0; i < 1000; i++) { - w.schedule(this); - } - - while (calls != 1000) { - Thread.sleep(100); - } - } finally { - scheduler.shutdown(); - } - } - - @Test - public void disposeSetFutureRace() { - for (int i = 0; i < 1000; i++) { - final SharedAction sa = new SharedAction(this, new CompositeDisposable()); - - final Disposable d = Disposables.empty(); - - Runnable r1 = new Runnable() { - @Override - public void run() { - sa.setFuture(d); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - sa.dispose(); - } - }; - - TestHelper.race(r1, r2, Schedulers.single()); - - assertTrue("Future not disposed", d.isDisposed()); - } - } - - @Test - public void runSetFutureRace() { - for (int i = 0; i < 1000; i++) { - final SharedAction sa = new SharedAction(this, new CompositeDisposable()); - - final Disposable d = Disposables.empty(); - - Runnable r1 = new Runnable() { - @Override - public void run() { - sa.setFuture(d); - } - }; - - Runnable r2 = new Runnable() { - @Override - public void run() { - sa.run(); - } - }; - - TestHelper.race(r1, r2, Schedulers.single()); - - assertFalse("Future disposed", d.isDisposed()); - assertEquals(i + 1, calls); - } - } -} diff --git a/src/test/java/hu/akarnokd/rxjava2/async/AsyncFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/async/AsyncFlowableTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/async/AsyncFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/async/AsyncFlowableTest.java index 9a569e7e..5810422c 100644 --- a/src/test/java/hu/akarnokd/rxjava2/async/AsyncFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/async/AsyncFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.atomic.*; -import org.junit.Test; -import org.reactivestreams.Subscriber; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.functions.*; -import io.reactivex.Flowable; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.processors.UnicastProcessor; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.functions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.processors.UnicastProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; public class AsyncFlowableTest { @@ -41,9 +41,9 @@ public void startDefault() { final AtomicInteger counter = new AtomicInteger(); - Flowable source = AsyncFlowable.start(new Callable() { + Flowable source = AsyncFlowable.start(new Supplier() { @Override - public Integer call() throws Exception { + public Integer get() throws Exception { return counter.incrementAndGet(); } }); @@ -61,9 +61,9 @@ public Integer call() throws Exception { public void startCustomScheduler() { final AtomicInteger counter = new AtomicInteger(); - Flowable source = AsyncFlowable.start(new Callable() { + Flowable source = AsyncFlowable.start(new Supplier() { @Override - public Integer call() throws Exception { + public Integer get() throws Exception { return counter.incrementAndGet(); } }, Schedulers.single()); @@ -78,69 +78,77 @@ public Integer call() throws Exception { } @SuppressWarnings("rawtypes") - static final class MultiFunction extends AtomicReference + static final class MultiFunction implements Action, Consumer, BiConsumer, Consumer3, Consumer4, Consumer5, Consumer6, Consumer7, Consumer8, Consumer9, - Supplier, Function, BiFunction, Function3, Function4, Function5, - Function6, Function7, Function8, Function9 { + SimpleCallable, Function, BiFunction, Function3, Function4, Function5, + Function6, Function7, Function8, Function9, Supplier { - private static final long serialVersionUID = 6872582538056292053L; + final AtomicReference state = new AtomicReference<>(); + + void setState(String s) { + state.set(s); + } + + String getState() { + return state.get(); + } @Override public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7, Object t8, Object t9) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9); + setState("" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9); } @Override public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7, Object t8) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8); + setState("" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8); } @Override public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6 + t7); + setState("" + t1 + t2 + t3 + t4 + t5 + t6 + t7); } @Override public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6); + setState("" + t1 + t2 + t3 + t4 + t5 + t6); } @Override public void accept(Object t1, Object t2, Object t3, Object t4, Object t5) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5); + setState("" + t1 + t2 + t3 + t4 + t5); } @Override public void accept(Object t1, Object t2, Object t3, Object t4) throws Exception { - set("" + t1 + t2 + t3 + t4); + setState("" + t1 + t2 + t3 + t4); } @Override public void accept(Object t1, Object t2, Object t3) throws Exception { - set("" + t1 + t2 + t3); + setState("" + t1 + t2 + t3); } @Override public void accept(Object t1, Object t2) throws Exception { - set("" + t1 + t2); + setState("" + t1 + t2); } @Override public void accept(Object t) throws Exception { if (t instanceof Object[]) { - set(Arrays.toString((Object[])t)); + setState(Arrays.toString((Object[])t)); } else { - set("" + t); + setState("" + t); } } @Override public void run() throws Exception { - set("-"); + setState("-"); } @Override @@ -198,7 +206,12 @@ public Object apply(Object t) throws Exception { public Object call() { return "-"; } - } + + @Override + public Object get() { + return "-"; + } +} @Test public void toAsyncConsumer0() { @@ -227,7 +240,7 @@ public void toAsyncConsumer1() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1"); + assertEquals(f.getState(), "1"); } @SuppressWarnings({ "unchecked" }) @@ -241,7 +254,7 @@ public void toAsyncConsumer2() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12"); + assertEquals(f.getState(), "12"); } @SuppressWarnings({ "unchecked" }) @@ -255,7 +268,7 @@ public void toAsyncConsumer3() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123"); + assertEquals(f.getState(), "123"); } @SuppressWarnings({ "unchecked" }) @@ -269,7 +282,7 @@ public void toAsyncConsumer4() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234"); + assertEquals(f.getState(), "1234"); } @SuppressWarnings({ "unchecked" }) @@ -283,7 +296,7 @@ public void toAsyncConsumer5() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345"); + assertEquals(f.getState(), "12345"); } @SuppressWarnings({ "unchecked" }) @@ -297,7 +310,7 @@ public void toAsyncConsumer6() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456"); + assertEquals(f.getState(), "123456"); } @SuppressWarnings({ "unchecked" }) @@ -311,7 +324,7 @@ public void toAsyncConsumer7() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234567"); + assertEquals(f.getState(), "1234567"); } @SuppressWarnings({ "unchecked" }) @@ -325,7 +338,7 @@ public void toAsyncConsumer8() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345678"); + assertEquals(f.getState(), "12345678"); } @SuppressWarnings({ "unchecked" }) @@ -339,29 +352,42 @@ public void toAsyncConsumer9() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456789"); + assertEquals(f.getState(), "123456789"); } @SuppressWarnings({ "unchecked" }) @Test public void toAsyncConsumerN() { MultiFunction f = new MultiFunction(); + Consumer f2 = f; - AsyncFlowable.toAsyncArray((Consumer)f) + AsyncFlowable.toAsyncArray(f2) .apply(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + assertEquals(f.getState(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void toAsyncCallableFunction0() { + MultiFunction f = new MultiFunction(); + + AsyncFlowable.toAsyncCallable((SimpleCallable)f) + .call() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("-"); } @SuppressWarnings({ "unchecked" }) @Test - public void toAsyncFunction0() { + public void toAsyncSupplierFunction0() { MultiFunction f = new MultiFunction(); - AsyncFlowable.toAsync((Supplier)f) + AsyncFlowable.toAsyncSupplier((Supplier)f) .call() .test() .awaitDone(5, TimeUnit.SECONDS) @@ -515,7 +541,7 @@ public void toAsyncConsumer1Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1"); + assertEquals(f.getState(), "1"); } @SuppressWarnings({ "unchecked" }) @@ -529,7 +555,7 @@ public void toAsyncConsumer2Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12"); + assertEquals(f.getState(), "12"); } @SuppressWarnings({ "unchecked" }) @@ -543,7 +569,7 @@ public void toAsyncConsumer3Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123"); + assertEquals(f.getState(), "123"); } @SuppressWarnings({ "unchecked" }) @@ -557,7 +583,7 @@ public void toAsyncConsumer4Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234"); + assertEquals(f.getState(), "1234"); } @SuppressWarnings({ "unchecked" }) @@ -571,7 +597,7 @@ public void toAsyncConsumer5Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345"); + assertEquals(f.getState(), "12345"); } @SuppressWarnings({ "unchecked" }) @@ -585,7 +611,7 @@ public void toAsyncConsumer6Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456"); + assertEquals(f.getState(), "123456"); } @SuppressWarnings({ "unchecked" }) @@ -599,7 +625,7 @@ public void toAsyncConsumer7Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234567"); + assertEquals(f.getState(), "1234567"); } @SuppressWarnings({ "unchecked" }) @@ -613,7 +639,7 @@ public void toAsyncConsumer8Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345678"); + assertEquals(f.getState(), "12345678"); } @SuppressWarnings({ "unchecked" }) @@ -627,29 +653,42 @@ public void toAsyncConsumer9Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456789"); + assertEquals(f.getState(), "123456789"); } @SuppressWarnings({ "unchecked" }) @Test public void toAsyncConsumerNScheduler() { MultiFunction f = new MultiFunction(); + Consumer f2 = f; - AsyncFlowable.toAsyncArray((Consumer)f, Schedulers.single()) + AsyncFlowable.toAsyncArray(f2, Schedulers.single()) .apply(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + assertEquals(f.getState(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void toAsyncCallableFunction0Scheduler() { + MultiFunction f = new MultiFunction(); + + AsyncFlowable.toAsyncCallable((SimpleCallable)f, Schedulers.single()) + .call() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("-"); } @SuppressWarnings({ "unchecked" }) @Test - public void toAsyncFunction0Scheduler() { + public void toAsyncSupplierFunction0Scheduler() { MultiFunction f = new MultiFunction(); - AsyncFlowable.toAsync((Supplier)f, Schedulers.single()) + AsyncFlowable.toAsyncSupplier((Supplier)f, Schedulers.single()) .call() .test() .awaitDone(5, TimeUnit.SECONDS) @@ -778,11 +817,11 @@ public void toAsyncFunctionNScheduler() { @Test public void startFuture() { - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + final FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); ft.run(); - AsyncFlowable.startFuture(new Callable>() { + AsyncFlowable.startFuture(new Supplier>() { @Override - public Future call() throws Exception { + public Future get() throws Exception { return ft; } }) @@ -793,11 +832,11 @@ public Future call() throws Exception { @Test public void startFutureNull() { - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, null); + final FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null); ft.run(); - AsyncFlowable.startFuture(new Callable>() { + AsyncFlowable.startFuture(new Supplier>() { @Override - public Future call() throws Exception { + public Future get() throws Exception { return ft; } }) @@ -808,11 +847,11 @@ public Future call() throws Exception { @Test public void startFutureCustomScheduler() { - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + final FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); ft.run(); - AsyncFlowable.startFuture(new Callable>() { + AsyncFlowable.startFuture(new Supplier>() { @Override - public Future call() throws Exception { + public Future get() throws Exception { return ft; } }, Schedulers.single()) @@ -823,12 +862,12 @@ public Future call() throws Exception { @Test public void deferFuture() { - final FutureTask> ft = new FutureTask>(Functions.EMPTY_RUNNABLE, Flowable.just(1)); + final FutureTask> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, Flowable.just(1)); ft.run(); - AsyncFlowable.deferFuture(new Callable>>() { + AsyncFlowable.deferFuture(new Supplier>>() { @Override - public Future> call() throws Exception { + public Future> get() throws Exception { return ft; } }) @@ -839,12 +878,12 @@ public Future> call() throws Exception { @Test public void deferFutureCustomScheduler() { - final FutureTask> ft = new FutureTask>(Functions.EMPTY_RUNNABLE, Flowable.just(1)); + final FutureTask> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, Flowable.just(1)); ft.run(); - AsyncFlowable.deferFuture(new Callable>>() { + AsyncFlowable.deferFuture(new Supplier>>() { @Override - public Future> call() throws Exception { + public Future> get() throws Exception { return ft; } }, Schedulers.single()) @@ -855,7 +894,7 @@ public Future> call() throws Exception { @Test public void forEachFutureC1() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncFlowable.forEachFuture(Flowable.range(1, 5), new Consumer() { @Override @@ -870,7 +909,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1Error() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncFlowable.forEachFuture(Flowable.error(new IOException()), new Consumer() { @@ -883,7 +922,7 @@ public void accept(Integer v) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertTrue(list.isEmpty()); @@ -891,7 +930,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1C2() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncFlowable.forEachFuture(Flowable.range(1, 5), new Consumer() { @Override @@ -911,7 +950,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2Error() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncFlowable.forEachFuture(Flowable.error(new IOException()), new Consumer() { @Override @@ -928,7 +967,7 @@ public void accept(Throwable e) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -936,7 +975,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2A3() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncFlowable.forEachFuture(Flowable.range(1, 5), new Consumer() { @Override @@ -961,7 +1000,7 @@ public void run() throws Exception { @Test public void forEachFutureC1C2A3Error() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncFlowable.forEachFuture(Flowable.error(new IOException()), new Consumer() { @Override @@ -983,7 +1022,7 @@ public void run() throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -991,7 +1030,7 @@ public void run() throws Exception { @Test public void forEachFutureC1Scheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncFlowable.forEachFuture(Flowable.range(1, 5), new Consumer() { @Override @@ -1006,7 +1045,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1ErrorScheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncFlowable.forEachFuture(Flowable.error(new IOException()), new Consumer() { @@ -1019,7 +1058,7 @@ public void accept(Integer v) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertTrue(list.isEmpty()); @@ -1027,7 +1066,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1C2Scheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncFlowable.forEachFuture(Flowable.range(1, 5), new Consumer() { @Override @@ -1047,7 +1086,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2ErrorScheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncFlowable.forEachFuture(Flowable.error(new IOException()), new Consumer() { @Override @@ -1064,7 +1103,7 @@ public void accept(Throwable e) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -1072,7 +1111,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2A3Scheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncFlowable.forEachFuture(Flowable.range(1, 5), new Consumer() { @Override @@ -1097,7 +1136,7 @@ public void run() throws Exception { @Test public void forEachFutureC1C2A3ErrorScheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncFlowable.forEachFuture(Flowable.error(new IOException()), new Consumer() { @Override @@ -1119,7 +1158,7 @@ public void run() throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -1128,7 +1167,7 @@ public void run() throws Exception { @Test public void runAsync() { - AsyncFlowable.runAsync(Schedulers.single(), new BiConsumer, Disposable>() { + AsyncFlowable.runAsync(Schedulers.single(), new BiConsumer, Disposable>() { @Override public void accept(Subscriber s, Disposable d) throws Exception { Thread.sleep(200); @@ -1150,7 +1189,7 @@ public void accept(Subscriber s, Disposable d) throws Exception public void runAsyncProcessor() { AsyncFlowable.runAsync(Schedulers.single(), UnicastProcessor.create(), - new BiConsumer, Disposable>() { + new BiConsumer, Disposable>() { @Override public void accept(Subscriber s, Disposable d) throws Exception { s.onNext(1); diff --git a/src/test/java/hu/akarnokd/rxjava2/async/AsyncObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/async/AsyncObservableTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/async/AsyncObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/async/AsyncObservableTest.java index cb36900d..cf5d05a0 100644 --- a/src/test/java/hu/akarnokd/rxjava2/async/AsyncObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/async/AsyncObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,26 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.async; +package hu.akarnokd.rxjava4.async; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.functions.*; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.UnicastSubject; +import hu.akarnokd.rxjava4.async.AsyncFlowableTest.MultiFunction; +import hu.akarnokd.rxjava4.functions.*; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.UnicastSubject; public class AsyncObservableTest { @@ -41,9 +42,9 @@ public void startDefault() { final AtomicInteger counter = new AtomicInteger(); - Observable source = AsyncObservable.start(new Callable() { + Observable source = AsyncObservable.start(new Supplier() { @Override - public Integer call() throws Exception { + public Integer get() throws Exception { return counter.incrementAndGet(); } }); @@ -61,9 +62,9 @@ public Integer call() throws Exception { public void startCustomScheduler() { final AtomicInteger counter = new AtomicInteger(); - Observable source = AsyncObservable.start(new Callable() { + Observable source = AsyncObservable.start(new Supplier() { @Override - public Integer call() throws Exception { + public Integer get() throws Exception { return counter.incrementAndGet(); } }, Schedulers.single()); @@ -77,129 +78,6 @@ public Integer call() throws Exception { } } - @SuppressWarnings("rawtypes") - static final class MultiFunction extends AtomicReference - implements Action, Consumer, BiConsumer, Consumer3, Consumer4, Consumer5, - Consumer6, Consumer7, Consumer8, Consumer9, - Supplier, Function, BiFunction, Function3, Function4, Function5, - Function6, Function7, Function8, Function9 { - - private static final long serialVersionUID = 6872582538056292053L; - - @Override - public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7, Object t8, - Object t9) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9); - } - - @Override - public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7, Object t8) - throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8); - } - - @Override - public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7) - throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6 + t7); - } - - @Override - public void accept(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5 + t6); - } - - @Override - public void accept(Object t1, Object t2, Object t3, Object t4, Object t5) throws Exception { - set("" + t1 + t2 + t3 + t4 + t5); - } - - @Override - public void accept(Object t1, Object t2, Object t3, Object t4) throws Exception { - set("" + t1 + t2 + t3 + t4); - } - - @Override - public void accept(Object t1, Object t2, Object t3) throws Exception { - set("" + t1 + t2 + t3); - } - - @Override - public void accept(Object t1, Object t2) throws Exception { - set("" + t1 + t2); - } - - @Override - public void accept(Object t) throws Exception { - if (t instanceof Object[]) { - set(Arrays.toString((Object[])t)); - } else { - set("" + t); - } - } - - @Override - public void run() throws Exception { - set("-"); - } - - @Override - public Object apply(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7, Object t8, - Object t9) throws Exception { - return "" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9; - } - - @Override - public Object apply(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7, Object t8) - throws Exception { - return "" + t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8; - } - - @Override - public Object apply(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6, Object t7) - throws Exception { - return "" + t1 + t2 + t3 + t4 + t5 + t6 + t7; - } - - @Override - public Object apply(Object t1, Object t2, Object t3, Object t4, Object t5, Object t6) throws Exception { - return "" + t1 + t2 + t3 + t4 + t5 + t6; - } - - @Override - public Object apply(Object t1, Object t2, Object t3, Object t4, Object t5) throws Exception { - return "" + t1 + t2 + t3 + t4 + t5; - } - - @Override - public Object apply(Object t1, Object t2, Object t3, Object t4) throws Exception { - return "" + t1 + t2 + t3 + t4; - } - - @Override - public Object apply(Object t1, Object t2, Object t3) throws Exception { - return "" + t1 + t2 + t3; - } - - @Override - public Object apply(Object t1, Object t2) throws Exception { - return "" + t1 + t2; - } - - @Override - public Object apply(Object t) throws Exception { - if (t instanceof Object[]) { - return Arrays.toString((Object[])t); - } - return "" + t; - } - - @Override - public Object call() { - return "-"; - } - } - @Test public void toAsyncConsumer0() { final AtomicInteger counter = new AtomicInteger(); @@ -227,7 +105,7 @@ public void toAsyncConsumer1() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1"); + assertEquals(f.getState(), "1"); } @SuppressWarnings({ "unchecked" }) @@ -241,7 +119,7 @@ public void toAsyncConsumer2() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12"); + assertEquals(f.getState(), "12"); } @SuppressWarnings({ "unchecked" }) @@ -255,7 +133,7 @@ public void toAsyncConsumer3() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123"); + assertEquals(f.getState(), "123"); } @SuppressWarnings({ "unchecked" }) @@ -269,7 +147,7 @@ public void toAsyncConsumer4() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234"); + assertEquals(f.getState(), "1234"); } @SuppressWarnings({ "unchecked" }) @@ -283,7 +161,7 @@ public void toAsyncConsumer5() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345"); + assertEquals(f.getState(), "12345"); } @SuppressWarnings({ "unchecked" }) @@ -297,7 +175,7 @@ public void toAsyncConsumer6() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456"); + assertEquals(f.getState(), "123456"); } @SuppressWarnings({ "unchecked" }) @@ -311,7 +189,7 @@ public void toAsyncConsumer7() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234567"); + assertEquals(f.getState(), "1234567"); } @SuppressWarnings({ "unchecked" }) @@ -325,7 +203,7 @@ public void toAsyncConsumer8() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345678"); + assertEquals(f.getState(), "12345678"); } @SuppressWarnings({ "unchecked" }) @@ -339,21 +217,22 @@ public void toAsyncConsumer9() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456789"); + assertEquals(f.getState(), "123456789"); } @SuppressWarnings({ "unchecked" }) @Test public void toAsyncConsumerN() { MultiFunction f = new MultiFunction(); + Consumer f2 = f; - AsyncObservable.toAsyncArray((Consumer)f) + AsyncObservable.toAsyncArray(f2) .apply(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + assertEquals(f.getState(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); } @SuppressWarnings({ "unchecked" }) @@ -361,7 +240,19 @@ public void toAsyncConsumerN() { public void toAsyncFunction0() { MultiFunction f = new MultiFunction(); - AsyncObservable.toAsync((Supplier)f) + AsyncObservable.toAsyncCallable((SimpleCallable)f) + .call() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("-"); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void toAsyncSupplierFunction0() { + MultiFunction f = new MultiFunction(); + + AsyncObservable.toAsyncSupplier((Supplier)f) .call() .test() .awaitDone(5, TimeUnit.SECONDS) @@ -515,7 +406,7 @@ public void toAsyncConsumer1Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1"); + assertEquals(f.getState(), "1"); } @SuppressWarnings({ "unchecked" }) @@ -529,7 +420,7 @@ public void toAsyncConsumer2Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12"); + assertEquals(f.getState(), "12"); } @SuppressWarnings({ "unchecked" }) @@ -543,7 +434,7 @@ public void toAsyncConsumer3Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123"); + assertEquals(f.getState(), "123"); } @SuppressWarnings({ "unchecked" }) @@ -557,7 +448,7 @@ public void toAsyncConsumer4Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234"); + assertEquals(f.getState(), "1234"); } @SuppressWarnings({ "unchecked" }) @@ -571,7 +462,7 @@ public void toAsyncConsumer5Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345"); + assertEquals(f.getState(), "12345"); } @SuppressWarnings({ "unchecked" }) @@ -585,7 +476,7 @@ public void toAsyncConsumer6Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456"); + assertEquals(f.getState(), "123456"); } @SuppressWarnings({ "unchecked" }) @@ -599,7 +490,7 @@ public void toAsyncConsumer7Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "1234567"); + assertEquals(f.getState(), "1234567"); } @SuppressWarnings({ "unchecked" }) @@ -613,7 +504,7 @@ public void toAsyncConsumer8Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "12345678"); + assertEquals(f.getState(), "12345678"); } @SuppressWarnings({ "unchecked" }) @@ -627,21 +518,34 @@ public void toAsyncConsumer9Scheduler() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "123456789"); + assertEquals(f.getState(), "123456789"); } @SuppressWarnings({ "unchecked" }) @Test public void toAsyncConsumerNScheduler() { MultiFunction f = new MultiFunction(); + Consumer f2 = f; - AsyncObservable.toAsyncArray((Consumer)f, Schedulers.single()) + AsyncObservable.toAsyncArray(f2, Schedulers.single()) .apply(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(AnyValue.INSTANCE); - assertEquals(f.get(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + assertEquals(f.getState(), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void toAsyncCallableFunction0Scheduler() { + MultiFunction f = new MultiFunction(); + + AsyncObservable.toAsyncCallable((SimpleCallable)f, Schedulers.single()) + .call() + .test() + .awaitDone(5, TimeUnit.SECONDS) + .assertResult("-"); } @SuppressWarnings({ "unchecked" }) @@ -649,7 +553,7 @@ public void toAsyncConsumerNScheduler() { public void toAsyncFunction0Scheduler() { MultiFunction f = new MultiFunction(); - AsyncObservable.toAsync((Supplier)f, Schedulers.single()) + AsyncObservable.toAsyncSupplier((Supplier)f, Schedulers.single()) .call() .test() .awaitDone(5, TimeUnit.SECONDS) @@ -778,11 +682,11 @@ public void toAsyncFunctionNScheduler() { @Test public void startFuture() { - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + final FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); ft.run(); - AsyncObservable.startFuture(new Callable>() { + AsyncObservable.startFuture(new Supplier>() { @Override - public Future call() throws Exception { + public Future get() throws Exception { return ft; } }) @@ -793,11 +697,11 @@ public Future call() throws Exception { @Test public void startFutureNull() { - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, null); + final FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null); ft.run(); - AsyncObservable.startFuture(new Callable>() { + AsyncObservable.startFuture(new Supplier>() { @Override - public Future call() throws Exception { + public Future get() throws Exception { return ft; } }) @@ -808,11 +712,11 @@ public Future call() throws Exception { @Test public void startFutureCustomScheduler() { - final FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + final FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); ft.run(); - AsyncObservable.startFuture(new Callable>() { + AsyncObservable.startFuture(new Supplier>() { @Override - public Future call() throws Exception { + public Future get() throws Exception { return ft; } }, Schedulers.single()) @@ -823,12 +727,12 @@ public Future call() throws Exception { @Test public void deferFuture() { - final FutureTask> ft = new FutureTask>(Functions.EMPTY_RUNNABLE, Observable.just(1)); + final FutureTask> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, Observable.just(1)); ft.run(); - AsyncObservable.deferFuture(new Callable>>() { + AsyncObservable.deferFuture(new Supplier>>() { @Override - public Future> call() throws Exception { + public Future> get() throws Exception { return ft; } }) @@ -839,12 +743,12 @@ public Future> call() throws Exception { @Test public void deferFutureCustomScheduler() { - final FutureTask> ft = new FutureTask>(Functions.EMPTY_RUNNABLE, Observable.just(1)); + final FutureTask> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, Observable.just(1)); ft.run(); - AsyncObservable.deferFuture(new Callable>>() { + AsyncObservable.deferFuture(new Supplier>>() { @Override - public Future> call() throws Exception { + public Future> get() throws Exception { return ft; } }, Schedulers.single()) @@ -855,7 +759,7 @@ public Future> call() throws Exception { @Test public void forEachFutureC1() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncObservable.forEachFuture(Observable.range(1, 5), new Consumer() { @Override @@ -870,7 +774,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1Error() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncObservable.forEachFuture(Observable.error(new IOException()), new Consumer() { @@ -883,7 +787,7 @@ public void accept(Integer v) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertTrue(list.isEmpty()); @@ -891,7 +795,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1C2() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncObservable.forEachFuture(Observable.range(1, 5), new Consumer() { @Override @@ -911,7 +815,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2Error() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncObservable.forEachFuture(Observable.error(new IOException()), new Consumer() { @Override @@ -928,7 +832,7 @@ public void accept(Throwable e) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -936,7 +840,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2A3() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncObservable.forEachFuture(Observable.range(1, 5), new Consumer() { @Override @@ -961,7 +865,7 @@ public void run() throws Exception { @Test public void forEachFutureC1C2A3Error() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncObservable.forEachFuture(Observable.error(new IOException()), new Consumer() { @Override @@ -983,7 +887,7 @@ public void run() throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -991,7 +895,7 @@ public void run() throws Exception { @Test public void forEachFutureC1Scheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncObservable.forEachFuture(Observable.range(1, 5), new Consumer() { @Override @@ -1006,7 +910,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1ErrorScheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncObservable.forEachFuture(Observable.error(new IOException()), new Consumer() { @@ -1019,7 +923,7 @@ public void accept(Integer v) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertTrue(list.isEmpty()); @@ -1027,7 +931,7 @@ public void accept(Integer v) throws Exception { @Test public void forEachFutureC1C2Scheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncObservable.forEachFuture(Observable.range(1, 5), new Consumer() { @Override @@ -1047,7 +951,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2ErrorScheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncObservable.forEachFuture(Observable.error(new IOException()), new Consumer() { @Override @@ -1064,7 +968,7 @@ public void accept(Throwable e) throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -1072,7 +976,7 @@ public void accept(Throwable e) throws Exception { @Test public void forEachFutureC1C2A3Scheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); assertNull(AsyncObservable.forEachFuture(Observable.range(1, 5), new Consumer() { @Override @@ -1097,7 +1001,7 @@ public void run() throws Exception { @Test public void forEachFutureC1C2A3ErrorScheduler() throws Exception { - final List list = new ArrayList(); + final List list = new ArrayList<>(); try { AsyncObservable.forEachFuture(Observable.error(new IOException()), new Consumer() { @Override @@ -1119,7 +1023,7 @@ public void run() throws Exception { fail("Should have thrown"); } catch (ExecutionException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } assertEquals(Arrays.asList(100), list); @@ -1128,7 +1032,7 @@ public void run() throws Exception { @Test public void runAsync() { - AsyncObservable.runAsync(Schedulers.single(), new BiConsumer, Disposable>() { + AsyncObservable.runAsync(Schedulers.single(), new BiConsumer, Disposable>() { @Override public void accept(Observer observer, Disposable d) throws Exception { Thread.sleep(200); @@ -1150,7 +1054,7 @@ public void accept(Observer observer, Disposable d) throws Excep public void runAsyncProcessor() { AsyncObservable.runAsync(Schedulers.single(), UnicastSubject.create(), - new BiConsumer, Disposable>() { + new BiConsumer, Disposable>() { @Override public void accept(Observer observer, Disposable d) throws Exception { observer.onNext(1); diff --git a/src/test/java/hu/akarnokd/rxjava2/basetypes/NonoProcessorTest.java b/src/test/java/hu/akarnokd/rxjava4/basetypes/NonoProcessorTest.java similarity index 87% rename from src/test/java/hu/akarnokd/rxjava2/basetypes/NonoProcessorTest.java rename to src/test/java/hu/akarnokd/rxjava4/basetypes/NonoProcessorTest.java index adba5d51..24679905 100644 --- a/src/test/java/hu/akarnokd/rxjava2/basetypes/NonoProcessorTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/basetypes/NonoProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; +import java.util.concurrent.Flow.*; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class NonoProcessorTest { @@ -74,7 +74,7 @@ public void error() { assertFalse(ms.hasComplete()); assertTrue(ms.hasThrowable()); - assertTrue(ms.getThrowable().toString(), ms.getThrowable() instanceof IOException); + assertTrue(ms.getThrowable() instanceof IOException, ms.getThrowable().toString()); assertFalse(ms.hasSubscribers()); assertEquals(0, ms.subscriberCount()); @@ -84,7 +84,7 @@ public void error() { assertFalse(ms.hasComplete()); assertTrue(ms.hasThrowable()); - assertTrue(ms.getThrowable().toString(), ms.getThrowable() instanceof IOException); + assertTrue(ms.getThrowable() instanceof IOException, ms.getThrowable().toString()); assertFalse(ms.hasSubscribers()); assertEquals(0, ms.subscriberCount()); } @@ -224,14 +224,16 @@ public void run() { } } - @Test(expected = NullPointerException.class) + @Test public void onNextNpe() { - NonoProcessor.create().onNext(null); + assertThrows(NullPointerException.class, () -> { + NonoProcessor.create().onNext(null); + }); } @Test public void crossCancelComplete() { - final TestSubscriber ts1 = new TestSubscriber(); + final TestSubscriber ts1 = new TestSubscriber<>(); TestSubscriber ts2 = new TestSubscriber() { @Override @@ -253,7 +255,7 @@ public void onComplete() { @Test public void crossCancelError() { - final TestSubscriber ts1 = new TestSubscriber(); + final TestSubscriber ts1 = new TestSubscriber<>(); TestSubscriber ts2 = new TestSubscriber() { @Override diff --git a/src/test/java/hu/akarnokd/rxjava2/basetypes/NonoTest.java b/src/test/java/hu/akarnokd/rxjava4/basetypes/NonoTest.java similarity index 85% rename from src/test/java/hu/akarnokd/rxjava2/basetypes/NonoTest.java rename to src/test/java/hu/akarnokd/rxjava4/basetypes/NonoTest.java index 6c2803a4..c842fd7d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/basetypes/NonoTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/basetypes/NonoTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,30 +14,28 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.*; - -import org.junit.*; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.Observable; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.QueueSubscription; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import java.util.concurrent.Flow.*; + +import org.junit.jupiter.api.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.operators.QueueSubscription; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class NonoTest implements Action, Consumer, LongConsumer, Cancellable { @@ -88,9 +86,9 @@ public void error() { @Test public void errorSupplier() { - Nono.error(new Callable() { + Nono.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { return new IOException(); } }) @@ -100,9 +98,9 @@ public Throwable call() throws Exception { @Test public void errorSupplierThrows() { - Nono.error(new Callable() { + Nono.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { throw new IOException(); } }) @@ -114,9 +112,9 @@ public Throwable call() throws Exception { public void defer() { final int[] counter = { 0 }; - Nono np = Nono.defer(new Callable() { + Nono np = Nono.defer(new Supplier() { @Override - public Nono call() throws Exception { + public Nono get() throws Exception { if (counter[0]++ == 0) { return Nono.error(new IOException()); } @@ -124,26 +122,26 @@ public Nono call() throws Exception { } }); - Assert.assertEquals(0, counter[0]); + assertEquals(0, counter[0]); np.test().assertFailure(IOException.class); - Assert.assertEquals(1, counter[0]); + assertEquals(1, counter[0]); np.test().assertFailure(IllegalArgumentException.class); - Assert.assertEquals(2, counter[0]); + assertEquals(2, counter[0]); np.test().assertFailure(IllegalArgumentException.class); - Assert.assertEquals(3, counter[0]); + assertEquals(3, counter[0]); } @Test public void deferThrows() { - Nono np = Nono.defer(new Callable() { + Nono np = Nono.defer(new Supplier() { @Override - public Nono call() throws Exception { + public Nono get() throws Exception { throw new IOException(); } }); @@ -162,15 +160,15 @@ public void run() throws Exception { } }); - Assert.assertEquals(0, counter[0]); + assertEquals(0, counter[0]); np.test().assertResult(); - Assert.assertEquals(1, counter[0]); + assertEquals(1, counter[0]); np.test().assertResult(); - Assert.assertEquals(2, counter[0]); + assertEquals(2, counter[0]); } @Test @@ -189,7 +187,7 @@ public void run() throws Exception { public void fromFuture() { final int[] counter = { 0 }; - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Void call() throws Exception { counter[0]++; @@ -203,14 +201,14 @@ public Void call() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(1, counter[0]); + assertEquals(1, counter[0]); } @Test public void fromFutureThrows() { final int[] counter = { 0 }; - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Void call() throws Exception { counter[0]++; @@ -224,14 +222,14 @@ public Void call() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); - Assert.assertEquals(1, counter[0]); + assertEquals(1, counter[0]); } @Test public void fromFutureWithTimeout() { final int[] counter = { 0 }; - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Void call() throws Exception { counter[0]++; @@ -245,14 +243,14 @@ public Void call() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(1, counter[0]); + assertEquals(1, counter[0]); } @Test public void fromFutureWithTimeoutError() { final int[] counter = { 0 }; - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Void call() throws Exception { counter[0]++; @@ -266,14 +264,14 @@ public Void call() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); - Assert.assertEquals(1, counter[0]); + assertEquals(1, counter[0]); } @Test public void fromFutureWithTimeoutDoTimeout() { final int[] counter = { 0 }; - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Void call() throws Exception { counter[0]++; @@ -287,7 +285,7 @@ public Void call() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); - Assert.assertEquals(0, counter[0]); + assertEquals(0, counter[0]); } @Test @@ -352,7 +350,7 @@ public void concatIterable() { .test() .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -361,7 +359,7 @@ public void concatPublisher() { .test() .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -371,7 +369,7 @@ public void concatPublisher2() { .test() .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -380,7 +378,7 @@ public void concatArray() { .test() .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -389,7 +387,7 @@ public void concatIterableError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -398,7 +396,7 @@ public void concatPublisherError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -407,7 +405,7 @@ public void concatPublisherMainError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -416,7 +414,7 @@ public void concatArrayError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -428,7 +426,7 @@ public void concatIterableDelayError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -440,7 +438,7 @@ public void concatPublisherDelayError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -454,7 +452,7 @@ public void concatPublisherDelayErrorMain() { .test() .assertFailure(IOException.class); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -466,7 +464,7 @@ public void concatPublisherDelayErrorMainBoundary() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -478,7 +476,7 @@ public void concatArrayDelayError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -734,60 +732,60 @@ public void timerScheduler() { @Test public void using() { Nono.using( - Functions.justCallable(1), + Functions.justSupplier(1), Functions.justFunction(Nono.complete()), this ) .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void usingError() { Nono.using( - Functions.justCallable(1), + Functions.justSupplier(1), Functions.justFunction(ioError), this ) .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void usingNonEager() { Nono.using( - Functions.justCallable(1), + Functions.justSupplier(1), Functions.justFunction(Nono.complete()), this, false ) .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void usingNonEagerError() { Nono.using( - Functions.justCallable(1), + Functions.justSupplier(1), Functions.justFunction(ioError), this, false ) .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void usingResourceThrows() { - Nono.using(new Callable() { + Nono.using(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { throw new IllegalArgumentException(); } }, @@ -800,7 +798,7 @@ public Object call() throws Exception { @Test public void usingSourceThrows() { - Nono.using(Functions.justCallable(0), + Nono.using(Functions.justSupplier(0), new Function() { @Override public Nono apply(Integer v) throws Exception { @@ -815,7 +813,7 @@ public Nono apply(Integer v) throws Exception { @Test public void usingDisposerThrows1() { - Nono.using(Functions.justCallable(0), + Nono.using(Functions.justSupplier(0), Functions.justFunction(Nono.complete()), new Consumer() { @Override @@ -830,7 +828,7 @@ public void accept(Integer t) throws Exception { @Test public void usingDisposerThrows2() { - Nono.using(Functions.justCallable(0), + TestSubscriber ts = Nono.using(Functions.justSupplier(0), Functions.justFunction(ioError), new Consumer() { @Override @@ -841,20 +839,16 @@ public void accept(Integer t) throws Exception { ) .test() .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @SuppressWarnings("unchecked") - @Override - public void accept(TestSubscriber ts) throws Exception { - TestHelper.assertCompositeExceptions(ts, IOException.class, IllegalArgumentException.class); - } - }); + ; + + TestHelper.assertCompositeExceptions(ts, IOException.class, IllegalArgumentException.class); } @Test public void usingDisposerThrows3() { List errors = TestHelper.trackPluginErrors(); try { - Nono.using(Functions.justCallable(0), + Nono.using(Functions.justSupplier(0), Functions.justFunction(Nono.complete()), new Consumer() { @Override @@ -874,7 +868,7 @@ public void accept(Integer t) throws Exception { @Test public void usingDisposerThrows4() { - Nono.using(Functions.justCallable(0), + TestSubscriber ts = Nono.using(Functions.justSupplier(0), new Function() { @Override public Nono apply(Integer v) throws Exception { @@ -890,21 +884,17 @@ public void accept(Integer t) throws Exception { ) .test() .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @SuppressWarnings("unchecked") - @Override - public void accept(TestSubscriber ts) throws Exception { - TestHelper.assertCompositeExceptions(ts, - IOException.class, IllegalArgumentException.class); - } - }); + ; + + TestHelper.assertCompositeExceptions(ts, + IOException.class, IllegalArgumentException.class); } @Test public void usingDisposerThrows5() { List errors = TestHelper.trackPluginErrors(); try { - Nono.using(Functions.justCallable(0), + Nono.using(Functions.justSupplier(0), new Function() { @Override public Nono apply(Integer v) throws Exception { @@ -969,7 +959,7 @@ public void fromPublisher6() { .test() .assertResult(); - Assert.assertSame(np, Nono.complete()); + assertSame(np, Nono.complete()); } @Test @@ -1084,7 +1074,7 @@ public void andThenNono1() { .test() .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -1093,7 +1083,7 @@ public void andThenNono2() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1102,7 +1092,7 @@ public void andThenNono3() { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1111,7 +1101,7 @@ public void delaySubscription1() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1120,7 +1110,7 @@ public void delaySubscription2() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1129,7 +1119,7 @@ public void delaySubscription3() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1138,7 +1128,7 @@ public void delaySubscription4() { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1147,7 +1137,7 @@ public void delaySubscription5() { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1157,7 +1147,7 @@ public void delaySubscriptionTime1() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1167,7 +1157,7 @@ public void delaySubscriptionTime2() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1184,7 +1174,7 @@ public void timeout1() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1193,7 +1183,7 @@ public void timeout2() { .test() .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -1202,7 +1192,7 @@ public void timeout3() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1211,7 +1201,7 @@ public void timeout4() { .test() .assertFailure(TimeoutException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1223,7 +1213,7 @@ public void timeout5() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1235,7 +1225,7 @@ public void timeout6() { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1247,7 +1237,7 @@ public void timeout7() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -1260,7 +1250,7 @@ public void timeout8() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test @@ -1272,7 +1262,7 @@ public void timeout9() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1284,7 +1274,7 @@ public void timeout10() { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1294,7 +1284,7 @@ public void timeout11() { .test() .assertFailure(IOException.class); - Assert.assertFalse(pp.hasSubscribers()); + assertFalse(pp.hasSubscribers()); } @Test @@ -1310,7 +1300,7 @@ public void onErrorComplete() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1326,7 +1316,7 @@ public void mapError() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1342,7 +1332,7 @@ public void onErrorResumeNext() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1351,7 +1341,7 @@ public void onErrorResumeNextError1() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1363,24 +1353,24 @@ public void onErrorResumeNextError2() { @Test public void flatMap1() { - Nono.fromAction(this).flatMap(Functions.justFunction(Flowable.just(1)), Functions.justCallable(Flowable.just(2))) + Nono.fromAction(this).flatMap(Functions.justFunction(Flowable.just(1)), Functions.justSupplier(Flowable.just(2))) .test() .assertResult(2); } @Test public void flatMap2() { - Nono.fromAction(this).flatMap(Functions.justFunction(Flowable.just(1)), Functions.justCallable(Flowable.range(10, 5))) + Nono.fromAction(this).flatMap(Functions.justFunction(Flowable.just(1)), Functions.justSupplier(Flowable.range(10, 5))) .rebatchRequests(1) .test() .assertResult(10, 11, 12, 13, 14); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void flatMap3() { - ioError.flatMap(Functions.justFunction(Flowable.just(1)), Functions.justCallable(Flowable.just(2))) + ioError.flatMap(Functions.justFunction(Flowable.just(1)), Functions.justSupplier(Flowable.just(2))) .test() .assertResult(1); } @@ -1389,7 +1379,7 @@ public void flatMap3() { public void flatMap4() { ioError.flatMap( Functions.justFunction(Flowable.error(new IllegalArgumentException())), - Functions.justCallable(Flowable.just(2))) + Functions.justSupplier(Flowable.just(2))) .test() .assertFailure(IllegalArgumentException.class); } @@ -1398,12 +1388,12 @@ public void flatMap4() { public void flatMap5() { Nono.fromAction(this).flatMap( Functions.justFunction(Flowable.just(1)), - Functions.justCallable(Flowable.error(new IllegalArgumentException())) + Functions.justSupplier(Flowable.error(new IllegalArgumentException())) ) .test() .assertFailure(IllegalArgumentException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1412,7 +1402,7 @@ public void compose() { .test() .assertResult(); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1425,17 +1415,19 @@ public Object apply(Nono np) throws Exception { } }); } catch (RuntimeException ex) { - Assert.assertTrue(ex.toString(), ex.getCause() instanceof IOException); + assertTrue(ex.getCause() instanceof IOException, ex.toString()); } } - @Test(expected = IllegalArgumentException.class) + @Test public void toError2() { - Nono.fromAction(this).to(new Function() { - @Override - public Object apply(Nono np) throws Exception { - throw new IllegalArgumentException(); - } + assertThrows(IllegalArgumentException.class, () -> { + Nono.fromAction(this).to(new Function() { + @Override + public Object apply(Nono np) throws Exception { + throw new IllegalArgumentException(); + } + }); }); } @@ -1445,7 +1437,7 @@ public void lift() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1454,7 +1446,7 @@ public void toFlowable() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1470,7 +1462,7 @@ public void toObservable() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1486,7 +1478,7 @@ public void toMaybe() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1502,7 +1494,7 @@ public void toCompletable() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1527,8 +1519,8 @@ public void run() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertNotNull(on[0]); - Assert.assertNotEquals(main, on[0]); + assertNotNull(on[0]); + assertNotEquals(main, on[0]); } @Test @@ -1547,8 +1539,8 @@ public void run() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); - Assert.assertNotNull(on[0]); - Assert.assertNotEquals(main, on[0]); + assertNotNull(on[0]); + assertNotEquals(main, on[0]); } @Test @@ -1566,8 +1558,8 @@ public void run() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertNotNull(on[0]); - Assert.assertEquals(main, on[0]); + assertNotNull(on[0]); + assertEquals(main, on[0]); } @Test @@ -1586,8 +1578,8 @@ public void run() throws Exception { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); - Assert.assertNotNull(on[0]); - Assert.assertEquals(main, on[0]); + assertNotNull(on[0]); + assertEquals(main, on[0]); } @Test @@ -1610,8 +1602,8 @@ public void run() throws Exception { cdl.await(); - Assert.assertNotNull(on[0]); - Assert.assertNotEquals(main, on[0]); + assertNotNull(on[0]); + assertNotEquals(main, on[0]); } @Test @@ -1621,7 +1613,7 @@ public void doOnComplete1() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1631,7 +1623,7 @@ public void doOnComplete2() { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1646,7 +1638,7 @@ public void run() throws Exception { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1656,7 +1648,7 @@ public void doOnError1() { .test() .assertResult(); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1666,7 +1658,7 @@ public void doOnError2() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1681,16 +1673,18 @@ public void accept(Throwable t) throws Exception { }) .test() .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { + .assertError(new Predicate() { @Override - public void accept(TestSubscriber ts) throws Exception { - List list = TestHelper.compositeList(ts.errors().get(0)); + public boolean test(Throwable error) throws Throwable { + List list = TestHelper.compositeList(error); TestHelper.assertError(list, 0, IOException.class); TestHelper.assertError(list, 1, IllegalArgumentException.class); + return true; } - }); + }) + ; - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1700,7 +1694,7 @@ public void doOnSubscribe() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1710,7 +1704,7 @@ public void doOnSubscribeError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1733,7 +1727,7 @@ public void doOnRequest() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1743,7 +1737,7 @@ public void doOnRequestError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1761,7 +1755,7 @@ public void accept(long t) throws Exception { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -1784,7 +1778,7 @@ public void doAfterTerminateError() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1802,7 +1796,7 @@ public void run() throws Exception { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -1825,7 +1819,7 @@ public void run() throws Exception { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); TestHelper.assertError(errors, 0, IllegalArgumentException.class); } finally { @@ -1840,7 +1834,7 @@ public void doFinally1() { .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -1850,23 +1844,21 @@ public void doFinally2() { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void doFinally3() { - Nono.never() + TestSubscriber ts = Nono.never() .doFinally(this) .test() - .assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - ts.cancel(); - } - }) - .assertEmpty(); + ; + + ts.cancel(); - Assert.assertEquals(1, count); + ts.assertEmpty(); + + assertEquals(1, count); } @Test @@ -1884,7 +1876,7 @@ public void run() throws Exception { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); TestHelper.assertError(errors, 0, IllegalArgumentException.class); } finally { @@ -1892,7 +1884,8 @@ public void run() throws Exception { } } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void repeat() { final int[] counter = { 0 }; @@ -1907,7 +1900,7 @@ public void run() throws Exception { .test() .assertFailure(CancellationException.class); - Assert.assertEquals(6, counter[0]); + assertEquals(6, counter[0]); } @Test @@ -1917,7 +1910,7 @@ public void repeatLimit() { .test() .assertResult(); - Assert.assertEquals(5, count); + assertEquals(5, count); } @Test @@ -1932,7 +1925,7 @@ public boolean getAsBoolean() throws Exception { .test() .assertResult(); - Assert.assertEquals(5, count); + assertEquals(5, count); } @Test @@ -1947,7 +1940,7 @@ public boolean getAsBoolean() throws Exception { .test() .assertFailure(IOException.class); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -1962,7 +1955,7 @@ public boolean getAsBoolean() throws Exception { .test() .assertFailure(IOException.class); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2032,7 +2025,8 @@ public Object apply(Object v) throws Exception { .assertFailure(IOException.class); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void retry() { Nono.fromAction(new Action() { @Override @@ -2046,14 +2040,15 @@ public void run() throws Exception { .assertResult(); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void retryNoError() { Nono.fromAction(this) .retry() .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2082,14 +2077,15 @@ public void run() throws Exception { .assertResult(); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void retryLimitNoError() { Nono.fromAction(this) .retry(5) .test() .assertResult(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2100,7 +2096,8 @@ public void retryPredicateNoError() { .assertResult(); } - @Test(timeout = 5000) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void retryPredicateNoRetry() { ioError .retry(Functions.alwaysFalse()) @@ -2151,12 +2148,13 @@ public boolean test(Throwable e) throws Exception { }) .test() .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { + .assertError(new Predicate() { @Override - public void accept(TestSubscriber ts) throws Exception { - List errors = TestHelper.compositeList(ts.errors().get(0)); + public boolean test(Throwable error) throws Throwable { + List errors = TestHelper.compositeList(error); TestHelper.assertError(errors, 0, IOException.class); TestHelper.assertError(errors, 1, IllegalArgumentException.class); + return true; } }); } @@ -2218,14 +2216,17 @@ public Throwable apply(Throwable v) throws Exception { .assertFailure(IllegalArgumentException.class); } - @Test(expected = NullPointerException.class) + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void subscribeActual() { - new Nono() { - @Override - protected void subscribeActual(Subscriber s) { - throw new NullPointerException(); - } - }.test(); + assertThrows(NullPointerException.class, () -> { + new Nono() { + @Override + protected void subscribeActual(Subscriber s) { + throw new NullPointerException(); + } + }.test(); + }); } @Test @@ -2238,20 +2239,20 @@ protected void subscribeActual(Subscriber s) { } }.test(false); } catch (NullPointerException ex) { - Assert.assertTrue(ex.toString(), ex.getCause() instanceof IllegalArgumentException); + assertTrue(ex.getCause() instanceof IllegalArgumentException, ex.toString()); } } @Test public void subscribeWith() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); - Assert.assertSame(ts, Nono.complete().subscribeWith(ts)); + assertSame(ts, Nono.complete().subscribeWith(ts)); } @Test public void onAssembly() { - Assert.assertNull(Nono.getOnAssemblyHandler()); + assertNull(Nono.getOnAssemblyHandler()); try { Nono.setOnAssemblyHandler(new Function() { @Override @@ -2260,24 +2261,24 @@ public Nono apply(Nono f) throws Exception { return f; } }); - Assert.assertNotNull(Nono.getOnAssemblyHandler()); + assertNotNull(Nono.getOnAssemblyHandler()); Nono.complete().delay(1, TimeUnit.MILLISECONDS); - Assert.assertEquals(2, count); + assertEquals(2, count); } finally { Nono.setOnAssemblyHandler(null); } - Assert.assertNull(Nono.getOnAssemblyHandler()); + assertNull(Nono.getOnAssemblyHandler()); Nono.complete().delay(1, TimeUnit.MILLISECONDS); - Assert.assertEquals(2, count); + assertEquals(2, count); } @Test public void onAssemblyThrows() { - Assert.assertNull(Nono.getOnAssemblyHandler()); + assertNull(Nono.getOnAssemblyHandler()); try { Nono.setOnAssemblyHandler(new Function() { @Override @@ -2285,11 +2286,11 @@ public Nono apply(Nono f) throws Exception { throw new IllegalArgumentException(); } }); - Assert.assertNotNull(Nono.getOnAssemblyHandler()); + assertNotNull(Nono.getOnAssemblyHandler()); try { Nono.complete().delay(1, TimeUnit.MILLISECONDS); - Assert.fail("Should have thrown"); + fail("Should have thrown"); } catch (IllegalArgumentException ex) { // expected } @@ -2297,11 +2298,11 @@ public Nono apply(Nono f) throws Exception { } finally { Nono.setOnAssemblyHandler(null); } - Assert.assertNull(Nono.getOnAssemblyHandler()); + assertNull(Nono.getOnAssemblyHandler()); Nono.complete().delay(1, TimeUnit.MILLISECONDS); - Assert.assertEquals(0, count); + assertEquals(0, count); } @Test @@ -2309,7 +2310,7 @@ public void subscribe1() { Nono.complete() .subscribe(this); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2319,7 +2320,7 @@ public void subscribe1Error() { ioError .subscribe(this); - Assert.assertEquals(0, count); + assertEquals(0, count); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -2332,7 +2333,7 @@ public void subscribe2() { Nono.complete() .subscribe(this, this); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2340,75 +2341,75 @@ public void subscribe2Error() { ioError .subscribe(this, this); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void blockingAwaitScalar() { - Assert.assertNull(Nono.complete().blockingAwait()); + assertNull(Nono.complete().blockingAwait()); } @Test public void blockingAwait() { - Assert.assertNull(Nono.complete().doOnComplete(this).blockingAwait()); + assertNull(Nono.complete().doOnComplete(this).blockingAwait()); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void blockingAwaitErrorScalar() { - Assert.assertNotNull(ioError.blockingAwait()); + assertNotNull(ioError.blockingAwait()); } @Test public void blockingAwaitError() { - Assert.assertNotNull(ioError.doOnError(this).blockingAwait()); + assertNotNull(ioError.doOnError(this).blockingAwait()); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void blockingAwaitDelayed() { - Assert.assertNull(Nono.complete().delay(10, TimeUnit.MILLISECONDS).blockingAwait()); + assertNull(Nono.complete().delay(10, TimeUnit.MILLISECONDS).blockingAwait()); } @Test public void blockingAwaitDelayedError() { - Assert.assertNotNull(ioError.delay(10, TimeUnit.MILLISECONDS).blockingAwait()); + assertNotNull(ioError.delay(10, TimeUnit.MILLISECONDS).blockingAwait()); } @Test public void blockingAwaitScalarWithTimeout() { - Assert.assertNull(Nono.complete().blockingAwait(5, TimeUnit.SECONDS)); + assertNull(Nono.complete().blockingAwait(5, TimeUnit.SECONDS)); } @Test public void blockingAwaitWithTimeoutDoTimeout() { Throwable t = Nono.never().blockingAwait(200, TimeUnit.MILLISECONDS); - Assert.assertTrue(t.toString(), t instanceof TimeoutException); + assertTrue(t instanceof TimeoutException, t.toString()); } @Test public void blockingAwaitErrorScalarWithTimeout() { Throwable t = ioError.blockingAwait(5, TimeUnit.SECONDS); - Assert.assertTrue(t.toString(), t instanceof IOException); + assertTrue(t instanceof IOException, t.toString()); } @Test public void blockingAwaitErrorWithTimeout() { - Assert.assertNotNull(ioError.doOnError(this).blockingAwait(5, TimeUnit.SECONDS)); + assertNotNull(ioError.doOnError(this).blockingAwait(5, TimeUnit.SECONDS)); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test public void blockingAwaitDelayedWithTimeout() { - Assert.assertNull(Nono.complete().delay(10, TimeUnit.MILLISECONDS).blockingAwait(5, TimeUnit.SECONDS)); + assertNull(Nono.complete().delay(10, TimeUnit.MILLISECONDS).blockingAwait(5, TimeUnit.SECONDS)); } @Test public void blockingAwaitDelayedErrorWithTimeout() { - Assert.assertNotNull(ioError.delay(10, TimeUnit.MILLISECONDS).blockingAwait(5, TimeUnit.SECONDS)); + assertNotNull(ioError.delay(10, TimeUnit.MILLISECONDS).blockingAwait(5, TimeUnit.SECONDS)); } @Test @@ -2416,7 +2417,7 @@ public void blockingAwaitInterrupt() { try { Thread.currentThread().interrupt(); Throwable t = Nono.never().blockingAwait(); - Assert.assertTrue(String.valueOf(t), t instanceof InterruptedException); + assertTrue(t instanceof InterruptedException, String.valueOf(t)); } finally { Thread.interrupted(); } @@ -2427,7 +2428,7 @@ public void blockingAwaitInterruptTiemout() { try { Thread.currentThread().interrupt(); Throwable t = Nono.never().blockingAwait(5, TimeUnit.SECONDS); - Assert.assertTrue(String.valueOf(t), t instanceof InterruptedException); + assertTrue(t instanceof InterruptedException, String.valueOf(t)); } finally { Thread.interrupted(); } @@ -2438,7 +2439,7 @@ public void blockingSubscribe1() { Nono.complete() .blockingSubscribe(this); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2448,7 +2449,7 @@ public void blockingSubscribe1Error() { ioError .blockingSubscribe(this); - Assert.assertEquals(0, count); + assertEquals(0, count); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -2461,7 +2462,7 @@ public void blockingSubscribe2() { Nono.complete() .blockingSubscribe(this, this); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2469,7 +2470,7 @@ public void blockingSubscribe2Error() { ioError .blockingSubscribe(this, this); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2518,7 +2519,7 @@ public void hide() { @Override public void onSubscribe(Subscription s) { - Assert.assertFalse(s instanceof QueueSubscription); + assertFalse(s instanceof QueueSubscription); } @Override @@ -2661,7 +2662,7 @@ public void takeUntil6() { public void subscribe() { Nono.fromAction(this).subscribe(); - Assert.assertEquals(1, count); + assertEquals(1, count); } @Test @@ -2791,9 +2792,11 @@ public void toFutureEmpty() throws Exception { assertNull(Nono.complete().toFuture().get()); } - @Test(expected = ExecutionException.class) + @Test public void toFutureError() throws Exception { - Nono.error(new IOException()).toFuture().get(); + assertThrows(ExecutionException.class, () -> { + Nono.error(new IOException()).toFuture().get(); + }); } @Test diff --git a/src/test/java/hu/akarnokd/rxjava2/basetypes/PerhapsTest.java b/src/test/java/hu/akarnokd/rxjava4/basetypes/PerhapsTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/basetypes/PerhapsTest.java rename to src/test/java/hu/akarnokd/rxjava4/basetypes/PerhapsTest.java index c7b40686..b5299ec1 100644 --- a/src/test/java/hu/akarnokd/rxjava2/basetypes/PerhapsTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/basetypes/PerhapsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,27 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class PerhapsTest implements Consumer, Action, LongConsumer, Cancellable { @@ -115,7 +115,7 @@ public Object apply(Integer v) throws Exception { @Test public void fromFuture() { - FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); ft.run(); Perhaps.fromFuture(ft) @@ -125,7 +125,7 @@ public void fromFuture() { @Test public void fromFutureNull() { - FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, null); + FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null); ft.run(); Perhaps.fromFuture(ft) @@ -135,7 +135,7 @@ public void fromFutureNull() { @Test public void fromFutureTimeout() { - FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); Perhaps.fromFuture(ft, 1, TimeUnit.MILLISECONDS) .test() @@ -144,7 +144,7 @@ public void fromFutureTimeout() { @Test public void fromFutureCrash() { - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Integer call() throws Exception { throw new IOException(); @@ -167,9 +167,11 @@ public void toFutureEmpty() throws Exception { assertNull(Perhaps.empty().toFuture().get()); } - @Test(expected = ExecutionException.class) + @Test public void toFutureError() throws Exception { - Perhaps.error(new IOException()).toFuture().get(); + assertThrows(ExecutionException.class, () -> { + Perhaps.error(new IOException()).toFuture().get(); + }); } @Test @@ -270,9 +272,9 @@ public void error() { @Test public void errorSupplier() { - Perhaps.error(new Callable() { + Perhaps.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { return new IOException(); } }) @@ -282,9 +284,9 @@ public Throwable call() throws Exception { @Test public void errorSupplierThrows() { - Perhaps.error(new Callable() { + Perhaps.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { throw new IOException(); } }) @@ -294,9 +296,9 @@ public Throwable call() throws Exception { @Test public void errorSupplierNull() { - Perhaps.error(new Callable() { + Perhaps.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { return null; } }) @@ -344,11 +346,11 @@ public void never() { @Test public void defer() { - Perhaps sp = Perhaps.defer(new Callable>() { + Perhaps sp = Perhaps.defer(new Supplier>() { int i; @Override - public Perhaps call() throws Exception { + public Perhaps get() throws Exception { return Perhaps.just(++i); } }); @@ -360,9 +362,9 @@ public Perhaps call() throws Exception { @Test public void deferThrows() { - Perhaps sp = Perhaps.defer(new Callable>() { + Perhaps sp = Perhaps.defer(new Supplier>() { @Override - public Perhaps call() throws Exception { + public Perhaps get() throws Exception { throw new IOException(); } }); @@ -423,7 +425,6 @@ public void fromSingleBackpressured() { .assertResult(1); } - @SuppressWarnings("unchecked") @Test public void ambIterable1() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -445,7 +446,6 @@ public void ambIterable1() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambIterable2() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -467,7 +467,6 @@ public void ambIterable2() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambIterable1Error() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -489,7 +488,6 @@ public void ambIterable1Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambIterable2Error() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -511,7 +509,6 @@ public void ambIterable2Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray1() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -533,7 +530,6 @@ public void ambArray1() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray2() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -555,7 +551,6 @@ public void ambArray2() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray1Error() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -577,7 +572,6 @@ public void ambArray1Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray2Error() { PerhapsProcessor sp1 = PerhapsProcessor.create(); @@ -599,7 +593,6 @@ public void ambArray2Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void concatIterable() { Perhaps.concat(Arrays.asList(Perhaps.just(1), Perhaps.just(2))) @@ -607,7 +600,6 @@ public void concatIterable() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatIterableError() { Perhaps.concat(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException()))) @@ -615,7 +607,6 @@ public void concatIterableError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatIterableError2() { Perhaps.concat(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2))) @@ -661,7 +652,6 @@ public void concatPublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArray() { Perhaps.concatArray(Perhaps.just(1), Perhaps.just(2)) @@ -669,7 +659,6 @@ public void concatArray() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatArrayError() { Perhaps.concatArray(Perhaps.just(1), Perhaps.error(new IOException())) @@ -677,7 +666,6 @@ public void concatArrayError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArrayError2() { Perhaps.concatArray(Perhaps.error(new IOException()), Perhaps.just(2)) @@ -685,7 +673,6 @@ public void concatArrayError2() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void concatIterableDelayError() { Perhaps.concatDelayError(Arrays.asList(Perhaps.just(1), Perhaps.just(2))) @@ -693,7 +680,6 @@ public void concatIterableDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatIterableDelayErrorError() { Perhaps.concatDelayError(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException()))) @@ -701,7 +687,6 @@ public void concatIterableDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatIterableDelayErrorError2() { Perhaps.concatDelayError(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2))) @@ -747,7 +732,6 @@ public void concatDelayErrorPublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArrayDelayError() { Perhaps.concatArrayDelayError(Perhaps.just(1), Perhaps.just(2)) @@ -755,7 +739,6 @@ public void concatArrayDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatArrayDelayErrorError() { Perhaps.concatArrayDelayError(Perhaps.just(1), Perhaps.error(new IOException())) @@ -763,7 +746,6 @@ public void concatArrayDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArrayDelayErrorError2() { Perhaps.concatArrayDelayError(Perhaps.error(new IOException()), Perhaps.just(2)) @@ -771,7 +753,6 @@ public void concatArrayDelayErrorError2() { .assertFailure(IOException.class, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterable() { Perhaps.merge(Arrays.asList(Perhaps.just(1), Perhaps.just(2))) @@ -779,7 +760,6 @@ public void mergeIterable() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterableError() { Perhaps.merge(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException()))) @@ -787,7 +767,6 @@ public void mergeIterableError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeIterableError2() { Perhaps.merge(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2))) @@ -833,7 +812,6 @@ public void mergePublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArray() { Perhaps.mergeArray(Perhaps.just(1), Perhaps.just(2)) @@ -841,7 +819,6 @@ public void mergeArray() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeArrayError() { Perhaps.mergeArray(Perhaps.just(1), Perhaps.error(new IOException())) @@ -849,7 +826,6 @@ public void mergeArrayError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArrayError2() { Perhaps.mergeArray(Perhaps.error(new IOException()), Perhaps.just(2)) @@ -857,7 +833,6 @@ public void mergeArrayError2() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayError() { Perhaps.mergeDelayError(Arrays.asList(Perhaps.just(1), Perhaps.just(2))) @@ -865,7 +840,6 @@ public void mergeIterableDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayErrorError() { Perhaps.mergeDelayError(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException()))) @@ -873,7 +847,6 @@ public void mergeIterableDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayErrorError2() { Perhaps.mergeDelayError(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2))) @@ -919,7 +892,6 @@ public void mergeDelayErrorPublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayError() { Perhaps.mergeArrayDelayError(Perhaps.just(1), Perhaps.just(2)) @@ -927,7 +899,6 @@ public void mergeArrayDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayErrorError() { Perhaps.mergeArrayDelayError(Perhaps.just(1), Perhaps.error(new IOException())) @@ -935,7 +906,6 @@ public void mergeArrayDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayErrorError2() { Perhaps.mergeArrayDelayError(Perhaps.error(new IOException()), Perhaps.just(2)) @@ -961,7 +931,7 @@ public void timerScheduler() { @Test public void usingEager() { - Perhaps.using(Functions.justCallable(1), + Perhaps.using(Functions.justSupplier(1), Functions.justFunction(Perhaps.just(1)), this) .test() .assertResult(1); @@ -971,7 +941,7 @@ public void usingEager() { @Test public void usingEagerError() { - Perhaps.using(Functions.justCallable(1), + Perhaps.using(Functions.justSupplier(1), Functions.justFunction(Perhaps.error(new IOException())), this) .test() .assertFailure(IOException.class); @@ -981,7 +951,7 @@ public void usingEagerError() { @Test public void usingNonEager() { - Perhaps.using(Functions.justCallable(1), + Perhaps.using(Functions.justSupplier(1), Functions.justFunction(Perhaps.just(1)), this, false) .test() @@ -990,7 +960,6 @@ public void usingNonEager() { assertEquals(1, count); } - @SuppressWarnings("unchecked") @Test public void zip() { Perhaps.zip(Arrays.asList(Perhaps.just(1), Perhaps.just(2)), new Function() { @@ -1003,7 +972,6 @@ public Object apply(Object[] a) throws Exception { .assertResult("12"); } - @SuppressWarnings("unchecked") @Test public void zipError1() { Perhaps.zip(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2)), new Function() { @@ -1016,7 +984,6 @@ public Object apply(Object[] a) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void zipError2() { Perhaps.zip(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException())), new Function() { @@ -1029,7 +996,6 @@ public Object apply(Object[] a) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void zipArray() { Perhaps.zipArray(new Function() { @@ -1042,7 +1008,6 @@ public Object apply(Object[] a) throws Exception { .assertResult("12"); } - @SuppressWarnings("unchecked") @Test public void zipArrayError1() { Perhaps.zipArray(new Function() { @@ -1055,7 +1020,6 @@ public Object apply(Object[] a) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void zipArrayError2() { Perhaps.zipArray(new Function() { @@ -1527,7 +1491,7 @@ public void flatMapSignal() { Perhaps.just(1).flatMap( Functions.justFunction(Perhaps.just(2)), Functions.justFunction(Perhaps.just(3)), - Functions.justCallable(Perhaps.just(4)) + Functions.justSupplier(Perhaps.just(4)) ) .test() .assertResult(2); @@ -1538,7 +1502,7 @@ public void flatMapSignalError() { Perhaps.error(new IOException()).flatMap( Functions.justFunction(Perhaps.just(2)), Functions.justFunction(Perhaps.just(3)), - Functions.justCallable(Perhaps.just(4)) + Functions.justSupplier(Perhaps.just(4)) ) .test() .assertResult(3); @@ -1549,7 +1513,7 @@ public void flatMapSignalError2() { Perhaps.just(1).flatMap( Functions.justFunction(Perhaps.error(new IOException())), Functions.justFunction(Perhaps.just(3)), - Functions.justCallable(Perhaps.just(4)) + Functions.justSupplier(Perhaps.just(4)) ) .test() .assertFailure(IOException.class); @@ -1560,7 +1524,7 @@ public void flatMapSignalError3() { Perhaps.error(new IOException()).flatMap( Functions.justFunction(Perhaps.just(2)), Functions.justFunction(Perhaps.error(new IllegalArgumentException())), - Functions.justCallable(Perhaps.just(4)) + Functions.justSupplier(Perhaps.just(4)) ) .test() .assertFailure(IllegalArgumentException.class); @@ -2049,14 +2013,16 @@ public void to() { .assertResult(1); } - @Test(expected = IllegalArgumentException.class) + @Test public void toThrows() { - Perhaps.just(1) - .to(new Function, Object>() { - @Override - public Object apply(Perhaps sp) throws Exception { - throw new IllegalArgumentException(); - } + assertThrows(IllegalArgumentException.class, () -> { + Perhaps.just(1) + .to(new Function, Object>() { + @Override + public Object apply(Perhaps sp) throws Exception { + throw new IllegalArgumentException(); + } + }); }); } @@ -2116,10 +2082,12 @@ public void repeatTimes() { .assertResult(1, 1, 1, 1, 1); } - @Test(expected = IllegalArgumentException.class) + @Test public void repeatTimesNegative() { - Perhaps.just(1) - .repeat(-5); + assertThrows(IllegalArgumentException.class, () -> { + Perhaps.just(1) + .repeat(-5); + }); } @Test @@ -2197,19 +2165,21 @@ public void retryTimes() { .assertFailure(IOException.class); } - @Test(expected = IllegalArgumentException.class) + @Test public void retryTimesNegative() { - Perhaps.just(1) - .retry(-5); + assertThrows(IllegalArgumentException.class, () -> { + Perhaps.just(1) + .retry(-5); + }); } @Test public void retryInfinite() { final int[] counter = { 0 }; - Perhaps.defer(new Callable>() { + Perhaps.defer(new Supplier>() { @Override - public Perhaps call() throws Exception { + public Perhaps get() throws Exception { if (++counter[0] == 5) { return Perhaps.just(1); } @@ -2225,9 +2195,9 @@ public Perhaps call() throws Exception { public void retryPredicate() { final int[] counter = { 0 }; - Perhaps.defer(new Callable>() { + Perhaps.defer(new Supplier>() { @Override - public Perhaps call() throws Exception { + public Perhaps get() throws Exception { if (++counter[0] == 5) { return Perhaps.error(new IllegalArgumentException()); } @@ -2414,15 +2384,17 @@ public void unsubscribeOnError() { .assertFailure(IOException.class); } - @Test(expected = NullPointerException.class) + @Test public void subscribeActualError() { - new Perhaps() { - @Override - protected void subscribeActual(Subscriber s) { - throw new NullPointerException(); + assertThrows(NullPointerException.class, () -> { + new Perhaps() { + @Override + protected void subscribeActual(Subscriber s) { + throw new NullPointerException(); + } } - } - .subscribe(); + .subscribe(); + }); } @Test @@ -2436,7 +2408,7 @@ protected void subscribeActual(Subscriber s) { } .subscribe(); } catch (NullPointerException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IllegalArgumentException); + assertTrue(ex.getCause() instanceof IllegalArgumentException, ex.toString()); } } @@ -2607,7 +2579,6 @@ public void mergeMaxConcurrent() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterableMaxConcurrent() { Perhaps.merge(Arrays.asList(Perhaps.just(1), Perhaps.just(2)), 1) @@ -2615,7 +2586,6 @@ public void mergeIterableMaxConcurrent() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeArrayMaxConcurrent() { Perhaps.mergeArray(1, Perhaps.just(1), Perhaps.just(2)) @@ -2623,7 +2593,6 @@ public void mergeArrayMaxConcurrent() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayErrorMaxConcurrent() { Perhaps.mergeArrayDelayError(1, Perhaps.just(1), Perhaps.just(2)) @@ -2631,7 +2600,6 @@ public void mergeArrayDelayErrorMaxConcurrent() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayErrorMaxConcurrent() { Perhaps.mergeDelayError(Arrays.asList(Perhaps.just(1), Perhaps.just(2)), 1) diff --git a/src/test/java/hu/akarnokd/rxjava2/basetypes/SoloTest.java b/src/test/java/hu/akarnokd/rxjava4/basetypes/SoloTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/basetypes/SoloTest.java rename to src/test/java/hu/akarnokd/rxjava4/basetypes/SoloTest.java index 97af2937..af180ce9 100644 --- a/src/test/java/hu/akarnokd/rxjava2/basetypes/SoloTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/basetypes/SoloTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,27 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.basetypes; +package hu.akarnokd.rxjava4.basetypes; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class SoloTest implements Consumer, Action, LongConsumer, Cancellable { @@ -211,9 +211,9 @@ public void error() { @Test public void errorSupplier() { - Solo.error(new Callable() { + Solo.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { return new IOException(); } }) @@ -223,9 +223,9 @@ public Throwable call() throws Exception { @Test public void errorSupplierThrows() { - Solo.error(new Callable() { + Solo.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { throw new IOException(); } }) @@ -235,9 +235,9 @@ public Throwable call() throws Exception { @Test public void errorSupplierNull() { - Solo.error(new Callable() { + Solo.error(new Supplier() { @Override - public Throwable call() throws Exception { + public Throwable get() throws Exception { return null; } }) @@ -285,11 +285,11 @@ public void never() { @Test public void defer() { - Solo sp = Solo.defer(new Callable>() { + Solo sp = Solo.defer(new Supplier>() { int i; @Override - public Solo call() throws Exception { + public Solo get() throws Exception { return Solo.just(++i); } }); @@ -301,9 +301,9 @@ public Solo call() throws Exception { @Test public void deferThrows() { - Solo sp = Solo.defer(new Callable>() { + Solo sp = Solo.defer(new Supplier>() { @Override - public Solo call() throws Exception { + public Solo get() throws Exception { throw new IOException(); } }); @@ -364,7 +364,6 @@ public void fromSingleBackpressured() { .assertResult(1); } - @SuppressWarnings("unchecked") @Test public void ambIterable1() { SoloProcessor sp1 = SoloProcessor.create(); @@ -386,7 +385,6 @@ public void ambIterable1() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambIterable2() { SoloProcessor sp1 = SoloProcessor.create(); @@ -408,7 +406,6 @@ public void ambIterable2() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambIterable1Error() { SoloProcessor sp1 = SoloProcessor.create(); @@ -430,7 +427,6 @@ public void ambIterable1Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambIterable2Error() { SoloProcessor sp1 = SoloProcessor.create(); @@ -452,7 +448,6 @@ public void ambIterable2Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray1() { SoloProcessor sp1 = SoloProcessor.create(); @@ -474,7 +469,6 @@ public void ambArray1() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray2() { SoloProcessor sp1 = SoloProcessor.create(); @@ -496,7 +490,6 @@ public void ambArray2() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray1Error() { SoloProcessor sp1 = SoloProcessor.create(); @@ -518,7 +511,6 @@ public void ambArray1Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void ambArray2Error() { SoloProcessor sp1 = SoloProcessor.create(); @@ -540,7 +532,6 @@ public void ambArray2Error() { assertFalse(sp2.hasSubscribers()); } - @SuppressWarnings("unchecked") @Test public void concatIterable() { Solo.concat(Arrays.asList(Solo.just(1), Solo.just(2))) @@ -548,7 +539,6 @@ public void concatIterable() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatIterableError() { Solo.concat(Arrays.asList(Solo.just(1), Solo.error(new IOException()))) @@ -556,7 +546,6 @@ public void concatIterableError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatIterableError2() { Solo.concat(Arrays.asList(Solo.error(new IOException()), Solo.just(2))) @@ -602,7 +591,6 @@ public void concatPublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArray() { Solo.concatArray(Solo.just(1), Solo.just(2)) @@ -610,7 +598,6 @@ public void concatArray() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatArrayError() { Solo.concatArray(Solo.just(1), Solo.error(new IOException())) @@ -618,7 +605,6 @@ public void concatArrayError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArrayError2() { Solo.concatArray(Solo.error(new IOException()), Solo.just(2)) @@ -626,7 +612,6 @@ public void concatArrayError2() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void concatIterableDelayError() { Solo.concatDelayError(Arrays.asList(Solo.just(1), Solo.just(2))) @@ -634,7 +619,6 @@ public void concatIterableDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatIterableDelayErrorError() { Solo.concatDelayError(Arrays.asList(Solo.just(1), Solo.error(new IOException()))) @@ -642,7 +626,6 @@ public void concatIterableDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatIterableDelayErrorError2() { Solo.concatDelayError(Arrays.asList(Solo.error(new IOException()), Solo.just(2))) @@ -688,7 +671,6 @@ public void concatDelayErrorPublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArrayDelayError() { Solo.concatArrayDelayError(Solo.just(1), Solo.just(2)) @@ -696,7 +678,6 @@ public void concatArrayDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void concatArrayDelayErrorError() { Solo.concatArrayDelayError(Solo.just(1), Solo.error(new IOException())) @@ -704,7 +685,6 @@ public void concatArrayDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void concatArrayDelayErrorError2() { Solo.concatArrayDelayError(Solo.error(new IOException()), Solo.just(2)) @@ -712,7 +692,6 @@ public void concatArrayDelayErrorError2() { .assertFailure(IOException.class, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterable() { Solo.merge(Arrays.asList(Solo.just(1), Solo.just(2))) @@ -720,7 +699,6 @@ public void mergeIterable() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterableError() { Solo.merge(Arrays.asList(Solo.just(1), Solo.error(new IOException()))) @@ -728,7 +706,6 @@ public void mergeIterableError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeIterableError2() { Solo.merge(Arrays.asList(Solo.error(new IOException()), Solo.just(2))) @@ -774,7 +751,6 @@ public void mergePublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArray() { Solo.mergeArray(Solo.just(1), Solo.just(2)) @@ -782,7 +758,6 @@ public void mergeArray() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeArrayError() { Solo.mergeArray(Solo.just(1), Solo.error(new IOException())) @@ -790,7 +765,6 @@ public void mergeArrayError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArrayError2() { Solo.mergeArray(Solo.error(new IOException()), Solo.just(2)) @@ -798,7 +772,6 @@ public void mergeArrayError2() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayError() { Solo.mergeDelayError(Arrays.asList(Solo.just(1), Solo.just(2))) @@ -806,7 +779,6 @@ public void mergeIterableDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayErrorError() { Solo.mergeDelayError(Arrays.asList(Solo.just(1), Solo.error(new IOException()))) @@ -814,7 +786,6 @@ public void mergeIterableDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeIterableDelayErrorError2() { Solo.mergeDelayError(Arrays.asList(Solo.error(new IOException()), Solo.just(2))) @@ -860,7 +831,6 @@ public void mergeDelayErrorPublisherError3() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayError() { Solo.mergeArrayDelayError(Solo.just(1), Solo.just(2)) @@ -868,7 +838,6 @@ public void mergeArrayDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayErrorError() { Solo.mergeArrayDelayError(Solo.just(1), Solo.error(new IOException())) @@ -876,7 +845,6 @@ public void mergeArrayDelayErrorError() { .assertFailure(IOException.class, 1); } - @SuppressWarnings("unchecked") @Test public void mergeArrayDelayErrorError2() { Solo.mergeArrayDelayError(Solo.error(new IOException()), Solo.just(2)) @@ -902,7 +870,7 @@ public void timerScheduler() { @Test public void usingEager() { - Solo.using(Functions.justCallable(1), + Solo.using(Functions.justSupplier(1), Functions.justFunction(Solo.just(1)), this) .test() .assertResult(1); @@ -912,7 +880,7 @@ public void usingEager() { @Test public void usingEagerError() { - Solo.using(Functions.justCallable(1), + Solo.using(Functions.justSupplier(1), Functions.justFunction(Solo.error(new IOException())), this) .test() .assertFailure(IOException.class); @@ -922,7 +890,7 @@ public void usingEagerError() { @Test public void usingNonEager() { - Solo.using(Functions.justCallable(1), + Solo.using(Functions.justSupplier(1), Functions.justFunction(Solo.just(1)), this, false) .test() @@ -931,7 +899,6 @@ public void usingNonEager() { assertEquals(1, count); } - @SuppressWarnings("unchecked") @Test public void zip() { Solo.zip(Arrays.asList(Solo.just(1), Solo.just(2)), new Function() { @@ -944,7 +911,6 @@ public Object apply(Object[] a) throws Exception { .assertResult("12"); } - @SuppressWarnings("unchecked") @Test public void zipError1() { Solo.zip(Arrays.asList(Solo.error(new IOException()), Solo.just(2)), new Function() { @@ -957,7 +923,6 @@ public Object apply(Object[] a) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void zipError2() { Solo.zip(Arrays.asList(Solo.just(1), Solo.error(new IOException())), new Function() { @@ -970,7 +935,6 @@ public Object apply(Object[] a) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void zipArray() { Solo.zipArray(new Function() { @@ -983,7 +947,6 @@ public Object apply(Object[] a) throws Exception { .assertResult("12"); } - @SuppressWarnings("unchecked") @Test public void zipArrayError1() { Solo.zipArray(new Function() { @@ -996,7 +959,6 @@ public Object apply(Object[] a) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void zipArrayError2() { Solo.zipArray(new Function() { @@ -1977,14 +1939,16 @@ public void to() { .assertResult(1); } - @Test(expected = IllegalArgumentException.class) + @Test public void toThrows() { - Solo.just(1) - .to(new Function, Object>() { - @Override - public Object apply(Solo sp) throws Exception { - throw new IllegalArgumentException(); - } + assertThrows(IllegalArgumentException.class, () -> { + Solo.just(1) + .to(new Function, Object>() { + @Override + public Object apply(Solo sp) throws Exception { + throw new IllegalArgumentException(); + } + }); }); } @@ -2044,10 +2008,12 @@ public void repeatTimes() { .assertResult(1, 1, 1, 1, 1); } - @Test(expected = IllegalArgumentException.class) + @Test public void repeatTimesNegative() { - Solo.just(1) - .repeat(-5); + assertThrows(IllegalArgumentException.class, () -> { + Solo.just(1) + .repeat(-5); + }); } @Test @@ -2125,19 +2091,21 @@ public void retryTimes() { .assertFailure(IOException.class); } - @Test(expected = IllegalArgumentException.class) + @Test public void retryTimesNegative() { - Solo.just(1) - .retry(-5); + assertThrows(IllegalArgumentException.class, () -> { + Solo.just(1) + .retry(-5); + }); } @Test public void retryInfinite() { final int[] counter = { 0 }; - Solo.defer(new Callable>() { + Solo.defer(new Supplier>() { @Override - public Solo call() throws Exception { + public Solo get() throws Exception { if (++counter[0] == 5) { return Solo.just(1); } @@ -2153,9 +2121,9 @@ public Solo call() throws Exception { public void retryPredicate() { final int[] counter = { 0 }; - Solo.defer(new Callable>() { + Solo.defer(new Supplier>() { @Override - public Solo call() throws Exception { + public Solo get() throws Exception { if (++counter[0] == 5) { return Solo.error(new IllegalArgumentException()); } @@ -2342,15 +2310,17 @@ public void unsubscribeOnError() { .assertFailure(IOException.class); } - @Test(expected = NullPointerException.class) + @Test public void subscribeActualError() { - new Solo() { - @Override - protected void subscribeActual(Subscriber s) { - throw new NullPointerException(); + assertThrows(NullPointerException.class, () -> { + new Solo() { + @Override + protected void subscribeActual(Subscriber s) { + throw new NullPointerException(); + } } - } - .subscribe(); + .subscribe(); + }); } @Test @@ -2364,7 +2334,7 @@ protected void subscribeActual(Subscriber s) { } .subscribe(); } catch (NullPointerException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof IllegalArgumentException); + assertTrue(ex.getCause() instanceof IllegalArgumentException, ex.toString()); } } @@ -2479,7 +2449,7 @@ public void blockingSubscribeThreeArgError() { @Test public void fromFuture() { - FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); ft.run(); Solo.fromFuture(ft) @@ -2489,7 +2459,7 @@ public void fromFuture() { @Test public void fromFutureNull() { - FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, null); + FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null); ft.run(); Solo.fromFuture(ft) @@ -2499,7 +2469,7 @@ public void fromFutureNull() { @Test public void fromFutureTimeout() { - FutureTask ft = new FutureTask(Functions.EMPTY_RUNNABLE, 1); + FutureTask ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 1); Solo.fromFuture(ft, 1, TimeUnit.MILLISECONDS) .test() @@ -2508,7 +2478,7 @@ public void fromFutureTimeout() { @Test public void fromFutureCrash() { - FutureTask ft = new FutureTask(new Callable() { + FutureTask ft = new FutureTask<>(new Callable() { @Override public Integer call() throws Exception { throw new IOException(); @@ -2526,9 +2496,11 @@ public void toFuture() throws Exception { assertEquals(1, Solo.just(1).toFuture().get().intValue()); } - @Test(expected = ExecutionException.class) + @Test public void toFutureError() throws Exception { - Solo.error(new IOException()).toFuture().get(); + assertThrows(ExecutionException.class, () -> { + Solo.error(new IOException()).toFuture().get(); + }); } @Test diff --git a/src/test/java/hu/akarnokd/rxjava2/consumers/CompletableConsumersTest.java b/src/test/java/hu/akarnokd/rxjava4/consumers/CompletableConsumersTest.java similarity index 78% rename from src/test/java/hu/akarnokd/rxjava2/consumers/CompletableConsumersTest.java rename to src/test/java/hu/akarnokd/rxjava4/consumers/CompletableConsumersTest.java index 4a44d493..f56212e1 100644 --- a/src/test/java/hu/akarnokd/rxjava2/consumers/CompletableConsumersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/consumers/CompletableConsumersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.CompletableSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.CompletableSubject; public class CompletableConsumersTest implements Consumer, Action { @@ -38,7 +38,7 @@ public class CompletableConsumersTest implements Consumer, Action { final CompletableSubject processor = CompletableSubject.create(); - final List events = new ArrayList(); + final List events = new ArrayList<>(); @Override public void run() throws Exception { @@ -62,7 +62,7 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onComplete(); @@ -77,15 +77,15 @@ public void onErrorError() { Disposable d = CompletableConsumers.subscribeAutoDispose(processor, composite, this, this); - assertTrue(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertTrue(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onError(new IOException()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -97,7 +97,7 @@ public void onCompleteNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onComplete(); @@ -114,11 +114,11 @@ public void onCompleteError() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onError(new IOException()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -130,7 +130,7 @@ public void onCompleteDispose() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); assertFalse(d.isDisposed()); @@ -157,7 +157,7 @@ public void accept(Throwable t) throws Exception { processor.onError(new IllegalArgumentException()); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, CompositeException.class); List inners = TestHelper.compositeList(errors.get(0)); @@ -181,7 +181,7 @@ public void run() throws Exception { processor.onComplete(); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -198,10 +198,10 @@ public void badSource() { @Override protected void subscribeActual( CompletableObserver observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); observer.onError(new IOException()); } diff --git a/src/test/java/hu/akarnokd/rxjava2/consumers/FlowableConsumersTest.java b/src/test/java/hu/akarnokd/rxjava4/consumers/FlowableConsumersTest.java similarity index 80% rename from src/test/java/hu/akarnokd/rxjava2/consumers/FlowableConsumersTest.java rename to src/test/java/hu/akarnokd/rxjava4/consumers/FlowableConsumersTest.java index c0f9731f..8d0cc5d1 100644 --- a/src/test/java/hu/akarnokd/rxjava2/consumers/FlowableConsumersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/consumers/FlowableConsumersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; +import java.util.concurrent.Flow.Subscriber; -import org.junit.Test; -import org.reactivestreams.Subscriber; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; public class FlowableConsumersTest implements Consumer, Action { @@ -40,7 +40,7 @@ public class FlowableConsumersTest implements Consumer, Action { final PublishProcessor processor = PublishProcessor.create(); - final List events = new ArrayList(); + final List events = new ArrayList<>(); @Override public void run() throws Exception { @@ -62,11 +62,11 @@ public void onNextNormal() { Disposable d = FlowableConsumers.subscribeAutoDispose(processor, composite, this); - assertFalse(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertFalse(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -88,7 +88,7 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -108,11 +108,11 @@ public void onErrorError() { Disposable d = FlowableConsumers.subscribeAutoDispose(processor, composite, this, this); - assertTrue(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertTrue(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -122,8 +122,8 @@ public void onErrorError() { processor.onError(new IOException()); - assertEquals(events.toString(), 1, events.get(0)); - assertTrue(events.toString(), events.get(1) instanceof IOException); + assertEquals(1, events.get(0), events.toString()); + assertTrue(events.get(1) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -135,7 +135,7 @@ public void onCompleteNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -157,7 +157,7 @@ public void onCompleteError() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -167,8 +167,8 @@ public void onCompleteError() { processor.onError(new IOException()); - assertEquals(events.toString(), 1, events.get(0)); - assertTrue(events.toString(), events.get(1) instanceof IOException); + assertEquals(1, events.get(0), events.toString()); + assertTrue(events.get(1) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -180,7 +180,7 @@ public void onCompleteDispose() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); assertFalse(d.isDisposed()); @@ -207,9 +207,9 @@ public void accept(Object t) throws Exception { processor.onNext(1); - assertTrue(errors.toString(), errors.isEmpty()); + assertTrue(errors.isEmpty(), errors.toString()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); } finally { RxJavaPlugins.reset(); } @@ -228,7 +228,7 @@ public void accept(Throwable t) throws Exception { processor.onError(new IllegalArgumentException()); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, CompositeException.class); List inners = TestHelper.compositeList(errors.get(0)); @@ -252,7 +252,7 @@ public void accept(Object t) throws Exception { processor.onNext(1); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); assertTrue(errors.get(0).getCause() instanceof IOException); diff --git a/src/test/java/hu/akarnokd/rxjava2/consumers/MaybeConsumersTest.java b/src/test/java/hu/akarnokd/rxjava4/consumers/MaybeConsumersTest.java similarity index 78% rename from src/test/java/hu/akarnokd/rxjava2/consumers/MaybeConsumersTest.java rename to src/test/java/hu/akarnokd/rxjava4/consumers/MaybeConsumersTest.java index 703e52e6..eee491b1 100644 --- a/src/test/java/hu/akarnokd/rxjava2/consumers/MaybeConsumersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/consumers/MaybeConsumersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.MaybeSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.MaybeSubject; public class MaybeConsumersTest implements Consumer, Action { @@ -38,7 +38,7 @@ public class MaybeConsumersTest implements Consumer, Action { final MaybeSubject processor = MaybeSubject.create(); - final List events = new ArrayList(); + final List events = new ArrayList<>(); @Override public void run() throws Exception { @@ -60,11 +60,11 @@ public void onSuccessNormal() { Disposable d = MaybeConsumers.subscribeAutoDispose(processor, composite, this); - assertFalse(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertFalse(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onSuccess(1); @@ -81,7 +81,7 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onSuccess(1); @@ -96,15 +96,15 @@ public void onErrorError() { Disposable d = MaybeConsumers.subscribeAutoDispose(processor, composite, this, this); - assertTrue(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertTrue(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onError(new IOException()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -116,7 +116,7 @@ public void onCompleteNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onComplete(); @@ -133,11 +133,11 @@ public void onCompleteError() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onError(new IOException()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -149,7 +149,7 @@ public void onCompleteDispose() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); assertFalse(d.isDisposed()); @@ -176,7 +176,7 @@ public void accept(Object t) throws Exception { processor.onSuccess(1); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -197,7 +197,7 @@ public void accept(Throwable t) throws Exception { processor.onError(new IllegalArgumentException()); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, CompositeException.class); List inners = TestHelper.compositeList(errors.get(0)); @@ -221,7 +221,7 @@ public void run() throws Exception { processor.onComplete(); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -238,10 +238,10 @@ public void badSource() { @Override protected void subscribeActual( MaybeObserver observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onSuccess(2); observer.onComplete(); observer.onError(new IOException()); diff --git a/src/test/java/hu/akarnokd/rxjava2/consumers/ObservableConsumersTest.java b/src/test/java/hu/akarnokd/rxjava4/consumers/ObservableConsumersTest.java similarity index 79% rename from src/test/java/hu/akarnokd/rxjava2/consumers/ObservableConsumersTest.java rename to src/test/java/hu/akarnokd/rxjava4/consumers/ObservableConsumersTest.java index b2560e2f..08149587 100644 --- a/src/test/java/hu/akarnokd/rxjava2/consumers/ObservableConsumersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/consumers/ObservableConsumersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.PublishSubject; public class ObservableConsumersTest implements Consumer, Action { @@ -39,7 +39,7 @@ public class ObservableConsumersTest implements Consumer, Action { final PublishSubject processor = PublishSubject.create(); - final List events = new ArrayList(); + final List events = new ArrayList<>(); @Override public void run() throws Exception { @@ -61,11 +61,11 @@ public void onNextNormal() { Disposable d = ObservableConsumers.subscribeAutoDispose(processor, composite, this); - assertFalse(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertFalse(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -87,7 +87,7 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -107,11 +107,11 @@ public void onErrorError() { Disposable d = ObservableConsumers.subscribeAutoDispose(processor, composite, this, this); - assertTrue(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertTrue(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -121,8 +121,8 @@ public void onErrorError() { processor.onError(new IOException()); - assertEquals(events.toString(), 1, events.get(0)); - assertTrue(events.toString(), events.get(1) instanceof IOException); + assertEquals(1, events.get(0), events.toString()); + assertTrue(events.get(1) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -134,7 +134,7 @@ public void onCompleteNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -156,7 +156,7 @@ public void onCompleteError() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onNext(1); @@ -166,8 +166,8 @@ public void onCompleteError() { processor.onError(new IOException()); - assertEquals(events.toString(), 1, events.get(0)); - assertTrue(events.toString(), events.get(1) instanceof IOException); + assertEquals(1, events.get(0), events.toString()); + assertTrue(events.get(1) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -179,7 +179,7 @@ public void onCompleteDispose() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); assertFalse(d.isDisposed()); @@ -206,9 +206,9 @@ public void accept(Object t) throws Exception { processor.onNext(1); - assertTrue(errors.toString(), errors.isEmpty()); + assertTrue(errors.isEmpty(), errors.toString()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); } finally { RxJavaPlugins.reset(); } @@ -227,7 +227,7 @@ public void accept(Throwable t) throws Exception { processor.onError(new IllegalArgumentException()); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, CompositeException.class); List inners = TestHelper.compositeList(errors.get(0)); @@ -251,7 +251,7 @@ public void accept(Object t) throws Exception { processor.onNext(1); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); assertTrue(errors.get(0).getCause() instanceof IOException); @@ -291,11 +291,11 @@ public void badSource() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(1); observer.onComplete(); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(2); observer.onComplete(); observer.onError(new IOException()); diff --git a/src/test/java/hu/akarnokd/rxjava2/consumers/SingleConsumersTest.java b/src/test/java/hu/akarnokd/rxjava4/consumers/SingleConsumersTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/consumers/SingleConsumersTest.java rename to src/test/java/hu/akarnokd/rxjava4/consumers/SingleConsumersTest.java index b2eb479d..95dacf11 100644 --- a/src/test/java/hu/akarnokd/rxjava2/consumers/SingleConsumersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/consumers/SingleConsumersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.consumers; +package hu.akarnokd.rxjava4.consumers; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.observers.LambdaConsumerIntrospection; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.SingleSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.*; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.observers.LambdaConsumerIntrospection; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.SingleSubject; public class SingleConsumersTest implements Consumer { @@ -38,7 +38,7 @@ public class SingleConsumersTest implements Consumer { final SingleSubject processor = SingleSubject.create(); - final List events = new ArrayList(); + final List events = new ArrayList<>(); @Override public void accept(Object t) throws Exception { @@ -55,11 +55,11 @@ public void onSuccessNormal() { Disposable d = SingleConsumers.subscribeAutoDispose(processor, composite, this); - assertFalse(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertFalse(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onSuccess(1); @@ -76,7 +76,7 @@ public void onErrorNormal() { assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onSuccess(1); @@ -91,15 +91,15 @@ public void onErrorError() { Disposable d = SingleConsumers.subscribeAutoDispose(processor, composite, this, this); - assertTrue(d.getClass().toString(), ((LambdaConsumerIntrospection)d).hasCustomOnError()); + assertTrue(((LambdaConsumerIntrospection)d).hasCustomOnError(), d.getClass().toString()); assertTrue(composite.size() > 0); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); processor.onError(new IOException()); - assertTrue(events.toString(), events.get(0) instanceof IOException); + assertTrue(events.get(0) instanceof IOException, events.toString()); assertEquals(0, composite.size()); } @@ -117,7 +117,7 @@ public void accept(Object t) throws Exception { processor.onSuccess(1); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { @@ -138,7 +138,7 @@ public void accept(Throwable t) throws Exception { processor.onError(new IllegalArgumentException()); - assertTrue(events.toString(), events.isEmpty()); + assertTrue(events.isEmpty(), events.toString()); TestHelper.assertError(errors, 0, CompositeException.class); List inners = TestHelper.compositeList(errors.get(0)); @@ -158,10 +158,10 @@ public void badSource() { @Override protected void subscribeActual( SingleObserver observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onSuccess(1); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onSuccess(2); observer.onError(new IOException()); } diff --git a/src/test/java/hu/akarnokd/rxjava2/debug/RxJava2AssemblyTrackingTest.java b/src/test/java/hu/akarnokd/rxjava4/debug/RxJava3AssemblyTrackingTest.java similarity index 88% rename from src/test/java/hu/akarnokd/rxjava2/debug/RxJava2AssemblyTrackingTest.java rename to src/test/java/hu/akarnokd/rxjava4/debug/RxJava3AssemblyTrackingTest.java index 3334d06f..15a73356 100644 --- a/src/test/java/hu/akarnokd/rxjava2/debug/RxJava2AssemblyTrackingTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/debug/RxJava3AssemblyTrackingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,28 +14,28 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug; +package hu.akarnokd.rxjava4.debug; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.concurrent.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Action; -import io.reactivex.observers.TestObserver; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Action; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.parallel.ParallelFlowable; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.subjects.PublishSubject; +import io.reactivex.rxjava4.subscribers.TestSubscriber; /** * Named as such to avoid being filtered out in stacktraces of this test. */ -public class RxJava2AssemblyTrackingTest { +public class RxJava3AssemblyTrackingTest { // @Test public void printFilter() { @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception { public void run() { System.err.println(new RxJavaAssemblyException().stacktrace()); } - }).blockingGet(); + }).blockingAwait(); ExecutorService exec = Executors.newSingleThreadExecutor(); @@ -97,7 +97,7 @@ public void flowable() { String st = RxJavaAssemblyException.find(ts.errors().get(0)).stacktrace(); - assertTrue(st, st.contains("RxJava2AssemblyTrackingTest.createFlowable")); + assertTrue(st.contains("RxJava3AssemblyTrackingTest.createFlowable"), st); } finally { RxJavaAssemblyTracking.disable(); @@ -122,7 +122,7 @@ public void observable() { String st = RxJavaAssemblyException.find(to.errors().get(0)).stacktrace(); - assertTrue(st, st.contains("RxJava2AssemblyTrackingTest.createObservable")); + assertTrue(st.contains("RxJava3AssemblyTrackingTest.createObservable"), st); } finally { RxJavaAssemblyTracking.disable(); @@ -147,7 +147,7 @@ public void single() { String st = RxJavaAssemblyException.find(to.errors().get(0)).stacktrace(); - assertTrue(st, st.contains("RxJava2AssemblyTrackingTest.createSingle")); + assertTrue(st.contains("RxJava3AssemblyTrackingTest.createSingle"), st); } finally { RxJavaAssemblyTracking.disable(); @@ -172,7 +172,7 @@ public void maybe() { String st = RxJavaAssemblyException.find(to.errors().get(0)).stacktrace(); - assertTrue(st, st.contains("RxJava2AssemblyTrackingTest.createMaybe")); + assertTrue(st.contains("RxJava3AssemblyTrackingTest.createMaybe"), st); } finally { RxJavaAssemblyTracking.disable(); @@ -197,7 +197,7 @@ public void completable() { String st = RxJavaAssemblyException.find(to.errors().get(0)).stacktrace(); - assertTrue(st, st.contains("RxJava2AssemblyTrackingTest.createCompletable")); + assertTrue(st.contains("RxJava3AssemblyTrackingTest.createCompletable"), st); } finally { RxJavaAssemblyTracking.disable(); @@ -222,7 +222,7 @@ public void parallelFlowable() { String st = RxJavaAssemblyException.find(ts.errors().get(0)).stacktrace(); - assertTrue(st, st.contains("RxJava2AssemblyTrackingTest.createParallelFlowable")); + assertTrue(st.contains("RxJava3AssemblyTrackingTest.createParallelFlowable"), st); } finally { RxJavaAssemblyTracking.disable(); diff --git a/src/test/java/hu/akarnokd/rxjava2/debug/multihook/OnScheduleMultiHandlerManagerTest.java b/src/test/java/hu/akarnokd/rxjava4/debug/multihook/OnScheduleMultiHandlerManagerTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/debug/multihook/OnScheduleMultiHandlerManagerTest.java rename to src/test/java/hu/akarnokd/rxjava4/debug/multihook/OnScheduleMultiHandlerManagerTest.java index cc5af99e..00b141c7 100644 --- a/src/test/java/hu/akarnokd/rxjava2/debug/multihook/OnScheduleMultiHandlerManagerTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/debug/multihook/OnScheduleMultiHandlerManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.multihook; +package hu.akarnokd.rxjava4.debug.multihook; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.lang.Thread.UncaughtExceptionHandler; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; public class OnScheduleMultiHandlerManagerTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/debug/validator/RxJavaProtocolValidatorTest.java b/src/test/java/hu/akarnokd/rxjava4/debug/validator/RxJavaProtocolValidatorTest.java similarity index 80% rename from src/test/java/hu/akarnokd/rxjava2/debug/validator/RxJavaProtocolValidatorTest.java rename to src/test/java/hu/akarnokd/rxjava4/debug/validator/RxJavaProtocolValidatorTest.java index dfd9c92a..df7d53de 100644 --- a/src/test/java/hu/akarnokd/rxjava2/debug/validator/RxJavaProtocolValidatorTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/debug/validator/RxJavaProtocolValidatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,27 +14,27 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.debug.validator; +package hu.akarnokd.rxjava4.debug.validator; + +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; - -import org.junit.*; -import org.reactivestreams.Subscriber; - -import hu.akarnokd.rxjava2.debug.*; -import hu.akarnokd.rxjava2.functions.PlainConsumer; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.*; -import io.reactivex.flowables.ConnectableFlowable; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.observables.ConnectableObservable; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.*; -import io.reactivex.subscribers.TestSubscriber; +import java.util.concurrent.Flow.Subscriber; + +import org.junit.jupiter.api.*; + +import hu.akarnokd.rxjava4.debug.*; +import hu.akarnokd.rxjava4.functions.PlainConsumer; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.parallel.ParallelFlowable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class RxJavaProtocolValidatorTest implements PlainConsumer { @@ -45,12 +45,12 @@ public void utilityClass() { List errors; - @Before + @BeforeEach public void before() { errors = TestHelper.trackPluginErrors(); } - @After + @AfterEach public void after() { RxJavaPlugins.setErrorHandler(null); } @@ -70,14 +70,14 @@ protected void subscribeActual(CompletableObserver observer) { observer.onError(null); observer.onError(new IOException()); observer.onSubscribe(null); - observer.onSubscribe(Disposables.empty()); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); } }; RxJavaProtocolValidator.enable(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Completable.complete().test().assertResult(); @@ -88,13 +88,13 @@ protected void subscribeActual(CompletableObserver observer) { c.test(); - Assert.assertEquals(9, errors.size()); + assertEquals(9, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnSubscribeParameterException.class); TestHelper.assertError(errors, 7, MultipleOnSubscribeCallsException.class); @@ -116,18 +116,18 @@ protected void subscribeActual(MaybeObserver observer) { observer.onSuccess(null); observer.onSuccess(1); observer.onSubscribe(null); - observer.onSubscribe(Disposables.empty()); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); observer.onSuccess(2); } }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Maybe.just(1).test().assertResult(1); @@ -139,13 +139,13 @@ protected void subscribeActual(MaybeObserver observer) { c.test(); - Assert.assertEquals(15, errors.size()); + assertEquals(15, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnSuccessParameterException.class); TestHelper.assertError(errors, 7, OnSubscribeNotCalledException.class); @@ -173,17 +173,17 @@ protected void subscribeActual(SingleObserver observer) { observer.onSuccess(null); observer.onSuccess(1); observer.onSubscribe(null); - observer.onSubscribe(Disposables.empty()); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); + observer.onSubscribe(Disposable.empty()); observer.onSuccess(2); } }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Single.just(1).test().assertResult(1); @@ -194,12 +194,12 @@ protected void subscribeActual(SingleObserver observer) { c.test(); - Assert.assertEquals(12, errors.size()); + assertEquals(12, errors.size()); TestHelper.assertError(errors, 0, NullOnErrorParameterException.class); TestHelper.assertError(errors, 1, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); - Assert.assertTrue("" + errors.get(3).getCause(), errors.get(3).getCause() instanceof IOException); + assertTrue(errors.get(3).getCause() instanceof IOException, "" + errors.get(3).getCause()); TestHelper.assertError(errors, 4, NullOnSuccessParameterException.class); TestHelper.assertError(errors, 5, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 6, OnSuccessAfterTerminationException.class); @@ -226,18 +226,18 @@ protected void subscribeActual(Observer observer) { observer.onNext(null); observer.onNext(1); observer.onSubscribe(null); - observer.onSubscribe(Disposables.empty()); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); observer.onNext(2); } }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Observable.just(1).test().assertResult(1); @@ -249,13 +249,13 @@ protected void subscribeActual(Observer observer) { o.test(); - Assert.assertEquals(15, errors.size()); + assertEquals(15, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnNextParameterException.class); TestHelper.assertError(errors, 7, OnSubscribeNotCalledException.class); @@ -292,10 +292,10 @@ protected void subscribeActual(Subscriber s) { }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Flowable.just(1).test().assertResult(1); @@ -306,13 +306,13 @@ protected void subscribeActual(Subscriber s) { c.test(0); - Assert.assertEquals(15, errors.size()); + assertEquals(15, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnNextParameterException.class); TestHelper.assertError(errors, 7, OnSubscribeNotCalledException.class); @@ -350,13 +350,17 @@ protected void subscribeActual(Subscriber s) { @Override public void connect(Consumer connection) { } + + @Override + public void reset() { + } }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Flowable.just(1).publish().autoConnect().test().assertResult(1); @@ -369,13 +373,13 @@ public void connect(Consumer connection) { c.connect(); - Assert.assertEquals(15, errors.size()); + assertEquals(15, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnNextParameterException.class); TestHelper.assertError(errors, 7, OnSubscribeNotCalledException.class); @@ -404,8 +408,8 @@ protected void subscribeActual(Observer observer) { observer.onNext(null); observer.onNext(1); observer.onSubscribe(null); - observer.onSubscribe(Disposables.empty()); - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); + observer.onSubscribe(Disposable.empty()); observer.onComplete(); observer.onNext(2); } @@ -413,13 +417,17 @@ protected void subscribeActual(Observer observer) { @Override public void connect(Consumer connection) { } + + @Override + public void reset() { + } }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Observable.just(1).test().assertResult(1); @@ -433,13 +441,13 @@ public void connect(Consumer connection) { co.connect(); - Assert.assertEquals(15, errors.size()); + assertEquals(15, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnNextParameterException.class); TestHelper.assertError(errors, 7, OnSubscribeNotCalledException.class); @@ -483,10 +491,10 @@ public int parallelism() { }; RxJavaProtocolValidator.setOnViolationHandler(this); - Assert.assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); + assertSame(this, RxJavaProtocolValidator.getOnViolationHandler()); SavedHooks h = RxJavaProtocolValidator.enableAndChain(); - Assert.assertTrue(RxJavaProtocolValidator.isEnabled()); + assertTrue(RxJavaProtocolValidator.isEnabled()); try { Flowable.just(1).publish().autoConnect().test().assertResult(1); @@ -497,13 +505,13 @@ public int parallelism() { c.subscribe(new Subscriber[] { new TestSubscriber(0) }); - Assert.assertEquals(15, errors.size()); + assertEquals(15, errors.size()); TestHelper.assertError(errors, 0, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 1, NullOnErrorParameterException.class); TestHelper.assertError(errors, 2, OnSubscribeNotCalledException.class); TestHelper.assertError(errors, 3, MultipleTerminationsException.class); TestHelper.assertError(errors, 4, OnSubscribeNotCalledException.class); - Assert.assertTrue("" + errors.get(4).getCause(), errors.get(4).getCause() instanceof IOException); + assertTrue(errors.get(4).getCause() instanceof IOException, "" + errors.get(4).getCause()); TestHelper.assertError(errors, 5, MultipleTerminationsException.class); TestHelper.assertError(errors, 6, NullOnNextParameterException.class); TestHelper.assertError(errors, 7, OnSubscribeNotCalledException.class); @@ -537,14 +545,14 @@ public void withAssemblyTracking() { h.restore(); - Assert.assertSame(o1, RxJavaPlugins.getOnCompletableAssembly()); - Assert.assertSame(o2, RxJavaPlugins.getOnSingleAssembly()); - Assert.assertSame(o3, RxJavaPlugins.getOnMaybeAssembly()); - Assert.assertSame(o4, RxJavaPlugins.getOnObservableAssembly()); - Assert.assertSame(o5, RxJavaPlugins.getOnFlowableAssembly()); - Assert.assertSame(o6, RxJavaPlugins.getOnConnectableFlowableAssembly()); - Assert.assertSame(o7, RxJavaPlugins.getOnConnectableObservableAssembly()); - Assert.assertSame(o8, RxJavaPlugins.getOnParallelAssembly()); + assertSame(o1, RxJavaPlugins.getOnCompletableAssembly()); + assertSame(o2, RxJavaPlugins.getOnSingleAssembly()); + assertSame(o3, RxJavaPlugins.getOnMaybeAssembly()); + assertSame(o4, RxJavaPlugins.getOnObservableAssembly()); + assertSame(o5, RxJavaPlugins.getOnFlowableAssembly()); + assertSame(o6, RxJavaPlugins.getOnConnectableFlowableAssembly()); + assertSame(o7, RxJavaPlugins.getOnConnectableObservableAssembly()); + assertSame(o8, RxJavaPlugins.getOnParallelAssembly()); } finally { RxJavaAssemblyTracking.disable(); } @@ -558,14 +566,14 @@ public void withAssemblyTrackingOverride() { RxJavaProtocolValidator.disable(); - Assert.assertNull(RxJavaPlugins.getOnCompletableAssembly()); - Assert.assertNull(RxJavaPlugins.getOnSingleAssembly()); - Assert.assertNull(RxJavaPlugins.getOnMaybeAssembly()); - Assert.assertNull(RxJavaPlugins.getOnObservableAssembly()); - Assert.assertNull(RxJavaPlugins.getOnFlowableAssembly()); - Assert.assertNull(RxJavaPlugins.getOnConnectableFlowableAssembly()); - Assert.assertNull(RxJavaPlugins.getOnConnectableObservableAssembly()); - Assert.assertNull(RxJavaPlugins.getOnParallelAssembly()); + assertNull(RxJavaPlugins.getOnCompletableAssembly()); + assertNull(RxJavaPlugins.getOnSingleAssembly()); + assertNull(RxJavaPlugins.getOnMaybeAssembly()); + assertNull(RxJavaPlugins.getOnObservableAssembly()); + assertNull(RxJavaPlugins.getOnFlowableAssembly()); + assertNull(RxJavaPlugins.getOnConnectableFlowableAssembly()); + assertNull(RxJavaPlugins.getOnConnectableObservableAssembly()); + assertNull(RxJavaPlugins.getOnParallelAssembly()); } finally { RxJavaAssemblyTracking.disable(); } @@ -573,19 +581,19 @@ public void withAssemblyTrackingOverride() { @Test public void protocolNonConformanceException() { - Assert.assertNotNull(new ProtocolNonConformanceException() { + assertNotNull(new ProtocolNonConformanceException() { private static final long serialVersionUID = -1400755866355428747L; }); - Assert.assertNotNull(new ProtocolNonConformanceException("Message") { + assertNotNull(new ProtocolNonConformanceException("Message") { private static final long serialVersionUID = -1400755866355428747L; }); - Assert.assertNotNull(new ProtocolNonConformanceException(new IOException()) { + assertNotNull(new ProtocolNonConformanceException(new IOException()) { private static final long serialVersionUID = -1400755866355428747L; }); - Assert.assertNotNull(new ProtocolNonConformanceException("Message", new IOException()) { + assertNotNull(new ProtocolNonConformanceException("Message", new IOException()) { private static final long serialVersionUID = -1400755866355428747L; }); } diff --git a/src/test/java/hu/akarnokd/rxjava2/expr/StatementCompletableTest.java b/src/test/java/hu/akarnokd/rxjava4/expr/StatementCompletableTest.java similarity index 84% rename from src/test/java/hu/akarnokd/rxjava2/expr/StatementCompletableTest.java rename to src/test/java/hu/akarnokd/rxjava4/expr/StatementCompletableTest.java index dd24535e..99675bcd 100644 --- a/src/test/java/hu/akarnokd/rxjava2/expr/StatementCompletableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/expr/StatementCompletableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,43 +14,42 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Completable; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.schedulers.TestScheduler; -import org.junit.Before; -import org.junit.Test; +import java.util.*; + +import org.junit.jupiter.api.*; import org.mockito.MockitoAnnotations; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Callable; +import io.reactivex.rxjava4.core.Completable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.TestScheduler; +@SuppressWarnings("rawtypes") public class StatementCompletableTest { TestScheduler scheduler; - Callable func; - Callable funcError; + Supplier func; + Supplier funcError; BooleanSupplier condition; BooleanSupplier conditionError; - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); scheduler = new TestScheduler(); - func = new Callable() { + func = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { return count++; } }; - funcError = new Callable() { + funcError = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { if (count == 2) { throw new RuntimeException("Forced failure!"); } @@ -82,11 +81,11 @@ public boolean getAsBoolean() { }; } - void observe(Completable source) { + void observe(Completable source) { source.test().assertComplete(); } - void observeError(Completable source, Class error) { + void observeError(Completable source, Class error) { source.test().assertFailure(error); } @@ -96,10 +95,11 @@ public void testSimple() { Completable source2 = Completable.complete(); Completable defaultSource = Completable.error(new RuntimeException("Forced Failure")); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(1, source1); map.put(2, source2); + @SuppressWarnings("unchecked") Completable result = StatementCompletable.switchCase(func, map, defaultSource); observe(result); @@ -111,9 +111,10 @@ public void testDefaultCase() { Completable source1 = Completable.error(new RuntimeException("Forced Failure")); Completable source2 = Completable.complete(); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(1, source1); + @SuppressWarnings("unchecked") Completable result = StatementCompletable.switchCase(func, map, source2); observeError(result, RuntimeException.class); @@ -125,9 +126,10 @@ public void testCaseSelectorThrows() { Completable source1 = Completable.complete(); Completable defaultSource = Completable.complete(); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(1, source1); + @SuppressWarnings("unchecked") Completable result = StatementCompletable.switchCase(funcError, map, defaultSource); observe(result); @@ -155,6 +157,7 @@ public Completable get(Object key) { map.put(1, source1); map.put(2, source2); + @SuppressWarnings("unchecked") Completable result = StatementCompletable.switchCase(func, map, defaultSource); observe(result); @@ -180,6 +183,7 @@ public Completable get(Object key) { }; map.put(1, source1); + @SuppressWarnings("unchecked") Completable result = StatementCompletable.switchCase(func, map, defaultSource); observe(result); @@ -192,10 +196,11 @@ public void testChosenCompletableThrows() { Completable source2 = Completable.error(new RuntimeException("Forced failure")); Completable defaultSource = Completable.complete(); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put(1, source1); map.put(2, source2); + @SuppressWarnings("unchecked") Completable result = StatementCompletable.switchCase(func, map, defaultSource); observe(result); diff --git a/src/test/java/hu/akarnokd/rxjava2/expr/StatementFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/expr/StatementFlowableTest.java similarity index 87% rename from src/test/java/hu/akarnokd/rxjava2/expr/StatementFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/expr/StatementFlowableTest.java index 097c4e2b..37c17e6d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/expr/StatementFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/expr/StatementFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,43 +14,42 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; import java.util.*; -import java.util.concurrent.Callable; -import org.junit.*; +import org.junit.jupiter.api.*; import org.mockito.MockitoAnnotations; -import io.reactivex.Flowable; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.schedulers.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.*; public class StatementFlowableTest { TestScheduler scheduler; - Callable func; - Callable funcError; + Supplier func; + Supplier funcError; BooleanSupplier condition; BooleanSupplier conditionError; int numRecursion = 250; - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); scheduler = new TestScheduler(); - func = new Callable() { + func = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { return count++; } }; - funcError = new Callable() { + funcError = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { if (count == 2) { throw new RuntimeException("Forced failure!"); } @@ -82,20 +81,22 @@ public boolean getAsBoolean() { }; } - void observe(Flowable source, T... values) { + @SafeVarargs + static void observe(Flowable source, T... values) { source.test().assertResult(values); } void observeSequence(Flowable source, Iterable values) { - source.test().assertValueSequence(values).assertNoErrors().assertComplete().assertSubscribed(); + source.test().assertValueSequence(values).assertNoErrors().assertComplete(); } - void observeError(Flowable source, Class error, T... valuesBeforeError) { + @SafeVarargs + static void observeError(Flowable source, Class error, T... valuesBeforeError) { source.test().assertFailure(error, valuesBeforeError); } void observeSequenceError(Flowable source, Class error, Iterable valuesBeforeError) { - source.test().assertValueSequence(valuesBeforeError).assertError(error).assertNotComplete().assertSubscribed(); + source.test().assertValueSequence(valuesBeforeError).assertError(error).assertNotComplete(); } @Test @@ -103,7 +104,7 @@ public void testSimple() { Flowable source1 = Flowable.just(1, 2, 3); Flowable source2 = Flowable.just(4, 5, 6); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); @@ -119,7 +120,7 @@ public void testDefaultCase() { Flowable source1 = Flowable.just(1, 2, 3); Flowable source2 = Flowable.just(4, 5, 6); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Flowable result = StatementFlowable.switchCase(func, map, source2); @@ -133,7 +134,7 @@ public void testDefaultCase() { public void testCaseSelectorThrows() { Flowable source1 = Flowable.just(1, 2, 3); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Flowable result = StatementFlowable.switchCase(funcError, map); @@ -197,7 +198,7 @@ public void testChosenFlowableThrows() { Flowable source1 = Flowable.just(1, 2, 3); Flowable source2 = Flowable.error(new RuntimeException("Forced failure")); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); @@ -280,7 +281,7 @@ public void testDoWhile() { } @Test - public void testDoWhileOnce() throws Exception { + public void testDoWhileOnce() throws Throwable { Flowable source1 = Flowable.just(1, 2, 3); condition.getAsBoolean(); // toggle to false @@ -290,7 +291,7 @@ public void testDoWhileOnce() throws Exception { } @Test - public void testDoWhileConditionThrows() throws Exception { + public void testDoWhileConditionThrows() throws Throwable { Flowable source1 = Flowable.just(1, 2, 3); conditionError.getAsBoolean(); Flowable result = StatementFlowable.doWhile(source1, conditionError); @@ -300,7 +301,7 @@ public void testDoWhileConditionThrows() throws Exception { @Test public void testDoWhileSourceThrows() { - Flowable source1 = Flowable.concat(Flowable.just(1, 2, 3), + Flowable source1 = Flowable.concatArray(Flowable.just(1, 2, 3), Flowable. error(new RuntimeException("Forced failure!"))); Flowable result = StatementFlowable.doWhile(source1, condition); @@ -323,7 +324,7 @@ public boolean getAsBoolean() { public void testDoWhileManyTimes() { Flowable source1 = Flowable.just(1, 2, 3).subscribeOn(Schedulers.trampoline()); - List expected = new ArrayList(numRecursion * 3); + List expected = new ArrayList<>(numRecursion * 3); for (int i = 0; i < numRecursion; i++) { expected.add(1); expected.add(2); @@ -363,7 +364,7 @@ public void testWhileDoZeroTimes() { public void testWhileDoManyTimes() { Flowable source1 = Flowable.just(1, 2, 3).subscribeOn(Schedulers.trampoline()); - List expected = new ArrayList(numRecursion * 3); + List expected = new ArrayList<>(numRecursion * 3); for (int i = 0; i < numRecursion; i++) { expected.add(1); expected.add(2); @@ -384,7 +385,7 @@ public void testWhileDoConditionThrows() { } @Test - public void testWhileDoConditionThrowsImmediately() throws Exception { + public void testWhileDoConditionThrowsImmediately() throws Throwable { Flowable source1 = Flowable.just(1, 2, 3); conditionError.getAsBoolean(); Flowable result = StatementFlowable.whileDo(source1, conditionError); @@ -394,7 +395,7 @@ public void testWhileDoConditionThrowsImmediately() throws Exception { @Test public void testWhileDoSourceThrows() { - Flowable source1 = Flowable.concat(Flowable.just(1, 2, 3), + Flowable source1 = Flowable.concatArray(Flowable.just(1, 2, 3), Flowable. error(new RuntimeException("Forced failure!"))); Flowable result = StatementFlowable.whileDo(source1, condition); diff --git a/src/test/java/hu/akarnokd/rxjava2/expr/StatementMaybeTest.java b/src/test/java/hu/akarnokd/rxjava4/expr/StatementMaybeTest.java similarity index 86% rename from src/test/java/hu/akarnokd/rxjava2/expr/StatementMaybeTest.java rename to src/test/java/hu/akarnokd/rxjava4/expr/StatementMaybeTest.java index 8737cd06..f97e6154 100644 --- a/src/test/java/hu/akarnokd/rxjava2/expr/StatementMaybeTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/expr/StatementMaybeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,43 +14,41 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Maybe; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.schedulers.TestScheduler; -import org.junit.Before; -import org.junit.Test; +import java.util.*; + +import org.junit.jupiter.api.*; import org.mockito.MockitoAnnotations; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Callable; +import io.reactivex.rxjava4.core.Maybe; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.TestScheduler; public class StatementMaybeTest { TestScheduler scheduler; - Callable func; - Callable funcError; + Supplier func; + Supplier funcError; BooleanSupplier condition; BooleanSupplier conditionError; - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); scheduler = new TestScheduler(); - func = new Callable() { + func = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { return count++; } }; - funcError = new Callable() { + funcError = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { if (count == 2) { throw new RuntimeException("Forced failure!"); } @@ -86,11 +84,11 @@ void observe(Maybe source) { source.test().assertNoValues().assertNoErrors(); } - void observe(Maybe source, T value) { + static void observe(Maybe source, T value) { source.test().assertResult(value); } - void observeError(Maybe source, Class error) { + static void observeError(Maybe source, Class error) { source.test().assertFailure(error); } @@ -99,7 +97,7 @@ public void testSimple() { Maybe source1 = Maybe.just(1); Maybe source2 = Maybe.just(2); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); @@ -115,7 +113,7 @@ public void testDefaultCase() { Maybe source1 = Maybe.just(1); Maybe defaultSource = Maybe.just(2); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Maybe result = StatementMaybe.switchCase(func, map, defaultSource); @@ -129,7 +127,7 @@ public void testDefaultCase() { public void testCaseSelectorThrows() { Maybe source1 = Maybe.just(1); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Maybe result = StatementMaybe.switchCase(funcError, map); @@ -193,7 +191,7 @@ public void testChosenMaybeThrows() { Maybe source1 = Maybe.just(1); Maybe source2 = Maybe.error(new RuntimeException("Forced failure")); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); diff --git a/src/test/java/hu/akarnokd/rxjava2/expr/StatementObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/expr/StatementObservableTest.java similarity index 87% rename from src/test/java/hu/akarnokd/rxjava2/expr/StatementObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/expr/StatementObservableTest.java index 5c35728f..cf0b686c 100644 --- a/src/test/java/hu/akarnokd/rxjava2/expr/StatementObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/expr/StatementObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,43 +14,42 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; import java.util.*; -import java.util.concurrent.Callable; -import org.junit.*; +import org.junit.jupiter.api.*; import org.mockito.MockitoAnnotations; -import io.reactivex.Observable; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.schedulers.*; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.*; public class StatementObservableTest { TestScheduler scheduler; - Callable func; - Callable funcError; + Supplier func; + Supplier funcError; BooleanSupplier condition; BooleanSupplier conditionError; int numRecursion = 250; - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); scheduler = new TestScheduler(); - func = new Callable() { + func = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { return count++; } }; - funcError = new Callable() { + funcError = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { if (count == 2) { throw new RuntimeException("Forced failure!"); } @@ -82,20 +81,22 @@ public boolean getAsBoolean() { }; } - void observe(Observable source, T... values) { + @SafeVarargs + static void observe(Observable source, T... values) { source.test().assertResult(values); } void observeSequence(Observable source, Iterable values) { - source.test().assertValueSequence(values).assertNoErrors().assertComplete().assertSubscribed(); + source.test().assertValueSequence(values).assertNoErrors().assertComplete(); } - void observeError(Observable source, Class error, T... valuesBeforeError) { + @SafeVarargs + static void observeError(Observable source, Class error, T... valuesBeforeError) { source.test().assertFailure(error, valuesBeforeError); } void observeSequenceError(Observable source, Class error, Iterable valuesBeforeError) { - source.test().assertValueSequence(valuesBeforeError).assertError(error).assertNotComplete().assertSubscribed(); + source.test().assertValueSequence(valuesBeforeError).assertError(error).assertNotComplete(); } @Test @@ -103,7 +104,7 @@ public void testSimple() { Observable source1 = Observable.just(1, 2, 3); Observable source2 = Observable.just(4, 5, 6); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); @@ -119,7 +120,7 @@ public void testDefaultCase() { Observable source1 = Observable.just(1, 2, 3); Observable source2 = Observable.just(4, 5, 6); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Observable result = StatementObservable.switchCase(func, map, source2); @@ -133,7 +134,7 @@ public void testDefaultCase() { public void testCaseSelectorThrows() { Observable source1 = Observable.just(1, 2, 3); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Observable result = StatementObservable.switchCase(funcError, map); @@ -197,7 +198,7 @@ public void testChosenObservableThrows() { Observable source1 = Observable.just(1, 2, 3); Observable source2 = Observable.error(new RuntimeException("Forced failure")); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); @@ -280,7 +281,7 @@ public void testDoWhile() { } @Test - public void testDoWhileOnce() throws Exception { + public void testDoWhileOnce() throws Throwable { Observable source1 = Observable.just(1, 2, 3); condition.getAsBoolean(); // toggle to false @@ -290,7 +291,7 @@ public void testDoWhileOnce() throws Exception { } @Test - public void testDoWhileConditionThrows() throws Exception { + public void testDoWhileConditionThrows() throws Throwable { Observable source1 = Observable.just(1, 2, 3); conditionError.getAsBoolean(); Observable result = StatementObservable.doWhile(source1, conditionError); @@ -300,7 +301,7 @@ public void testDoWhileConditionThrows() throws Exception { @Test public void testDoWhileSourceThrows() { - Observable source1 = Observable.concat(Observable.just(1, 2, 3), + Observable source1 = Observable.concatArray(Observable.just(1, 2, 3), Observable. error(new RuntimeException("Forced failure!"))); Observable result = StatementObservable.doWhile(source1, condition); @@ -323,7 +324,7 @@ public boolean getAsBoolean() { public void testDoWhileManyTimes() { Observable source1 = Observable.just(1, 2, 3).subscribeOn(Schedulers.trampoline()); - List expected = new ArrayList(numRecursion * 3); + List expected = new ArrayList<>(numRecursion * 3); for (int i = 0; i < numRecursion; i++) { expected.add(1); expected.add(2); @@ -363,7 +364,7 @@ public void testWhileDoZeroTimes() { public void testWhileDoManyTimes() { Observable source1 = Observable.just(1, 2, 3).subscribeOn(Schedulers.trampoline()); - List expected = new ArrayList(numRecursion * 3); + List expected = new ArrayList<>(numRecursion * 3); for (int i = 0; i < numRecursion; i++) { expected.add(1); expected.add(2); @@ -384,7 +385,7 @@ public void testWhileDoConditionThrows() { } @Test - public void testWhileDoConditionThrowsImmediately() throws Exception { + public void testWhileDoConditionThrowsImmediately() throws Throwable { Observable source1 = Observable.just(1, 2, 3); conditionError.getAsBoolean(); Observable result = StatementObservable.whileDo(source1, conditionError); @@ -394,7 +395,7 @@ public void testWhileDoConditionThrowsImmediately() throws Exception { @Test public void testWhileDoSourceThrows() { - Observable source1 = Observable.concat(Observable.just(1, 2, 3), + Observable source1 = Observable.concatArray(Observable.just(1, 2, 3), Observable. error(new RuntimeException("Forced failure!"))); Observable result = StatementObservable.whileDo(source1, condition); diff --git a/src/test/java/hu/akarnokd/rxjava2/expr/StatementSingleTest.java b/src/test/java/hu/akarnokd/rxjava4/expr/StatementSingleTest.java similarity index 86% rename from src/test/java/hu/akarnokd/rxjava2/expr/StatementSingleTest.java rename to src/test/java/hu/akarnokd/rxjava4/expr/StatementSingleTest.java index f289b1e8..9cd0e71f 100644 --- a/src/test/java/hu/akarnokd/rxjava2/expr/StatementSingleTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/expr/StatementSingleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,44 +14,41 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.expr; +package hu.akarnokd.rxjava4.expr; -import io.reactivex.Single; -import io.reactivex.SingleSource; -import io.reactivex.functions.BooleanSupplier; -import io.reactivex.schedulers.TestScheduler; -import org.junit.Before; -import org.junit.Test; +import java.util.*; + +import org.junit.jupiter.api.*; import org.mockito.MockitoAnnotations; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Callable; +import io.reactivex.rxjava4.core.Single; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.TestScheduler; public class StatementSingleTest { TestScheduler scheduler; - Callable func; - Callable funcError; + Supplier func; + Supplier funcError; BooleanSupplier condition; BooleanSupplier conditionError; - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); scheduler = new TestScheduler(); - func = new Callable() { + func = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { return count++; } }; - funcError = new Callable() { + funcError = new Supplier() { int count = 1; @Override - public Integer call() { + public Integer get() { if (count == 2) { throw new RuntimeException("Forced failure!"); } @@ -97,7 +94,7 @@ public void testSimple() { Single source2 = Single.just(2); Single defaultSource = Single.just(Integer.MAX_VALUE); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); @@ -112,7 +109,7 @@ public void testDefaultCase() { Single source1 = Single.just(1); Single source2 = Single.just(2); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Single result = StatementSingle.switchCase(func, map, source2); @@ -127,7 +124,7 @@ public void testCaseSelectorThrows() { Single source1 = Single.just(1); Single defaultSource = Single.just(Integer.MAX_VALUE); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); Single result = StatementSingle.switchCase(funcError, map, defaultSource); @@ -194,7 +191,7 @@ public void testChosenSingleThrows() { Single source2 = Single.error(new RuntimeException("Forced failure")); Single defaultSource = Single.just(Integer.MAX_VALUE); - Map> map = new HashMap>(); + Map> map = new HashMap<>(); map.put(1, source1); map.put(2, source2); diff --git a/src/test/java/hu/akarnokd/rxjava2/functions/FunctionTaggingTest.java b/src/test/java/hu/akarnokd/rxjava4/functions/FunctionTaggingTest.java similarity index 86% rename from src/test/java/hu/akarnokd/rxjava2/functions/FunctionTaggingTest.java rename to src/test/java/hu/akarnokd/rxjava4/functions/FunctionTaggingTest.java index ce4b55ee..31fc82d0 100644 --- a/src/test/java/hu/akarnokd/rxjava2/functions/FunctionTaggingTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/functions/FunctionTaggingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.functions; +package hu.akarnokd.rxjava4.functions; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.functions.FunctionTagging.FunctionTaggingException; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.functions.FunctionTagging.FunctionTaggingException; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; public class FunctionTaggingTest { @@ -50,7 +50,7 @@ public void addLastWhenCausePresent() { new FunctionTaggingException("Tag").appendLast(ex); - assertTrue(ex.getCause().getCause().toString(), ex.getCause().getCause().toString().contains("Tag")); + assertTrue(ex.getCause().getCause().toString().contains("Tag"), ex.getCause().getCause().toString()); } @Test @@ -89,7 +89,7 @@ public void addLastWhenLoopCause() { } @Test - public void f1Tag() throws Exception { + public void f1Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { FunctionTagging.disable(); @@ -109,12 +109,12 @@ public void f1Tag() throws Exception { f.apply(null); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction(new Function() { @Override - public Integer apply(Integer a) throws Exception { + public Integer apply(Integer a) throws Throwable { return null; } }, "Custom tag"); @@ -123,12 +123,12 @@ public Integer apply(Integer a) throws Exception { f.apply(1); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction(new Function() { @Override - public Integer apply(Integer a) throws Exception { + public Integer apply(Integer a) throws Throwable { throw new IOException(); } }, "Custom tag"); @@ -137,7 +137,7 @@ public Integer apply(Integer a) throws Exception { f.apply(1); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -148,14 +148,14 @@ public Integer apply(Integer a) throws Exception { } @Test - public void f2Tag() throws Exception { + public void f2Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { FunctionTagging.disable(); BiFunction f = FunctionTagging.tagBiFunction(new BiFunction() { @Override - public Integer apply(Integer a, Integer b) throws Exception { + public Integer apply(Integer a, Integer b) throws Throwable { return a; } }, "Custom tag"); @@ -165,7 +165,7 @@ public Integer apply(Integer a, Integer b) throws Exception { f = FunctionTagging.tagBiFunction(new BiFunction() { @Override - public Integer apply(Integer a, Integer b) throws Exception { + public Integer apply(Integer a, Integer b) throws Throwable { return b; } }, "Custom tag"); @@ -179,7 +179,7 @@ public Integer apply(Integer a, Integer b) throws Exception { f = FunctionTagging.tagBiFunction(new BiFunction() { @Override - public Integer apply(Integer a, Integer b) throws Exception { + public Integer apply(Integer a, Integer b) throws Throwable { return a; } }, "Custom tag"); @@ -190,12 +190,12 @@ public Integer apply(Integer a, Integer b) throws Exception { f.apply(null, 2); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagBiFunction(new BiFunction() { @Override - public Integer apply(Integer a, Integer b) throws Exception { + public Integer apply(Integer a, Integer b) throws Throwable { return b; } }, "Custom tag"); @@ -206,14 +206,14 @@ public Integer apply(Integer a, Integer b) throws Exception { f.apply(1, null); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } // oooooooooooooooooooooooooooooooo f = FunctionTagging.tagBiFunction(new BiFunction() { @Override - public Integer apply(Integer a, Integer b) throws Exception { + public Integer apply(Integer a, Integer b) throws Throwable { return null; } }, "Custom tag"); @@ -222,12 +222,12 @@ public Integer apply(Integer a, Integer b) throws Exception { f.apply(1, 2); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagBiFunction(new BiFunction() { @Override - public Integer apply(Integer a, Integer b) throws Exception { + public Integer apply(Integer a, Integer b) throws Throwable { throw new IOException(); } }, "Custom tag"); @@ -236,7 +236,7 @@ public Integer apply(Integer a, Integer b) throws Exception { f.apply(1, 2); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -247,14 +247,14 @@ public Integer apply(Integer a, Integer b) throws Exception { } @Test - public void f3Tag() throws Exception { + public void f3Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { FunctionTagging.disable(); Function3 f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return a; } }, "Custom tag"); @@ -264,7 +264,7 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return b; } }, "Custom tag"); @@ -274,7 +274,7 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return c; } }, "Custom tag"); @@ -288,7 +288,7 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return a; } }, "Custom tag"); @@ -299,12 +299,12 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f.apply(null, 2, 3); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return b; } }, "Custom tag"); @@ -315,12 +315,12 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f.apply(1, null, 3); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return c; } }, "Custom tag"); @@ -331,14 +331,14 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f.apply(1, 2, null); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } // oooooooooooooooooooooooooooooooo f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { return null; } }, "Custom tag"); @@ -347,12 +347,12 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f.apply(1, 2, 3); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction3(new Function3() { @Override - public Integer apply(Integer a, Integer b, Integer c) throws Exception { + public Integer apply(Integer a, Integer b, Integer c) throws Throwable { throw new IOException(); } }, "Custom tag"); @@ -361,7 +361,7 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { f.apply(1, 2, 3); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -372,7 +372,7 @@ public Integer apply(Integer a, Integer b, Integer c) throws Exception { } @Test - public void f4Tag() throws Exception { + public void f4Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { FunctionTagging.disable(); @@ -380,7 +380,7 @@ public void f4Tag() throws Exception { Function4 f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return a; } }, "Custom tag"); @@ -391,7 +391,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return b; } }, "Custom tag"); @@ -402,7 +402,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return c; } }, "Custom tag"); @@ -413,7 +413,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return d; } }, "Custom tag"); @@ -428,7 +428,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return a; } }, "Custom tag"); @@ -439,13 +439,13 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f.apply(null, 2, 3, 4); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return b; } }, "Custom tag"); @@ -456,13 +456,13 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f.apply(1, null, 3, 4); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return c; } }, "Custom tag"); @@ -473,13 +473,13 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f.apply(1, 2, null, 4); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return d; } }, "Custom tag"); @@ -490,7 +490,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f.apply(1, 2, 3, null); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } // oooooooooooooooooooooooooooooooo @@ -498,7 +498,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { return null; } }, "Custom tag"); @@ -507,13 +507,13 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f.apply(1, 2, 3, 4); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction4( new Function4() { @Override - public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exception { + public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Throwable { throw new IOException(); } }, "Custom tag"); @@ -522,7 +522,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio f.apply(1, 2, 3, 4); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -533,7 +533,7 @@ public Integer apply(Integer a, Integer b, Integer c, Integer d) throws Exceptio } @Test - public void f5Tag() throws Exception { + public void f5Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { FunctionTagging.disable(); @@ -585,8 +585,8 @@ public void f5Tag() throws Exception { f.apply(t1, t2, t3, t4, t5); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); - assertTrue(ex.getMessage(), ex.getMessage().contains("t" + i + " is null")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); + assertTrue(ex.getMessage().contains("t" + i + " is null"), ex.getMessage()); } } @@ -599,7 +599,7 @@ public void f5Tag() throws Exception { f.apply(1, 2, 3, 4, 5); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction5( @@ -609,7 +609,7 @@ public void f5Tag() throws Exception { f.apply(1, 2, 3, 4, 5); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -620,7 +620,7 @@ public void f5Tag() throws Exception { } @Test - public void f6Tag() throws Exception { + public void f6Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { Function6 f; @@ -679,8 +679,8 @@ public void f6Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); - assertTrue(ex.getMessage(), ex.getMessage().contains("t" + i + " is null")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); + assertTrue(ex.getMessage().contains("t" + i + " is null"), ex.getMessage()); } } @@ -700,7 +700,7 @@ public void f6Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction6( @@ -710,7 +710,7 @@ public void f6Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -721,7 +721,7 @@ public void f6Tag() throws Exception { } @Test - public void f7Tag() throws Exception { + public void f7Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { Function7 f; @@ -784,8 +784,8 @@ public void f7Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); - assertTrue(ex.getMessage(), ex.getMessage().contains("t" + i + " is null")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); + assertTrue(ex.getMessage().contains("t" + i + " is null"), ex.getMessage()); } } @@ -806,7 +806,7 @@ public void f7Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction7( @@ -816,7 +816,7 @@ public void f7Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -827,7 +827,7 @@ public void f7Tag() throws Exception { } @Test - public void f8Tag() throws Exception { + public void f8Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { Function8 f; @@ -894,8 +894,8 @@ public void f8Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7, t8); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); - assertTrue(ex.getMessage(), ex.getMessage().contains("t" + i + " is null")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); + assertTrue(ex.getMessage().contains("t" + i + " is null"), ex.getMessage()); } } @@ -917,7 +917,7 @@ public void f8Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7, t8); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction8( @@ -927,7 +927,7 @@ public void f8Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7, t8); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -938,7 +938,7 @@ public void f8Tag() throws Exception { } @Test - public void f9Tag() throws Exception { + public void f9Tag() throws Throwable { boolean enabled = FunctionTagging.isEnabled(); try { Function9 f; @@ -1009,8 +1009,8 @@ public void f9Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7, t8, t9); throw new AssertionError("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); - assertTrue(ex.getMessage(), ex.getMessage().contains("t" + i + " is null")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); + assertTrue(ex.getMessage().contains("t" + i + " is null"), ex.getMessage()); } } @@ -1033,7 +1033,7 @@ public void f9Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7, t8, t9); fail("Should have thrown!"); } catch (NullPointerException ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Custom tag")); + assertTrue(ex.getMessage().contains("Custom tag"), ex.getMessage()); } f = FunctionTagging.tagFunction9( @@ -1043,7 +1043,7 @@ public void f9Tag() throws Exception { f.apply(t1, t2, t3, t4, t5, t6, t7, t8, t9); fail("Should have thrown!"); } catch (IOException ex) { - assertTrue(ex.getCause().getMessage(), ex.getCause().getMessage().contains("Custom tag")); + assertTrue(ex.getCause().getMessage().contains("Custom tag"), ex.getCause().getMessage()); } } finally { @@ -1073,7 +1073,7 @@ static final class FunctionTaggingComposite implements @Override public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8, Integer t9) - throws Exception { + throws Throwable { if (crash) { throw new IOException(); } @@ -1098,7 +1098,7 @@ public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, @Override public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8) - throws Exception { + throws Throwable { if (crash) { throw new IOException(); } @@ -1121,7 +1121,7 @@ public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, @Override public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, - Integer t5, Integer t6, Integer t7) throws Exception { + Integer t5, Integer t6, Integer t7) throws Throwable { if (crash) { throw new IOException(); } @@ -1143,7 +1143,7 @@ public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, @Override public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, - Integer t5, Integer t6) throws Exception { + Integer t5, Integer t6) throws Throwable { if (crash) { throw new IOException(); } @@ -1164,7 +1164,7 @@ public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, @Override public Integer apply(Integer t1, Integer t2, Integer t3, Integer t4, - Integer t5) throws Exception { + Integer t5) throws Throwable { if (crash) { throw new IOException(); } diff --git a/src/test/java/hu/akarnokd/rxjava2/joins/OperatorJoinsTest.java b/src/test/java/hu/akarnokd/rxjava4/joins/OperatorJoinsTest.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/joins/OperatorJoinsTest.java rename to src/test/java/hu/akarnokd/rxjava4/joins/OperatorJoinsTest.java index b2ac8aed..2a73bf38 100644 --- a/src/test/java/hu/akarnokd/rxjava2/joins/OperatorJoinsTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/joins/OperatorJoinsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.joins; +package hu.akarnokd.rxjava4.joins; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.concurrent.Callable; -import org.junit.*; +import org.junit.jupiter.api.*; import org.mockito.*; -import hu.akarnokd.rxjava2.test.TestException; -import io.reactivex.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestException; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.subjects.PublishSubject; public class OperatorJoinsTest { @Mock @@ -184,25 +184,29 @@ public R apply(Integer t1, Integer t2) { return call(); } } - ThrowFunc throwFunc = new ThrowFunc(); + ThrowFunc throwFunc = new ThrowFunc<>(); Observable some = Observable.just(1); Observable error = Observable.error(new TestException("Forced failure")); - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } - @Test(expected = NullPointerException.class) + @Test public void and2ArgumentNull() { - JoinObservable.from(some).and(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void and3argumentNull() { - JoinObservable.from(some).and(some).and(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(null); + }); } void verifyAnd(JoinObservable m, int count) { @@ -262,49 +266,67 @@ public void and3Error3() { verifyError(JoinObservable.when(JoinObservable.from(some).and(some).and(error).then(add))); } - @Test(expected = NullPointerException.class) + @Test public void thenArgumentNull() { - JoinObservable.from(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then2ArgumentNull() { - JoinObservable.from(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then3ArgumentNull() { - JoinObservable.from(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then4ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then5ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then6ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then7ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then8ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void then9ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + }); } @Test @@ -327,9 +349,12 @@ public void thenNArgumentNull() { } } - @Test(expected = NullPointerException.class) + @Test public void then10ArgumentNull() { - JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).and(some).then(null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.from(some).and(some).and(some).and(some).and(some).and(some) + .and(some).and(some).and(some).and(some).then(null); + }); } @Test @@ -357,14 +382,18 @@ public void then3Throws() { verifyError(JoinObservable.when(JoinObservable.from(some).and(some).and(some).then(throwFunc))); } - @Test(expected = NullPointerException.class) + @Test public void whenArgumentNull1() { - JoinObservable.when((Plan[]) null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.when((Plan[]) null); + }); } - @Test(expected = NullPointerException.class) + @Test public void whenArgumentNull2() { - JoinObservable.when((Iterable>) null); + assertThrows(NullPointerException.class, () -> { + JoinObservable.when((Iterable>) null); + }); } @Test @@ -447,7 +476,7 @@ public void whenComplicated() { JoinObservable.from(ys).and(zs).then(sub2) // 4-7=-3, 5-8=-3, 6-9=-3 ).toObservable(); - TestObserver to = new TestObserver(observer); + TestObserver to = new TestObserver<>(observer); m.subscribe(to); xs.onNext(1); // t == 210, xs[1], ys[], zs[] @@ -470,10 +499,10 @@ public void whenComplicated() { zs.onComplete(); // t == 300, completed 3, triggers when() oncompleted - System.out.println("Events: " + to.valueCount()); + System.out.println("Events: " + to.values().size()); to.assertValues(7, 16, 7, -4); - to.assertTerminated(); + to.assertNoErrors().assertComplete(); InOrder inOrder = inOrder(observer); diff --git a/src/test/java/hu/akarnokd/rxjava2/math/MathFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/math/MathFlowableTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/math/MathFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/math/MathFlowableTest.java index c68d0b5e..0b300e64 100644 --- a/src/test/java/hu/akarnokd/rxjava2/math/MathFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/math/MathFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import static hu.akarnokd.rxjava2.math.MathFlowable.*; +import static hu.akarnokd.rxjava4.math.MathFlowable.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.BaseTest; -import io.reactivex.Flowable; +import hu.akarnokd.rxjava4.test.BaseTest; +import io.reactivex.rxjava4.core.Flowable; public class MathFlowableTest extends BaseTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/math/MathObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/math/MathObservableTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/math/MathObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/math/MathObservableTest.java index 870b1fd8..9638e075 100644 --- a/src/test/java/hu/akarnokd/rxjava2/math/MathObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/math/MathObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.math; +package hu.akarnokd.rxjava4.math; -import static hu.akarnokd.rxjava2.math.MathObservable.*; +import static hu.akarnokd.rxjava4.math.MathObservable.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.BaseTest; -import io.reactivex.Observable; +import hu.akarnokd.rxjava4.test.BaseTest; +import io.reactivex.rxjava4.core.Observable; public class MathObservableTest extends BaseTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalCompletableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalCompletableTest.java similarity index 80% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalCompletableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalCompletableTest.java index 6193ec69..dea236f0 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalCompletableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalCompletableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.CompletableSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.CompletableSubject; public class CompletableFlatMapSignalCompletableTest { @@ -35,9 +33,9 @@ public void normal() { Completable.complete() .compose(CompletableTransformers.flatMap( - new Callable() { + new Supplier() { @Override - public CompletableSource call() throws Exception { + public CompletableSource get() throws Exception { counts[0]++; return Completable.complete(); } @@ -64,9 +62,9 @@ public void error() { Completable.error(new TestException()) .compose(CompletableTransformers.flatMap( - new Callable() { + new Supplier() { @Override - public CompletableSource call() throws Exception { + public CompletableSource get() throws Exception { counts[0]++; return Completable.complete(); } @@ -93,9 +91,9 @@ public void normalCrash() { Completable.complete() .compose(CompletableTransformers.flatMap( - new Callable() { + new Supplier() { @Override - public CompletableSource call() throws Exception { + public CompletableSource get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -110,7 +108,8 @@ public CompletableSource apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -122,9 +121,9 @@ public void errorCrash() { Completable.error(new TestException("main")) .compose(CompletableTransformers.flatMap( - new Callable() { + new Supplier() { @Override - public CompletableSource call() throws Exception { + public CompletableSource get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -139,7 +138,8 @@ public CompletableSource apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -149,9 +149,9 @@ public CompletableSource apply(Throwable e) public void disposed() { TestHelper.checkDisposed(CompletableSubject.create() .compose(CompletableTransformers.flatMap( - new Callable() { + new Supplier() { @Override - public CompletableSource call() throws Exception { + public CompletableSource get() throws Exception { return Completable.complete(); } }, @@ -172,9 +172,9 @@ public void doubleOnSubscribe() { @Override public CompletableSource apply(Completable c) throws Exception { return c.compose(CompletableTransformers.flatMap( - new Callable() { + new Supplier() { @Override - public CompletableSource call() throws Exception { + public CompletableSource get() throws Exception { return Completable.complete(); } }, diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalFlowableTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalFlowableTest.java index 2ef1824e..34f55757 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.CompletableSubject; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.CompletableSubject; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class CompletableFlatMapSignalFlowableTest { @@ -35,10 +33,10 @@ public void success() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapFlowable( - new Callable>() { + .to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[0]++; return Flowable.just(1); } @@ -64,10 +62,10 @@ public void empty() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapFlowable( - new Callable>() { + .to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[0]++; return Flowable.empty(); } @@ -93,10 +91,10 @@ public void error() { final int[] counts = { 0, 0 }; Completable.error(new TestException()) - .as(Completables.flatMapFlowable( - new Callable>() { + .to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[0]++; return Flowable.empty(); } @@ -120,9 +118,9 @@ public Flowable apply(Throwable e) @Test public void backpressure() { TestSubscriber ts = Completable.complete() - .as(Completables.flatMapFlowable(new Callable>() { + .to(Completables.flatMapFlowable(new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { return Flowable.range(1, 5); } }, @@ -155,10 +153,10 @@ public void normalCrash() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapFlowable( - new Callable>() { + .to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -173,7 +171,8 @@ public Flowable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -184,10 +183,10 @@ public void errorCrash() { final int[] counts = { 0, 0 }; Completable.error(new TestException("main")) - .as(Completables.flatMapFlowable( - new Callable>() { + .to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -202,7 +201,8 @@ public Flowable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -211,10 +211,10 @@ public Flowable apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(CompletableSubject.create() - .as(Completables.flatMapFlowable( - new Callable>() { + .to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { return Flowable.empty(); } }, @@ -234,10 +234,10 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeCompletableToFlowable(new Function>() { @Override public Flowable apply(Completable c) throws Exception { - return c.as(Completables.flatMapFlowable( - new Callable>() { + return c.to(Completables.flatMapFlowable( + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { return Flowable.empty(); } }, diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalMaybeTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalMaybeTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalMaybeTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalMaybeTest.java index 7c8d0552..88e6c030 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalMaybeTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalMaybeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.CompletableSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.CompletableSubject; public class CompletableFlatMapSignalMaybeTest { @@ -34,10 +32,10 @@ public void success() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapMaybe( - new Callable>() { + .to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[0]++; return Maybe.just(1); } @@ -63,10 +61,10 @@ public void empty() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapMaybe( - new Callable>() { + .to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[0]++; return Maybe.empty(); } @@ -92,10 +90,10 @@ public void error() { final int[] counts = { 0, 0 }; Completable.error(new TestException()) - .as(Completables.flatMapMaybe( - new Callable>() { + .to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[0]++; return Maybe.empty(); } @@ -121,10 +119,10 @@ public void normalCrash() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapMaybe( - new Callable>() { + .to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -139,7 +137,8 @@ public Maybe apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -150,10 +149,10 @@ public void errorCrash() { final int[] counts = { 0, 0 }; Completable.error(new TestException("main")) - .as(Completables.flatMapMaybe( - new Callable>() { + .to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -168,7 +167,8 @@ public Maybe apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -177,10 +177,10 @@ public Maybe apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(CompletableSubject.create() - .as(Completables.flatMapMaybe( - new Callable>() { + .to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { return Maybe.empty(); } }, @@ -200,10 +200,10 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeCompletableToMaybe(new Function>() { @Override public Maybe apply(Completable c) throws Exception { - return c.as(Completables.flatMapMaybe( - new Callable>() { + return c.to(Completables.flatMapMaybe( + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { return Maybe.empty(); } }, diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalObservableTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalObservableTest.java index 518c4efd..6396d3f4 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.CompletableSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.CompletableSubject; public class CompletableFlatMapSignalObservableTest { @@ -34,10 +32,10 @@ public void success() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapObservable( - new Callable>() { + .to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[0]++; return Observable.just(1); } @@ -63,10 +61,10 @@ public void empty() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapObservable( - new Callable>() { + .to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[0]++; return Observable.empty(); } @@ -92,10 +90,10 @@ public void error() { final int[] counts = { 0, 0 }; Completable.error(new TestException()) - .as(Completables.flatMapObservable( - new Callable>() { + .to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[0]++; return Observable.empty(); } @@ -121,10 +119,10 @@ public void normalCrash() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapObservable( - new Callable>() { + .to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -139,7 +137,8 @@ public Observable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -150,10 +149,10 @@ public void errorCrash() { final int[] counts = { 0, 0 }; Completable.error(new TestException("main")) - .as(Completables.flatMapObservable( - new Callable>() { + .to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -168,7 +167,8 @@ public Observable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -177,10 +177,10 @@ public Observable apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(CompletableSubject.create() - .as(Completables.flatMapObservable( - new Callable>() { + .to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { return Observable.empty(); } }, @@ -200,10 +200,10 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeCompletableToObservable(new Function>() { @Override public Observable apply(Completable c) throws Exception { - return c.as(Completables.flatMapObservable( - new Callable>() { + return c.to(Completables.flatMapObservable( + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { return Observable.empty(); } }, diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalSingleTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalSingleTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalSingleTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalSingleTest.java index 89cb20f5..1af5c924 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableFlatMapSignalSingleTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableFlatMapSignalSingleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.CompletableSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.CompletableSubject; public class CompletableFlatMapSignalSingleTest { @@ -34,10 +32,10 @@ public void success() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapSingle( - new Callable>() { + .to(Completables.flatMapSingle( + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[0]++; return Single.just(1); } @@ -63,10 +61,10 @@ public void error() { final int[] counts = { 0, 0 }; Completable.error(new TestException()) - .as(Completables.flatMapSingle( - new Callable>() { + .to(Completables.flatMapSingle( + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[0]++; return Single.just(1); } @@ -92,10 +90,10 @@ public void normalCrash() { final int[] counts = { 0, 0 }; Completable.complete() - .as(Completables.flatMapSingle( - new Callable>() { + .to(Completables.flatMapSingle( + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -110,7 +108,8 @@ public Single apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -121,10 +120,10 @@ public void errorCrash() { final int[] counts = { 0, 0 }; Completable.error(new TestException("main")) - .as(Completables.flatMapSingle( - new Callable>() { + .to(Completables.flatMapSingle( + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[0]++; throw new TestException("onComplete"); } @@ -139,7 +138,8 @@ public Single apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -148,10 +148,10 @@ public Single apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(CompletableSubject.create() - .as(Completables.flatMapSingle( - new Callable>() { + .to(Completables.flatMapSingle( + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { return Single.just(1); } }, @@ -171,10 +171,10 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeCompletableToSingle(new Function>() { @Override public Single apply(Completable c) throws Exception { - return c.as(Completables.flatMapSingle( - new Callable>() { + return c.to(Completables.flatMapSingle( + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { return Single.just(1); } }, diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableTransformersTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableTransformersTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletableTransformersTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletableTransformersTest.java index de0bef2f..b94b08cb 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletableTransformersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletableTransformersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class CompletableTransformersTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/CompletablesTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/CompletablesTest.java similarity index 81% rename from src/test/java/hu/akarnokd/rxjava2/operators/CompletablesTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/CompletablesTest.java index d706aa91..de882606 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/CompletablesTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/CompletablesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class CompletablesTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableBufferPredicateTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableBufferPredicateTest.java similarity index 84% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableBufferPredicateTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableBufferPredicateTest.java index 7b9846e4..5abb0030 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableBufferPredicateTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableBufferPredicateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.*; -import java.util.concurrent.Callable; +import java.util.concurrent.Flow.*; +import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Subscriber; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; public class FlowableBufferPredicateTest { - @SuppressWarnings("unchecked") @Test public void whileNormal() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -50,7 +49,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void whileNormalHidden() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6).hide() @@ -69,7 +67,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void whileNormalBackpressured() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -96,7 +93,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void whileMatchBegin() { Flowable.just(-1, 1, 2) @@ -113,7 +109,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilNormal() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -132,7 +127,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilNormalHidden() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6).hide() @@ -151,7 +145,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilNormalBackpressured() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -178,7 +171,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilMatchBegin() { Flowable.just(-1, 1, 2) @@ -195,7 +187,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void emptyWhile() { Flowable.empty() @@ -209,7 +200,6 @@ public boolean test(Integer v) throws Exception { .assertResult(); } - @SuppressWarnings("unchecked") @Test public void emptyUntil() { Flowable.empty() @@ -223,7 +213,6 @@ public boolean test(Integer v) throws Exception { .assertResult(); } - @SuppressWarnings("unchecked") @Test public void errorWhile() { Flowable.error(new IOException()) @@ -237,7 +226,6 @@ public boolean test(Integer v) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void errorUntil() { Flowable.error(new IOException()) @@ -251,7 +239,6 @@ public boolean test(Integer v) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void whileTake() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -269,7 +256,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilTake() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -287,7 +273,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void predicateCrash() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -301,7 +286,6 @@ public boolean test(Integer v) throws Exception { .assertFailure(IllegalArgumentException.class); } - @SuppressWarnings("unchecked") @Test public void bufferSupplierCrash0() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -310,9 +294,9 @@ public void bufferSupplierCrash0() { public boolean test(Integer v) throws Exception { return v == -1; } - }, new Callable>() { + }, new Supplier>() { @Override - public List call() throws Exception { + public List get() throws Exception { throw new IllegalArgumentException(); } })) @@ -320,7 +304,6 @@ public List call() throws Exception { .assertFailure(IllegalArgumentException.class); } - @SuppressWarnings("unchecked") @Test public void bufferSupplierCrash1() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -329,21 +312,20 @@ public void bufferSupplierCrash1() { public boolean test(Integer v) throws Exception { return v == -1; } - }, new Callable>() { + }, new Supplier>() { int c; @Override - public List call() throws Exception { + public List get() throws Exception { if (c++ == 1) { throw new IllegalArgumentException(); } - return new ArrayList(); + return new ArrayList<>(); } })) .test() .assertFailure(IllegalArgumentException.class, Arrays.asList(1, 2, -1)); } - @SuppressWarnings("unchecked") @Test public void bufferSupplierCrash2() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -352,21 +334,20 @@ public void bufferSupplierCrash2() { public boolean test(Integer v) throws Exception { return v != -1; } - }, new Callable>() { + }, new Supplier>() { int c; @Override - public List call() throws Exception { + public List get() throws Exception { if (c++ == 1) { throw new IllegalArgumentException(); } - return new ArrayList(); + return new ArrayList<>(); } })) .test() .assertFailure(IllegalArgumentException.class, Arrays.asList(1, 2)); } - @SuppressWarnings("unchecked") @Test public void bufferSupplierCrash3() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -375,21 +356,20 @@ public void bufferSupplierCrash3() { public boolean test(Integer v) throws Exception { return v == -1; } - }, new Callable>() { + }, new Supplier>() { int c; @Override - public List call() throws Exception { + public List get() throws Exception { if (c++ == 1) { throw new IllegalArgumentException(); } - return new ArrayList(); + return new ArrayList<>(); } })) .test() .assertFailure(IllegalArgumentException.class, Arrays.asList(1, 2)); } - @SuppressWarnings("unchecked") @Test public void doubleError() { List errors = TestHelper.trackPluginErrors(); @@ -417,7 +397,6 @@ public boolean test(Integer v) throws Exception { } } - @SuppressWarnings("unchecked") @Test public void splitNormal() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -436,7 +415,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void splitNormalHidden() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6).hide() @@ -455,7 +433,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void splitNormalBackpressured() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -482,7 +459,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void splitMatchBegin() { Flowable.just(-1, 1, 2) @@ -498,4 +474,52 @@ public boolean test(Integer v) throws Exception { Arrays.asList(1, 2) ); } + + @Test + public void untilAlways() { + Flowable.range(1, 5) + .compose(FlowableTransformers.bufferUntil(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return true; + } + })) + .test(0) + .assertEmpty() + .requestMore(1) + .assertValuesOnly(Arrays.asList(1)) + .requestMore(2) + .assertValuesOnly( + Arrays.asList(1), + Arrays.asList(2), + Arrays.asList(3) + ) + .requestMore(2) + .assertResult( + Arrays.asList(1), + Arrays.asList(2), + Arrays.asList(3), + Arrays.asList(4), + Arrays.asList(5) + ) + ; + } + + @Test + public void untilAlways2() { + Flowable.range(1, 1000) + .compose(FlowableTransformers.bufferUntil(new Predicate() { + @Override + public boolean test(Integer v) throws Exception { + return true; + } + })) + .flatMap(new Function, Publisher>() { + @Override + public Publisher apply(List v) throws Throwable { + return Flowable.timer(10, TimeUnit.MILLISECONDS); + } + }) + .blockingLast(); + } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableCacheLastTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableCacheLastTest.java similarity index 87% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableCacheLastTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableCacheLastTest.java index 389dd70e..59b1032e 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableCacheLastTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableCacheLastTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.Consumer; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableCacheLastTest implements Consumer { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableCoalesceTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableCoalesceTest.java similarity index 86% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableCoalesceTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableCoalesceTest.java index 171374e7..f5924685 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableCoalesceTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableCoalesceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.*; -import java.util.concurrent.Callable; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.BiConsumer; -import io.reactivex.internal.functions.Functions; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableCoalesceTest { - Callable> listSupplier = Functions.createArrayList(16); + Supplier> listSupplier = Functions.createArrayList(16); BiConsumer, Integer> listAdd = new BiConsumer, Integer>() { @Override @@ -59,7 +58,6 @@ public void accept(List a, Integer b) throws Exception { }; @Test - @SuppressWarnings("unchecked") public void empty() { Flowable.empty() .compose(FlowableTransformers.coalesce(listSupplier, listAdd)) @@ -77,7 +75,6 @@ public void never() { } @Test - @SuppressWarnings("unchecked") public void error() { Flowable.error(new IOException()) .compose(FlowableTransformers.coalesce(listSupplier, listAdd)) @@ -86,7 +83,6 @@ public void error() { } @Test - @SuppressWarnings("unchecked") public void coalescerCrash() { Flowable.just(1) .compose(FlowableTransformers.coalesce(listSupplier, listAddCrash)) @@ -95,7 +91,6 @@ public void coalescerCrash() { } @Test - @SuppressWarnings("unchecked") public void range() { Flowable.range(1, 5) .compose(FlowableTransformers.coalesce(listSupplier, listAdd)) @@ -104,7 +99,6 @@ public void range() { } @Test - @SuppressWarnings("unchecked") public void take() { Flowable.range(1, 5) .compose(FlowableTransformers.coalesce(listSupplier, listAdd)) @@ -114,7 +108,6 @@ public void take() { } @Test - @SuppressWarnings("unchecked") public void rangeBackpressured() { Flowable.range(1, 5) .compose(FlowableTransformers.coalesce(listSupplier, listAdd)) @@ -125,7 +118,6 @@ public void rangeBackpressured() { } @Test - @SuppressWarnings("unchecked") public void rangeBackpressuredMixed() { Flowable.range(1, 5) .compose(FlowableTransformers.coalesce(listSupplier, listAdd)) @@ -136,7 +128,6 @@ public void rangeBackpressuredMixed() { } @Test - @SuppressWarnings("unchecked") public void onNextRequestRace() { for (int i = 0; i < 1000; i++) { final PublishProcessor pp = PublishProcessor.create(); @@ -168,7 +159,6 @@ public void run() { } @Test - @SuppressWarnings("unchecked") public void slowPathQueueUse() { final PublishProcessor pp = PublishProcessor.create(); @@ -191,7 +181,6 @@ public void onNext(List t) { } @Test - @SuppressWarnings("unchecked") public void slowPathQueueUseCrash() { final PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableDebounceFirstTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableDebounceFirstTest.java similarity index 91% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableDebounceFirstTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableDebounceFirstTest.java index 3696e49a..3e9e2e60 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableDebounceFirstTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableDebounceFirstTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableDebounceFirstTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableErrorJumpTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableErrorJumpTest.java similarity index 91% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableErrorJumpTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableErrorJumpTest.java index f436ddd2..eb852180 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableErrorJumpTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableErrorJumpTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.*; +import java.util.concurrent.Flow.Publisher; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableErrorJumpTest { @@ -68,7 +68,6 @@ public Publisher apply(Flowable v) { } @Test - @SuppressWarnings("unchecked") public void errorJump() { Flowable.range(1, 5) .concatWith(Flowable.error(new TestException())) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableEveryTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableEveryTest.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableEveryTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableEveryTest.java index 984a56c3..76a9124b 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableEveryTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableEveryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; +import io.reactivex.rxjava4.core.Flowable; public class FlowableEveryTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableExpandTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableExpandTest.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableExpandTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableExpandTest.java index dd3620b7..f6651119 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableExpandTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableExpandTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; + +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.*; -import org.reactivestreams.*; +import org.junit.jupiter.api.*; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.Functions; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableExpandTest { @@ -107,14 +109,13 @@ public void recursiveCountdown() { .compose(FlowableTransformers.expand(countDown, strategy)) .test() .withTag(tag) - .assertSubscribed() .assertNoErrors() .assertComplete() .assertValueCount(i + 1); List list = ts.values(); for (int j = 0; j <= i; j++) { - Assert.assertEquals(tag + ", " + list, i - j, list.get(j).intValue()); + assertEquals(i - j, list.get(j).intValue(), tag + ", " + list); } } } @@ -188,7 +189,7 @@ static final class Node { Node(String name, Node... nodes) { this.name = name; - this.children = new ArrayList(); + this.children = new ArrayList<>(); for (Node n : nodes) { children.add(n); } @@ -248,7 +249,8 @@ Node createTest() { ); } - @Test(timeout = 5000) + @Test + @Timeout(5) public void depthFirst() { Node root = createTest(); @@ -276,7 +278,8 @@ public String apply(Node v) throws Exception { ); } - @Test(timeout = 5000) + @Test + @Timeout(5) public void depthFirstAsync() { Node root = createTest(); @@ -305,7 +308,8 @@ public String apply(Node v) throws Exception { ); } - @Test(timeout = 5000) + @Test + @Timeout(5) public void breadthFirst() { Node root = createTest(); @@ -332,7 +336,8 @@ public String apply(Node v) throws Exception { ); } - @Test(timeout = 5000) + @Test + @Timeout(5) public void breadthFirstAsync() { Node root = createTest(); @@ -365,7 +370,7 @@ public void depthFirstCancel() { final PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = new TestSubscriber(); + final TestSubscriber ts = new TestSubscriber<>(); FlowableSubscriber s = new FlowableSubscriber() { @@ -400,7 +405,7 @@ public void onComplete() { .compose(FlowableTransformers.expand(Functions.justFunction(pp), ExpandStrategy.DEPTH_FIRST)) .subscribe(s); - Assert.assertFalse(pp.hasSubscribers()); + assertFalse(pp.hasSubscribers()); ts.assertResult(1); } @@ -518,7 +523,7 @@ public void run() { source.subscribe(ts); - Assert.assertTrue(cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS)); } } @@ -539,7 +544,9 @@ public Publisher apply(Integer v) } }, ExpandStrategy.DEPTH_FIRST)) .test() - .assertFailureAndMessage(IOException.class, "error", 10, 9); + .assertFailure(IOException.class, 10, 9) + .assertError(TestHelper.assertErrorMessage("error")); + ; } @Test @@ -559,7 +566,8 @@ public Publisher apply(Integer v) } }, ExpandStrategy.DEPTH_FIRST)) .test() - .assertFailureAndMessage(IOException.class, "error", 10, 9, 5, 4, 3, 2, 1, 0); + .assertFailure(IOException.class, 10, 9, 5, 4, 3, 2, 1, 0) + .assertError(TestHelper.assertErrorMessage("error")); } @Test @@ -579,7 +587,9 @@ public Publisher apply(Integer v) } }, ExpandStrategy.BREADTH_FIRST)) .test() - .assertFailureAndMessage(IOException.class, "error", 10, 5, 9, 4); + .assertFailure(IOException.class, 10, 5, 9, 4) + .assertError(TestHelper.assertErrorMessage("error")); + ; } @Test @@ -599,6 +609,7 @@ public Publisher apply(Integer v) } }, ExpandStrategy.BREADTH_FIRST)) .test() - .assertFailureAndMessage(IOException.class, "error", 10, 5, 9, 4, 3, 2, 1, 0); + .assertFailure(IOException.class, 10, 5, 9, 4, 3, 2, 1, 0) + .assertError(TestHelper.assertErrorMessage("error")); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableFilterAsyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableFilterAsyncTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableFilterAsyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableFilterAsyncTest.java index ba5e056f..c0d8c367 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableFilterAsyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableFilterAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; + +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; -import org.junit.*; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.basetypes.Solo; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.basetypes.Solo; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableFilterAsyncTest { @@ -370,7 +371,7 @@ public Publisher apply(Integer v) throws Exception { .test() .cancel(); - Assert.assertFalse(pp.hasSubscribers()); + assertFalse(pp.hasSubscribers()); } @Test @@ -394,7 +395,7 @@ public Publisher apply(Integer v) throws Exception { .test() .assertResult(); - Assert.assertEquals(1000, calls[0]); + assertEquals(1000, calls[0]); } @Test @@ -418,6 +419,6 @@ public Publisher apply(Integer v) throws Exception { .test() .assertResult(); - Assert.assertEquals(1000, calls[0]); + assertEquals(1000, calls[0]); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapAsyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapAsyncTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapAsyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapAsyncTest.java index 3ffd9b8f..bae26531 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapAsyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.*; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableFlatMapAsyncTest { - @Test(timeout = 10000) + @Test + @Timeout(10) public void normal() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -45,7 +46,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void normalHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -63,7 +65,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void normalAsync() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -81,7 +84,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void normalAsyncHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -99,7 +103,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 1000000) + @Test + @Timeout(100) public void normalAsyncHidden2() { for (int m = 1; m < 1011; m = m < 16 ? m + 1 : m + 10) { // System.out.println(m); @@ -121,7 +126,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadth() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -139,7 +145,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadthHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -157,7 +164,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadthAsync() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -175,7 +183,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadthAsyncHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -213,7 +222,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 60000) + @Test + @Timeout(60) public void breadthAsyncHidden2() { for (int m = 1; m < 1011; m = m < 16 ? m + 1 : m + 10) { // System.out.println(m); diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapSyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapSyncTest.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapSyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapSyncTest.java index e153a1ac..2a8fae0e 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableFlatMapSyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableFlatMapSyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,21 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.*; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableFlatMapSyncTest { - @Test(timeout = 10000) + @Test + @Timeout(10) public void normal() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -44,7 +45,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void normalHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -61,7 +63,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void normalAsync() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -79,7 +82,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void normalAsyncHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -97,7 +101,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 1000000) + @Test + @Timeout(100) public void normalAsyncHidden2() { for (int m = 1; m < 1011; m = m < 16 ? m + 1 : m + 10) { // System.out.println(m); @@ -119,7 +124,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadth() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -136,7 +142,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadthHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -153,7 +160,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadthAsync() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -171,7 +179,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 10000) + @Test + @Timeout(10) public void breadthAsyncHidden() { for (final int n : new int[] { 0, 1, 2, 10, 100, 1000 }) { Flowable.range(1, 1000) @@ -189,7 +198,8 @@ public Publisher apply(Integer v) throws Exception { } } - @Test(timeout = 1000000) + @Test + @Timeout(60) public void breadthAsyncHidden2() { for (int m = 1; m < 1011; m = m < 16 ? m + 1 : m + 10) { // System.out.println(m); diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableGenerateAsyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableGenerateAsyncTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableGenerateAsyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableGenerateAsyncTest.java index ca2c23b1..d36ab0be 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableGenerateAsyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableGenerateAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.operators.FlowableGenerateAsync.AtomicCancellable; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.operators.FlowableGenerateAsync.AtomicCancellable; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Completable; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableGenerateAsyncTest { @@ -80,7 +80,7 @@ public Completable nextValue(final Consumer onValue) { index = i + 1; return Completable.fromAction(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { onValue.accept(i); } }) @@ -93,37 +93,37 @@ public void run() throws Exception { public void simple() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return new SyncRange(1, 5); } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { Completable c = state.nextValue(new Consumer() { @Override - public void accept(Integer v) throws Exception { + public void accept(Integer v) throws Throwable { emitter.onNext(v); } }); final Disposable d = c.subscribe(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { emitter.onComplete(); } }, new Consumer() { @Override - public void accept(Throwable e) throws Exception { + public void accept(Throwable e) throws Throwable { emitter.onError(e); } }); emitter.replaceCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { d.dispose(); } }); @@ -133,7 +133,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -148,19 +148,19 @@ public void accept(SyncRange state) throws Exception { public void simpleEven() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return new SyncRange(1, 12); } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { Completable c = state.nextValue(new Consumer() { @Override - public void accept(Integer v) throws Exception { + public void accept(Integer v) throws Throwable { if (v % 2 == 0) { emitter.onNext(v); } else if (v == 11) { @@ -173,18 +173,18 @@ public void accept(Integer v) throws Exception { final Disposable d = c.subscribe(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { emitter.onComplete(); } }, new Consumer() { @Override - public void accept(Throwable e) throws Exception { + public void accept(Throwable e) throws Throwable { emitter.onError(e); } }); emitter.replaceCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { d.dispose(); } }); @@ -194,7 +194,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -209,37 +209,37 @@ public void accept(SyncRange state) throws Exception { public void error() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return new SyncRange(1, 12); } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { Completable c = state.nextValue(new Consumer() { @Override - public void accept(Integer v) throws Exception { + public void accept(Integer v) throws Throwable { emitter.onError(new TestException()); } }); final Disposable d = c.subscribe(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { emitter.onComplete(); } }, new Consumer() { @Override - public void accept(Throwable e) throws Exception { + public void accept(Throwable e) throws Throwable { emitter.onError(e); } }); emitter.replaceCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { d.dispose(); } }); @@ -249,7 +249,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -263,43 +263,43 @@ public void accept(SyncRange state) throws Exception { @Test public void take() { final AtomicBoolean cancelled1 = new AtomicBoolean(); - final AtomicReference> emitterRef = new AtomicReference>(); + final AtomicReference> emitterRef = new AtomicReference<>(); final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return new SyncRange(1, 5); } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { cancelled1.set(emitter.isCancelled()); emitterRef.set(emitter); Completable c = state.nextValue(new Consumer() { @Override - public void accept(Integer v) throws Exception { + public void accept(Integer v) throws Throwable { emitter.onNext(v); } }); final Disposable d = c.subscribe(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { emitter.onComplete(); } }, new Consumer() { @Override - public void accept(Throwable e) throws Exception { + public void accept(Throwable e) throws Throwable { emitter.onError(e); } }); emitter.replaceCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { d.dispose(); } }); @@ -309,7 +309,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -330,23 +330,23 @@ public void initialStateCrash() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { throw new TestException(); } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { generator.incrementAndGet(); return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -359,7 +359,7 @@ public void accept(SyncRange state) throws Exception { } @Test - public void cancelledCancel() throws Exception { + public void cancelledCancel() throws Throwable { FlowableGenerateAsync.AtomicCancellable.CANCELLED.cancel(); } @@ -370,19 +370,19 @@ public void cancellableCrash() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.setCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { throw new TestException(); } }); @@ -392,7 +392,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -413,23 +413,23 @@ public void cleanupCrash() { List errors = TestHelper.trackPluginErrors(); try { Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onComplete(); return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { throw new TestException(); } } @@ -448,22 +448,22 @@ public void generatorCrash() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { throw new TestException(); } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -481,16 +481,16 @@ public void doubleOnError() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onError(new TestException("One")); emitter.onError(new TestException("Two")); return state; @@ -498,13 +498,14 @@ public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emit }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } ) .test() - .assertFailureAndMessage(TestException.class, "One"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("One")); assertEquals(1, cleanup.get()); @@ -519,22 +520,22 @@ public void never() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -550,23 +551,23 @@ public void onNextAlreadyAvailable() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onNext(1); return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -587,16 +588,16 @@ public void onNextAlreadyAvailableAndComplete() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onNext(1); emitter.onComplete(); return state; @@ -604,7 +605,7 @@ public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emit }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -622,16 +623,16 @@ public void onNothingAndComplete() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { // in practice, there could be a request being serviced while // the following emitter.onNothing() is executing // after which the complete tags the state with it's done indicator @@ -642,7 +643,7 @@ public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emit }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -658,23 +659,23 @@ public void empty() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onComplete(); return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -694,7 +695,7 @@ public void atomicCancellableSetCancelled() { ac.setCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { calls.incrementAndGet(); } }); @@ -707,12 +708,12 @@ public void setCancelRace() { final AtomicCancellable ac = new AtomicCancellable(); final Cancellable c1 = new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { } }; final Cancellable c2 = new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { } }; @@ -745,37 +746,37 @@ public void run() { public void backpressured() { final AtomicInteger cleanup = new AtomicInteger(); TestSubscriber ts = Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return new SyncRange(1, 1024); } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { Completable c = state.nextValue(new Consumer() { @Override - public void accept(Integer v) throws Exception { + public void accept(Integer v) throws Throwable { emitter.onNext(v); } }); final Disposable d = c.subscribe(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { emitter.onComplete(); } }, new Consumer() { @Override - public void accept(Throwable e) throws Exception { + public void accept(Throwable e) throws Throwable { emitter.onError(e); } }); emitter.replaceCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { d.dispose(); } }); @@ -785,7 +786,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -810,37 +811,37 @@ public void accept(SyncRange state) throws Exception { public void asyncBbackpressured() { final AtomicInteger cleanup = new AtomicInteger(); TestSubscriber ts = Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public AsyncRange call() throws Exception { + public AsyncRange get() throws Throwable { return new AsyncRange(1, 256); } }, new BiFunction, AsyncRange>() { @Override public AsyncRange apply(AsyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { Completable c = state.nextValue(new Consumer() { @Override - public void accept(Integer v) throws Exception { + public void accept(Integer v) throws Throwable { emitter.onNext(v); } }); final Disposable d = c.subscribe(new Action() { @Override - public void run() throws Exception { + public void run() throws Throwable { emitter.onComplete(); } }, new Consumer() { @Override - public void accept(Throwable e) throws Exception { + public void accept(Throwable e) throws Throwable { emitter.onError(e); } }); emitter.replaceCancellable(new Cancellable() { @Override - public void cancel() throws Exception { + public void cancel() throws Throwable { d.dispose(); } }); @@ -850,7 +851,7 @@ public void cancel() throws Exception { }, new Consumer() { @Override - public void accept(AsyncRange state) throws Exception { + public void accept(AsyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -878,23 +879,23 @@ public void nullItem() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onNext(null); return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } @@ -910,23 +911,23 @@ public void nullThrowable() { final AtomicInteger cleanup = new AtomicInteger(); Flowables.generateAsync( - new Callable() { + new Supplier() { @Override - public SyncRange call() throws Exception { + public SyncRange get() throws Throwable { return null; } }, new BiFunction, SyncRange>() { @Override public SyncRange apply(SyncRange state, final FlowableAsyncEmitter emitter) - throws Exception { + throws Throwable { emitter.onError(null); return state; } }, new Consumer() { @Override - public void accept(SyncRange state) throws Exception { + public void accept(SyncRange state) throws Throwable { cleanup.incrementAndGet(); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableIndexOfTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableIndexOfTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableIndexOfTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableIndexOfTest.java index 3f4c9fdf..322fd9b4 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableIndexOfTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableIndexOfTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; +import java.util.concurrent.Flow.Subscriber; -import org.junit.Test; -import org.reactivestreams.Subscriber; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscriptions.BooleanSubscription; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Predicate; public class FlowableIndexOfTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableIntervalBackpressureTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableIntervalBackpressureTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableIntervalBackpressureTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableIntervalBackpressureTest.java index 422b0511..b0fee2b2 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableIntervalBackpressureTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableIntervalBackpressureTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableIntervalBackpressureTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapAsyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapAsyncTest.java similarity index 95% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapAsyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapAsyncTest.java index 380740e2..601a26f2 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapAsyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; + +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; -import org.junit.*; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.basetypes.*; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.basetypes.Perhaps; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableMapAsyncTest { @@ -321,7 +322,7 @@ public Publisher apply(Integer v) throws Exception { .test() .cancel(); - Assert.assertFalse(pp.hasSubscribers()); + assertFalse(pp.hasSubscribers()); } @Test @@ -447,6 +448,6 @@ public Publisher apply(Integer v) throws Exception { .test() .assertResult(); - Assert.assertEquals(1000, calls[0]); + assertEquals(1000, calls[0]); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapFilterConditionalTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapFilterConditionalTest.java similarity index 87% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapFilterConditionalTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapFilterConditionalTest.java index a7b3e0a7..5c3867f7 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapFilterConditionalTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapFilterConditionalTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,21 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.BiConsumer; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.QueueFuseable; -import io.reactivex.processors.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.BiConsumer; +import io.reactivex.rxjava4.operators.QueueFuseable; +import io.reactivex.rxjava4.processors.*; public class FlowableMapFilterConditionalTest { @@ -234,7 +233,7 @@ public void accept(Integer t, BasicEmitter e) throws Exception { @Test public void mapFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -246,13 +245,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(2, 4, 6, 8, 10); } @Test public void mapAsyncFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -267,13 +266,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.ASYNC)) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(2, 4, 6, 8, 10); } @Test public void filterFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -287,13 +286,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(4, 8); } @Test public void consumerThrowsFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -305,13 +304,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertFailure(IOException.class); } @Test public void consumerSignalsErrorFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -323,13 +322,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertFailure(IOException.class); } @Test public void consumerCompleteFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -341,7 +340,7 @@ public void accept(Integer t, BasicEmitter e) throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(); } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapFilterTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapFilterTest.java similarity index 87% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapFilterTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapFilterTest.java index ad96f372..45aafeb3 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableMapFilterTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableMapFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,20 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.BiConsumer; -import io.reactivex.internal.fuseable.QueueFuseable; -import io.reactivex.processors.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.BiConsumer; +import io.reactivex.rxjava4.operators.QueueFuseable; +import io.reactivex.rxjava4.processors.*; public class FlowableMapFilterTest { @@ -220,7 +219,7 @@ public void accept(Integer t, BasicEmitter e) throws Exception { @Test public void mapFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -231,13 +230,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { })) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(2, 4, 6, 8, 10); } @Test public void mapAsyncFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -251,13 +250,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { })) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.ASYNC)) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(2, 4, 6, 8, 10); } @Test public void filterFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -270,13 +269,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { })) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(4, 8); } @Test public void consumerThrowsFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -287,13 +286,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { })) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertFailure(IOException.class); } @Test public void consumerSignalsErrorFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -304,13 +303,13 @@ public void accept(Integer t, BasicEmitter e) throws Exception { })) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertFailure(IOException.class); } @Test public void consumerCompleteFused() { - TestSubscriber ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); + TestSubscriberEx ts = TestHelper.fusedSubscriber(QueueFuseable.ANY); Flowable.range(1, 5) .compose(FlowableTransformers.mapFilter(new BiConsumer>() { @@ -321,7 +320,7 @@ public void accept(Integer t, BasicEmitter e) throws Exception { })) .subscribe(ts); - ts.assertOf(TestHelper.assertFusedSubscriber(QueueFuseable.SYNC)) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(); } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeoutTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableOnBackpressureTimeoutTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeoutTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableOnBackpressureTimeoutTest.java index d8e8a602..dd837552 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableOnBackpressureTimeoutTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableOnBackpressureTimeoutTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,27 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; + +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; -import org.junit.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.Consumer; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Consumer; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableOnBackpressureTimeoutTest implements Consumer { - final List evicted = Collections.synchronizedList(new ArrayList()); + final List evicted = Collections.synchronizedList(new ArrayList<>()); @Override public void accept(Object t) throws Exception { @@ -146,7 +148,7 @@ public void bufferLimit() { .requestMore(1) .assertResult(5); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4), evicted); + assertEquals(Arrays.asList(1, 2, 3, 4), evicted); } @Test @@ -188,7 +190,7 @@ public void timeoutLimit() { .requestMore(1) .assertResult(5); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4), evicted); + assertEquals(Arrays.asList(1, 2, 3, 4), evicted); } @Test @@ -208,7 +210,7 @@ public void cancelEvictAll() { ts.cancel(); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted); } @Test @@ -225,7 +227,7 @@ public void timeoutEvictAll() { .requestMore(1) .assertResult(); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted); } @Test @@ -234,7 +236,7 @@ public void evictCancels() { PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = new TestSubscriber(0L); + final TestSubscriber ts = new TestSubscriber<>(0L); pp .compose(FlowableTransformers.onBackpressureTimeout(10, 1, TimeUnit.SECONDS, scheduler, new Consumer() { @@ -250,7 +252,7 @@ public void accept(Integer e) throws Exception { scheduler.advanceTimeBy(1, TimeUnit.MINUTES); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted); + assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted); } @Test @@ -261,7 +263,7 @@ public void evictThrows() { PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = new TestSubscriber(0L); + final TestSubscriber ts = new TestSubscriber<>(0L); pp .compose(FlowableTransformers.onBackpressureTimeout(10, 1, TimeUnit.SECONDS, scheduler, new Consumer() { @@ -311,6 +313,6 @@ public void example() { .awaitDone(5, TimeUnit.SECONDS) .assertResult(); - Assert.assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L), evicted); + assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L), evicted); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableOrderedMergeTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableOrderedMergeTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableOrderedMergeTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableOrderedMergeTest.java index 932b2621..404a5361 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableOrderedMergeTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableOrderedMergeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableOrderedMergeTest { - @SuppressWarnings("unchecked") @Test public void normal1() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -40,7 +39,6 @@ public void normal1() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void normal2() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -49,7 +47,6 @@ public void normal2() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8); } - @SuppressWarnings("unchecked") @Test public void normal3() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -58,7 +55,6 @@ public void normal3() { .assertResult(1, 2, 3, 4, 5, 6, 7); } - @SuppressWarnings("unchecked") @Test public void normal4() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -67,7 +63,6 @@ public void normal4() { .assertResult(1, 1, 3, 3, 5, 5, 7, 7); } - @SuppressWarnings("unchecked") @Test public void normal1Hidden() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -76,7 +71,6 @@ public void normal1Hidden() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void normal2Hidden() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -85,7 +79,6 @@ public void normal2Hidden() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8); } - @SuppressWarnings("unchecked") @Test public void normal3Hidden() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -94,7 +87,6 @@ public void normal3Hidden() { .assertResult(1, 2, 3, 4, 5, 6, 7); } - @SuppressWarnings("unchecked") @Test public void normal4Hidden() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -103,7 +95,6 @@ public void normal4Hidden() { .assertResult(1, 1, 3, 3, 5, 5, 7, 7); } - @SuppressWarnings("unchecked") @Test public void backpressure1() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -113,7 +104,6 @@ public void backpressure1() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8); } - @SuppressWarnings("unchecked") @Test public void backpressure2() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -123,7 +113,6 @@ public void backpressure2() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void backpressure3() { Flowables.orderedMerge(Functions.naturalComparator(), false, 1, @@ -133,7 +122,6 @@ public void backpressure3() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8); } - @SuppressWarnings("unchecked") @Test public void take() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -143,7 +131,6 @@ public void take() { .assertResult(1, 2, 3, 4, 5); } - @SuppressWarnings("unchecked") @Test public void firstErrors() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -153,7 +140,6 @@ public void firstErrors() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void firstErrorsBackpressured() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -163,7 +149,6 @@ public void firstErrorsBackpressured() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void secondErrors() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -174,7 +159,6 @@ public void secondErrors() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void secondErrorsBackpressured() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -185,7 +169,6 @@ public void secondErrorsBackpressured() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void bothError() { List errors = TestHelper.trackPluginErrors(); @@ -195,7 +178,8 @@ public void bothError() { Flowable.error(new IOException("second")) ) .test() - .assertFailureAndMessage(IOException.class, "first"); + .assertFailure(IOException.class) + .assertError(TestHelper.assertErrorMessage("first")); TestHelper.assertUndeliverable(errors, 0, IOException.class, "second"); } finally { @@ -203,7 +187,6 @@ public void bothError() { } } - @SuppressWarnings("unchecked") @Test public void bothErrorDelayed() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -213,18 +196,18 @@ public void bothErrorDelayed() { ) .test() .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { + .assertError(new Predicate() { @Override - public void accept(TestSubscriber ts) throws Exception { - List list = TestHelper.compositeList(ts.errors().get(0)); + public boolean test(Throwable error) throws Throwable { + List list = TestHelper.compositeList(error); TestHelper.assertError(list, 0, IOException.class, "first"); TestHelper.assertError(list, 1, IOException.class, "second"); + return true; } }); } - @SuppressWarnings("unchecked") @Test public void bothErrorDelayedBackpressured() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -234,18 +217,18 @@ public void bothErrorDelayedBackpressured() { ) .test(0L) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { + .assertError(new Predicate() { @Override - public void accept(TestSubscriber ts) throws Exception { - List list = TestHelper.compositeList(ts.errors().get(0)); + public boolean test(Throwable error) throws Throwable { + List list = TestHelper.compositeList(error); TestHelper.assertError(list, 0, IOException.class, "first"); TestHelper.assertError(list, 1, IOException.class, "second"); + return true; } }); } - @SuppressWarnings("unchecked") @Test public void nonEmptyBothErrorDelayed() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -255,18 +238,18 @@ public void nonEmptyBothErrorDelayed() { ) .test() .assertFailure(CompositeException.class, 1, 2) - .assertOf(new Consumer>() { + .assertError(new Predicate() { @Override - public void accept(TestSubscriber ts) throws Exception { - List list = TestHelper.compositeList(ts.errors().get(0)); + public boolean test(Throwable error) throws Throwable { + List list = TestHelper.compositeList(error); TestHelper.assertError(list, 0, IOException.class, "first"); TestHelper.assertError(list, 1, IOException.class, "second"); + return true; } }); } - @SuppressWarnings("unchecked") @Test public void nonEmptyBothErrorDelayed2() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -277,33 +260,28 @@ public void nonEmptyBothErrorDelayed2() { .rebatchRequests(1) .test() .assertFailure(CompositeException.class, 1, 2) - .assertOf(new Consumer>() { + .assertError(new Predicate() { @Override - public void accept(TestSubscriber ts) throws Exception { - List list = TestHelper.compositeList(ts.errors().get(0)); + public boolean test(Throwable error) throws Throwable { + List list = TestHelper.compositeList(error); TestHelper.assertError(list, 0, IOException.class, "first"); TestHelper.assertError(list, 1, IOException.class, "second"); + return true; } }); } - @SuppressWarnings("unchecked") @Test public void never() { - Flowables.orderedMerge(Functions.naturalComparator(), + TestSubscriber ts = Flowables.orderedMerge(Functions.naturalComparator(), Flowable.never(), Flowable.never()) - .test() - .assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - ts.cancel(); - } - }) - .assertEmpty(); + .test(); + + ts.cancel(); + ts.assertEmpty(); } - @SuppressWarnings("unchecked") @Test public void fusedThrowsInDrainLoop() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -318,7 +296,6 @@ public Integer apply(Integer v) throws Exception { .assertFailure(IllegalArgumentException.class); } - @SuppressWarnings("unchecked") @Test public void fusedThrowsInDrainLoopDelayed() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -334,7 +311,6 @@ public Integer apply(Integer v) throws Exception { .assertFailure(IllegalArgumentException.class, 2, 3); } - @SuppressWarnings("unchecked") @Test public void fusedThrowsInPostEmissionCheck() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -349,7 +325,6 @@ public Integer apply(Integer v) throws Exception { .assertFailure(IllegalArgumentException.class); } - @SuppressWarnings("unchecked") @Test public void fusedThrowsInPostEmissionCheckErrorDelayed() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -366,7 +341,6 @@ public Integer apply(Integer v) throws Exception { .assertFailure(IllegalArgumentException.class, 2, 3); } - @SuppressWarnings("unchecked") @Test public void iterable() { Flowables.orderedMerge(Arrays.asList(Flowable.just(1, 3, 5, 7), Flowable.just(2, 4, 6, 8)), @@ -385,7 +359,6 @@ public void iterableEmpty() { .assertResult(); } - @SuppressWarnings("unchecked") @Test public void iterableSingleton() { Flowables.orderedMerge(Arrays.asList(Flowable.just(1, 3, 5, 7)), @@ -395,7 +368,6 @@ public void iterableSingleton() { .assertResult(1, 3, 5, 7); } - @SuppressWarnings("unchecked") @Test public void iterableDelayErrors() { Flowables.orderedMerge(Arrays.asList(Flowable.just(1, 3, 5, 7), Flowable.just(2, 4, 6, 8)), @@ -405,7 +377,6 @@ public void iterableDelayErrors() { .assertResult(1, 2, 3, 4, 5, 6, 7, 8); } - @SuppressWarnings("unchecked") @Test public void iterableDelayErrorsAndPrefetch() { Flowables.orderedMerge(Arrays.asList(Flowable.just(1, 3, 5, 7), Flowable.just(2, 4, 6, 8)), @@ -417,7 +388,7 @@ public void iterableDelayErrorsAndPrefetch() { @Test public void iterableMany() { - List> sources = new ArrayList>(); + List> sources = new ArrayList<>(); for (int i = 0; i < 32; i++) { sources.add(Flowable.just(i)); @@ -433,7 +404,6 @@ public void iterableMany() { 24, 25, 26, 27, 28, 29, 30, 31); } - @SuppressWarnings("unchecked") @Test public void iterableNull() { Flowables.orderedMerge(Arrays.asList(Flowable.just(1, 3, 5, 7), null), @@ -443,7 +413,6 @@ public void iterableNull() { .assertFailure(NullPointerException.class); } - @SuppressWarnings("unchecked") @Test public void nullSecond() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -452,7 +421,6 @@ public void nullSecond() { .assertFailure(NullPointerException.class); } - @SuppressWarnings("unchecked") @Test public void nullSecondDelayErrors() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -462,7 +430,6 @@ public void nullSecondDelayErrors() { .assertFailure(NullPointerException.class, 1); } - @SuppressWarnings("unchecked") @Test public void nullFirst() { Flowables.orderedMerge(Functions.naturalComparator(), @@ -471,7 +438,6 @@ public void nullFirst() { .assertFailure(NullPointerException.class); } - @SuppressWarnings("unchecked") @Test public void comparatorThrows() { Flowables.orderedMerge(new Comparator() { @@ -485,7 +451,6 @@ public int compare(Integer a, Integer b) { .assertFailure(IllegalArgumentException.class); } - @SuppressWarnings("unchecked") @Test public void selfComparableArray() { Flowables.orderedMerge( @@ -494,7 +459,6 @@ public void selfComparableArray() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void selfComparableArrayDelayError() { Flowables.orderedMerge(true, @@ -503,7 +467,6 @@ public void selfComparableArrayDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void selfComparableArrayDelayErrorPrefetch() { Flowables.orderedMerge(true, 1, @@ -512,7 +475,6 @@ public void selfComparableArrayDelayErrorPrefetch() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void selfComparableIterable() { Flowables.orderedMerge( @@ -521,7 +483,6 @@ public void selfComparableIterable() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void selfComparableIterableDelayError() { Flowables.orderedMerge( @@ -532,7 +493,6 @@ public void selfComparableIterableDelayError() { .assertResult(1, 2); } - @SuppressWarnings("unchecked") @Test public void selfComparableIterableDelayErrorPrefetch() { Flowables.orderedMerge( diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowablePartialCollectTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowablePartialCollectTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowablePartialCollectTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowablePartialCollectTest.java index 0f888fa1..50147e82 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowablePartialCollectTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowablePartialCollectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,26 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.List; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.Flowable; -import io.reactivex.exceptions.MissingBackpressureException; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.core.config.StandardBufferedConfig; +import io.reactivex.rxjava4.exceptions.MissingBackpressureException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowablePartialCollectTest { @@ -184,7 +184,8 @@ public void accept( } }, Functions.emptyConsumer(), 128)) .test() - .assertFailureAndMessage(TestException.class, "first"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("first")); TestHelper.assertUndeliverable(errors, 0, TestException.class, "second"); } finally { @@ -479,7 +480,7 @@ public void accept(String s) throws Exception { System.out.println("Item: " + s); } }) - .observeOn(Schedulers.computation(), false, 1) + .observeOn(Schedulers.computation(), new StandardBufferedConfig(false, 1)) .test() .awaitDone(10, TimeUnit.SECONDS) .assertResult( diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRepeatCallableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRepeatCallableTest.java similarity index 71% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableRepeatCallableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableRepeatCallableTest.java index d3704e7a..5eb42e1a 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRepeatCallableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRepeatCallableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; -import java.util.concurrent.Callable; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.internal.functions.Functions; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Supplier; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableRepeatCallableTest { @Test public void fastPathCrash() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { throw new IOException(); } }) @@ -41,9 +41,9 @@ public Object call() throws Exception { @Test public void slowPathCrash() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { throw new IOException(); } }) @@ -53,9 +53,9 @@ public Object call() throws Exception { @Test public void requestLimited() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { return 1; } }) @@ -76,9 +76,9 @@ public void onNext(Object t) { } }; - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { return 1; } }) @@ -89,9 +89,9 @@ public Object call() throws Exception { @Test public void fused() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { return 1; } }) @@ -103,9 +103,9 @@ public Object call() throws Exception { @Test public void fastPathCrashConditional() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { throw new IOException(); } }) @@ -116,9 +116,9 @@ public Object call() throws Exception { @Test public void slowPathCrashConditional() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { throw new IOException(); } }) @@ -129,9 +129,9 @@ public Object call() throws Exception { @Test public void requestLimitedConditional() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { return 1; } }) @@ -153,9 +153,9 @@ public void onNext(Object t) { } }; - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { return 1; } }) @@ -167,9 +167,9 @@ public Object call() throws Exception { @Test public void fusedConditional() { - Flowables.repeatCallable(new Callable() { + Flowables.repeatSupplier(new Supplier() { @Override - public Object call() throws Exception { + public Object get() throws Exception { return 1; } }) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestObserveOnTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestObserveOnTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestObserveOnTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestObserveOnTest.java index 39fb5cda..b8157841 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestObserveOnTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestObserveOnTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.internal.schedulers.ImmediateThinScheduler; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.ImmediateThinScheduler; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableRequestObserveOnTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTest.java similarity index 85% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTest.java index 48e3056b..49c9592c 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,32 +14,31 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.util.List; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.exceptions.MissingBackpressureException; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.MissingBackpressureException; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableRequestSampleTest { @Test public void normal() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .compose(FlowableTransformers.requestSample(Flowable.interval(1, TimeUnit.MILLISECONDS, Schedulers.single()))) .take(5) .test() @@ -49,7 +48,7 @@ public void normal() { @Test public void normal2() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .compose(FlowableTransformers.requestSample( Flowable.fromArray(10, 50, 100, 200, 500) .concatMap(new Function>() { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTimeTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTimeTest.java similarity index 81% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTimeTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTimeTest.java index b59aeef6..a86b40f9 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableRequestSampleTimeTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableRequestSampleTimeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,28 +14,27 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.List; +import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Subscriber; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.exceptions.MissingBackpressureException; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.MissingBackpressureException; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableRequestSampleTimeTest { @Test public void normal() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .compose(FlowableTransformers.requestSample(1, TimeUnit.MILLISECONDS, Schedulers.single())) .take(5) .test() diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSpanoutTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSpanoutTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableSpanoutTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableSpanoutTest.java index 160c9171..2c38cbb4 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSpanoutTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSpanoutTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableSpanoutTest { @@ -177,7 +177,7 @@ public void normal3() { @Test public void normal4() { Flowable.range(1, 3) - .compose(FlowableTransformers.spanout(100L, TimeUnit.MILLISECONDS, Schedulers.io())) + .compose(FlowableTransformers.spanout(100L, TimeUnit.MILLISECONDS, Schedulers.cached())) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3); @@ -186,7 +186,7 @@ public void normal4() { @Test public void normal5() { Flowable.range(1, 3) - .compose(FlowableTransformers.spanout(100L, TimeUnit.MILLISECONDS, Schedulers.io(), true)) + .compose(FlowableTransformers.spanout(100L, TimeUnit.MILLISECONDS, Schedulers.cached(), true)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3); @@ -213,7 +213,7 @@ public void normalInitial3() { @Test public void normalInitial4() { Flowable.range(1, 3) - .compose(FlowableTransformers.spanout(50L, 100L, TimeUnit.MILLISECONDS, Schedulers.io())) + .compose(FlowableTransformers.spanout(50L, 100L, TimeUnit.MILLISECONDS, Schedulers.cached())) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3); @@ -222,7 +222,7 @@ public void normalInitial4() { @Test public void normalInitial5() { Flowable.range(1, 3) - .compose(FlowableTransformers.spanout(50L, 100L, TimeUnit.MILLISECONDS, Schedulers.io(), true)) + .compose(FlowableTransformers.spanout(50L, 100L, TimeUnit.MILLISECONDS, Schedulers.cached(), true)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3); diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchFlatMapTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchFlatMapTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchFlatMapTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchFlatMapTest.java index 11e8de08..5d1aa082 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchFlatMapTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchFlatMapTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.util.List; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.*; - -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.*; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import org.junit.jupiter.api.Test; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.*; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableSwitchFlatMapTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyArrayTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyArrayTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyArrayTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyArrayTest.java index 438cd1fb..879629b3 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyArrayTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyArrayTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.Arrays; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.Test; -import io.reactivex.*; -import io.reactivex.schedulers.Schedulers; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableSwitchIfEmptyManyArrayTest { - @SuppressWarnings("unchecked") @Test public void normalNonEmpty() { Flowable.range(1, 5) @@ -55,7 +54,6 @@ public void nullAlternative() { .assertFailure(NullPointerException.class); } - @SuppressWarnings("unchecked") @Test public void normalNonEmptyBackpressured() { Flowable.range(1, 5) @@ -167,7 +165,6 @@ public void normalBackpressured2() { } } - @SuppressWarnings("unchecked") @Test public void take() { Flowable.range(1, 5) @@ -177,7 +174,6 @@ public void take() { .assertResult(1, 2, 3); } - @SuppressWarnings("unchecked") @Test public void take2() { Flowable.empty() @@ -187,7 +183,6 @@ public void take2() { .assertResult(10, 11, 12); } - @SuppressWarnings("unchecked") @Test public void cancel() { Flowable.range(1, 5) @@ -196,7 +191,6 @@ public void cancel() { .assertEmpty(); } - @SuppressWarnings("unchecked") @Test public void emptyEmpty() { Flowable.empty() diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyTest.java index 93926da0..2fe3e97f 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchIfEmptyManyTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchIfEmptyManyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,21 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.*; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.schedulers.Schedulers; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableSwitchIfEmptyManyTest { - @SuppressWarnings("unchecked") @Test public void normalNonEmpty() { Flowable.range(1, 5) @@ -37,7 +36,6 @@ public void normalNonEmpty() { .assertResult(1, 2, 3, 4, 5); } - @SuppressWarnings("unchecked") @Test public void error() { Flowable.error(new IOException()) @@ -46,7 +44,6 @@ public void error() { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void nullAlternative() { Flowable.empty() @@ -55,7 +52,6 @@ public void nullAlternative() { .assertFailure(NullPointerException.class); } - @SuppressWarnings("unchecked") @Test public void normalNonEmptyBackpressured() { Flowable.range(1, 5) @@ -65,7 +61,6 @@ public void normalNonEmptyBackpressured() { .assertResult(1, 2, 3, 4, 5); } - @SuppressWarnings("unchecked") @Test public void normalNonEmptyBackpressured2() { Flowable.range(1, 5) @@ -165,7 +160,6 @@ public void normalBackpressured2() { } } - @SuppressWarnings("unchecked") @Test public void take() { Flowable.range(1, 5) @@ -175,7 +169,6 @@ public void take() { .assertResult(1, 2, 3); } - @SuppressWarnings("unchecked") @Test public void take2() { Flowable.empty() @@ -185,7 +178,6 @@ public void take2() { .assertResult(10, 11, 12); } - @SuppressWarnings("unchecked") @Test public void cancel() { Flowable.range(1, 5) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchOnFirstTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchOnFirstTest.java similarity index 96% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchOnFirstTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchOnFirstTest.java index 87aa9a0d..7856cd41 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableSwitchOnFirstTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableSwitchOnFirstTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.Flowable; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableSwitchOnFirstTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableTimeoutLastTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableTimeoutLastTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableTimeoutLastTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableTimeoutLastTest.java index 8394d340..2e666f2c 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableTimeoutLastTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableTimeoutLastTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; +import java.util.concurrent.Flow.Publisher; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.jupiter.api.Test; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.schedulers.Schedulers; public class FlowableTimeoutLastTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableTransformersTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableTransformersTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableTransformersTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableTransformersTest.java index 4817e204..a061970d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableTransformersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableTransformersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class FlowableTransformersTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableValveTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableValveTest.java similarity index 90% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableValveTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableValveTest.java index 1295c97a..4ecc8706 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableValveTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableValveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableValveTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableWindowPredicateTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableWindowPredicateTest.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableWindowPredicateTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableWindowPredicateTest.java index 7d8deec2..13b33f82 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableWindowPredicateTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableWindowPredicateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,20 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; import java.util.*; +import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.reactivestreams.Subscriber; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.Single; -import io.reactivex.functions.Function; -import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; public class FlowableWindowPredicateTest { @@ -44,7 +42,6 @@ public Single> apply(Flowable f) { }; } - @SuppressWarnings("unchecked") @Test public void whileNormal() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -64,7 +61,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void whileNormalHidden() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6).hide() @@ -84,7 +80,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void whileNormalBackpressured() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -131,7 +126,6 @@ public boolean test(Integer v) throws Exception { .assertValueCount(4); } - @SuppressWarnings("unchecked") @Test public void whileMatchBegin() { Flowable.just(-1, 1, 2) @@ -149,7 +143,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilNormal() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -169,7 +162,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilNormalHidden() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6).hide() @@ -189,7 +181,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilNormalBackpressured() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -236,7 +227,6 @@ public boolean test(Integer v) throws Exception { .assertValueCount(4); } - @SuppressWarnings("unchecked") @Test public void untilMatchBegin() { Flowable.just(-1, 1, 2) @@ -280,7 +270,6 @@ public boolean test(Integer v) throws Exception { .assertNoValues(); } - @SuppressWarnings("unchecked") @Test public void errorWhile() { Flowable.error(new IOException()) @@ -295,7 +284,6 @@ public boolean test(Integer v) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void errorUntil() { Flowable.error(new IOException()) @@ -310,7 +298,6 @@ public boolean test(Integer v) throws Exception { .assertFailure(IOException.class); } - @SuppressWarnings("unchecked") @Test public void whileTake() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -329,7 +316,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void untilTake() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -348,7 +334,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void predicateCrash() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -363,7 +348,6 @@ public boolean test(Integer v) throws Exception { .assertFailure(IllegalArgumentException.class); } - @SuppressWarnings("unchecked") @Test public void doubleError() { List errors = TestHelper.trackPluginErrors(); @@ -392,7 +376,6 @@ public boolean test(Integer v) throws Exception { } } - @SuppressWarnings("unchecked") @Test public void splitNormal() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -412,7 +395,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void splitNormalHidden() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6).hide() @@ -432,7 +414,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void splitNormalBackpressured() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -479,7 +460,6 @@ public boolean test(Integer v) throws Exception { .assertValueCount(4); } - @SuppressWarnings("unchecked") @Test public void splitMatchBegin() { Flowable.just(-1, 1, 2) @@ -497,7 +477,6 @@ public boolean test(Integer v) throws Exception { ); } - @SuppressWarnings("unchecked") @Test public void cancellation() { Flowable.just(1, 2, -1, 3, 4, 5, -1, -1, 6) @@ -526,7 +505,7 @@ public Flowable apply(Flowable f) { @Test public void whileDrainQueue() { // test that window is emitted right away, not when next value arrives - Flowable.concat(Flowable.just(1L, 2L, -1L), Flowable.timer(1, TimeUnit.SECONDS)) + Flowable.concatArray(Flowable.just(1L, 2L, -1L), Flowable.timer(1, TimeUnit.SECONDS)) .compose(FlowableTransformers.windowWhile(new Predicate() { @Override public boolean test(Long v) throws Exception { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableZipLatestTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableZipLatestTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowableZipLatestTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowableZipLatestTest.java index e078073a..377ceea9 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowableZipLatestTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowableZipLatestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,26 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; + +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.TimeUnit; -import org.junit.*; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.exceptions.ProtocolViolationException; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.exceptions.ProtocolViolationException; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.processors.PublishProcessor; +import io.reactivex.rxjava4.schedulers.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableZipLatestTest { @@ -126,7 +128,6 @@ public void zipLatest4c() { .assertResult("[2, 3, 6, 7]"); } - @SuppressWarnings("unchecked") @Test public void zipLatestArrayEmpty() { Flowables.zipLatest(toString) @@ -134,7 +135,6 @@ public void zipLatestArrayEmpty() { .assertResult(); } - @SuppressWarnings("unchecked") @Test public void zipLatestArrayEmptyScheduler() { Flowables.zipLatest(toString, Schedulers.single()) @@ -158,7 +158,6 @@ public void zipLatestIterableEmptyScheduler() { .assertResult(); } - @SuppressWarnings("unchecked") @Test public void zipLatestArray() { TestScheduler scheduler = new TestScheduler(); @@ -182,7 +181,6 @@ public void zipLatestArray() { ts.assertResult("[2, 4]", "[4, 5]", "[6, 6]"); } - @SuppressWarnings("unchecked") @Test public void zipLatestIterable() { TestScheduler scheduler = new TestScheduler(); @@ -210,8 +208,8 @@ public void zipLatestIterable() { @Test public void zipLatestIterableMany() { int n = 20; - List> sources = new ArrayList>(); - List results = new ArrayList(); + List> sources = new ArrayList<>(); + List results = new ArrayList<>(); for (int i = 0; i < n; i++) { sources.add(Flowable.just(i)); results.add(i); @@ -222,7 +220,6 @@ public void zipLatestIterableMany() { .assertResult(results.toString()); } - @SuppressWarnings("unchecked") @Test public void zipLatestTake2() { TestScheduler scheduler = new TestScheduler(); @@ -267,7 +264,7 @@ public void firstErrors() { pp1.onError(new IOException()); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); ts.assertFailure(IOException.class, "[1, 2]"); } @@ -292,7 +289,7 @@ public void secondErrors() { pp2.onError(new IOException()); - Assert.assertFalse(pp1.hasSubscribers()); + assertFalse(pp1.hasSubscribers()); ts.assertFailure(IOException.class, "[1, 2]"); } @@ -317,7 +314,7 @@ public void firstErrorsBackpressured() { pp1.onError(new IOException()); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); ts.assertFailure(IOException.class, "[1, 2]"); } @@ -342,7 +339,7 @@ public void firstCompletesBackpressured() { pp1.onComplete(); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); ts.assertResult("[1, 2]"); } @@ -374,8 +371,8 @@ public void cancel() { ts.cancel(); - Assert.assertFalse(pp1.hasSubscribers()); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp1.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); ts.assertValue("[1, 2]") .assertNotComplete() @@ -402,8 +399,8 @@ public void cancelBackpressure() { ts.cancel(); - Assert.assertFalse(pp1.hasSubscribers()); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp1.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); ts.assertValue("[1, 2]") .assertNotComplete() @@ -449,7 +446,7 @@ public void firstCompleteBackpressure() { pp1.onNext(1); pp1.onComplete(); - Assert.assertTrue(pp2.hasSubscribers()); + assertTrue(pp2.hasSubscribers()); ts.assertEmpty(); @@ -457,7 +454,7 @@ public void firstCompleteBackpressure() { ts.assertResult("[1, 2]"); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); } @Test @@ -473,7 +470,7 @@ public void firstCompleteBackpressure2() { pp1.onNext(1); pp1.onComplete(); - Assert.assertTrue(pp2.hasSubscribers()); + assertTrue(pp2.hasSubscribers()); ts.assertEmpty(); @@ -485,7 +482,7 @@ public void firstCompleteBackpressure2() { ts.assertResult("[1, 2]"); - Assert.assertFalse(pp2.hasSubscribers()); + assertFalse(pp2.hasSubscribers()); } @Test @@ -543,8 +540,9 @@ public void terminationRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriber ts = Flowables.zipLatest(pp1, pp2, toString2) - .test(); + TestSubscriberEx ts = new TestSubscriberEx<>(); + + Flowables.zipLatest(pp1, pp2, toString2).subscribe(ts); final Throwable ex = new IOException(); @@ -564,9 +562,9 @@ public void run() { TestHelper.race(r1, r2, Schedulers.single()); - if (ts.errorCount() != 0) { + if (ts.errors().size() != 0) { ts.assertFailure(IOException.class); - Assert.assertTrue(errors.toString(), errors.isEmpty()); + assertTrue(errors.isEmpty(), errors.toString()); } else { ts.assertResult(); if (!errors.isEmpty()) { @@ -601,8 +599,8 @@ protected void subscribeActual(Subscriber s) { BooleanSubscription bs2 = new BooleanSubscription(); s.onSubscribe(bs2); - Assert.assertFalse(bs1.isCancelled()); - Assert.assertTrue(bs2.isCancelled()); + assertFalse(bs1.isCancelled()); + assertTrue(bs2.isCancelled()); } }; diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/FlowablesTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/FlowablesTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/FlowablesTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/FlowablesTest.java index 5d399fe0..94213c88 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/FlowablesTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/FlowablesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,12 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.internal.functions.Functions; +import hu.akarnokd.rxjava4.internal.rxcopy.Functions; +import hu.akarnokd.rxjava4.test.TestHelper; public class FlowablesTest { @@ -66,7 +66,7 @@ public void repeatScalarSlowPathConditional() { @Test public void repeatCallable() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .take(5) .test() .assertResult(1, 1, 1, 1, 1); @@ -74,7 +74,7 @@ public void repeatCallable() { @Test public void repeatCallableSlowPath() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .rebatchRequests(1) .take(5) .test() @@ -83,7 +83,7 @@ public void repeatCallableSlowPath() { @Test public void repeatCallableConditional() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .filter(Functions.alwaysTrue()) .take(5) .test() @@ -92,7 +92,7 @@ public void repeatCallableConditional() { @Test public void repeatCallableSlowPathConditional() { - Flowables.repeatCallable(Functions.justCallable(1)) + Flowables.repeatSupplier(Functions.justSupplier(1)) .filter(Functions.alwaysTrue()) .rebatchRequests(1) .take(5) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalCompletableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalCompletableTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalCompletableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalCompletableTest.java index bde4d1bc..ec191d6b 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalCompletableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalCompletableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.MaybeSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.MaybeSubject; public class MaybeFlatMapSignalCompletableTest { @@ -34,7 +32,7 @@ public void normalEmpty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -51,9 +49,9 @@ public Completable apply(Throwable e) return Completable.error(e); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; return Completable.complete(); } @@ -72,7 +70,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Maybe.just(0) - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -89,9 +87,9 @@ public Completable apply(Throwable e) return Completable.error(e); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; return Completable.complete(); } @@ -110,7 +108,7 @@ public void empty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -127,9 +125,9 @@ public Completable apply(Throwable e) return Completable.error(e); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; return Completable.complete(); } @@ -148,7 +146,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException()) - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -165,9 +163,9 @@ public Completable apply(Throwable e) return Completable.error(e); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; return Completable.complete(); } @@ -186,7 +184,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Maybe.just(1) - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -203,16 +201,17 @@ public Completable apply(Throwable e) throw new TestException("onError"); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -224,7 +223,7 @@ public void normalEmptyCrash() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -241,16 +240,17 @@ public Completable apply(Throwable e) throw new TestException("onError"); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(0, counts[0]); assertEquals(0, counts[1]); @@ -262,7 +262,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException("main")) - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -279,16 +279,17 @@ public Completable apply(Throwable e) throw new TestException("onError"); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -298,7 +299,7 @@ public Completable call() throws Exception { @Test public void disposed() { TestHelper.checkDisposed(MaybeSubject.create() - .as(Maybes.flatMapCompletable( + .to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -313,9 +314,9 @@ public Completable apply(Throwable e) return Completable.error(e); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { return Completable.complete(); } } @@ -328,7 +329,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeMaybeToCompletable(new Function, Completable>() { @Override public Completable apply(Maybe c) throws Exception { - return c.as(Maybes.flatMapCompletable( + return c.to(Maybes.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -343,9 +344,9 @@ public Completable apply(Throwable e) return Completable.error(e); } }, - new Callable() { + new Supplier() { @Override - public Completable call() throws Exception { + public Completable get() throws Exception { return Completable.complete(); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalFlowableTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalFlowableTest.java index de4e81ff..0e98721d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.MaybeSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.MaybeSubject; public class MaybeFlatMapSignalFlowableTest { @@ -34,7 +32,7 @@ public void normalEmpty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -51,9 +49,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; return Flowable.just(1); } @@ -72,7 +70,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Maybe.just(0) - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -89,9 +87,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; return Flowable.just(1); } @@ -110,7 +108,7 @@ public void backpressure() { final int[] counts = { 0, 0, 0 }; Maybe.just(0) - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -127,9 +125,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; return Flowable.just(1); } @@ -154,7 +152,7 @@ public void empty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -171,9 +169,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; return Flowable.empty(); } @@ -192,7 +190,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException()) - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -209,9 +207,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; return Flowable.empty(); } @@ -230,7 +228,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Maybe.just(1) - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -247,16 +245,17 @@ public Flowable apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -268,7 +267,7 @@ public void normalEmptyCrash() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -285,16 +284,17 @@ public Flowable apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(0, counts[0]); assertEquals(0, counts[1]); @@ -306,7 +306,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException("main")) - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -323,16 +323,17 @@ public Flowable apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -342,7 +343,7 @@ public Flowable call() throws Exception { @Test public void disposed() { TestHelper.checkDisposed(MaybeSubject.create() - .as(Maybes.flatMapFlowable( + .to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -357,9 +358,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { return Flowable.empty(); } } @@ -372,7 +373,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeMaybeToFlowable(new Function, Flowable>() { @Override public Flowable apply(Maybe c) throws Exception { - return c.as(Maybes.flatMapFlowable( + return c.to(Maybes.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -387,9 +388,9 @@ public Flowable apply(Throwable e) return Flowable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Flowable call() throws Exception { + public Flowable get() throws Exception { return Flowable.empty(); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalMaybeTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalMaybeTest.java similarity index 86% rename from src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalMaybeTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalMaybeTest.java index 7556d998..343812ed 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalMaybeTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalMaybeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.MaybeSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Maybe; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.MaybeSubject; public class MaybeFlatMapSignalMaybeTest { @@ -51,9 +49,9 @@ public Maybe apply(Throwable e) return Maybe.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; return Maybe.just(1); } @@ -89,9 +87,9 @@ public Maybe apply(Throwable e) return Maybe.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; return Maybe.just(1); } @@ -127,9 +125,9 @@ public Maybe apply(Throwable e) return Maybe.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; return Maybe.empty(); } @@ -165,9 +163,9 @@ public Maybe apply(Throwable e) return Maybe.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; return Maybe.empty(); } @@ -203,16 +201,17 @@ public Maybe apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -241,16 +240,17 @@ public Maybe apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(0, counts[0]); assertEquals(0, counts[1]); @@ -279,16 +279,17 @@ public Maybe apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -313,9 +314,9 @@ public Maybe apply(Throwable e) return Maybe.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { return Maybe.empty(); } } @@ -343,9 +344,9 @@ public Maybe apply(Throwable e) return Maybe.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Maybe call() throws Exception { + public Maybe get() throws Exception { return Maybe.empty(); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalObservableTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalObservableTest.java index 05a04624..57f70e93 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.MaybeSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.MaybeSubject; public class MaybeFlatMapSignalObservableTest { @@ -34,7 +32,7 @@ public void normalEmpty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -51,9 +49,9 @@ public Observable apply(Throwable e) return Observable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; return Observable.just(1); } @@ -72,7 +70,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Maybe.just(0) - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -89,9 +87,9 @@ public Observable apply(Throwable e) return Observable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; return Observable.just(1); } @@ -110,7 +108,7 @@ public void empty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -127,9 +125,9 @@ public Observable apply(Throwable e) return Observable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; return Observable.empty(); } @@ -148,7 +146,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException()) - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -165,9 +163,9 @@ public Observable apply(Throwable e) return Observable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; return Observable.empty(); } @@ -186,7 +184,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Maybe.just(1) - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -203,16 +201,17 @@ public Observable apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -224,7 +223,7 @@ public void normalEmptyCrash() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -241,16 +240,17 @@ public Observable apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(0, counts[0]); assertEquals(0, counts[1]); @@ -262,7 +262,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException("main")) - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -279,16 +279,17 @@ public Observable apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -298,7 +299,7 @@ public Observable call() throws Exception { @Test public void disposed() { TestHelper.checkDisposed(MaybeSubject.create() - .as(Maybes.flatMapObservable( + .to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -313,9 +314,9 @@ public Observable apply(Throwable e) return Observable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { return Observable.empty(); } } @@ -328,7 +329,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeMaybeToObservable(new Function, Observable>() { @Override public Observable apply(Maybe maybe) throws Exception { - return maybe.as(Maybes.flatMapObservable( + return maybe.to(Maybes.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -343,9 +344,9 @@ public Observable apply(Throwable e) return Observable.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Observable call() throws Exception { + public Observable get() throws Exception { return Observable.empty(); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalSingleTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalSingleTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalSingleTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalSingleTest.java index 1da6b0a7..62c1183d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/MaybeFlatMapSignalSingleTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/MaybeFlatMapSignalSingleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.concurrent.Callable; +import org.junit.jupiter.api.Test; -import org.junit.Test; - -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.MaybeSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.subjects.MaybeSubject; public class MaybeFlatMapSignalSingleTest { @@ -34,7 +32,7 @@ public void normalEmpty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -51,9 +49,9 @@ public Single apply(Throwable e) return Single.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; return Single.just(1); } @@ -72,7 +70,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Maybe.just(0) - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -89,9 +87,9 @@ public Single apply(Throwable e) return Single.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; return Single.just(1); } @@ -110,7 +108,7 @@ public void empty() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -127,9 +125,9 @@ public Single apply(Throwable e) return Single.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; return Single.just(2); } @@ -148,7 +146,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException()) - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -165,9 +163,9 @@ public Single apply(Throwable e) return Single.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; return Single.just(3); } @@ -186,7 +184,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Maybe.just(1) - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -203,16 +201,17 @@ public Single apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -224,7 +223,7 @@ public void normalEmptyCrash() { final int[] counts = { 0, 0, 0 }; Maybe.empty() - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -241,16 +240,17 @@ public Single apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onComplete"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onComplete")); assertEquals(0, counts[0]); assertEquals(0, counts[1]); @@ -262,7 +262,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Maybe.error(new TestException("main")) - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -279,16 +279,17 @@ public Single apply(Throwable e) throw new TestException("onError"); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { counts[2]++; throw new TestException("onComplete"); } } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -298,7 +299,7 @@ public Single call() throws Exception { @Test public void disposed() { TestHelper.checkDisposed(MaybeSubject.create() - .as(Maybes.flatMapSingle( + .to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -313,9 +314,9 @@ public Single apply(Throwable e) return Single.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { return Single.just(3); } } @@ -328,7 +329,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeMaybeToSingle(new Function, Single>() { @Override public Single apply(Maybe c) throws Exception { - return c.as(Maybes.flatMapSingle( + return c.to(Maybes.flatMapSingle( new Function>() { @Override public Single apply(Integer e) @@ -343,9 +344,9 @@ public Single apply(Throwable e) return Single.error(e); } }, - new Callable>() { + new Supplier>() { @Override - public Single call() throws Exception { + public Single get() throws Exception { return Single.just(3); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableErrorJumpTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableErrorJumpTest.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableErrorJumpTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableErrorJumpTest.java index 9ee3b334..79b97523 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableErrorJumpTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableErrorJumpTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,17 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.Observable; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.observers.TestObserver; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.exceptions.CompositeException; +import io.reactivex.rxjava4.observers.TestObserver; public class ObservableErrorJumpTest { @@ -68,7 +68,6 @@ public ObservableSource apply(Observable v) { } @Test - @SuppressWarnings("unchecked") public void errorJump() { Observable.range(1, 5) .concatWith(Observable.error(new TestException())) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableFilterAsyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableFilterAsyncTest.java similarity index 91% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableFilterAsyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableFilterAsyncTest.java index 1c30c4a7..7277ad65 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableFilterAsyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableFilterAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposables; -import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.PublishSubject; public class ObservableFilterAsyncTest { @@ -263,7 +263,7 @@ public ObservableSource apply(Integer v) @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(true); observer.onNext(false); observer.onError(new TestException()); @@ -289,7 +289,7 @@ public void mainErrorsAfterInnerErrors() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(1); observer.onError(new TestException("outer")); } @@ -302,7 +302,8 @@ public ObservableSource apply(Integer v) } })) .test() - .assertFailureAndMessage(TestException.class, "inner"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("inner")); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); } finally { @@ -314,13 +315,13 @@ public ObservableSource apply(Integer v) public void innerErrorsAfterMainErrors() { List errors = TestHelper.trackPluginErrors(); try { - final AtomicReference> refInner = new AtomicReference>(); + final AtomicReference> refInner = new AtomicReference<>(); new Observable() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(1); observer.onError(new TestException("outer")); refInner.get().onError(new TestException("inner")); @@ -334,14 +335,15 @@ public ObservableSource apply(Integer v) @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); refInner.set(observer); } }; } }, 10)) .test() - .assertFailureAndMessage(TestException.class, "outer"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("outer")); TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner"); } finally { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapDropTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapDropTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapDropTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapDropTest.java index 92b1d88e..261657fc 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapDropTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapDropTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.Disposables; -import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.PublishSubject; public class ObservableFlatMapDropTest { @@ -205,7 +205,7 @@ public void lateErrorOuter() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onError(new IOException("first")); observer.onError(new IOException("second")); } @@ -218,7 +218,8 @@ public ObservableSource apply(Integer v) } })) .test() - .assertFailureAndMessage(IOException.class, "first"); + .assertFailure(IOException.class) + .assertError(TestHelper.assertErrorMessage("first")); TestHelper.assertUndeliverable(errors, 0, IOException.class, "second"); } finally { @@ -230,7 +231,7 @@ public ObservableSource apply(Integer v) public void lateErrorInner() { List errors = TestHelper.trackPluginErrors(); try { - final AtomicReference> ref = new AtomicReference>(); + final AtomicReference> ref = new AtomicReference<>(); TestObserver to = Observable.just(1) .compose(ObservableTransformers.flatMapDrop(new Function>() { @@ -241,7 +242,7 @@ public ObservableSource apply(Integer v) @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); ref.set(observer); } }; @@ -252,7 +253,9 @@ protected void subscribeActual( ref.get().onError(new IOException("first")); ref.get().onError(new IOException("second")); - to.assertFailureAndMessage(IOException.class, "first"); + to + .assertFailure(IOException.class) + .assertError(TestHelper.assertErrorMessage("first")); TestHelper.assertUndeliverable(errors, 0, IOException.class, "second"); } finally { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapLatestTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapLatestTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapLatestTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapLatestTest.java index a3aedde8..10e77801 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableFlatMapLatestTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableFlatMapLatestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.disposables.Disposables; -import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.subjects.PublishSubject; public class ObservableFlatMapLatestTest { @@ -211,7 +211,7 @@ public void lateErrorOuter() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onError(new IOException("first")); observer.onError(new IOException("second")); } @@ -224,7 +224,8 @@ public ObservableSource apply(Integer v) } })) .test() - .assertFailureAndMessage(IOException.class, "first"); + .assertFailure(IOException.class) + .assertError(TestHelper.assertErrorMessage("first")); TestHelper.assertUndeliverable(errors, 0, IOException.class, "second"); } finally { @@ -236,7 +237,7 @@ public ObservableSource apply(Integer v) public void lateErrorInner() { List errors = TestHelper.trackPluginErrors(); try { - final AtomicReference> ref = new AtomicReference>(); + final AtomicReference> ref = new AtomicReference<>(); TestObserver to = Observable.just(1) .compose(ObservableTransformers.flatMapLatest(new Function>() { @@ -247,7 +248,7 @@ public ObservableSource apply(Integer v) @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); ref.set(observer); } }; @@ -258,7 +259,9 @@ protected void subscribeActual( ref.get().onError(new IOException("first")); ref.get().onError(new IOException("second")); - to.assertFailureAndMessage(IOException.class, "first"); + to + .assertFailure(IOException.class) + .assertError(TestHelper.assertErrorMessage("first")); TestHelper.assertUndeliverable(errors, 0, IOException.class, "second"); } finally { @@ -268,7 +271,7 @@ protected void subscribeActual( @Test public void disposeWhileInDrain() { - final TestObserver to = new TestObserver(); + final TestObserver to = new TestObserver<>(); Observable.just(1) .compose(ObservableTransformers.flatMapLatest(new Function>() { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableIndexOfTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableIndexOfTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableIndexOfTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableIndexOfTest.java index ed44e665..d5b4d0b5 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableIndexOfTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableIndexOfTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import io.reactivex.*; -import io.reactivex.disposables.Disposables; -import io.reactivex.functions.Predicate; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.Predicate; public class ObservableIndexOfTest { @@ -70,7 +70,7 @@ public void foundWithUnconditionalOnCompleteAfter() { new Observable() { @Override protected void subscribeActual(Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(10); observer.onComplete(); } diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableMapAsyncTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableMapAsyncTest.java similarity index 91% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableMapAsyncTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableMapAsyncTest.java index f0c5d3f1..9c1fe757 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableMapAsyncTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableMapAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.disposables.Disposables; -import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.PublishSubject; public class ObservableMapAsyncTest { @@ -284,7 +284,7 @@ public ObservableSource apply(Integer v) @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(2); observer.onNext(3); observer.onError(new TestException()); @@ -310,7 +310,7 @@ public void mainErrorsAfterInnerErrors() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(1); observer.onError(new TestException("outer")); } @@ -323,7 +323,8 @@ public ObservableSource apply(Integer v) } })) .test() - .assertFailureAndMessage(TestException.class, "inner"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("inner")); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); } finally { @@ -335,13 +336,13 @@ public ObservableSource apply(Integer v) public void innerErrorsAfterMainErrors() { List errors = TestHelper.trackPluginErrors(); try { - final AtomicReference> refInner = new AtomicReference>(); + final AtomicReference> refInner = new AtomicReference<>(); new Observable() { @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); observer.onNext(1); observer.onError(new TestException("outer")); refInner.get().onError(new TestException("inner")); @@ -355,14 +356,15 @@ public ObservableSource apply(Integer v) @Override protected void subscribeActual( Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); refInner.set(observer); } }; } }, 10)) .test() - .assertFailureAndMessage(TestException.class, "outer"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("outer")); TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner"); } finally { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnDropTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnDropTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnDropTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnDropTest.java index 624dcc05..e7b4bbb5 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnDropTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnDropTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,37 +14,32 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.schedulers.Schedulers; public class ObservableObserveOnDropTest { @Test public void normal() { - Observable.range(1, 1000000) + TestObserver to = Observable.range(1, 1000000) .compose(ObservableTransformers.observeOnDrop(Schedulers.computation())) .test() .awaitDone(5, TimeUnit.SECONDS) - .assertComplete() - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - assertTrue("" + to.valueCount(), - to.valueCount() >= 1 && to.valueCount() <= 1000000); - } - }); + .assertComplete(); + + assertTrue(to.values().size() >= 1 && to.values().size() <= 1000000, "" + to.values().size()); } @Test diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnLatestTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnLatestTest.java similarity index 76% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnLatestTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnLatestTest.java index d4c99eaf..c0a6a4a0 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableObserveOnLatestTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableObserveOnLatestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,37 +14,32 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.*; -import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.schedulers.Schedulers; public class ObservableObserveOnLatestTest { @Test public void normal() { - Observable.range(1, 1000000) + TestObserver to = Observable.range(1, 1000000) .compose(ObservableTransformers.observeOnLatest(Schedulers.computation())) .test() .awaitDone(5, TimeUnit.SECONDS) - .assertComplete() - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - assertTrue("" + to.valueCount(), - to.valueCount() >= 1 && to.valueCount() <= 1000000); - } - }); + .assertComplete(); + + assertTrue(to.values().size() >= 1 && to.values().size() <= 1000000, "" + to.values().size()); } @Test diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableTransformersTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableTransformersTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableTransformersTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableTransformersTest.java index 83b66405..7bebf036 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableTransformersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableTransformersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class ObservableTransformersTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableValveTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableValveTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservableValveTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservableValveTest.java index ee2959f8..d0405693 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservableValveTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservableValveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Observable; -import io.reactivex.functions.Function; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.PublishSubject; public class ObservableValveTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/ObservablesTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/ObservablesTest.java similarity index 81% rename from src/test/java/hu/akarnokd/rxjava2/operators/ObservablesTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/ObservablesTest.java index 05051060..a942405d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/ObservablesTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/ObservablesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class ObservablesTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalCompletableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalCompletableTest.java similarity index 88% rename from src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalCompletableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalCompletableTest.java index da2ea4da..c34a5d59 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalCompletableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalCompletableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.SingleSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subjects.SingleSubject; public class SingleFlatMapSignalCompletableTest { @@ -32,7 +32,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Single.just(0) - .as(Singles.flatMapCompletable( + .to(Singles.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -63,7 +63,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException()) - .as(Singles.flatMapCompletable( + .to(Singles.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -94,7 +94,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Single.just(1) - .as(Singles.flatMapCompletable( + .to(Singles.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -113,7 +113,8 @@ public Completable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -125,7 +126,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException("main")) - .as(Singles.flatMapCompletable( + .to(Singles.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -144,7 +145,8 @@ public Completable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -154,7 +156,7 @@ public Completable apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(SingleSubject.create() - .as(Singles.flatMapCompletable( + .to(Singles.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) @@ -178,7 +180,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeSingleToCompletable(new Function, Completable>() { @Override public Completable apply(Single c) throws Exception { - return c.as(Singles.flatMapCompletable( + return c.to(Singles.flatMapCompletable( new Function() { @Override public Completable apply(Integer e) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalFlowableTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalFlowableTest.java index 1c1da048..8a756228 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.SingleSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subjects.SingleSubject; public class SingleFlatMapSignalFlowableTest { @@ -32,7 +32,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Single.just(0) - .as(Singles.flatMapFlowable( + .to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -63,7 +63,7 @@ public void backpressure() { final int[] counts = { 0, 0, 0 }; Single.just(0) - .as(Singles.flatMapFlowable( + .to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -100,7 +100,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException()) - .as(Singles.flatMapFlowable( + .to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -131,7 +131,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Single.just(1) - .as(Singles.flatMapFlowable( + .to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -150,7 +150,8 @@ public Flowable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -162,7 +163,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException("main")) - .as(Singles.flatMapFlowable( + .to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -181,7 +182,8 @@ public Flowable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -191,7 +193,7 @@ public Flowable apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(SingleSubject.create() - .as(Singles.flatMapFlowable( + .to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) @@ -215,7 +217,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeSingleToFlowable(new Function, Flowable>() { @Override public Flowable apply(Single c) throws Exception { - return c.as(Singles.flatMapFlowable( + return c.to(Singles.flatMapFlowable( new Function>() { @Override public Flowable apply(Integer e) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalMaybeTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalMaybeTest.java similarity index 89% rename from src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalMaybeTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalMaybeTest.java index 1d8754c5..c372fe3b 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalMaybeTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalMaybeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.SingleSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subjects.SingleSubject; public class SingleFlatMapSignalMaybeTest { @@ -32,7 +32,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Single.just(0) - .as(Singles.flatMapMaybe( + .to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) @@ -63,7 +63,7 @@ public void successEmpty() { final int[] counts = { 0, 0, 0 }; Single.just(0) - .as(Singles.flatMapMaybe( + .to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) @@ -94,7 +94,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException()) - .as(Singles.flatMapMaybe( + .to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) @@ -125,7 +125,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Single.just(1) - .as(Singles.flatMapMaybe( + .to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) @@ -144,7 +144,8 @@ public Maybe apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -156,7 +157,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException("main")) - .as(Singles.flatMapMaybe( + .to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) @@ -175,7 +176,8 @@ public Maybe apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -185,7 +187,7 @@ public Maybe apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(SingleSubject.create() - .as(Singles.flatMapMaybe( + .to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) @@ -209,7 +211,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeSingleToMaybe(new Function, Maybe>() { @Override public Maybe apply(Single c) throws Exception { - return c.as(Singles.flatMapMaybe( + return c.to(Singles.flatMapMaybe( new Function>() { @Override public Maybe apply(Integer e) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalObservableTest.java similarity index 88% rename from src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalObservableTest.java index ffacc880..f0301a72 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.Function; -import io.reactivex.subjects.SingleSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subjects.SingleSubject; public class SingleFlatMapSignalObservableTest { @@ -32,7 +32,7 @@ public void normalSuccess() { final int[] counts = { 0, 0, 0 }; Single.just(0) - .as(Singles.flatMapObservable( + .to(Singles.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -63,7 +63,7 @@ public void error() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException()) - .as(Singles.flatMapObservable( + .to(Singles.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -94,7 +94,7 @@ public void normalSuccessCrash() { final int[] counts = { 0, 0, 0 }; Single.just(1) - .as(Singles.flatMapObservable( + .to(Singles.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -113,7 +113,8 @@ public Observable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -125,7 +126,7 @@ public void errorCrash() { final int[] counts = { 0, 0, 0 }; Single.error(new TestException("main")) - .as(Singles.flatMapObservable( + .to(Singles.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -144,7 +145,8 @@ public Observable apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); @@ -154,7 +156,7 @@ public Observable apply(Throwable e) @Test public void disposed() { TestHelper.checkDisposed(SingleSubject.create() - .as(Singles.flatMapObservable( + .to(Singles.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) @@ -178,7 +180,7 @@ public void doubleOnSubscribe() { TestHelper.checkDoubleOnSubscribeSingleToObservable(new Function, Observable>() { @Override public Observable apply(Single single) throws Exception { - return single.as(Singles.flatMapObservable( + return single.to(Singles.flatMapObservable( new Function>() { @Override public Observable apply(Integer e) diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalSingleTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalSingleTest.java similarity index 91% rename from src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalSingleTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalSingleTest.java index 3a4eb8db..7bcac262 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SingleFlatMapSignalSingleTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SingleFlatMapSignalSingleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,16 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.Single; -import io.reactivex.functions.Function; -import io.reactivex.subjects.SingleSubject; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Single; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subjects.SingleSubject; public class SingleFlatMapSignalSingleTest { @@ -113,7 +113,8 @@ public Single apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onSuccess"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onSuccess")); assertEquals(1, counts[0]); assertEquals(0, counts[1]); @@ -144,7 +145,8 @@ public Single apply(Throwable e) } )) .test() - .assertFailureAndMessage(TestException.class, "onError"); + .assertFailure(TestException.class) + .assertError(TestHelper.assertErrorMessage("onError")); assertEquals(0, counts[0]); assertEquals(1, counts[1]); diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SingleTransformersTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SingleTransformersTest.java similarity index 82% rename from src/test/java/hu/akarnokd/rxjava2/operators/SingleTransformersTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SingleTransformersTest.java index e66a8150..27d7eae0 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SingleTransformersTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SingleTransformersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class SingleTransformersTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/operators/SinglesTest.java b/src/test/java/hu/akarnokd/rxjava4/operators/SinglesTest.java similarity index 81% rename from src/test/java/hu/akarnokd/rxjava2/operators/SinglesTest.java rename to src/test/java/hu/akarnokd/rxjava4/operators/SinglesTest.java index 2c5697dd..cd9d0854 100644 --- a/src/test/java/hu/akarnokd/rxjava2/operators/SinglesTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/operators/SinglesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.operators; +package hu.akarnokd.rxjava4.operators; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class SinglesTest { diff --git a/src/test/java/hu/akarnokd/rxjava4/parallel/ParallelOrderedMergeTest.java b/src/test/java/hu/akarnokd/rxjava4/parallel/ParallelOrderedMergeTest.java new file mode 100644 index 00000000..cbd94ab8 --- /dev/null +++ b/src/test/java/hu/akarnokd/rxjava4/parallel/ParallelOrderedMergeTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.parallel; + +import java.util.Random; + +import org.junit.jupiter.api.Test; + +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.schedulers.Schedulers; + +public class ParallelOrderedMergeTest { + @Test + public void testBasicOrder() throws InterruptedException { + final Random rnd = new Random(); + ParallelTransformers.orderedMerge(Flowable.range(1, 5).parallel(4).runOn(Schedulers.computation()).map(new Function() { + @Override + public Integer apply(Integer t) throws Exception { + Thread.sleep(0, 50 + rnd.nextInt(1000)); + return t; + } + })).test().await().assertResult(1, 2, 3, 4, 5); + } +} diff --git a/src/test/java/hu/akarnokd/rxjava2/parallel/ParallelSumTest.java b/src/test/java/hu/akarnokd/rxjava4/parallel/ParallelSumTest.java similarity index 91% rename from src/test/java/hu/akarnokd/rxjava2/parallel/ParallelSumTest.java rename to src/test/java/hu/akarnokd/rxjava4/parallel/ParallelSumTest.java index 454d9f89..2279f9ea 100644 --- a/src/test/java/hu/akarnokd/rxjava2/parallel/ParallelSumTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/parallel/ParallelSumTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,16 +14,18 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.parallel; +package hu.akarnokd.rxjava4.parallel; + +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; -import org.junit.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Flowable; -import io.reactivex.functions.*; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.schedulers.Schedulers; public class ParallelSumTest { @@ -163,6 +165,6 @@ public Long apply(Long a, Long b) throws Exception { }) .blockingLast(); - Assert.assertEquals(999999L * 500000L, n); + assertEquals(999999L * 500000L, n); } } diff --git a/src/test/java/hu/akarnokd/rxjava2/processors/DispatchWorkProcessorTest.java b/src/test/java/hu/akarnokd/rxjava4/processors/DispatchWorkProcessorTest.java similarity index 93% rename from src/test/java/hu/akarnokd/rxjava2/processors/DispatchWorkProcessorTest.java rename to src/test/java/hu/akarnokd/rxjava4/processors/DispatchWorkProcessorTest.java index 2d9cd650..178fd659 100644 --- a/src/test/java/hu/akarnokd/rxjava2/processors/DispatchWorkProcessorTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/processors/DispatchWorkProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,25 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.*; -import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class DispatchWorkProcessorTest { @@ -83,7 +83,7 @@ public void online() { ts1.assertValuesOnly(1, 2); - ts1.dispose(); + ts1.cancel(); assertFalse(dws.hasSubscribers()); @@ -232,7 +232,7 @@ public void addRemoveRace() { final TestSubscriber ts = dws.test(); - final TestSubscriber ts2 = new TestSubscriber(); + final TestSubscriber ts2 = new TestSubscriber<>(); Runnable r1 = new Runnable() { @Override @@ -264,7 +264,7 @@ public void doubleConsume() { @Override public HashSet apply(List a, List b) throws Exception { - HashSet set = new HashSet(); + HashSet set = new HashSet<>(); set.addAll(a); set.addAll(b); return set; @@ -368,7 +368,7 @@ public void longBackpressured() { @Override public HashSet apply(List a, List b) throws Exception { - HashSet set = new HashSet(); + HashSet set = new HashSet<>(); set.addAll(a); set.addAll(b); return set; @@ -390,7 +390,7 @@ public HashSet apply(List a, List b) assertEquals(n, set.size()); for (int i = 0; i < n; i++) { - assertTrue("" + i, set.remove(i)); + assertTrue(set.remove(i), "" + i); } assertTrue(set.isEmpty()); @@ -406,7 +406,7 @@ public void longBackpressured2() { @Override public HashSet apply(List a, List b) throws Exception { - HashSet set = new HashSet(); + HashSet set = new HashSet<>(); set.addAll(a); set.addAll(b); return set; @@ -428,7 +428,7 @@ public HashSet apply(List a, List b) assertEquals(n, set.size()); for (int i = 0; i < n; i++) { - assertTrue("" + i, set.remove(i)); + assertTrue(set.remove(i), "" + i); } assertTrue(set.isEmpty()); @@ -453,7 +453,7 @@ public void accept(Integer v) throws Exception { @Override public HashSet apply(List a, List b) throws Exception { - HashSet set = new HashSet(); + HashSet set = new HashSet<>(); set.addAll(a); set.addAll(b); return set; @@ -476,7 +476,7 @@ public HashSet apply(List a, List b) assertEquals(n, set.size()); for (int i = 0; i < n; i++) { - assertTrue("" + i, set.remove(i)); + assertTrue(set.remove(i), "" + i); } assertTrue(set.isEmpty()); @@ -501,7 +501,7 @@ public void limit() { dws.onNext(2); dws.onComplete(); - dws.limit(1).test().assertResult(1); + dws.take(1).test().assertResult(1); assertFalse(dws.hasSubscribers()); } diff --git a/src/test/java/hu/akarnokd/rxjava2/processors/FlowableProcessorsTest.java b/src/test/java/hu/akarnokd/rxjava4/processors/FlowableProcessorsTest.java similarity index 88% rename from src/test/java/hu/akarnokd/rxjava2/processors/FlowableProcessorsTest.java rename to src/test/java/hu/akarnokd/rxjava4/processors/FlowableProcessorsTest.java index 6570c93a..1af1e4b2 100644 --- a/src/test/java/hu/akarnokd/rxjava2/processors/FlowableProcessorsTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/processors/FlowableProcessorsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; +import java.util.concurrent.Flow.*; -import org.junit.Test; -import org.reactivestreams.*; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.processors.*; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.processors.*; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableProcessorsTest { @@ -171,9 +171,11 @@ public void utilityClass() { TestHelper.checkUtilityClass(FlowableProcessors.class); } - @Test(expected = UnsupportedOperationException.class) + @Test public void hasSubscribers() { - FlowableProcessors.wrap(sp).hasSubscribers(); + assertThrows(UnsupportedOperationException.class, () -> { + FlowableProcessors.wrap(sp).hasSubscribers(); + }); } @Test diff --git a/src/test/java/hu/akarnokd/rxjava2/processors/RefCountProcessorTest.java b/src/test/java/hu/akarnokd/rxjava4/processors/RefCountProcessorTest.java similarity index 85% rename from src/test/java/hu/akarnokd/rxjava2/processors/RefCountProcessorTest.java rename to src/test/java/hu/akarnokd/rxjava4/processors/RefCountProcessorTest.java index 7f65740e..366e43ed 100644 --- a/src/test/java/hu/akarnokd/rxjava2/processors/RefCountProcessorTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/processors/RefCountProcessorTest.java @@ -1,31 +1,34 @@ -/** - * Copyright (c) 2016-present, RxJava Contributors. +/* + * Copyright 2016-present David Karnok * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -package hu.akarnokd.rxjava2.processors; +package hu.akarnokd.rxjava4.processors; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; +import java.util.concurrent.Flow.Subscription; -import org.junit.Test; -import org.reactivestreams.Subscription; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.FlowableSubscriber; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.processors.*; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import hu.akarnokd.rxjava4.internal.rxcopy.BooleanSubscription; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.processors.*; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class RefCountProcessorTest { @@ -165,7 +168,9 @@ public void multipleSubscribers() { assertFalse(source.hasSubscribers()); - rcp.test().assertFailureAndMessage(IllegalStateException.class, "RefCountProcessor terminated"); + rcp.test() + .assertFailure(IllegalStateException.class) + .assertError(TestHelper.assertErrorMessage("RefCountProcessor terminated")); } @Test @@ -193,7 +198,7 @@ public void cancelTwice() { assertTrue(source.hasSubscribers()); - final TestSubscriber ts = new TestSubscriber(); + final TestSubscriber ts = new TestSubscriber<>(); rcp.subscribe(new FlowableSubscriber() { @@ -237,7 +242,7 @@ public void cancelTwiceDontCancelUp() { TestSubscriber ts0 = rcp.test(); - final TestSubscriber ts = new TestSubscriber(); + final TestSubscriber ts = new TestSubscriber<>(); rcp.subscribe(new FlowableSubscriber() { diff --git a/src/test/java/hu/akarnokd/rxjava2/string/FlowableCharSequenceTest.java b/src/test/java/hu/akarnokd/rxjava4/string/FlowableCharSequenceTest.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/string/FlowableCharSequenceTest.java rename to src/test/java/hu/akarnokd/rxjava4/string/FlowableCharSequenceTest.java index 3d2f5995..3b908f17 100644 --- a/src/test/java/hu/akarnokd/rxjava2/string/FlowableCharSequenceTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/string/FlowableCharSequenceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; -import org.junit.Test; -import org.reactivestreams.Publisher; +import java.util.concurrent.Flow.Publisher; -import io.reactivex.Flowable; -import io.reactivex.functions.Function; -import io.reactivex.subscribers.TestSubscriber; +import org.junit.jupiter.api.Test; + +import io.reactivex.rxjava4.core.Flowable; +import io.reactivex.rxjava4.functions.Function; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public class FlowableCharSequenceTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/string/StringFlowableTest.java b/src/test/java/hu/akarnokd/rxjava4/string/StringFlowableTest.java similarity index 96% rename from src/test/java/hu/akarnokd/rxjava2/string/StringFlowableTest.java rename to src/test/java/hu/akarnokd/rxjava4/string/StringFlowableTest.java index 87c72b8b..e2ce0bbc 100644 --- a/src/test/java/hu/akarnokd/rxjava2/string/StringFlowableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/string/StringFlowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.BaseTest; -import io.reactivex.Flowable; +import hu.akarnokd.rxjava4.test.BaseTest; +import io.reactivex.rxjava4.core.Flowable; public class StringFlowableTest extends BaseTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/string/StringObservableTest.java b/src/test/java/hu/akarnokd/rxjava4/string/StringObservableTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/string/StringObservableTest.java rename to src/test/java/hu/akarnokd/rxjava4/string/StringObservableTest.java index 1f02fe48..c36ade73 100644 --- a/src/test/java/hu/akarnokd/rxjava2/string/StringObservableTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/string/StringObservableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.string; +package hu.akarnokd.rxjava4.string; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.BaseTest; +import hu.akarnokd.rxjava4.test.BaseTest; public class StringObservableTest extends BaseTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubjectTest.java b/src/test/java/hu/akarnokd/rxjava4/subjects/DispatchWorkSubjectTest.java similarity index 90% rename from src/test/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubjectTest.java rename to src/test/java/hu/akarnokd/rxjava4/subjects/DispatchWorkSubjectTest.java index d6aab107..cd9c19ff 100644 --- a/src/test/java/hu/akarnokd/rxjava2/subjects/DispatchWorkSubjectTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/subjects/DispatchWorkSubjectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,23 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.Single; -import io.reactivex.disposables.*; -import io.reactivex.functions.BiFunction; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.Schedulers; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.core.Single; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.functions.BiFunction; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; public class DispatchWorkSubjectTest { @@ -123,7 +123,7 @@ public void dispose() { assertFalse(dws.isDisposed()); - Disposable d = Disposables.empty(); + Disposable d = Disposable.empty(); dws.onSubscribe(d); @@ -205,7 +205,7 @@ public void addRemove() { dws.test(); - to.cancel(); + to.dispose(); dws.test(true); } @@ -230,7 +230,7 @@ public void addRemoveRace() { final TestObserver to = dws.test(); - final TestObserver to2 = new TestObserver(); + final TestObserver to2 = new TestObserver<>(); Runnable r1 = new Runnable() { @Override @@ -242,7 +242,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -262,7 +262,7 @@ public void doubleConsume() { @Override public HashSet apply(List a, List b) throws Exception { - HashSet set = new HashSet(); + HashSet set = new HashSet<>(); set.addAll(a); set.addAll(b); return set; diff --git a/src/test/java/hu/akarnokd/rxjava2/subjects/RefCountSubjectTest.java b/src/test/java/hu/akarnokd/rxjava4/subjects/RefCountSubjectTest.java similarity index 83% rename from src/test/java/hu/akarnokd/rxjava2/subjects/RefCountSubjectTest.java rename to src/test/java/hu/akarnokd/rxjava4/subjects/RefCountSubjectTest.java index 27732009..415d725f 100644 --- a/src/test/java/hu/akarnokd/rxjava2/subjects/RefCountSubjectTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/subjects/RefCountSubjectTest.java @@ -1,30 +1,33 @@ -/** - * Copyright (c) 2016-present, RxJava Contributors. +/* + * Copyright 2016-present David Karnok * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; -import io.reactivex.Observer; -import io.reactivex.disposables.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.*; +import hu.akarnokd.rxjava4.test.TestHelper; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.*; public class RefCountSubjectTest { @@ -52,7 +55,7 @@ public void normal() { to.assertValues(1, 2); - to.cancel(); + to.dispose(); assertFalse(source.hasObservers()); @@ -154,15 +157,17 @@ public void multipleSubscribers() { TestObserver to1 = rcp.test(); TestObserver to2 = rcp.test(); - to1.cancel(); + to1.dispose(); assertTrue(source.hasObservers()); - to2.cancel(); + to2.dispose(); assertFalse(source.hasObservers()); - rcp.test().assertFailureAndMessage(IllegalStateException.class, "RefCountSubject terminated"); + rcp.test() + .assertFailure(IllegalStateException.class) + .assertError(TestHelper.assertErrorMessage("RefCountSubject terminated")); } @Test @@ -190,7 +195,7 @@ public void cancelTwice() { assertTrue(source.hasObservers()); - final TestObserver to = new TestObserver(); + final TestObserver to = new TestObserver<>(); rcp.subscribe(new Observer() { @@ -237,7 +242,7 @@ public void cancelTwiceDontCancelUp() { TestObserver to0 = rcp.test(); - final TestObserver to = new TestObserver(); + final TestObserver to = new TestObserver<>(); rcp.subscribe(new Observer() { @@ -290,14 +295,14 @@ public void addRemoveRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; Runnable r2 = new Runnable() { @Override public void run() { - rcp.test().cancel(); + rcp.test().dispose(); } }; @@ -309,11 +314,11 @@ public void run() { public void doubleOnSubscribe() { final Subject rcp = Subjects.refCount(PublishSubject.create()); - Disposable bs1 = Disposables.empty(); + Disposable bs1 = Disposable.empty(); rcp.onSubscribe(bs1); - Disposable bs2 = Disposables.empty(); + Disposable bs2 = Disposable.empty(); rcp.onSubscribe(bs2); diff --git a/src/test/java/hu/akarnokd/rxjava2/subjects/SubjectsTest.java b/src/test/java/hu/akarnokd/rxjava4/subjects/SubjectsTest.java similarity index 79% rename from src/test/java/hu/akarnokd/rxjava2/subjects/SubjectsTest.java rename to src/test/java/hu/akarnokd/rxjava4/subjects/SubjectsTest.java index 3cc51135..13e64f4d 100644 --- a/src/test/java/hu/akarnokd/rxjava2/subjects/SubjectsTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/subjects/SubjectsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,11 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.subjects.Subjects; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class SubjectsTest { diff --git a/src/test/java/hu/akarnokd/rxjava2/subjects/UnicastWorkSubjectTest.java b/src/test/java/hu/akarnokd/rxjava4/subjects/UnicastWorkSubjectTest.java similarity index 90% rename from src/test/java/hu/akarnokd/rxjava2/subjects/UnicastWorkSubjectTest.java rename to src/test/java/hu/akarnokd/rxjava4/subjects/UnicastWorkSubjectTest.java index b00c9723..9e9e72dd 100644 --- a/src/test/java/hu/akarnokd/rxjava2/subjects/UnicastWorkSubjectTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/subjects/UnicastWorkSubjectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.subjects; +package hu.akarnokd.rxjava4.subjects; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.*; -import io.reactivex.disposables.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.plugins.RxJavaPlugins; +import hu.akarnokd.rxjava4.test.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; public class UnicastWorkSubjectTest { @@ -100,18 +100,22 @@ public void online() { assertNull(uws.getThrowable()); } - @Test(expected = NullPointerException.class) + @Test public void nullOnNext() { - UnicastWorkSubject uws = UnicastWorkSubject.create(); + assertThrows(NullPointerException.class, () -> { + UnicastWorkSubject uws = UnicastWorkSubject.create(); - uws.onNext(null); + uws.onNext(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void nullOnError() { - UnicastWorkSubject uws = UnicastWorkSubject.create(); + assertThrows(NullPointerException.class, () -> { + UnicastWorkSubject uws = UnicastWorkSubject.create(); - uws.onError(null); + uws.onError(null); + }); } @Test @@ -173,7 +177,7 @@ public void errorEager() { public void dispose() { UnicastWorkSubject uws = UnicastWorkSubject.create(); - Disposable d = Disposables.empty(); + Disposable d = Disposable.empty(); uws.onSubscribe(d); @@ -272,7 +276,7 @@ public void run() { assertFalse(uws.hasObservers()); - uws.test().assertNotTerminated(); + uws.subscribeWith(new TestObserverEx<>()).assertNotTerminated(); } } @@ -360,7 +364,7 @@ public void run() { public void onNextSubscribeRace() { for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { final UnicastWorkSubject uws = UnicastWorkSubject.create(); - final TestObserver to = new TestObserver(); + final TestObserver to = new TestObserver<>(); Runnable r1 = new Runnable() { @Override @@ -409,7 +413,7 @@ public void run() { assertFalse(uws.hasObservers()); - uws.test().assertNotTerminated(); + uws.subscribeWith(new TestObserverEx<>()).assertNotTerminated(); } } } diff --git a/src/test/java/hu/akarnokd/rxjava2/test/BaseTest.java b/src/test/java/hu/akarnokd/rxjava4/test/BaseTest.java similarity index 73% rename from src/test/java/hu/akarnokd/rxjava2/test/BaseTest.java rename to src/test/java/hu/akarnokd/rxjava4/test/BaseTest.java index 9a7e91d9..d4de2e7a 100644 --- a/src/test/java/hu/akarnokd/rxjava2/test/BaseTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/test/BaseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,18 +14,19 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.test; +package hu.akarnokd.rxjava4.test; -import org.reactivestreams.Publisher; +import java.util.concurrent.Flow.Publisher; -import io.reactivex.*; -import io.reactivex.observers.TestObserver; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.subscribers.TestSubscriber; public abstract class BaseTest { + @SafeVarargs public static void assertResult(ObservableSource source, T... array) { - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); source.subscribe(to); @@ -34,8 +35,9 @@ public static void assertResult(ObservableSource source, T... array) { to.assertComplete(); } + @SafeVarargs public static void assertResult(Publisher source, T... array) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); source.subscribe(ts); @@ -44,10 +46,12 @@ public static void assertResult(Publisher source, T... array) { .assertComplete(); } + @SafeVarargs public static Observable observe(T... array) { return Observable.fromArray(array); } + @SafeVarargs public static Flowable flow(T... array) { return Flowable.fromArray(array); } diff --git a/src/test/java/hu/akarnokd/rxjava4/test/BaseTestConsumerEx.java b/src/test/java/hu/akarnokd/rxjava4/test/BaseTestConsumerEx.java new file mode 100644 index 00000000..7c4e5372 --- /dev/null +++ b/src/test/java/hu/akarnokd/rxjava4/test/BaseTestConsumerEx.java @@ -0,0 +1,239 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.test; + +import java.util.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.ExceptionHelper; +import io.reactivex.rxjava4.functions.Predicate; +import io.reactivex.rxjava4.observers.BaseTestConsumer; +import io.reactivex.rxjava4.operators.QueueFuseable; + +/** + * Base class with shared infrastructure to support TestSubscriber and TestObserver. + * @param the value type consumed + * @param the subclass of this BaseTestConsumer + */ +public abstract class BaseTestConsumerEx> +extends BaseTestConsumer { + + protected int initialFusionMode; + + protected int establishedFusionMode; + + /** + * The optional tag associated with this test consumer. + * @since 2.0.7 + */ + protected CharSequence tag; + + public BaseTestConsumerEx() { + super(); + } + + /** + * Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber. + * @return the last thread which called the onXXX methods + */ + public final Thread lastThread() { + return lastThread; + } + + // assertion methods + + /** + * Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to + * the given value with respect to null-safe Object.equals. + * + *

History: 2.0.5 - experimental + * @param value the value to expect not being received + * @return this + * @since 2.1 + */ + @SuppressWarnings("unchecked") + public final U assertNever(T value) { + int s = values.size(); + + for (int i = 0; i < s; i++) { + T v = this.values.get(i); + if (Objects.equals(v, value)) { + throw fail("Value at position " + i + " is equal to " + valueAndClass(value) + "; Expected them to be different"); + } + } + return (U) this; + } + + /** + * Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which + * the provided predicate returns true. + * + *

History: 2.0.5 - experimental + * @param valuePredicate the predicate that receives the onNext value + * and should return true for the expected value. + * @return this + * @since 2.1 + */ + @SuppressWarnings("unchecked") + public final U assertNever(Predicate valuePredicate) { + int s = values.size(); + + for (int i = 0; i < s; i++) { + T v = this.values.get(i); + try { + if (valuePredicate.test(v)) { + throw fail("Value at position " + i + " matches predicate " + valuePredicate.toString() + ", which was not expected."); + } + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + return (U)this; + } + + /** + * Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero). + * @return this + */ + @SuppressWarnings("unchecked") + public final U assertTerminated() { + if (done.getCount() != 0) { + throw fail("Subscriber still running!"); + } + long c = completions; + if (c > 1) { + throw fail("Terminated with multiple completions: " + c); + } + int s = errors.size(); + if (s > 1) { + throw fail("Terminated with multiple errors: " + s); + } + + if (c != 0 && s != 0) { + throw fail("Terminated with multiple completions and errors: " + c); + } + return (U)this; + } + + /** + * Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero). + * @return this + */ + @SuppressWarnings("unchecked") + public final U assertNotTerminated() { + if (done.getCount() == 0) { + throw fail("Subscriber terminated!"); + } + return (U)this; + } + + /** + * Assert that there is a single error and it has the given message. + * @param message the message expected + * @return this + */ + @SuppressWarnings("unchecked") + public final U assertErrorMessage(String message) { + int s = errors.size(); + if (s == 0) { + throw fail("No errors"); + } else + if (s == 1) { + Throwable e = errors.get(0); + String errorMessage = e.getMessage(); + if (!Objects.equals(message, errorMessage)) { + throw fail("Error message differs; exptected: " + message + " but was: " + errorMessage); + } + } else { + throw fail("Multiple errors"); + } + return (U)this; + } + + /** + * Assert that the upstream signalled the specified values in order and then failed + * with a Throwable for which the provided predicate returns true. + * @param errorPredicate + * the predicate that receives the error Throwable + * and should return true for expected errors. + * @param values the expected values, asserted in order + * @return this + */ + @SafeVarargs + public final U assertFailure(Predicate errorPredicate, T... values) { + return assertSubscribed() + .assertValues(values) + .assertError(errorPredicate) + .assertNotComplete(); + } + + /** + * Assert that the upstream signalled the specified values in order, + * then failed with a specific class or subclass of Throwable + * and with the given exact error message. + * @param error the expected exception (parent) class + * @param message the expected failure message + * @param values the expected values, asserted in order + * @return this + */ + @SafeVarargs + public final U assertFailureAndMessage(Class error, + String message, T... values) { + return assertSubscribed() + .assertValues(values) + .assertError(error) + .assertErrorMessage(message) + .assertNotComplete(); + } + + /** + * Returns true if this test consumer has terminated in any fashion. + * @return true if this test consumer has terminated in any fashion + */ + public final boolean isTerminated() { + return done.getCount() == 0; + } + + /** + * Returns the number of times onComplete() was called. + * @return the number of times onComplete() was called + */ + public final long completions() { + return completions; + } + + /** + * Fail with the given message and add the sequence of errors as suppressed ones. + *

Note this is deliberately the only fail method. Most of the times an assertion + * would fail but it is possible it was due to an exception somewhere. This construct + * will capture those potential errors and report it along with the original failure. + * + * @param message the message to use + * @return AssertionError the prepared AssertionError instance + */ + public final AssertionError failWith(String message) { + return fail(message); + } + + static String fusionModeToString(int mode) { + switch (mode) { + case QueueFuseable.NONE : return "NONE"; + case QueueFuseable.SYNC : return "SYNC"; + case QueueFuseable.ASYNC : return "ASYNC"; + default: return "Unknown(" + mode + ")"; + } + } +} \ No newline at end of file diff --git a/src/test/java/hu/akarnokd/rxjava2/test/TestException.java b/src/test/java/hu/akarnokd/rxjava4/test/TestException.java similarity index 95% rename from src/test/java/hu/akarnokd/rxjava2/test/TestException.java rename to src/test/java/hu/akarnokd/rxjava4/test/TestException.java index 0b80b6b3..bc678fd5 100644 --- a/src/test/java/hu/akarnokd/rxjava2/test/TestException.java +++ b/src/test/java/hu/akarnokd/rxjava4/test/TestException.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.test; +package hu.akarnokd.rxjava4.test; /** * Exception for testing if unchecked expections propagate as-is without confusing with diff --git a/src/test/java/hu/akarnokd/rxjava2/test/TestHelper.java b/src/test/java/hu/akarnokd/rxjava4/test/TestHelper.java similarity index 84% rename from src/test/java/hu/akarnokd/rxjava2/test/TestHelper.java rename to src/test/java/hu/akarnokd/rxjava4/test/TestHelper.java index e6ad5547..76256987 100644 --- a/src/test/java/hu/akarnokd/rxjava2/test/TestHelper.java +++ b/src/test/java/hu/akarnokd/rxjava4/test/TestHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,9 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.test; +package hu.akarnokd.rxjava4.test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -25,33 +25,27 @@ import java.net.URL; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.Flow.*; import java.util.concurrent.atomic.AtomicInteger; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.reactivestreams.*; - -import io.reactivex.*; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.disposables.*; -import io.reactivex.exceptions.*; -import io.reactivex.functions.*; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.operators.completable.CompletableToFlowable; -import io.reactivex.internal.operators.maybe.MaybeToFlowable; -import io.reactivex.internal.operators.single.SingleToFlowable; -import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.observers.*; -import io.reactivex.parallel.ParallelFlowable; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.processors.PublishProcessor; -import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.Subject; -import io.reactivex.subscribers.TestSubscriber; + +import hu.akarnokd.rxjava4.internal.rxcopy.*; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.core.Observable; +import io.reactivex.rxjava4.core.Observer; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.exceptions.*; +import io.reactivex.rxjava4.functions.*; +import io.reactivex.rxjava4.observers.TestObserver; +import io.reactivex.rxjava4.operators.*; +import io.reactivex.rxjava4.parallel.ParallelFlowable; +import io.reactivex.rxjava4.plugins.RxJavaPlugins; +import io.reactivex.rxjava4.schedulers.Schedulers; +import io.reactivex.rxjava4.subjects.Subject; +import io.reactivex.rxjava4.subscribers.TestSubscriber; /** * Common methods for helping with tests from 1.x mostly. @@ -198,7 +192,7 @@ public static void assertError(List list, int index, Class list, int index, Class to, int index, Class cel = ce.getExceptions(); - assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); + assertTrue(clazz.isInstance(cel.get(index)), cel.get(index).toString()); } else { fail(ex.toString() + ": not a CompositeException"); } @@ -246,7 +240,7 @@ public static void assertError(TestSubscriber ts, int index, Class cel = ce.getExceptions(); - assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); + assertTrue(clazz.isInstance(cel.get(index)), cel.get(index).toString()); } else { fail(ex.toString() + ": not a CompositeException"); } @@ -257,7 +251,7 @@ public static void assertError(TestObserver to, int index, Class cel = ce.getExceptions(); - assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); + assertTrue(clazz.isInstance(cel.get(index)), cel.get(index).toString()); assertEquals(message, cel.get(index).getMessage()); } else { fail(ex.toString() + ": not a CompositeException"); @@ -269,7 +263,7 @@ public static void assertError(TestSubscriber ts, int index, Class cel = ce.getExceptions(); - assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index))); + assertTrue(clazz.isInstance(cel.get(index)), cel.get(index).toString()); assertEquals(message, cel.get(index).getMessage()); } else { fail(ex.toString() + ": not a CompositeException"); @@ -353,7 +347,7 @@ public void onComplete() { throw new AssertionError(ex.getMessage()); } - assertTrue(list.toString(), list.get(0) instanceof IllegalArgumentException); + assertTrue(list.get(0) instanceof IllegalArgumentException, list.toString()); assertEquals("n > 0 required but it was -99", list.get(0).getMessage()); } finally { RxJavaPlugins.setErrorHandler(null); @@ -501,7 +495,6 @@ public static Consumer> subscriberSingleNot(final T value) @Override public void accept(TestSubscriber ts) throws Exception { ts - .assertSubscribed() .assertValueCount(1) .assertNoErrors() .assertComplete(); @@ -524,7 +517,6 @@ public static Consumer> observerSingleNot(final T value) { @Override public void accept(TestObserver to) throws Exception { to - .assertSubscribed() .assertValueCount(1) .assertNoErrors() .assertComplete(); @@ -569,11 +561,11 @@ public static void doubleOnSubscribe(Subscriber subscriber) { public static void doubleOnSubscribe(Observer observer) { List errors = trackPluginErrors(); try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -595,11 +587,11 @@ public static void doubleOnSubscribe(Observer observer) { public static void doubleOnSubscribe(SingleObserver o) { List errors = trackPluginErrors(); try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); o.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); o.onSubscribe(d2); @@ -621,11 +613,11 @@ public static void doubleOnSubscribe(SingleObserver o) { public static void doubleOnSubscribe(CompletableObserver observer) { List errors = trackPluginErrors(); try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -647,11 +639,11 @@ public static void doubleOnSubscribe(CompletableObserver observer) { public static void doubleOnSubscribe(MaybeObserver o) { List errors = trackPluginErrors(); try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); o.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); o.onSubscribe(d2); @@ -672,7 +664,7 @@ public static void doubleOnSubscribe(MaybeObserver o) { * @param source the source to test */ public static void checkDisposed(Flowable source) { - final TestSubscriber ts = new TestSubscriber(0L); + final TestSubscriber ts = new TestSubscriber<>(0L); source.subscribe(new FlowableSubscriber() { @Override public void onSubscribe(Subscription s) { @@ -742,13 +734,13 @@ public void onComplete() { }); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("Reports disposed upfront?", false, b[0]); - assertEquals("Didn't report disposed after?", true, b[1]); + assertEquals(false, b[0], "Reports disposed upfront?"); + assertEquals(true, b[1], "Didn't report disposed after?"); } /** @@ -793,13 +785,13 @@ public void onComplete() { }); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("Reports disposed upfront?", false, b[0]); - assertEquals("Didn't report disposed after?", true, b[1]); + assertEquals(false, b[0], "Reports disposed upfront?"); + assertEquals(true, b[1], "Didn't report disposed after?"); } /** @@ -839,13 +831,13 @@ public void onError(Throwable e) { }); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("Reports disposed upfront?", false, b[0]); - assertEquals("Didn't report disposed after?", true, b[1]); + assertEquals(false, b[0], "Reports disposed upfront?"); + assertEquals(true, b[1], "Didn't report disposed after?"); } /** @@ -885,13 +877,13 @@ public void onComplete() { }); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("Reports disposed upfront?", false, b[0]); - assertEquals("Didn't report disposed after?", true, b[1]); + assertEquals(false, b[0], "Reports disposed upfront?"); + assertEquals(true, b[1], "Didn't report disposed after?"); } /** @@ -948,11 +940,11 @@ public static void checkDoubleOnSubscribeMaybe(Function, ? exten @Override protected void subscribeActual(MaybeObserver observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -969,13 +961,13 @@ protected void subscribeActual(MaybeObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1002,11 +994,11 @@ public static void checkDoubleOnSubscribeMaybeToSingle(Function, @Override protected void subscribeActual(MaybeObserver observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1023,13 +1015,13 @@ protected void subscribeActual(MaybeObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1056,11 +1048,11 @@ public static void checkDoubleOnSubscribeMaybeToObservable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1077,13 +1069,13 @@ protected void subscribeActual(MaybeObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1110,11 +1102,11 @@ public static void checkDoubleOnSubscribeMaybeToFlowable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1131,13 +1123,13 @@ protected void subscribeActual(MaybeObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1164,11 +1156,11 @@ public static void checkDoubleOnSubscribeSingleToMaybe(Function @Override protected void subscribeActual(SingleObserver observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1185,13 +1177,13 @@ protected void subscribeActual(SingleObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1217,11 +1209,11 @@ public static void checkDoubleOnSubscribeSingleToCompletable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1238,13 +1230,13 @@ protected void subscribeActual(SingleObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1271,11 +1263,11 @@ public static void checkDoubleOnSubscribeSingleToObservable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1292,13 +1284,13 @@ protected void subscribeActual(SingleObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1325,11 +1317,11 @@ public static void checkDoubleOnSubscribeSingleToFlowable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1346,13 +1338,13 @@ protected void subscribeActual(SingleObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1378,11 +1370,11 @@ public static void checkDoubleOnSubscribeMaybeToCompletable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1399,13 +1391,13 @@ protected void subscribeActual(MaybeObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1432,11 +1424,11 @@ public static void checkDoubleOnSubscribeSingle(Function, ? ext @Override protected void subscribeActual(SingleObserver observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1453,13 +1445,13 @@ protected void subscribeActual(SingleObserver observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1507,13 +1499,13 @@ protected void subscribeActual(Subscriber subscriber) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Subscription already set!"); } catch (Throwable ex) { @@ -1540,11 +1532,11 @@ public static void checkDoubleOnSubscribeObservable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1561,13 +1553,13 @@ protected void subscribeActual(Observer observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1594,11 +1586,11 @@ public static void checkDoubleOnSubscribeObservableToSingle(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1615,13 +1607,13 @@ protected void subscribeActual(Observer observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1648,11 +1640,11 @@ public static void checkDoubleOnSubscribeObservableToMaybe(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1669,13 +1661,13 @@ protected void subscribeActual(Observer observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1701,11 +1693,11 @@ public static void checkDoubleOnSubscribeObservableToCompletable(Function observer) { try { - Disposable d1 = Disposables.empty(); + Disposable d1 = Disposable.empty(); observer.onSubscribe(d1); - Disposable d2 = Disposables.empty(); + Disposable d2 = Disposable.empty(); observer.onSubscribe(d2); @@ -1722,13 +1714,13 @@ protected void subscribeActual(Observer observer) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First disposed?", false, b[0]); - assertEquals("Second not disposed?", true, b[1]); + assertEquals(false, b[0], "First disposed?"); + assertEquals(true, b[1], "Second not disposed?"); assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } catch (Throwable ex) { @@ -1776,13 +1768,13 @@ protected void subscribeActual(Subscriber subscriber) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First cancelled?", false, b[0]); - assertEquals("Second not cancelled?", true, b[1]); + assertEquals(false, b[0], "First cancelled?"); + assertEquals(true, b[1], "Second not cancelled?"); assertError(errors, 0, IllegalStateException.class, "Subscription already set!"); } catch (Throwable ex) { @@ -1830,13 +1822,13 @@ protected void subscribeActual(Subscriber subscriber) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First cancelled?", false, b[0]); - assertEquals("Second not cancelled?", true, b[1]); + assertEquals(false, b[0], "First cancelled?"); + assertEquals(true, b[1], "Second not cancelled?"); assertError(errors, 0, IllegalStateException.class, "Subscription already set!"); } catch (Throwable ex) { @@ -1884,13 +1876,13 @@ protected void subscribeActual(Subscriber subscriber) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First cancelled?", false, b[0]); - assertEquals("Second not cancelled?", true, b[1]); + assertEquals(false, b[0], "First cancelled?"); + assertEquals(true, b[1], "Second not cancelled?"); assertError(errors, 0, IllegalStateException.class, "Subscription already set!"); } catch (Throwable ex) { @@ -1937,13 +1929,13 @@ protected void subscribeActual(Subscriber subscriber) { out.subscribe(NoOpConsumer.INSTANCE); try { - assertTrue("Timed out", cdl.await(5, TimeUnit.SECONDS)); + assertTrue(cdl.await(5, TimeUnit.SECONDS), "Timed out"); } catch (InterruptedException ex) { throw ExceptionHelper.wrapOrThrow(ex); } - assertEquals("First cancelled?", false, b[0]); - assertEquals("Second not cancelled?", true, b[1]); + assertEquals(false, b[0], "First cancelled?"); + assertEquals(true, b[1], "Second not cancelled?"); assertError(errors, 0, IllegalStateException.class, "Subscription already set!"); } catch (Throwable ex) { @@ -1968,11 +1960,11 @@ public static void checkDoubleOnSubscribeCompletable(Function void checkDoubleOnSubscribeCompletableToMaybe(Function void checkDoubleOnSubscribeCompletableToSingle(Function the source value type - * @param the output value type - * @param composer the function to apply an operator to the provided Maybe source - */ - public static void checkDisposedMaybe(Function, ? extends MaybeSource> composer) { - PublishProcessor pp = PublishProcessor.create(); - - TestSubscriber ts = new TestSubscriber(); - - try { - new MaybeToFlowable(composer.apply(pp.singleElement())).subscribe(ts); - } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); - } - - assertTrue("Not subscribed to source!", pp.hasSubscribers()); - - ts.cancel(); - - assertFalse("Dispose not propagated!", pp.hasSubscribers()); - } - - /** - * Check if the operator applied to a Completable source propagates dispose properly. - * @param composer the function to apply an operator to the provided Completable source - */ - public static void checkDisposedCompletable(Function composer) { - PublishProcessor pp = PublishProcessor.create(); - - TestSubscriber ts = new TestSubscriber(); - - try { - new CompletableToFlowable(composer.apply(pp.ignoreElements())).subscribe(ts); - } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); - } - - assertTrue("Not subscribed to source!", pp.hasSubscribers()); - - ts.cancel(); - - assertFalse("Dispose not propagated!", pp.hasSubscribers()); - } - - /** - * Check if the operator applied to a Maybe source propagates dispose properly. - * @param the source value type - * @param the output value type - * @param composer the function to apply an operator to the provided Maybe source - */ - public static void checkDisposedMaybeToSingle(Function, ? extends SingleSource> composer) { - PublishProcessor pp = PublishProcessor.create(); - - TestSubscriber ts = new TestSubscriber(); - - try { - new SingleToFlowable(composer.apply(pp.singleElement())).subscribe(ts); - } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); - } - - assertTrue(pp.hasSubscribers()); - - ts.cancel(); - - assertFalse(pp.hasSubscribers()); - } - /** * Check if the TestSubscriber has a CompositeException with the specified class * of Throwables in the given order. * @param ts the TestSubscriber instance * @param classes the array of expected Throwables inside the Composite */ - public static void assertCompositeExceptions(TestSubscriber ts, Class... classes) { + @SafeVarargs + public static void assertCompositeExceptions(TestSubscriber ts, final Class... classes) { ts - .assertSubscribed() .assertError(CompositeException.class) - .assertNotComplete(); - - List list = compositeList(ts.errors().get(0)); + .assertNotComplete() + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + List list = compositeList(error); - assertEquals(classes.length, list.size()); + assertEquals(classes.length, list.size()); - for (int i = 0; i < classes.length; i++) { - assertError(list, i, classes[i]); - } + for (int i = 0; i < classes.length; i++) { + assertError(list, i, classes[i]); + } + return true; + } + }); } /** @@ -2316,7 +2243,6 @@ public static void assertCompositeExceptions(TestSubscriber ts, Class ts, Object... classes) { ts - .assertSubscribed() .assertError(CompositeException.class) .assertNotComplete(); @@ -2335,9 +2261,9 @@ public static void assertCompositeExceptions(TestSubscriber ts, Object... cla * @param to the TestSubscriber instance * @param classes the array of expected Throwables inside the Composite */ + @SafeVarargs public static void assertCompositeExceptions(TestObserver to, Class... classes) { to - .assertSubscribed() .assertError(CompositeException.class) .assertNotComplete(); @@ -2360,7 +2286,6 @@ public static void assertCompositeExceptions(TestObserver to, Class to, Object... classes) { to - .assertSubscribed() .assertError(CompositeException.class) .assertNotComplete(); @@ -2379,6 +2304,7 @@ public static void assertCompositeExceptions(TestObserver to, Object... class * @param p the target processor * @param values the values to emit */ + @SafeVarargs public static void emit(Processor p, T... values) { for (T v : values) { p.onNext(v); @@ -2392,6 +2318,7 @@ public static void emit(Processor p, T... values) { * @param p the target subject * @param values the values to emit */ + @SafeVarargs public static void emit(Subject p, T... values) { for (T v : values) { p.onNext(v); @@ -2455,11 +2382,11 @@ public void onComplete() { try { assertTrue(cdl.await(5, TimeUnit.SECONDS)); - assertTrue("Not fuseable", state[0]); - assertTrue("Fusion rejected", state[1]); + assertTrue(state[0], "Not fuseable"); + assertTrue(state[1], "Fusion rejected"); assertNotNull(state[2]); - assertTrue("Did not empty", state[3]); + assertTrue(state[3], "Did not empty"); } catch (InterruptedException ex) { throw new RuntimeException(ex); } @@ -2521,11 +2448,11 @@ public void onComplete() { try { assertTrue(cdl.await(5, TimeUnit.SECONDS)); - assertTrue("Not fuseable", state[0]); - assertTrue("Fusion rejected", state[1]); + assertTrue(state[0], "Not fuseable"); + assertTrue(state[1], "Fusion rejected"); assertNotNull(state[2]); - assertTrue("Did not empty", state[3]); + assertTrue(state[3], "Did not empty"); } catch (InterruptedException ex) { throw new RuntimeException(ex); } @@ -2567,7 +2494,7 @@ public static void checkBadSourceObservable(Function, Object> boolean once; @Override protected void subscribeActual(Observer observer) { - observer.onSubscribe(Disposables.empty()); + observer.onSubscribe(Disposable.empty()); if (once) { return; @@ -2596,20 +2523,23 @@ protected void subscribeActual(Observer observer) { if (o instanceof ObservableSource) { ObservableSource os = (ObservableSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2618,20 +2548,23 @@ protected void subscribeActual(Observer observer) { if (o instanceof Publisher) { Publisher os = (Publisher) o; - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); os.subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); - ts.assertSubscribed(); - if (expected != null) { ts.assertValues(expected); } if (error) { ts.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { ts.assertNoErrors().assertComplete(); @@ -2640,20 +2573,23 @@ protected void subscribeActual(Observer observer) { if (o instanceof SingleSource) { SingleSource os = (SingleSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2662,20 +2598,23 @@ protected void subscribeActual(Observer observer) { if (o instanceof MaybeSource) { MaybeSource os = (MaybeSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2684,20 +2623,23 @@ protected void subscribeActual(Observer observer) { if (o instanceof CompletableSource) { CompletableSource os = (CompletableSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2755,20 +2697,23 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof ObservableSource) { ObservableSource os = (ObservableSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2777,20 +2722,23 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof Publisher) { Publisher os = (Publisher) o; - TestSubscriber ts = new TestSubscriber(); + TestSubscriber ts = new TestSubscriber<>(); os.subscribe(ts); ts.awaitDone(5, TimeUnit.SECONDS); - ts.assertSubscribed(); - if (expected != null) { ts.assertValues(expected); } if (error) { ts.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { ts.assertNoErrors().assertComplete(); @@ -2799,20 +2747,23 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof SingleSource) { SingleSource os = (SingleSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2821,20 +2772,23 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof MaybeSource) { MaybeSource os = (MaybeSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2843,20 +2797,23 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof CompletableSource) { CompletableSource os = (CompletableSource) o; - TestObserver to = new TestObserver(); + TestObserver to = new TestObserver<>(); os.subscribe(to); to.awaitDone(5, TimeUnit.SECONDS); - to.assertSubscribed(); - if (expected != null) { to.assertValues(expected); } if (error) { to.assertError(TestException.class) - .assertErrorMessage("error") + .assertError(new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals("error"); + } + }) .assertNotComplete(); } else { to.assertNoErrors().assertComplete(); @@ -2879,7 +2836,7 @@ public static void checkInvalidParallelSubscribers(ParallelFlowable sourc @SuppressWarnings("unchecked") TestSubscriber[] tss = new TestSubscriber[n + 1]; for (int i = 0; i <= n; i++) { - tss[i] = new TestSubscriber().withTag("" + i); + tss[i] = new TestSubscriber<>().withTag("" + i); } source.subscribe(tss); @@ -2889,29 +2846,12 @@ public static void checkInvalidParallelSubscribers(ParallelFlowable sourc } } - public static TestSubscriber fusedSubscriber(int mode) { - TestSubscriber ts = new TestSubscriber(); - try { - Field f = BaseTestConsumer.class.getDeclaredField("initialFusionMode"); - f.setAccessible(true); - f.set(ts, mode); - } catch (Throwable ex) { - throw Exceptions.propagate(ex); - } + public static TestSubscriberEx fusedSubscriber(int mode) { + TestSubscriberEx ts = new TestSubscriberEx<>(); + ts.setInitialFusionMode(mode); return ts; } - public static Consumer> assertFusedSubscriber(final int mode) { - return new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - Field f = BaseTestConsumer.class.getDeclaredField("establishedFusionMode"); - f.setAccessible(true); - assertEquals(mode, f.get(ts)); - } - }; - } - /** * Find the base source directory of this project. * @return the File pointing to the source @@ -2933,7 +2873,7 @@ public static File findSourceDir() throws Exception { // find end of any potential postfix to /RxJava int j = path.indexOf("/", i + 6); - String p = path.substring(0, j + 1) + "src/main/java/hu/akarnokd/rxjava2"; + String p = path.substring(0, j + 1) + "src/main/java/hu/akarnokd/rxjava4"; File f = new File(p); @@ -2945,4 +2885,12 @@ public static File findSourceDir() throws Exception { return f; } + public static Predicate assertErrorMessage(final String message) { + return new Predicate() { + @Override + public boolean test(Throwable error) throws Throwable { + return error.getMessage().equals(message); + } + }; + } } \ No newline at end of file diff --git a/src/test/java/hu/akarnokd/rxjava4/test/TestObserverEx.java b/src/test/java/hu/akarnokd/rxjava4/test/TestObserverEx.java new file mode 100644 index 00000000..3bd9ee91 --- /dev/null +++ b/src/test/java/hu/akarnokd/rxjava4/test/TestObserverEx.java @@ -0,0 +1,322 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.test; + +import java.util.concurrent.atomic.AtomicReference; + +import hu.akarnokd.rxjava4.internal.rxcopy.DisposableHelper; +import io.reactivex.rxjava4.core.*; +import io.reactivex.rxjava4.disposables.Disposable; +import io.reactivex.rxjava4.operators.*; + +/** + * An extended test Observer that records events and allows making assertions about them. + * + *

You can override the onSubscribe, onNext, onError, onComplete, onSuccess and + * cancel methods but not the others (this is by design). + * + *

The TestObserver implements Disposable for convenience where dispose calls cancel. + * + * @param the value type + */ +public class TestObserverEx +extends BaseTestConsumerEx> +implements Observer, Disposable, MaybeObserver, SingleObserver, CompletableObserver { + /** The actual observer to forward events to. */ + private final Observer downstream; + + /** Holds the current subscription if any. */ + private final AtomicReference upstream = new AtomicReference<>(); + + private QueueDisposable qd; + + /** + * Constructs a non-forwarding TestObserver. + */ + public TestObserverEx() { + this(EmptyObserver.INSTANCE); + } + + /** + * Constructs a forwarding TestObserver. + * @param downstream the actual Observer to forward events to + */ + public TestObserverEx(Observer downstream) { + this.downstream = downstream; + } + + /** + * Constructs a TestObserverEx with the given initial fusion mode. + * @param fusionMode the fusion mode, see {@link QueueFuseable} + */ + public TestObserverEx(int fusionMode) { + this(); + setInitialFusionMode(fusionMode); + } + + @SuppressWarnings("unchecked") + @Override + public void onSubscribe(Disposable d) { + lastThread = Thread.currentThread(); + + if (d == null) { + errors.add(new NullPointerException("onSubscribe received a null Subscription")); + return; + } + if (!upstream.compareAndSet(null, d)) { + d.dispose(); + if (upstream.get() != DisposableHelper.DISPOSED) { + errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + d)); + } + return; + } + + if (initialFusionMode != 0) { + if (d instanceof QueueDisposable) { + qd = (QueueDisposable)d; + + int m = qd.requestFusion(initialFusionMode); + establishedFusionMode = m; + + if (m == QueueFuseable.SYNC) { + checkSubscriptionOnce = true; + lastThread = Thread.currentThread(); + try { + T t; + while ((t = qd.poll()) != null) { + values.add(t); + } + completions++; + + upstream.lazySet(DisposableHelper.DISPOSED); + } catch (Throwable ex) { + errors.add(ex); + } + return; + } + } + } + + downstream.onSubscribe(d); + } + + @Override + public void onNext(T t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + + lastThread = Thread.currentThread(); + + if (establishedFusionMode == QueueFuseable.ASYNC) { + try { + while ((t = qd.poll()) != null) { + values.add(t); + } + } catch (Throwable ex) { + errors.add(ex); + qd.dispose(); + } + return; + } + + values.add(t); + + if (t == null) { + errors.add(new NullPointerException("onNext received a null value")); + } + + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + + try { + lastThread = Thread.currentThread(); + if (t == null) { + errors.add(new NullPointerException("onError received a null Throwable")); + } else { + errors.add(t); + } + + downstream.onError(t); + } finally { + done.countDown(); + } + } + + @Override + public void onComplete() { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + + try { + lastThread = Thread.currentThread(); + completions++; + + downstream.onComplete(); + } finally { + done.countDown(); + } + } + + @Override + public final void dispose() { + DisposableHelper.dispose(upstream); + } + + @Override + public final boolean isDisposed() { + return DisposableHelper.isDisposed(upstream.get()); + } + + // state retrieval methods + /** + * Returns true if this TestObserver received a subscription. + * @return true if this TestObserver received a subscription + */ + public final boolean hasSubscription() { + return upstream.get() != null; + } + + /** + * Assert that the onSubscribe method was called exactly once. + * @return this; + */ + @Override + public final TestObserverEx assertSubscribed() { + if (upstream.get() == null) { + throw fail("Not subscribed!"); + } + return this; + } + + /** + * Assert that the onSubscribe method hasn't been called at all. + * @return this; + */ + public final TestObserverEx assertNotSubscribed() { + if (upstream.get() != null) { + throw fail("Subscribed!"); + } else + if (!errors.isEmpty()) { + throw fail("Not subscribed but errors found"); + } + return this; + } + + /** + * Sets the initial fusion mode if the upstream supports fusion. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @param mode the mode to establish, see the {@link QueueDisposable} constants + * @return this + */ + public final TestObserverEx setInitialFusionMode(int mode) { + this.initialFusionMode = mode; + return this; + } + + /** + * Asserts that the given fusion mode has been established + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @param mode the expected mode + * @return this + */ + public final TestObserverEx assertFusionMode(int mode) { + int m = establishedFusionMode; + if (m != mode) { + if (qd != null) { + throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) + + ", actual: " + fusionModeToString(m)); + } else { + throw fail("Upstream is not fuseable"); + } + } + return this; + } + + /** + * Assert that the upstream is a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @return this + */ + public final TestObserverEx assertFuseable() { + if (qd == null) { + throw new AssertionError("Upstream is not fuseable."); + } + return this; + } + + /** + * Assert that the upstream is not a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @return this + */ + public final TestObserverEx assertNotFuseable() { + if (qd != null) { + throw new AssertionError("Upstream is fuseable."); + } + return this; + } + + @Override + public void onSuccess(T value) { + onNext(value); + onComplete(); + } + + /** + * An observer that ignores all events and does not report errors. + */ + enum EmptyObserver implements Observer { + INSTANCE; + + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(Object t) { + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onComplete() { + } + } +} \ No newline at end of file diff --git a/src/test/java/hu/akarnokd/rxjava4/test/TestSubscriberEx.java b/src/test/java/hu/akarnokd/rxjava4/test/TestSubscriberEx.java new file mode 100644 index 00000000..a9240410 --- /dev/null +++ b/src/test/java/hu/akarnokd/rxjava4/test/TestSubscriberEx.java @@ -0,0 +1,390 @@ +/* + * Copyright 2016-present David Karnok + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package hu.akarnokd.rxjava4.test; + +import java.util.concurrent.Flow.*; +import java.util.concurrent.atomic.*; + +import hu.akarnokd.rxjava4.internal.rxcopy.SubscriptionHelper; +import io.reactivex.rxjava4.core.FlowableSubscriber; +import io.reactivex.rxjava4.operators.*; + +/** + * An extended test subscriber that records events and allows making assertions about them. + * + *

You can override the onSubscribe, onNext, onError, onComplete, request and + * cancel methods but not the others (this is by design). + * + *

The TestSubscriber implements Disposable for convenience where dispose calls cancel. + * + *

When calling the default request method, you are requesting on behalf of the + * wrapped actual subscriber. + * + * @param the value type + */ +public class TestSubscriberEx +extends BaseTestConsumerEx> +implements FlowableSubscriber, Subscription { + /** The actual subscriber to forward events to. */ + private final Subscriber downstream; + + /** Makes sure the incoming Subscriptions get cancelled immediately. */ + private volatile boolean cancelled; + + /** Holds the current subscription if any. */ + private final AtomicReference upstream; + + /** Holds the requested amount until a subscription arrives. */ + private final AtomicLong missedRequested; + + private QueueSubscription qs; + + /** + * Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE. + */ + public TestSubscriberEx() { + this(EmptySubscriber.INSTANCE, Long.MAX_VALUE); + } + + /** + * Constructs a non-forwarding TestSubscriber with the specified initial request value. + *

The TestSubscriber doesn't validate the initialRequest value so one can + * test sources with invalid values as well. + * @param initialRequest the initial request value + */ + public TestSubscriberEx(long initialRequest) { + this(EmptySubscriber.INSTANCE, initialRequest); + } + + /** + * Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber. + * @param downstream the actual Subscriber to forward events to + */ + public TestSubscriberEx(Subscriber downstream) { + this(downstream, Long.MAX_VALUE); + } + + /** + * Constructs a forwarding TestSubscriber with the specified initial request value. + *

The TestSubscriber doesn't validate the initialRequest value so one can + * test sources with invalid values as well. + * @param downstream the actual Subscriber to forward events to + * @param initialRequest the initial request value + */ + public TestSubscriberEx(Subscriber downstream, long initialRequest) { + super(); + if (initialRequest < 0) { + throw new IllegalArgumentException("Negative initial request not allowed"); + } + this.downstream = downstream; + this.upstream = new AtomicReference<>(); + this.missedRequested = new AtomicLong(initialRequest); + } + + @SuppressWarnings("unchecked") + @Override + public void onSubscribe(Subscription s) { + lastThread = Thread.currentThread(); + + if (s == null) { + errors.add(new NullPointerException("onSubscribe received a null Subscription")); + return; + } + if (!upstream.compareAndSet(null, s)) { + s.cancel(); + if (upstream.get() != SubscriptionHelper.CANCELLED) { + errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + s)); + } + return; + } + + if (initialFusionMode != 0) { + if (s instanceof QueueSubscription) { + qs = (QueueSubscription)s; + + int m = qs.requestFusion(initialFusionMode); + establishedFusionMode = m; + + if (m == QueueFuseable.SYNC) { + checkSubscriptionOnce = true; + lastThread = Thread.currentThread(); + try { + T t; + while ((t = qs.poll()) != null) { + values.add(t); + } + completions++; + } catch (Throwable ex) { + // Exceptions.throwIfFatal(e); TODO add fatal exceptions? + errors.add(ex); + } + return; + } + } + } + + downstream.onSubscribe(s); + + long mr = missedRequested.getAndSet(0L); + if (mr != 0L) { + s.request(mr); + } + + onStart(); + } + + /** + * Called after the onSubscribe is called and handled. + */ + protected void onStart() { + + } + + @Override + public void onNext(T t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + lastThread = Thread.currentThread(); + + if (establishedFusionMode == QueueFuseable.ASYNC) { + try { + while ((t = qs.poll()) != null) { + values.add(t); + } + } catch (Throwable ex) { + // Exceptions.throwIfFatal(e); TODO add fatal exceptions? + errors.add(ex); + qs.cancel(); + } + return; + } + + values.add(t); + + if (t == null) { + errors.add(new NullPointerException("onNext received a null value")); + } + + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new NullPointerException("onSubscribe not called in proper order")); + } + } + try { + lastThread = Thread.currentThread(); + errors.add(t); + + if (t == null) { + errors.add(new IllegalStateException("onError received a null Throwable")); + } + + downstream.onError(t); + } finally { + done.countDown(); + } + } + + @Override + public void onComplete() { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + try { + lastThread = Thread.currentThread(); + completions++; + + downstream.onComplete(); + } finally { + done.countDown(); + } + } + + @Override + public final void request(long n) { + SubscriptionHelper.deferredRequest(upstream, missedRequested, n); + } + + @Override + public final void cancel() { + if (!cancelled) { + cancelled = true; + SubscriptionHelper.cancel(upstream); + } + } + + /** + * Returns true if this TestSubscriber has been cancelled. + * @return true if this TestSubscriber has been cancelled + */ + public final boolean isCancelled() { + return cancelled; + } + + @Override + protected final void dispose() { + cancel(); + } + + @Override + protected final boolean isDisposed() { + return cancelled; + } + + // state retrieval methods + + /** + * Returns true if this TestSubscriber received a subscription. + * @return true if this TestSubscriber received a subscription + */ + public final boolean hasSubscription() { + return upstream.get() != null; + } + + // assertion methods + + /** + * Assert that the onSubscribe method was called exactly once. + * @return this + */ + @Override + public final TestSubscriberEx assertSubscribed() { + if (upstream.get() == null) { + throw fail("Not subscribed!"); + } + return this; + } + + /** + * Assert that the onSubscribe method hasn't been called at all. + * @return this + */ + public final TestSubscriberEx assertNotSubscribed() { + if (upstream.get() != null) { + throw fail("Subscribed!"); + } else + if (!errors.isEmpty()) { + throw fail("Not subscribed but errors found"); + } + return this; + } + + /** + * Sets the initial fusion mode if the upstream supports fusion. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @param mode the mode to establish, see the {@link QueueSubscription} constants + * @return this + */ + public final TestSubscriberEx setInitialFusionMode(int mode) { + this.initialFusionMode = mode; + return this; + } + + /** + * Asserts that the given fusion mode has been established + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @param mode the expected mode + * @return this + */ + public final TestSubscriberEx assertFusionMode(int mode) { + int m = establishedFusionMode; + if (m != mode) { + if (qs != null) { + throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) + + ", actual: " + fusionModeToString(m)); + } else { + throw fail("Upstream is not fuseable"); + } + } + return this; + } + + /** + * Assert that the upstream is a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @return this + */ + public final TestSubscriberEx assertFuseable() { + if (qs == null) { + throw new AssertionError("Upstream is not fuseable."); + } + return this; + } + + /** + * Assert that the upstream is not a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @return this + */ + public final TestSubscriberEx assertNotFuseable() { + if (qs != null) { + throw new AssertionError("Upstream is fuseable."); + } + return this; + } + + /** + * Calls {@link #request(long)} and returns this. + *

History: 2.0.1 - experimental + * @param n the request amount + * @return this + * @since 2.1 + */ + public final TestSubscriberEx requestMore(long n) { + request(n); + return this; + } + + /** + * A subscriber that ignores all events and does not report errors. + */ + enum EmptySubscriber implements FlowableSubscriber { + INSTANCE; + + @Override + public void onSubscribe(Subscription s) { + } + + @Override + public void onNext(Object t) { + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onComplete() { + } + } +} \ No newline at end of file diff --git a/src/test/java/hu/akarnokd/rxjava2/util/SpmcLinkedArrayQueueTest.java b/src/test/java/hu/akarnokd/rxjava4/util/SpmcLinkedArrayQueueTest.java similarity index 88% rename from src/test/java/hu/akarnokd/rxjava2/util/SpmcLinkedArrayQueueTest.java rename to src/test/java/hu/akarnokd/rxjava4/util/SpmcLinkedArrayQueueTest.java index 4f6e5150..74d45399 100644 --- a/src/test/java/hu/akarnokd/rxjava2/util/SpmcLinkedArrayQueueTest.java +++ b/src/test/java/hu/akarnokd/rxjava4/util/SpmcLinkedArrayQueueTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,28 +14,29 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.util; +package hu.akarnokd.rxjava4.util; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.*; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; public class SpmcLinkedArrayQueueTest { - @Test(timeout = 5000) + @Test + @Timeout(5) public void simple() { - SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue(32); + SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue<>(32); for (int i = 0; i < 128; i++) { assertTrue(q.isEmpty()); assertTrue(q.offer(i)); assertFalse(q.isEmpty()); assertEquals(i, q.poll().intValue()); - assertTrue("" + i, q.isEmpty()); + assertTrue(q.isEmpty(), "" + i); assertNull(q.poll()); } @@ -58,9 +59,10 @@ public void simple() { assertTrue(q.isEmpty()); } - @Test(timeout = 5000) + @Test + @Timeout(5) public void simple2() { - SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue(32); + SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue<>(32); for (int i = 0; i < 128; i++) { assertTrue(q.isEmpty()); @@ -68,7 +70,7 @@ public void simple2() { assertFalse(q.isEmpty()); assertEquals(i, q.poll().intValue()); assertEquals(i, q.poll().intValue()); - assertTrue("" + i, q.isEmpty()); + assertTrue(q.isEmpty(), "" + i); assertNull(q.poll()); } @@ -95,13 +97,13 @@ public void simple2() { @Test public void consumerRace() { for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { - final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue(32); + final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue<>(32); for (int j = 0; j < 1000; j++) { q.offer(j); } - final Set set1 = new HashSet(); + final Set set1 = new HashSet<>(); Runnable r1 = new Runnable() { @Override public void run() { @@ -115,7 +117,7 @@ public void run() { } }; - final Set set2 = new HashSet(); + final Set set2 = new HashSet<>(); Runnable r2 = new Runnable() { @Override public void run() { @@ -146,7 +148,7 @@ public void run() { @Test public void consumerRaceLong() { for (int i = 0; i < TestHelper.RACE_LONG_LOOPS / 25; i++) { - final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue(32); + final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue<>(32); int n = 50000; @@ -154,7 +156,7 @@ public void consumerRaceLong() { q.offer(j); } - final Set set1 = new HashSet(); + final Set set1 = new HashSet<>(); Runnable r1 = new Runnable() { @Override public void run() { @@ -168,7 +170,7 @@ public void run() { } }; - final Set set2 = new HashSet(); + final Set set2 = new HashSet<>(); Runnable r2 = new Runnable() { @Override public void run() { @@ -199,13 +201,13 @@ public void run() { @Test public void consumerRace2() { for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { - final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue(32); + final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue<>(32); for (int j = 0; j < 1000; j++) { q.offer(j); } - final Set set1 = new HashSet(); + final Set set1 = new HashSet<>(); Runnable r1 = new Runnable() { @Override public void run() { @@ -219,7 +221,7 @@ public void run() { } }; - final Set set2 = new HashSet(); + final Set set2 = new HashSet<>(); Runnable r2 = new Runnable() { @Override public void run() { @@ -250,7 +252,7 @@ public void run() { @Test public void produceConsumeRace() { for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { - final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue(32); + final SpmcLinkedArrayQueue q = new SpmcLinkedArrayQueue<>(32); Runnable r1 = new Runnable() { @Override @@ -261,7 +263,7 @@ public void run() { } }; - final List list = new ArrayList(); + final List list = new ArrayList<>(); Runnable r2 = new Runnable() { @Override public void run() { diff --git a/src/test/java/hu/akarnokd/rxjava2/validation/CheckLocalVariablesInTests.java b/src/test/java/hu/akarnokd/rxjava4/validation/CheckLocalVariablesInTests.java similarity index 92% rename from src/test/java/hu/akarnokd/rxjava2/validation/CheckLocalVariablesInTests.java rename to src/test/java/hu/akarnokd/rxjava4/validation/CheckLocalVariablesInTests.java index 8c2b8c97..4ae037dc 100644 --- a/src/test/java/hu/akarnokd/rxjava2/validation/CheckLocalVariablesInTests.java +++ b/src/test/java/hu/akarnokd/rxjava4/validation/CheckLocalVariablesInTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,15 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.validation; +package hu.akarnokd.rxjava4.validation; import java.io.*; import java.util.*; import java.util.regex.Pattern; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; /** * Checks for commonly copy-pasted but not-renamed local variables in unit tests. @@ -52,7 +52,7 @@ static void findPattern(String pattern, boolean checkMain) throws Exception { return; } - Queue dirs = new ArrayDeque(); + Queue dirs = new ArrayDeque<>(); StringBuilder fail = new StringBuilder(); fail.append("The following code pattern was found: ").append(pattern).append("\n"); @@ -93,11 +93,23 @@ static void findPattern(String pattern, boolean checkMain) throws Exception { if (!line.startsWith("//") && !line.startsWith("*")) { if (p.matcher(line).find()) { + + int j = u.getAbsolutePath().lastIndexOf("rxjava4"); + var classPathName = u.getAbsolutePath().substring(j + 7).replace('\\', '.').replace('/', '.'); + fail .append(fname) .append("#L").append(lineNum) .append(" ").append(line) - .append("\n"); + .append("\n") + .append(" at hu.akarnokd.rxjava4") + .append(classPathName) + .append("Method(") + .append(fname) + .append(":") + .append(lineNum) + .append(")\n") + ; total++; } } diff --git a/src/test/java/hu/akarnokd/rxjava2/validation/NewLinesBeforeAnnotation.java b/src/test/java/hu/akarnokd/rxjava4/validation/NewLinesBeforeAnnotation.java similarity index 95% rename from src/test/java/hu/akarnokd/rxjava2/validation/NewLinesBeforeAnnotation.java rename to src/test/java/hu/akarnokd/rxjava4/validation/NewLinesBeforeAnnotation.java index 230a7008..d2ecd58c 100644 --- a/src/test/java/hu/akarnokd/rxjava2/validation/NewLinesBeforeAnnotation.java +++ b/src/test/java/hu/akarnokd/rxjava4/validation/NewLinesBeforeAnnotation.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.validation; +package hu.akarnokd.rxjava4.validation; import java.io.*; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; /** * These tests verify the code style that a typical closing curly brace @@ -75,7 +75,7 @@ static void findPattern(int newLines) throws Exception { return; } - Queue dirs = new ArrayDeque(); + Queue dirs = new ArrayDeque<>(); StringBuilder fail = new StringBuilder(); fail.append("The following code pattern was found: "); @@ -105,7 +105,7 @@ static void findPattern(int newLines) throws Exception { String fname = u.getName(); if (fname.endsWith(".java")) { - List lines = new ArrayList(); + List lines = new ArrayList<>(); BufferedReader in = new BufferedReader(new FileReader(u)); try { for (;;) { diff --git a/src/test/java/hu/akarnokd/rxjava2/validation/TooManyEmptyNewLines.java b/src/test/java/hu/akarnokd/rxjava4/validation/TooManyEmptyNewLines.java similarity index 94% rename from src/test/java/hu/akarnokd/rxjava2/validation/TooManyEmptyNewLines.java rename to src/test/java/hu/akarnokd/rxjava4/validation/TooManyEmptyNewLines.java index cb6293df..2b63d9f4 100644 --- a/src/test/java/hu/akarnokd/rxjava2/validation/TooManyEmptyNewLines.java +++ b/src/test/java/hu/akarnokd/rxjava4/validation/TooManyEmptyNewLines.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 David Karnok + * Copyright 2016-present David Karnok * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ * limitations under the License. */ -package hu.akarnokd.rxjava2.validation; +package hu.akarnokd.rxjava4.validation; import java.io.*; import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import hu.akarnokd.rxjava2.test.TestHelper; +import hu.akarnokd.rxjava4.test.TestHelper; /** * Test verifying there are no 2..5 empty newlines in the code. @@ -55,7 +55,7 @@ static void findPattern(int newLines) throws Exception { return; } - Queue dirs = new ArrayDeque(); + Queue dirs = new ArrayDeque<>(); StringBuilder fail = new StringBuilder(); fail.append("The following code pattern was found: "); @@ -85,7 +85,7 @@ static void findPattern(int newLines) throws Exception { String fname = u.getName(); if (fname.endsWith(".java")) { - List lines = new ArrayList(); + List lines = new ArrayList<>(); BufferedReader in = new BufferedReader(new FileReader(u)); try { for (;;) { diff --git a/src/test/resources/junit-platform.properties b/src/test/resources/junit-platform.properties new file mode 100644 index 00000000..a7619809 --- /dev/null +++ b/src/test/resources/junit-platform.properties @@ -0,0 +1,5 @@ +junit.jupiter.execution.timeout.test.method.default=30s +# Or other formats: 500ms, 2m, 1h, etc. + +junit.jupiter.execution.timeout.mode=disabled_on_debug +# (or disabled)