├── .gitignore ├── .mvn ├── jvm.config ├── maven.config └── wrapper │ └── maven-wrapper.properties ├── .whitesource ├── LICENSE ├── README.md ├── _data └── module-info.java ├── deploy.sh ├── docker-compose.yml ├── docker_compile_locale.sh ├── docker_compile_locale_with_nexus.sh ├── pom.xml ├── src ├── main │ └── java │ │ └── com │ │ └── svenruppert │ │ └── functional │ │ ├── Converting.java │ │ ├── ExceptionFunctions.java │ │ ├── StreamFunctions.java │ │ ├── StringFunctions.java │ │ ├── SystemProperties.java │ │ ├── Transformations.java │ │ ├── functions │ │ ├── CheckedBiFunction.java │ │ ├── CheckedConsumer.java │ │ ├── CheckedExecutor.java │ │ ├── CheckedFunction.java │ │ ├── CheckedPredicate.java │ │ ├── CheckedSupplier.java │ │ ├── CheckedTriFunction.java │ │ ├── QuadFunction.java │ │ └── TriFunction.java │ │ ├── matcher │ │ └── Case.java │ │ ├── memoizer │ │ └── Memoizer.java │ │ ├── model │ │ ├── Pair.java │ │ ├── Quad.java │ │ ├── Quint.java │ │ ├── Result.java │ │ ├── Sept.java │ │ ├── Sext.java │ │ ├── Single.java │ │ ├── Triple.java │ │ └── serial │ │ │ ├── Pair.java │ │ │ ├── Quad.java │ │ │ ├── Quint.java │ │ │ ├── Sept.java │ │ │ ├── Sext.java │ │ │ ├── Single.java │ │ │ └── Triple.java │ │ └── reactive │ │ └── CompletableFutureQueue.java └── test │ └── java │ ├── demo │ ├── DemoCase.java │ ├── DemoCompletableFuture.java │ ├── DemoCompletableFutureQueue.java │ ├── DemoExceptions.java │ ├── DemoExtraction.java │ ├── DemoFunctionalInterfaces.java │ ├── DemoMemoizingLegacy.java │ ├── DemoMigration.java │ ├── DemoObserver.java │ ├── DemoOptional.java │ ├── DemoRegistration.java │ ├── DemoResult.java │ └── OOversusFRP.java │ └── junit │ └── com │ └── svenruppert │ └── functional │ ├── ConvertingTest.java │ ├── StreamFunctionsTest.java │ ├── StringFunctionsTest.java │ ├── TransformationsTest.java │ ├── functions │ ├── CheckedBiFunctionTest.java │ ├── CheckedExecutorTest.java │ ├── CheckedFunctionTest.java │ ├── CheckedPredicateTest.java │ └── CheckedSupplierTest.java │ ├── matcher │ └── CaseTest.java │ └── model │ ├── PairTest.java │ ├── QuadTest.java │ ├── QuintTest.java │ ├── ResultTest.java │ ├── SeptTest.java │ ├── SextTest.java │ ├── SingleTest.java │ └── TripleTest.java └── version-number-rules.xml /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx256m -Xms128m -Djava.awt.headless=true -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Dmaven.test.failure.ignore=false -P_java-and-kotlin -e -X 2 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 2 | -------------------------------------------------------------------------------- /.whitesource: -------------------------------------------------------------------------------- 1 | { 2 | "scanSettings": { 3 | "baseBranches": [] 4 | }, 5 | "checkRunSettings": { 6 | "vulnerableCheckRunConclusionLevel": "failure", 7 | "displayMode": "diff" 8 | }, 9 | "issueSettings": { 10 | "minSeverityLevel": "LOW" 11 | } 12 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.rapidpm/rapidpm-functional-reactive/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.rapidpm/rapidpm-functional-reactive) 2 | 3 | 4 | ![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=functional-reactive_functional-reactive-lib&metric=security_rating) 5 | ![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=functional-reactive_functional-reactive-lib&metric=sqale_rating) 6 | 7 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a0b7d530374d400fa9a79d270cf95c1a)](https://www.codacy.com/app/sven-ruppert/functional-reactive-lib?utm_source=github.com&utm_medium=referral&utm_content=functional-reactive/functional-reactive-lib&utm_campaign=Badge_Grade) 8 | 9 | 10 | # Functional Reactive Lib with Core Java 11 | This is a nano lib, based on a few classes that will give you 12 | a handful of functional elements that you can use in your core Java project. 13 | If you want to know more about it, have a look at my Youtube Series about this topic. 14 | 15 | * (EN): [https://youtu.be/jMP9r5_bi5c](https://youtu.be/jMP9r5_bi5c) 16 | * (DE): [https://youtu.be/S5ysVvritIg](https://youtu.be/S5ysVvritIg) 17 | 18 | ## Please, subscribe my **Youtube channel** 19 | * Youtube: [DE] - [bit.ly/Youtube-Sven](https://bit.ly/Youtube-Sven) 20 | * Youtube: [EN] - [bit.ly/Outdoor-Nerd](https://bit.ly/Outdoor-Nerd) 21 | 22 | ## JDK8 or JDK9 and above 23 | I compiled this with the Open JDK8. 24 | Previous versions at maven central are build ith JDK10. 25 | I went away from the JDK10, because most projects I know, are using JDK8 in production right know. 26 | But, if you want to use this with JDK9/10/11/... you can use it.. it is working perfect! 27 | Only if you start using the JMS, it could be helpful to add a **module-info.java** 28 | Add the following lines, switch inside the pom.xml to the JDK version you prefer, 29 | start a **mvn clean install** and be happy ;-) 30 | 31 | ```java 32 | module com.svenruppert.functional.reactive { 33 | exports com.svenruppert.frp; 34 | exports com.svenruppert.functional.functions; 35 | exports com.svenruppert.functional.matcher; 36 | exports com.svenruppert.functional.memoizer; 37 | exports com.svenruppert.functional.model; 38 | exports com.svenruppert.functional.model.serial; 39 | exports com.svenruppert.functional.reactive; 40 | } 41 | ``` 42 | 43 | 44 | # Release Notes 45 | 46 | ## 03.00.00 - BREAKING CHANGES 47 | I switched to dependencies com.svenruppert with version 06.00.00 48 | This is the same as rapidpm dependencies, but in a new namespace and smaller updates. 49 | This project is switching to the namespace com.svenruppert as well. 50 | no new features are included. 51 | 52 | ## 02.00.04-SRU 53 | fixed jdk in jitpack yml 54 | 55 | ## 02.00.03-SRU 56 | updated parent, and maven minimum version to 3.9.6 57 | 58 | ## 02.00.02-SRU 59 | Switched groupid to 02.00.02-SRU - jitpack custom domain name is not working properly 60 | updated to parent version 05.00.03-SRU 61 | 62 | ## 02.00.00-SRU 63 | Changing to new namespace. The package will be under 64 | com.svenruppert:functional-reactive now 65 | 66 | 67 | ## 01.01.00-RPM-SNAPSHOT 68 | This release we will increase test coverage and documentation. 69 | The basic structures and functions are in production used since longer time. 70 | Adding Apache Lic header to all files 71 | 72 | ## 01.00.07-RPM 73 | 74 | * Transformations 75 | * static Function, Stream> iteratorToStream() 76 | * Result thenCombineFlat(V value, BiFunction func) 77 | * started Youtube Series about this lib. 78 | * removed JitCI from production pipeline 79 | 80 | ## 01.00.03-RPM 81 | * added JitCI for deployment as well 82 | * version updates 83 | 84 | ## 01.00.02-RPM 85 | * static CheckedFunction asCheckedFunc(Function f) 86 | * Converting.convertToString 87 | * Converting.convertToInteger 88 | * Converting.convertToDouble 89 | * SystemProperties Util Functions 90 | * Single 91 | 92 | ## 01.00.01-RPM 93 | * BUGFIX in case, the result was calculated two times. 94 | 95 | ## 01.00.00-RPM 96 | * defined it as final, as there was no big change since a long time using it in a bunch of projects 97 | * JDK8 is used to create the jar 98 | * module-info.java is available inside the folder **_data** 99 | 100 | ## 00.07.06-RPM 101 | * parent pom update - version updates 102 | 103 | ## 00.07.05-RPM 104 | * parent pom update - version updates 105 | * added docker based deploy scripts 106 | 107 | ## 00.07.04-RPM 108 | * switched to new version numbers format 109 | To make search/replace easier, I started with a new version format. 110 | 00.07.04-RPM ( -SNAPSHOT). The x.y.z is used in the same way, as before, but added RPM 111 | and leading zeros to make this format different from others. 112 | With this it is less possible to mix/change version numbers from 113 | other dependencies. A **0.7.4** could be used from different 114 | dependencies. ;-) 115 | 116 | ## 0.7.3 117 | * dependency updates 118 | * added ```CompletableFutureQueue thenCombineAsyncFromArray(Function[] nextTransformations)``` 119 | 120 | ## 0.7.2 121 | * bug fix for **modules-info.java** 122 | 123 | ## 0.7.1 - DONT USED THIS VERSION !! broken module-info.java 124 | * activated JIGSAW 125 | * updated to rapidpm-dependencies 4.0.2 126 | 127 | ## 0.7.0 && 0.7.0-JDK8-SNAPSHOT 128 | * started with JDK10/11 support 129 | * using JDK11 for development and JDK10 for deployment 130 | 131 | ## 0.6.2 132 | * latest JDK8 only version! - switching to JDK10/11 -- JDK8 model 133 | 134 | ## 0.6.1 135 | * Added docker scripts for cross JDK compiles 136 | * updates parent versions 137 | * deactivated nexus mirror for drone 138 | * deactivated orig IBM JDK 8/9 Docker images 139 | 140 | ## 0.6.0 141 | This release is a maintenance release only, no new functionality 142 | * switched to new dependencies version 0.6.3 143 | * this includes the lic header plugin 144 | * version updates 145 | * minimized profiles 146 | * removed indirect dependency to old nexus 147 | * updated all file headers 148 | 149 | ## 0.5.3 150 | * added ```CheckedTriFunction extends TriFunction>``` 151 | * typo unCurryBifunction -> unCurryBiFunction 152 | * typo unCurryTrifunction -> unCurryTriFunction 153 | * curry / un-curry Checked Functions ```Transformations``` 154 | * curryCheckedBiFunction() - ```Function, Function>>``` 155 | * unCurryCheckedBiFunction() - ```Function>, CheckedBiFunction>``` 156 | * curryCheckedTriFunction() - ```Function< 157 | CheckedTriFunction, 158 | Function>>>``` 159 | * unCurryCheckedTriFunction() - ```Function< 160 | Function>>, 161 | CheckedTriFunction>``` 162 | 163 | ## 0.5.2 164 | * extend Result with a fluent API 165 | * void ifFailed -> Result ifFailed 166 | * void ifPresent -> Result ifPresent 167 | * void ifAbsent -> Result ifAbsent 168 | 169 | ## 0.5.1 170 | * renamed Tripel (german) to Triple (en) 171 | * pitest is working with junit5 now 172 | 173 | ## 0.5.0 174 | * Result added ```void ifFailed(Consumer failed);``` 175 | * switched to jUnit5 176 | * updated parent pom to 3.5.7 177 | 178 | ## 0.1.0 179 | * Result added ``` Result asFailure()``` 180 | * Result added ``` Result flatMap(Function> mapper)``` 181 | * ExceptionFunctions.message() extended exception message with Exception Classname 182 | * added CompletableFutureQueue 183 | 184 | ## 0.0.6 185 | * ExceptionFunctions added ```Function message()``` 186 | * ExceptionFunctions added ```Function> toStackTraceStream()``` 187 | * added Sext and Sept data-classes 188 | 189 | ## 0.0.5 190 | * added model.serial pkg with Data classes only for ```extends Serializable``` types 191 | * Transformations 192 | + curry / unCurry - BiFunction / TriFunction 193 | * StreamFunctions added ``` Function, Function, Stream>> streamFilter()``` 194 | * Result.ofNullable 195 | * Result renamed ```bind(Consumer success, Consumer failure)``` 196 | to 197 | ```ifPresentOrElse(Consumer success, Consumer failure)``` 198 | * Result added JDK9 signature ```ifPresentOrElse(Consumer action, Runnable emptyAction)``` 199 | * Result added JDK9 signature ```Stream stream()``` 200 | * Result added ```Result or(Supplier> supplier)``` 201 | * Result added ```void ifAbsent(Runnable action)``` 202 | * Result added ``` Result map(Function mapper)``` 203 | 204 | 205 | ## 0.0.4 206 | * added Result.thenCombine 207 | * added Result.thenCombineAsync 208 | * added CheckedBiFunction 209 | 210 | ## 0.0.3 211 | * added CheckedPredicate 212 | 213 | ## 0.0.2 214 | * basic Datastructures like Pair, Triple, Quad 215 | * added fromOptional and toOptional to the class Result 216 | * added CheckedFunction , CheckedConsumer and CheckedSupplier 217 | * extracted TriFunction from Memoizer to pkg functions 218 | * added QuadFunction 219 | * added StringFunctions 220 | * added Transformations 221 | * added StringFunctions 222 | * ported Strman-java to functional style -------------------------------------------------------------------------------- /_data/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | module rapidpm.functional.reactive { 17 | exports org.rapidpm.frp; 18 | exports com.svenruppert.functional.functions; 19 | exports com.svenruppert.functional.matcher; 20 | exports com.svenruppert.functional.memoizer; 21 | exports com.svenruppert.functional.model; 22 | exports com.svenruppert.functional.model.serial; 23 | exports com.svenruppert.functional.reactive; 24 | } -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | docker rm deploy-functional-reactive 19 | docker-compose up 20 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | version: '3.5' 18 | 19 | services: 20 | deploy: 21 | image: svenruppert/deploy:21.0.1-zulu 22 | container_name: deploy-functional-reactive 23 | hostname: deploy-functional-reactive 24 | volumes: 25 | - /var/run/docker.sock:/tmp/docker.sock:ro 26 | - $PWD/:/usr/src/mymaven 27 | working_dir: /usr/src/mymaven 28 | # command: 'mvn help:active-profiles 29 | command: 'mvn license:format clean deploy 30 | -P_release_prepare 31 | -P_release_sign-artifacts 32 | -Dmaven.test.skip=true' -------------------------------------------------------------------------------- /docker_compile_locale.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | 19 | docker run \ 20 | --rm \ 21 | --name compile \ 22 | -v "$(pwd)":/usr/src/mymaven \ 23 | -v "$(pwd)":/usr/src/mymaven \ 24 | -w /usr/src/mymaven \ 25 | svenruppert/zulu-dev:21.0.1-zulu \ 26 | mvn clean install 27 | -------------------------------------------------------------------------------- /docker_compile_locale_with_nexus.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | 19 | docker run \ 20 | --rm \ 21 | --name compile \ 22 | -v "$(pwd)/_data/nexus/settings.xml":/root/.m2/settings.xml.backup \ 23 | -v "$(pwd)":/usr/src/mymaven \ 24 | -w /usr/src/mymaven \ 25 | svenruppert/maven-3.6.1-adopt:1.8.212-04 \ 26 | mvn clean install 27 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 4.0.0 23 | 24 | 25 | com.svenruppert 26 | dependencies 27 | 06.00.04 28 | 29 | 30 | functional-reactive 31 | 03.00.01-SNAPSHOT 32 | jar 33 | 34 | 2017 35 | 36 | Functional Reactive 37 | http://www.functional-reactive.org 38 | 39 | 40 | https://github.com/svenruppert/functional-reactive-lib 41 | RapidPM Functional Reactive Lib 42 | Functional Reactive with Core Java 43 | 44 | https://github.com/svenruppert/functional-reactive-lib 45 | scm:git:https://github.com/svenruppert/functional-reactive-lib.git 46 | scm:git:https://github.com/svenruppert/functional-reactive-lib.git 47 | 48 | HEAD 49 | 50 | 51 | 52 | Sven Ruppert 53 | sven.ruppert@gmail.com 54 | 55 | Developer 56 | 57 | +1 58 | 59 | 60 | 61 | Github 62 | https://github.com/svenruppert/functional-reactive-lib/issues 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | The Apache Software License, Version 2.0 71 | http://www.apache.org/licenses/LICENSE-2.0.txt 72 | repo 73 | A business-friendly OSS license 74 | 75 | 76 | 77 | 78 | 24 79 | ${jdk.version} 80 | ${jdk.version} 81 | 82 | 83 | UTF-8 84 | UTF-8 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | true 94 | always 95 | 96 | reposilite-repository-snapshots 97 | Reposilite Repository 98 | http://0.0.0.0:8080/snapshots 99 | 100 | 101 | reposilite-repository-releases 102 | Reposilite Repository 103 | http://0.0.0.0:8080/releases 104 | 105 | 106 | 107 | false 108 | 109 | central 110 | libs-release 111 | https://repo.maven.apache.org/maven2/ 112 | 113 | 114 | 115 | 116 | 117 | 118 | false 119 | 120 | reposilite-repository-releases 121 | Reposilite Repository 122 | http://0.0.0.0:8080/releases 123 | 124 | 125 | 126 | false 127 | 128 | central 129 | libs-release 130 | https://repo.maven.apache.org/maven2/ 131 | 132 | 133 | 134 | 135 | 136 | 137 | org.slf4j 138 | slf4j-api 139 | test 140 | 141 | 142 | org.slf4j 143 | slf4j-simple 144 | test 145 | 146 | 147 | org.hamcrest 148 | hamcrest 149 | test 150 | 151 | 152 | 153 | 154 | 155 | 156 | org.codehaus.mojo 157 | versions-maven-plugin 158 | 159 | file://${basedir}/version-number-rules.xml 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/Converting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional; 17 | 18 | import java.util.function.Function; 19 | 20 | import com.svenruppert.functional.model.Result; 21 | 22 | public interface Converting { 23 | 24 | 25 | static 26 | Function> convertToString(Function func) { 27 | return Transformations.asCheckedFunc(func); 28 | } 29 | 30 | static 31 | Function> convertToString() { 32 | return convertToString(String::valueOf); 33 | } 34 | 35 | static 36 | Function> convertToBoolean(Function func) { 37 | return Transformations.asCheckedFunc(func); 38 | } 39 | 40 | static 41 | Function> convertToBoolean() { 42 | return Converting 43 | .convertToString() 44 | .andThen(s -> s.map(Boolean::parseBoolean)); 45 | } 46 | 47 | static 48 | Function> convertToInteger(Function func) { 49 | return Transformations.asCheckedFunc(func); 50 | } 51 | 52 | static 53 | Function> convertToInteger() { 54 | return Converting 55 | .convertToString() 56 | .andThen(s -> s.map(Integer::parseInt)); 57 | } 58 | 59 | static 60 | Function> convertToDouble(Function func) { 61 | return Transformations.asCheckedFunc(func); 62 | } 63 | 64 | static 65 | Function> convertToDouble() { 66 | return Converting 67 | .convertToString() 68 | .andThen(s -> s.map(Double::parseDouble)); 69 | } 70 | 71 | 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/ExceptionFunctions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional; 17 | 18 | import java.util.Arrays; 19 | import java.util.Objects; 20 | import java.util.function.Function; 21 | import java.util.stream.Stream; 22 | 23 | /** 24 | *

ExceptionFunctions interface.

25 | * 26 | * @author svenruppert 27 | * @version $Id: $Id 28 | */ 29 | public interface ExceptionFunctions { 30 | 31 | /** 32 | *

message.

33 | * 34 | * @return a {@link java.util.function.Function} object. 35 | */ 36 | static Function message() { 37 | return (e) -> { 38 | Objects.requireNonNull(e , "Exception instance was null."); 39 | final String message = e.getMessage(); 40 | final String simpleName = e.getClass().getSimpleName(); 41 | return (message != null ? simpleName + " - " + message : simpleName + " - no message"); 42 | }; 43 | } 44 | 45 | /** 46 | *

toStackTraceStream.

47 | * 48 | * @return a {@link java.util.function.Function} object. 49 | */ 50 | static Function> toStackTraceStream() { 51 | return (e) -> { 52 | final StackTraceElement[] stackTrace = e.getStackTrace(); 53 | return Arrays.stream(stackTrace); 54 | // return (stackTrace != null) 55 | // ? Arrays.stream(stackTrace) 56 | // : Stream.empty(); 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/StreamFunctions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional; 17 | 18 | import java.util.function.Function; 19 | import java.util.function.Predicate; 20 | import java.util.stream.Stream; 21 | 22 | /** 23 | *

StreamFunctions interface.

24 | * 25 | * @author svenruppert 26 | * @version $Id: $Id 27 | */ 28 | public interface StreamFunctions { 29 | 30 | /** 31 | *

streamFilter.

32 | * 33 | * @param a T object. 34 | * @return a {@link java.util.function.Function} object. 35 | */ 36 | static Function, Function, Stream>> streamFilter() { 37 | return (filter) -> (Function, Stream>) inputStream -> inputStream.filter(filter); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/SystemProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional; 17 | 18 | import static java.lang.System.getProperty; 19 | import static com.svenruppert.functional.Converting.convertToBoolean; 20 | import static com.svenruppert.functional.Converting.convertToDouble; 21 | import static com.svenruppert.functional.Converting.convertToInteger; 22 | import static com.svenruppert.functional.model.Result.ofNullable; 23 | 24 | import java.util.function.BiFunction; 25 | import java.util.function.Function; 26 | 27 | import com.svenruppert.functional.model.Result; 28 | 29 | public interface SystemProperties { 30 | 31 | static BiFunction qualifiedParameter() { 32 | return (clazz , unqualifiedName) -> clazz.getName() + "." + unqualifiedName; 33 | } 34 | 35 | static BiFunction hasSystemProperty() { 36 | return qualifiedParameter().andThen(key -> getProperty(key) != null); 37 | } 38 | 39 | static Function hasSystemProperty(Class qualifier) { 40 | return (key) -> hasSystemProperty().apply(qualifier , key); 41 | } 42 | 43 | 44 | static BiFunction> systemProperty() { 45 | return qualifiedParameter().andThen(key -> ofNullable(getProperty(key))); 46 | } 47 | 48 | static BiFunction> systemProperty(String defaultValue) { 49 | return qualifiedParameter().andThen(key -> ofNullable(getProperty(key , defaultValue))); 50 | } 51 | 52 | 53 | static Function> systemProperty(Class qualifier) { 54 | return (key) -> qualifiedParameter() 55 | .andThen(k -> ofNullable(getProperty(k))) 56 | .apply(qualifier , key); 57 | } 58 | 59 | static Function> systemProperty(Class qualifier , String defaultValue) { 60 | return (key) -> qualifiedParameter() 61 | .andThen(k -> ofNullable(getProperty(k , defaultValue))) 62 | .apply(qualifier , key); 63 | } 64 | 65 | 66 | static Function> systemPropertyBoolean(Class qualifier) { 67 | return (key) -> systemProperty(qualifier) 68 | .apply(key) 69 | .flatMap(convertToBoolean()); 70 | } 71 | 72 | static Function> systemPropertyBoolean(Class qualifier , String defaultValue) { 73 | return (key) -> systemProperty(qualifier, defaultValue) 74 | .apply(key) 75 | .flatMap(convertToBoolean()); 76 | } 77 | 78 | static Function> systemPropertyInt(Class qualifier) { 79 | return (key) -> systemProperty(qualifier) 80 | .apply(key) 81 | .flatMap(convertToInteger()); 82 | } 83 | 84 | static Function> systemPropertyInt(Class qualifier , String defaultValue) { 85 | return (key) -> systemProperty(qualifier, defaultValue) 86 | .apply(key) 87 | .flatMap(convertToInteger()); 88 | } 89 | 90 | static Function> systemPropertyDouble(Class qualifier) { 91 | return (key) -> systemProperty(qualifier) 92 | .apply(key) 93 | .flatMap(convertToDouble()); 94 | } 95 | 96 | static Function> systemPropertyDouble(Class qualifier , String defaultValue) { 97 | return (key) -> systemProperty(qualifier, defaultValue) 98 | .apply(key) 99 | .flatMap(convertToDouble()); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/Transformations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional; 17 | 18 | import com.svenruppert.functional.functions.CheckedBiFunction; 19 | import com.svenruppert.functional.functions.CheckedFunction; 20 | import com.svenruppert.functional.functions.CheckedTriFunction; 21 | import com.svenruppert.functional.functions.TriFunction; 22 | 23 | import java.util.Enumeration; 24 | import java.util.Iterator; 25 | import java.util.Spliterator; 26 | import java.util.Spliterators; 27 | import java.util.function.*; 28 | import java.util.stream.Stream; 29 | import java.util.stream.StreamSupport; 30 | 31 | /** 32 | * Created by svenruppert on 24.04.17. 33 | * 34 | * @author svenruppert 35 | * @version $Id: $Id 36 | */ 37 | public interface Transformations { 38 | 39 | 40 | /** 41 | *

not.

42 | * 43 | * @return a {@link java.util.function.Function} object. 44 | */ 45 | static Function not() { 46 | return (input) -> !input; 47 | } 48 | 49 | 50 | /** 51 | *

higherCompose.

52 | * 53 | * @param a T object. 54 | * @param a U object. 55 | * @param a V object. 56 | * @return a {@link java.util.function.Function} object. 57 | */ 58 | static Function, Function, Function>> higherCompose() { 59 | return (Function f) -> (Function g) -> (T x) -> f.apply(g.apply(x)); 60 | } 61 | 62 | 63 | /** 64 | *

enumToStream.

65 | * 66 | * @param a T object. 67 | * @return a {@link java.util.function.Function} object. 68 | */ 69 | static Function, Stream> enumToStream() { 70 | return (e) -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator() { 71 | public T next() { 72 | return e.nextElement(); 73 | } 74 | 75 | public boolean hasNext() { 76 | return e.hasMoreElements(); 77 | } 78 | }, Spliterator.ORDERED), false); 79 | } 80 | 81 | static Function, Stream> iteratorToStream() { 82 | return (e) -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator() { 83 | public T next() { 84 | return e.next(); 85 | } 86 | 87 | public boolean hasNext() { 88 | return e.hasNext(); 89 | } 90 | }, Spliterator.ORDERED), false); 91 | } 92 | 93 | /** 94 | *

curryBiFunction.

95 | * 96 | * @param a A object. 97 | * @param a B object. 98 | * @param a R object. 99 | * @return a {@link java.util.function.Function} object. 100 | */ 101 | static Function, Function>> curryBiFunction() { 102 | return (func) -> a -> b -> func.apply(a, b); 103 | } 104 | 105 | /** 106 | *

curryCheckedBiFunction.

107 | * 108 | * @param
a A object. 109 | * @param a B object. 110 | * @param a R object. 111 | * @return a {@link java.util.function.Function} object. 112 | */ 113 | static Function, Function>> curryCheckedBiFunction() { 114 | return (func) -> a -> b -> func.applyWithException(a, b); 115 | } 116 | 117 | /** 118 | *

unCurryBifunction.

119 | * 120 | * @param
a A object. 121 | * @param a B object. 122 | * @param a R object. 123 | * @return a {@link java.util.function.Function} object. 124 | */ 125 | static Function>, BiFunction> unCurryBiFunction() { 126 | return (func) -> (a, b) -> func.apply(a) 127 | .apply(b); 128 | } 129 | 130 | /** 131 | *

unCurryCheckedBifunction.

132 | * 133 | * @param
a A object. 134 | * @param a B object. 135 | * @param a R object. 136 | * @return a {@link java.util.function.Function} object. 137 | */ 138 | static Function>, CheckedBiFunction> unCurryCheckedBiFunction() { 139 | return (func) -> (a, b) -> func.apply(a) 140 | .applyWithException(b); 141 | } 142 | 143 | /** 144 | *

curryTriFunction.

145 | * 146 | * @param
a A object. 147 | * @param a B object. 148 | * @param a C object. 149 | * @param a R object. 150 | * @return a {@link java.util.function.Function} object. 151 | */ 152 | static Function, Function>>> curryTriFunction() { 153 | return (func) -> a -> b -> c -> func.apply(a, b, c); 154 | } 155 | 156 | /** 157 | *

curryCheckedTriFunction.

158 | * 159 | * @param
a A object. 160 | * @param a B object. 161 | * @param a C object. 162 | * @param a R object. 163 | * @return a {@link java.util.function.Function} object. 164 | */ 165 | static Function, Function>>> curryCheckedTriFunction() { 166 | return (func) -> a -> b -> c -> func.applyWithException(a, b, c); 167 | } 168 | 169 | /** 170 | *

unCurryTrifunction.

171 | * 172 | * @param
a A object. 173 | * @param a B object. 174 | * @param a C object. 175 | * @param a R object. 176 | * @return a {@link java.util.function.Function} object. 177 | */ 178 | static Function>>, TriFunction> unCurryTriFunction() { 179 | return (func) -> (a, b, c) -> func.apply(a) 180 | .apply(b) 181 | .apply(c); 182 | } 183 | 184 | 185 | /** 186 | *

unCurryTrifunction.

187 | * 188 | * @param
a A object. 189 | * @param a B object. 190 | * @param a C object. 191 | * @param a R object. 192 | * @return a {@link java.util.function.Function} object. 193 | */ 194 | static Function>>, CheckedTriFunction> unCurryCheckedTriFunction() { 195 | return (func) -> (a, b, c) -> func.apply(a) 196 | .apply(b) 197 | .applyWithException(c); 198 | } 199 | 200 | 201 | //Function Casts 202 | 203 | /** 204 | *

not.

205 | * 206 | * @param p a {@link java.util.function.Predicate} object. 207 | * @param a T object. 208 | * @return a {@link java.util.function.Predicate} object. 209 | */ 210 | static Predicate not(Predicate p) { 211 | return t -> !p.test(t); 212 | } 213 | 214 | /** 215 | *

asPredicate.

216 | * 217 | * @param predicate a {@link java.util.function.Predicate} object. 218 | * @param a T object. 219 | * @return a {@link java.util.function.Predicate} object. 220 | */ 221 | static Predicate asPredicate(Predicate predicate) { 222 | return predicate; 223 | } 224 | 225 | /** 226 | *

asConsumer.

227 | * 228 | * @param consumer a {@link java.util.function.Consumer} object. 229 | * @param a T object. 230 | * @return a {@link java.util.function.Consumer} object. 231 | */ 232 | static Consumer asConsumer(Consumer consumer) { 233 | return consumer; 234 | } 235 | 236 | /** 237 | *

asSupplier.

238 | * 239 | * @param supplier a {@link java.util.function.Supplier} object. 240 | * @param a T object. 241 | * @return a {@link java.util.function.Supplier} object. 242 | */ 243 | static Supplier asSupplier(Supplier supplier) { 244 | return supplier; 245 | } 246 | 247 | /** 248 | *

asFunc.

249 | * 250 | * @param function a {@link java.util.function.Function} object. 251 | * @param a T object. 252 | * @param a R object. 253 | * @return a {@link java.util.function.Function} object. 254 | */ 255 | static Function asFunc(Function function) { 256 | return function; 257 | } 258 | 259 | 260 | static CheckedFunction asCheckedFunc(Function f) { 261 | return f::apply; 262 | } 263 | 264 | 265 | } 266 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import static com.svenruppert.functional.ExceptionFunctions.message; 19 | 20 | import java.util.function.BiFunction; 21 | 22 | import com.svenruppert.functional.model.Result; 23 | 24 | /** 25 | * 26 | */ 27 | public interface CheckedBiFunction extends BiFunction> { 28 | @Override 29 | default Result apply(T1 t1, T2 t2) { 30 | try { 31 | return Result.success(applyWithException(t1, t2)); 32 | } catch (Exception e) { 33 | return Result.failure(message().apply(e)); 34 | } 35 | } 36 | 37 | R applyWithException(T1 t1, T2 t2) throws Exception; 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | /** 19 | * Created by svenruppert on 25.04.17. 20 | * 21 | * @author svenruppert 22 | * @version $Id: $Id 23 | */ 24 | @FunctionalInterface 25 | public interface CheckedConsumer extends CheckedFunction { 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import static com.svenruppert.functional.ExceptionFunctions.message; 19 | 20 | import java.util.function.Function; 21 | 22 | import com.svenruppert.functional.model.Result; 23 | 24 | /** 25 | * Created by svenruppert on 25.04.17. 26 | * 27 | * @author svenruppert 28 | * @version $Id: $Id 29 | */ 30 | @FunctionalInterface 31 | public interface CheckedExecutor extends Function> { 32 | 33 | default Result execute() { 34 | return apply(null); 35 | } 36 | 37 | 38 | @Override 39 | default Result apply(Void t) { 40 | try { 41 | applyWithException(); 42 | return Result.success(null); 43 | } catch (Exception e) { 44 | return Result.failure(message().apply(e)); 45 | } 46 | } 47 | 48 | void applyWithException() throws Exception; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import static com.svenruppert.functional.ExceptionFunctions.message; 19 | 20 | import java.util.function.Function; 21 | 22 | import com.svenruppert.functional.model.Result; 23 | 24 | /** 25 | * Created by svenruppert on 25.04.17. 26 | */ 27 | @FunctionalInterface 28 | public interface CheckedFunction extends Function> { 29 | @Override 30 | default Result apply(T t) { 31 | try { 32 | return Result.success(applyWithException(t)); 33 | } catch (Exception e) { 34 | return Result.failure(message().apply(e)); 35 | } 36 | } 37 | R applyWithException(T t) throws Exception; 38 | } -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import java.util.function.Predicate; 19 | 20 | /** 21 | * if an exception is thrown, the predicate will give back false; 22 | */ 23 | public interface CheckedPredicate extends Predicate { 24 | @Override 25 | default boolean test(T t) { 26 | try { 27 | return testWithExceptions(t); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | return false; 31 | } 32 | } 33 | 34 | boolean testWithExceptions(T t) throws Exception; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import static com.svenruppert.functional.ExceptionFunctions.message; 19 | 20 | import java.util.function.Supplier; 21 | 22 | import com.svenruppert.functional.model.Result; 23 | 24 | /** 25 | * Created by svenruppert on 25.04.17. 26 | */ 27 | @FunctionalInterface 28 | public interface CheckedSupplier extends Supplier> { 29 | 30 | @Override 31 | default Result get() { 32 | try { 33 | return Result.success(getWithException()); 34 | } catch (Exception e) { 35 | return Result.failure(message().apply(e)); 36 | } 37 | } 38 | 39 | T getWithException() throws Exception; 40 | 41 | default T getOrElse(Supplier supplier) { 42 | return get().getOrElse(supplier); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/CheckedTriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import com.svenruppert.functional.model.Result; 19 | 20 | import static com.svenruppert.functional.ExceptionFunctions.message; 21 | 22 | public interface CheckedTriFunction extends TriFunction> { 23 | @Override 24 | default Result apply(T1 t1, T2 t2, T3 t3) { 25 | try { 26 | return Result.success(applyWithException(t1, t2, t3)); 27 | } catch (Exception e) { 28 | return Result.failure(message().apply(e)); 29 | } 30 | } 31 | 32 | R applyWithException(T1 t1, T2 t2, T3 t3) throws Exception; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/QuadFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import java.util.Objects; 19 | import java.util.function.Function; 20 | 21 | /** 22 | * Created by svenruppert on 24.04.17. 23 | */ 24 | @FunctionalInterface 25 | public interface QuadFunction { 26 | R apply(T1 t1, T2 t2, T3 t3, T4 t4); 27 | 28 | default QuadFunction andThen(Function after) { 29 | Objects.requireNonNull(after); 30 | return (T1 t1, T2 t2, T3 t3, T4 t4) -> after.apply(apply(t1, t2, t3, t4)); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/functions/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.functions; 17 | 18 | import java.util.Objects; 19 | import java.util.function.Function; 20 | 21 | /** 22 | * Created by svenruppert on 24.04.17. 23 | */ 24 | @FunctionalInterface 25 | public interface TriFunction { 26 | R apply(T1 t1, T2 t2, T3 t3); 27 | 28 | default TriFunction andThen(Function after) { 29 | Objects.requireNonNull(after); 30 | return (T1 t1, T2 t2, T3 t3) -> after.apply(apply(t1, t2, t3)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/matcher/Case.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.matcher; 17 | 18 | import java.util.function.Supplier; 19 | import java.util.stream.Stream; 20 | 21 | import com.svenruppert.functional.model.Pair; 22 | import com.svenruppert.functional.model.Result; 23 | 24 | public class Case extends Pair, Supplier>> { 25 | 26 | /** 27 | *

Constructor for Case.

28 | * 29 | * @param booleanSupplier a {@link java.util.function.Supplier} object. 30 | * @param resultSupplier a {@link java.util.function.Supplier} object. 31 | */ 32 | public Case(final Supplier booleanSupplier , final Supplier> resultSupplier) { 33 | super(booleanSupplier , resultSupplier); 34 | } 35 | 36 | /** 37 | *

matchCase.

38 | * 39 | * @param condition a {@link java.util.function.Supplier} object. 40 | * @param value a {@link java.util.function.Supplier} object. 41 | * @param a T object. 42 | * @return a {@link com.svenruppert.functional.matcher.Case} object. 43 | */ 44 | public static Case matchCase(Supplier condition , 45 | Supplier> value) { 46 | return new Case<>(condition , value); 47 | } 48 | 49 | /** 50 | *

matchCase.

51 | * 52 | * @param value a {@link java.util.function.Supplier} object. 53 | * @param a T object. 54 | * @return a {@link com.svenruppert.functional.matcher.Case.DefaultCase} object. 55 | */ 56 | public static DefaultCase matchCase(Supplier> value) { 57 | return new DefaultCase<>(() -> true , value); 58 | } 59 | 60 | /** 61 | *

isMatching.

62 | * 63 | * @return a boolean. 64 | */ 65 | private boolean isMatching() { 66 | return getT1().get(); 67 | } 68 | 69 | /** 70 | *

result.

71 | * 72 | * @return a {@link com.svenruppert.functional.model.Result} object. 73 | */ 74 | public Result result() { 75 | return getT2().get(); 76 | } 77 | 78 | /** 79 | *

match.

80 | * 81 | * @param defaultCase a {@link com.svenruppert.functional.matcher.Case.DefaultCase} object. 82 | * @param matchers a {@link com.svenruppert.functional.matcher.Case} object. 83 | * @param a T object. 84 | * @return a {@link com.svenruppert.functional.model.Result} object. 85 | */ 86 | @SafeVarargs 87 | public static Result match(DefaultCase defaultCase , Case... matchers) { 88 | return Stream 89 | .of(matchers) 90 | .filter(Case::isMatching) 91 | .map(Case::result) 92 | .findFirst() 93 | .orElseGet(defaultCase::result); 94 | } 95 | 96 | public static class DefaultCase extends Case { 97 | public DefaultCase(final Supplier booleanSupplier , final Supplier> resultSupplier) { 98 | super(booleanSupplier , resultSupplier); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/memoizer/Memoizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.memoizer; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.ConcurrentHashMap; 20 | import java.util.function.BiFunction; 21 | import java.util.function.Function; 22 | import java.util.function.Supplier; 23 | 24 | import com.svenruppert.functional.Transformations; 25 | import com.svenruppert.functional.functions.TriFunction; 26 | 27 | /** 28 | * Copyright (C) 2010 RapidPM 29 | * Licensed under the Apache License, Version 2.0 (the "License"); 30 | * you may not use this file except in compliance with the License. 31 | * You may obtain a copy of the License at 32 | * http://www.apache.org/licenses/LICENSE-2.0 33 | * Unless required by applicable law or agreed to in writing, software 34 | * distributed under the License is distributed on an "AS IS" BASIS, 35 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 36 | * See the License for the specific language governing permissions and 37 | * limitations under the License. 38 | *

39 | * Created by RapidPM - Team on 10.12.16. 40 | * 41 | * @author svenruppert 42 | * @version $Id: $Id 43 | */ 44 | public class Memoizer { 45 | private final Map memoizationCache = new ConcurrentHashMap<>(); 46 | 47 | private Supplier doMemoize(final Supplier function) { 48 | return new Supplier() { 49 | private T value; 50 | 51 | @Override 52 | public T get() { 53 | if (value == null) value = function.get(); 54 | return value; 55 | } 56 | }; 57 | } 58 | 59 | 60 | private Function doMemoize(final Function function) { 61 | return input -> memoizationCache.computeIfAbsent(input, function); 62 | } 63 | 64 | /** 65 | *

memoize.

66 | * 67 | * @param function a {@link java.util.function.Supplier} object. 68 | * @param a T object. 69 | * @return a {@link java.util.function.Supplier} object. 70 | */ 71 | public static Supplier memoize(final Supplier function) { 72 | return new Memoizer().doMemoize(function); 73 | } 74 | 75 | /** 76 | *

memoize.

77 | * 78 | * @param function a {@link java.util.function.Function} object. 79 | * @param a T object. 80 | * @param a U object. 81 | * @return a {@link java.util.function.Function} object. 82 | */ 83 | public static Function memoize(final Function function) { 84 | return new Memoizer().doMemoize(function); 85 | } 86 | 87 | 88 | /** 89 | *

memoize.

90 | * 91 | * @param biFunc a {@link java.util.function.BiFunction} object. 92 | * @param a T1 object. 93 | * @param a T2 object. 94 | * @param a R object. 95 | * @return a {@link java.util.function.BiFunction} object. 96 | */ 97 | public static BiFunction memoize(final BiFunction biFunc) { 98 | final Function> transformed = Memoizer.memoize(x -> Memoizer.memoize(y -> biFunc.apply(x, y))); 99 | return Transformations 100 | .unCurryBiFunction() 101 | .apply(transformed); 102 | } 103 | 104 | // public static BiFunction memoize(final BiFunction biFunc) { 105 | // final Function> transformed = Memoizer.memoize(x -> Memoizer.memoize(y -> biFunc.apply(x, y))); 106 | // return (x, y) -> transformed.apply(x).apply(y); 107 | // } 108 | 109 | /** 110 | *

memoize.

111 | * 112 | * @param threeFunc a {@link com.svenruppert.functional.functions.TriFunction} object. 113 | * @param a T1 object. 114 | * @param a T2 object. 115 | * @param a T3 object. 116 | * @param a R object. 117 | * @return a {@link com.svenruppert.functional.functions.TriFunction} object. 118 | */ 119 | public static TriFunction memoize(final TriFunction threeFunc) { 120 | final Function>> transformed 121 | = Memoizer.memoize(x -> Memoizer.memoize(y -> Memoizer.memoize(z -> threeFunc.apply(x, y, z)))); 122 | return Transformations 123 | .unCurryTriFunction() 124 | .apply(transformed); 125 | // return (x, y, z) -> transformed.apply(x).apply(y).apply(z); 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * Copyright (C) 2010 RapidPM 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * Unless required by applicable law or agreed to in writing, software 27 | * distributed under the License is distributed on an "AS IS" BASIS, 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | * See the License for the specific language governing permissions and 30 | * limitations under the License. 31 | *

32 | * Created by RapidPM - Team on 10.12.16. 33 | * 34 | * @author svenruppert 35 | * @version $Id: $Id 36 | */ 37 | public class Pair { 38 | private T1 t1; 39 | private T2 t2; 40 | 41 | /** 42 | *

Constructor for Pair.

43 | * 44 | * @param t1 a T1 object. 45 | * @param t2 a T2 object. 46 | */ 47 | public Pair(final T1 t1, final T2 t2) { 48 | this.t1 = t1; 49 | this.t2 = t2; 50 | } 51 | 52 | /** 53 | *

Getter for the field t1.

54 | * 55 | * @return a T1 object. 56 | */ 57 | public T1 getT1() { 58 | return t1; 59 | } 60 | 61 | /** 62 | *

Getter for the field t2.

63 | * 64 | * @return a T2 object. 65 | */ 66 | public T2 getT2() { 67 | return t2; 68 | } 69 | 70 | /** {@inheritDoc} */ 71 | @Override 72 | public String toString() { 73 | return "Pair{" + 74 | "t1=" + t1 + 75 | ", t2=" + t2 + 76 | '}'; 77 | } 78 | 79 | /** {@inheritDoc} */ 80 | @Override 81 | public boolean equals(final Object o) { 82 | if (this == o) return true; 83 | if (! (o instanceof Pair)) return false; 84 | final Pair pair = (Pair) o; 85 | return Objects.equals(t1, pair.t1) && 86 | Objects.equals(t2, pair.t2); 87 | } 88 | 89 | /** {@inheritDoc} */ 90 | @Override 91 | public int hashCode() { 92 | return Objects.hash(t1, t2); 93 | } 94 | 95 | /** 96 | *

next.

97 | * 98 | * @param a a T1 object. 99 | * @param b a T2 object. 100 | * @param a T1 object. 101 | * @param a T2 object. 102 | * @return a {@link com.svenruppert.functional.model.Pair} object. 103 | */ 104 | public static Pair next(T1 a, T2 b) { 105 | return new Pair<>(a, b); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Quad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | /** 19 | * Copyright (C) 2010 RapidPM 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * http://www.apache.org/licenses/LICENSE-2.0 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an "AS IS" BASIS, 26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | *

30 | * Created by RapidPM - Team on 10.12.16. 31 | * 32 | * @author svenruppert 33 | * @version $Id: $Id 34 | */ 35 | public class Quad { 36 | 37 | private T1 t1; 38 | private T2 t2; 39 | private T3 t3; 40 | private T4 t4; 41 | 42 | /** 43 | *

Constructor for Quad.

44 | * 45 | * @param t1 a T1 object. 46 | * @param t2 a T2 object. 47 | * @param t3 a T3 object. 48 | * @param t4 a T4 object. 49 | */ 50 | public Quad(final T1 t1, final T2 t2, final T3 t3, final T4 t4) { 51 | this.t1 = t1; 52 | this.t2 = t2; 53 | this.t3 = t3; 54 | this.t4 = t4; 55 | } 56 | 57 | /** 58 | *

Getter for the field t4.

59 | * 60 | * @return a T4 object. 61 | */ 62 | public T4 getT4() { 63 | return t4; 64 | } 65 | 66 | /** 67 | *

Getter for the field t3.

68 | * 69 | * @return a T3 object. 70 | */ 71 | public T3 getT3() { 72 | return t3; 73 | } 74 | 75 | /** 76 | *

Getter for the field t1.

77 | * 78 | * @return a T1 object. 79 | */ 80 | public T1 getT1() { 81 | return t1; 82 | } 83 | 84 | /** 85 | *

Getter for the field t2.

86 | * 87 | * @return a T2 object. 88 | */ 89 | public T2 getT2() { 90 | return t2; 91 | } 92 | 93 | /** {@inheritDoc} */ 94 | @Override 95 | public boolean equals(Object o) { 96 | if (this == o) return true; 97 | if (! (o instanceof Quad)) return false; 98 | 99 | Quad quad = (Quad) o; 100 | 101 | if (t1 != null ? ! t1.equals(quad.t1) : quad.t1 != null) return false; 102 | if (t2 != null ? ! t2.equals(quad.t2) : quad.t2 != null) return false; 103 | if (t3 != null ? ! t3.equals(quad.t3) : quad.t3 != null) return false; 104 | return t4 != null ? t4.equals(quad.t4) : quad.t4 == null; 105 | } 106 | 107 | /** {@inheritDoc} */ 108 | @Override 109 | public int hashCode() { 110 | int result = t1 != null ? t1.hashCode() : 0; 111 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 112 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 113 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 114 | return result; 115 | } 116 | 117 | /** {@inheritDoc} */ 118 | @Override 119 | public String toString() { 120 | return "Quad{" + 121 | "t1=" + t1 + 122 | ", t2=" + t2 + 123 | ", t3=" + t3 + 124 | ", t4=" + t4 + 125 | '}'; 126 | } 127 | 128 | /** 129 | *

next.

130 | * 131 | * @param t1 a T1 object. 132 | * @param t2 a T2 object. 133 | * @param t3 a T3 object. 134 | * @param t4 a T4 object. 135 | * @param a T1 object. 136 | * @param a T2 object. 137 | * @param a T3 object. 138 | * @param a T4 object. 139 | * @return a {@link com.svenruppert.functional.model.Quad} object. 140 | */ 141 | public static Quad next(final T1 t1, final T2 t2, final T3 t3, final T4 t4) { 142 | return new Quad<>(t1, t2, t3, t4); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Quint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | /** 19 | * Copyright (C) 2010 RapidPM 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * http://www.apache.org/licenses/LICENSE-2.0 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an "AS IS" BASIS, 26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | *

30 | * Created by RapidPM - Team on 10.12.16. 31 | * 32 | * @author svenruppert 33 | * @version $Id: $Id 34 | */ 35 | public class Quint { 36 | 37 | private T1 t1; 38 | private T2 t2; 39 | private T3 t3; 40 | private T4 t4; 41 | private T5 t5; 42 | 43 | /** 44 | *

Constructor for Quint.

45 | * 46 | * @param t1 a T1 object. 47 | * @param t2 a T2 object. 48 | * @param t3 a T3 object. 49 | * @param t4 a T4 object. 50 | * @param t5 a T5 object. 51 | */ 52 | public Quint(final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4 , final T5 t5) { 53 | this.t1 = t1; 54 | this.t2 = t2; 55 | this.t3 = t3; 56 | this.t4 = t4; 57 | this.t5 = t5; 58 | } 59 | 60 | /** 61 | *

Getter for the field t5.

62 | * 63 | * @return a T5 object. 64 | */ 65 | public T5 getT5() { 66 | return t5; 67 | } 68 | 69 | /** 70 | *

Getter for the field t4.

71 | * 72 | * @return a T4 object. 73 | */ 74 | public T4 getT4() { 75 | return t4; 76 | } 77 | 78 | /** 79 | *

Getter for the field t3.

80 | * 81 | * @return a T3 object. 82 | */ 83 | public T3 getT3() { 84 | return t3; 85 | } 86 | 87 | /** 88 | *

Getter for the field t1.

89 | * 90 | * @return a T1 object. 91 | */ 92 | public T1 getT1() { 93 | return t1; 94 | } 95 | 96 | /** 97 | *

Getter for the field t2.

98 | * 99 | * @return a T2 object. 100 | */ 101 | public T2 getT2() { 102 | return t2; 103 | } 104 | 105 | 106 | /** {@inheritDoc} */ 107 | @Override 108 | public boolean equals(Object o) { 109 | if (this == o) return true; 110 | if (! (o instanceof Quint)) return false; 111 | 112 | Quint quint = (Quint) o; 113 | 114 | if (t1 != null ? ! t1.equals(quint.t1) : quint.t1 != null) return false; 115 | if (t2 != null ? ! t2.equals(quint.t2) : quint.t2 != null) return false; 116 | if (t3 != null ? ! t3.equals(quint.t3) : quint.t3 != null) return false; 117 | if (t4 != null ? ! t4.equals(quint.t4) : quint.t4 != null) return false; 118 | return t5 != null ? t5.equals(quint.t5) : quint.t5 == null; 119 | } 120 | 121 | /** {@inheritDoc} */ 122 | @Override 123 | public int hashCode() { 124 | int result = t1 != null ? t1.hashCode() : 0; 125 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 126 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 127 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 128 | result = 31 * result + (t5 != null ? t5.hashCode() : 0); 129 | return result; 130 | } 131 | 132 | /** {@inheritDoc} */ 133 | @Override 134 | public String toString() { 135 | return "Quint{" + 136 | "t1=" + t1 + 137 | ", t2=" + t2 + 138 | ", t3=" + t3 + 139 | ", t4=" + t4 + 140 | ", t5=" + t5 + 141 | '}'; 142 | } 143 | 144 | /** 145 | *

next.

146 | * 147 | * @param t1 a T1 object. 148 | * @param t2 a T2 object. 149 | * @param t3 a T3 object. 150 | * @param t4 a T4 object. 151 | * @param t5 a T5 object. 152 | * @param a T1 object. 153 | * @param a T2 object. 154 | * @param a T3 object. 155 | * @param a T4 object. 156 | * @param a T5 object. 157 | * @return a {@link com.svenruppert.functional.model.Quint} object. 158 | */ 159 | public static Quint next(final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4 , final T5 t5) { 160 | return new Quint<>(t1 , t2 , t3 , t4 , t5); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | import com.svenruppert.functional.functions.CheckedFunction; 19 | 20 | import java.util.Objects; 21 | import java.util.Optional; 22 | import java.util.concurrent.CompletableFuture; 23 | import java.util.function.BiFunction; 24 | import java.util.function.Consumer; 25 | import java.util.function.Function; 26 | import java.util.function.Supplier; 27 | import java.util.stream.Stream; 28 | 29 | /** 30 | * Copyright (C) 2017 RapidPM - Sven Ruppert 31 | * Licensed under the Apache License, Version 2.0 (the "License"); 32 | * you may not use this file except in compliance with the License. 33 | * You may obtain a copy of the License at 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * Unless required by applicable law or agreed to in writing, software 36 | * distributed under the License is distributed on an "AS IS" BASIS, 37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | * See the License for the specific language governing permissions and 39 | * limitations under the License. 40 | *

41 | * Created by Sven Ruppert - RapidPM - Team on 16.03.17. 42 | */ 43 | public interface Result { 44 | 45 | void ifPresentOrElse(Consumer action, Runnable emptyAction); 46 | 47 | void ifPresentOrElse(Consumer success, Consumer failure); 48 | 49 | void ifPresentOrElseAsync(Consumer action, Runnable emptyAction); 50 | 51 | void ifPresentOrElseAsync(Consumer success, Consumer failure); 52 | 53 | static Result failure(String errorMessage) { 54 | Objects.requireNonNull(errorMessage); 55 | return new Result.Failure<>(errorMessage); 56 | } 57 | 58 | static Result success(T value) { 59 | return new Result.Success<>(value); 60 | } 61 | 62 | static Result ofNullable(T value) { 63 | return ofNullable(value, "Object was null"); 64 | } 65 | 66 | static Result ofNullable(T value, String failedMessage) { 67 | return (Objects.nonNull(value)) 68 | ? success(value) 69 | : failure(failedMessage); 70 | } 71 | 72 | T get(); 73 | 74 | T getOrElse(Supplier supplier); 75 | 76 | Boolean isPresent(); 77 | 78 | Boolean isAbsent(); 79 | 80 | Result ifPresent(Consumer consumer); 81 | 82 | Result ifAbsent(Runnable action); 83 | 84 | Result ifFailed(Consumer failed); 85 | 86 | default Stream stream() { 87 | if (!isPresent()) { 88 | return Stream.empty(); 89 | } else { 90 | return Stream.of(get()); 91 | } 92 | } 93 | 94 | default Result or(Supplier> supplier) { 95 | Objects.requireNonNull(supplier); 96 | if (isPresent()) { 97 | return this; 98 | } else { 99 | @SuppressWarnings("unchecked") 100 | Result r = (Result) supplier.get(); 101 | return Objects.requireNonNull(r); 102 | } 103 | } 104 | 105 | 106 | default Optional toOptional() { 107 | return Optional.ofNullable(get()); 108 | } 109 | 110 | static Result fromOptional(Optional optional) { 111 | Objects.requireNonNull(optional); 112 | return optional 113 | .map(Result::success) 114 | .orElseGet(() -> failure("Optional hold a null value")); 115 | } 116 | 117 | default Result thenCombine(V value, BiFunction> func) { 118 | return func.apply(get(), value); 119 | } 120 | default Result thenCombineFlat(V value, BiFunction func) { 121 | return Result.ofNullable(func.apply(get(), value)); 122 | } 123 | 124 | default CompletableFuture> thenCombineAsync(V value, BiFunction> func) { 125 | return CompletableFuture.supplyAsync(() -> func.apply(get(), value)); 126 | } 127 | 128 | default Result map(Function mapper) { 129 | Objects.requireNonNull(mapper); 130 | return isPresent() 131 | ? ((CheckedFunction) mapper::apply).apply(get()) 132 | : this.asFailure(); 133 | } 134 | 135 | default Result flatMap(Function> mapper) { 136 | Objects.requireNonNull(mapper); 137 | return this.isPresent() 138 | ? mapper.apply(get()) 139 | : this.asFailure(); 140 | } 141 | 142 | 143 | default Result asFailure() { 144 | return (isAbsent()) 145 | ? ofNullable(null) 146 | : failure("converted to Failure orig was " + this); 147 | } 148 | 149 | 150 | abstract class AbstractResult implements Result { 151 | protected final T value; 152 | 153 | public AbstractResult(T value) { 154 | this.value = value; 155 | } 156 | 157 | @Override 158 | public Result ifPresent(Consumer consumer) { 159 | Objects.requireNonNull(consumer); 160 | if (value != null) consumer.accept(value); 161 | return (this instanceof Failure) 162 | ? this 163 | : ofNullable(value); 164 | } 165 | 166 | @Override 167 | public Result ifAbsent(Runnable action) { 168 | Objects.requireNonNull(action); 169 | if (value == null) action.run(); 170 | return (this instanceof Failure) 171 | ? this 172 | : ofNullable(value); 173 | } 174 | 175 | public Boolean isPresent() { 176 | return (value != null) ? Boolean.TRUE : Boolean.FALSE; 177 | } 178 | 179 | public Boolean isAbsent() { 180 | return (value == null) ? Boolean.TRUE : Boolean.FALSE; 181 | } 182 | 183 | @Override 184 | public T get() { 185 | return Objects.requireNonNull(value); 186 | } 187 | 188 | @Override 189 | public T getOrElse(Supplier supplier) { 190 | Objects.requireNonNull(supplier); 191 | return (value != null) ? value : Objects.requireNonNull(supplier.get()); 192 | } 193 | } 194 | 195 | class Success extends AbstractResult { 196 | 197 | public Success(T value) { 198 | super(value); 199 | } 200 | 201 | @Override 202 | public void ifPresentOrElse(Consumer action, Runnable emptyAction) { 203 | action.accept(value); 204 | } 205 | 206 | @Override 207 | public void ifPresentOrElse(final Consumer success, final Consumer failure) { 208 | // TODO check if usefull -> Objects.requireNonNull(value); 209 | success.accept(value); 210 | } 211 | 212 | @Override 213 | public void ifPresentOrElseAsync(Consumer action, Runnable emptyAction) { 214 | CompletableFuture.runAsync(() -> action.accept(value)); 215 | } 216 | 217 | @Override 218 | public void ifPresentOrElseAsync(Consumer success, Consumer failure) { 219 | CompletableFuture.runAsync(() -> success.accept(value)); 220 | } 221 | 222 | public Result ifFailed(Consumer failed) { 223 | Objects.requireNonNull(failed); 224 | //nothing do do , I am a Success 225 | return ofNullable(value); 226 | } 227 | 228 | } 229 | 230 | class Failure extends AbstractResult { 231 | 232 | private final String errorMessage; 233 | 234 | public Failure(final String errorMessage) { 235 | super(null); 236 | this.errorMessage = errorMessage; 237 | } 238 | 239 | @Override 240 | public void ifPresentOrElse(Consumer action, Runnable emptyAction) { 241 | emptyAction.run(); 242 | } 243 | 244 | @Override 245 | public void ifPresentOrElse(final Consumer success, final Consumer failure) { 246 | failure.accept(errorMessage); 247 | } 248 | 249 | @Override 250 | public void ifPresentOrElseAsync(Consumer action, Runnable emptyAction) { 251 | CompletableFuture.runAsync(emptyAction); 252 | } 253 | 254 | @Override 255 | public void ifPresentOrElseAsync(Consumer success, Consumer failure) { 256 | CompletableFuture.runAsync(() -> failure.accept(errorMessage)); 257 | } 258 | 259 | public Result ifFailed(Consumer failed) { 260 | Objects.requireNonNull(failed); 261 | failed.accept(errorMessage); 262 | // I am a Failure - hold errorMessage, value already null; 263 | return this; 264 | } 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Sept.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | /** 19 | *

Sept class.

20 | * 21 | * @author svenruppert 22 | * @version $Id: $Id 23 | */ 24 | public class Sept { 25 | 26 | private T1 t1; 27 | private T2 t2; 28 | private T3 t3; 29 | private T4 t4; 30 | private T5 t5; 31 | private T6 t6; 32 | private T7 t7; 33 | 34 | /** 35 | *

Constructor for Sept.

36 | * 37 | * @param t1 a T1 object. 38 | * @param t2 a T2 object. 39 | * @param t3 a T3 object. 40 | * @param t4 a T4 object. 41 | * @param t5 a T5 object. 42 | * @param t6 a T6 object. 43 | * @param t7 a T7 object. 44 | */ 45 | public Sept(T1 t1 , T2 t2 , T3 t3 , T4 t4 , T5 t5 , T6 t6 , T7 t7) { 46 | this.t1 = t1; 47 | this.t2 = t2; 48 | this.t3 = t3; 49 | this.t4 = t4; 50 | this.t5 = t5; 51 | this.t6 = t6; 52 | this.t7 = t7; 53 | } 54 | 55 | /** {@inheritDoc} */ 56 | @Override 57 | public boolean equals(Object o) { 58 | if (this == o) return true; 59 | if (! (o instanceof Sept)) return false; 60 | 61 | Sept sept = (Sept) o; 62 | 63 | if (t1 != null ? ! t1.equals(sept.t1) : sept.t1 != null) return false; 64 | if (t2 != null ? ! t2.equals(sept.t2) : sept.t2 != null) return false; 65 | if (t3 != null ? ! t3.equals(sept.t3) : sept.t3 != null) return false; 66 | if (t4 != null ? ! t4.equals(sept.t4) : sept.t4 != null) return false; 67 | if (t5 != null ? ! t5.equals(sept.t5) : sept.t5 != null) return false; 68 | if (t6 != null ? ! t6.equals(sept.t6) : sept.t6 != null) return false; 69 | return t7 != null ? t7.equals(sept.t7) : sept.t7 == null; 70 | } 71 | 72 | /** {@inheritDoc} */ 73 | @Override 74 | public int hashCode() { 75 | int result = t1 != null ? t1.hashCode() : 0; 76 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 77 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 78 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 79 | result = 31 * result + (t5 != null ? t5.hashCode() : 0); 80 | result = 31 * result + (t6 != null ? t6.hashCode() : 0); 81 | result = 31 * result + (t7 != null ? t7.hashCode() : 0); 82 | return result; 83 | } 84 | 85 | /** {@inheritDoc} */ 86 | @Override 87 | public String toString() { 88 | return "Sept{" + 89 | "t1=" + t1 + 90 | ", t2=" + t2 + 91 | ", t3=" + t3 + 92 | ", t4=" + t4 + 93 | ", t5=" + t5 + 94 | ", t6=" + t6 + 95 | ", t7=" + t7 + 96 | '}'; 97 | } 98 | 99 | /** 100 | *

next.

101 | * 102 | * @param t1 a T1 object. 103 | * @param t2 a T2 object. 104 | * @param t3 a T3 object. 105 | * @param t4 a T4 object. 106 | * @param t5 a T5 object. 107 | * @param t6 a T6 object. 108 | * @param t7 a T7 object. 109 | * @param a T1 object. 110 | * @param a T2 object. 111 | * @param a T3 object. 112 | * @param a T4 object. 113 | * @param a T5 object. 114 | * @param a T6 object. 115 | * @param a T7 object. 116 | * @return a {@link com.svenruppert.functional.model.Sept} object. 117 | */ 118 | public static Sept next(final T1 t1 , final T2 t2 , final T3 t3 , 119 | final T4 t4 , final T5 t5 , final T6 t6 , final T7 t7) { 120 | return new Sept<>(t1 , t2 , t3 , t4 , t5 , t6 , t7); 121 | } 122 | 123 | 124 | /** 125 | *

Getter for the field t1.

126 | * 127 | * @return a T1 object. 128 | */ 129 | public T1 getT1() { 130 | return t1; 131 | } 132 | 133 | /** 134 | *

Getter for the field t2.

135 | * 136 | * @return a T2 object. 137 | */ 138 | public T2 getT2() { 139 | return t2; 140 | } 141 | 142 | /** 143 | *

Getter for the field t3.

144 | * 145 | * @return a T3 object. 146 | */ 147 | public T3 getT3() { 148 | return t3; 149 | } 150 | 151 | /** 152 | *

Getter for the field t4.

153 | * 154 | * @return a T4 object. 155 | */ 156 | public T4 getT4() { 157 | return t4; 158 | } 159 | 160 | /** 161 | *

Getter for the field t5.

162 | * 163 | * @return a T5 object. 164 | */ 165 | public T5 getT5() { 166 | return t5; 167 | } 168 | 169 | /** 170 | *

Getter for the field t6.

171 | * 172 | * @return a T6 object. 173 | */ 174 | public T6 getT6() { 175 | return t6; 176 | } 177 | 178 | /** 179 | *

Getter for the field t7.

180 | * 181 | * @return a T7 object. 182 | */ 183 | public T7 getT7() { 184 | return t7; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Sext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | /** 19 | *

Sext class.

20 | * 21 | * @author svenruppert 22 | * @version $Id: $Id 23 | */ 24 | public class Sext { 25 | 26 | private T1 t1; 27 | private T2 t2; 28 | private T3 t3; 29 | private T4 t4; 30 | private T5 t5; 31 | private T6 t6; 32 | 33 | /** 34 | *

Constructor for Sext.

35 | * 36 | * @param t1 a T1 object. 37 | * @param t2 a T2 object. 38 | * @param t3 a T3 object. 39 | * @param t4 a T4 object. 40 | * @param t5 a T5 object. 41 | * @param t6 a T6 object. 42 | */ 43 | public Sext(final T1 t1 , final T2 t2 , final T3 t3 , 44 | final T4 t4 , final T5 t5 , final T6 t6) { 45 | this.t1 = t1; 46 | this.t2 = t2; 47 | this.t3 = t3; 48 | this.t4 = t4; 49 | this.t5 = t5; 50 | this.t6 = t6; 51 | } 52 | 53 | /** 54 | *

Getter for the field t6.

55 | * 56 | * @return a T6 object. 57 | */ 58 | public T6 getT6() { 59 | return t6; 60 | } 61 | 62 | /** 63 | *

Getter for the field t5.

64 | * 65 | * @return a T5 object. 66 | */ 67 | public T5 getT5() { 68 | return t5; 69 | } 70 | 71 | /** 72 | *

Getter for the field t4.

73 | * 74 | * @return a T4 object. 75 | */ 76 | public T4 getT4() { 77 | return t4; 78 | } 79 | 80 | /** 81 | *

Getter for the field t3.

82 | * 83 | * @return a T3 object. 84 | */ 85 | public T3 getT3() { 86 | return t3; 87 | } 88 | 89 | /** 90 | *

Getter for the field t1.

91 | * 92 | * @return a T1 object. 93 | */ 94 | public T1 getT1() { 95 | return t1; 96 | } 97 | 98 | /** 99 | *

Getter for the field t2.

100 | * 101 | * @return a T2 object. 102 | */ 103 | public T2 getT2() { 104 | return t2; 105 | } 106 | 107 | 108 | /** {@inheritDoc} */ 109 | @Override 110 | public boolean equals(Object o) { 111 | if (this == o) return true; 112 | if (! (o instanceof Sext)) return false; 113 | 114 | Sext sext = (Sext) o; 115 | 116 | if (t1 != null ? ! t1.equals(sext.t1) : sext.t1 != null) return false; 117 | if (t2 != null ? ! t2.equals(sext.t2) : sext.t2 != null) return false; 118 | if (t3 != null ? ! t3.equals(sext.t3) : sext.t3 != null) return false; 119 | if (t4 != null ? ! t4.equals(sext.t4) : sext.t4 != null) return false; 120 | if (t5 != null ? ! t5.equals(sext.t5) : sext.t5 != null) return false; 121 | return t6 != null ? t6.equals(sext.t6) : sext.t6 == null; 122 | } 123 | 124 | /** {@inheritDoc} */ 125 | @Override 126 | public int hashCode() { 127 | int result = t1 != null ? t1.hashCode() : 0; 128 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 129 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 130 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 131 | result = 31 * result + (t5 != null ? t5.hashCode() : 0); 132 | result = 31 * result + (t6 != null ? t6.hashCode() : 0); 133 | return result; 134 | } 135 | 136 | /** {@inheritDoc} */ 137 | @Override 138 | public String toString() { 139 | return "Sext{" + 140 | "t1=" + t1 + 141 | ", t2=" + t2 + 142 | ", t3=" + t3 + 143 | ", t4=" + t4 + 144 | ", t5=" + t5 + 145 | ", t6=" + t6 + 146 | '}'; 147 | } 148 | 149 | /** 150 | *

next.

151 | * 152 | * @param t1 a T1 object. 153 | * @param t2 a T2 object. 154 | * @param t3 a T3 object. 155 | * @param t4 a T4 object. 156 | * @param t5 a T5 object. 157 | * @param t6 a T6 object. 158 | * @param a T1 object. 159 | * @param a T2 object. 160 | * @param a T3 object. 161 | * @param a T4 object. 162 | * @param a T5 object. 163 | * @param a T6 object. 164 | * @return a {@link com.svenruppert.functional.model.Sext} object. 165 | */ 166 | public static Sext next(final T1 t1 , final T2 t2 , final T3 t3 , 167 | final T4 t4 , final T5 t5, final T6 t6) { 168 | return new Sext<>(t1 , t2 , t3 , t4 , t5, t6); 169 | } 170 | 171 | 172 | } 173 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Single.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | import java.util.Objects; 19 | 20 | public class Single { 21 | private T1 t1; 22 | 23 | /** 24 | *

Constructor for Pair.

25 | * 26 | * @param t1 a T1 object. 27 | */ 28 | public Single(final T1 t1) { 29 | this.t1 = t1; 30 | } 31 | 32 | /** 33 | *

Getter for the field t1.

34 | * 35 | * @return a T1 object. 36 | */ 37 | public T1 getT1() { 38 | return t1; 39 | } 40 | 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public String toString() { 47 | return "Single{" + 48 | "t1=" + t1 + 49 | '}'; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) return true; 55 | if (! (o instanceof Single)) return false; 56 | Single single = (Single) o; 57 | return Objects.equals(t1 , single.t1); 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return Objects.hash(t1); 63 | } 64 | 65 | /** 66 | *

next.

67 | * 68 | * @param a a T1 object. 69 | * @param a T1 object. 70 | * @return a {@link com.svenruppert.functional.model.Pair} object. 71 | */ 72 | public static Single next(T1 a) { 73 | return new Single<>(a); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/Triple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model; 17 | 18 | /** 19 | * Copyright (C) 2010 RapidPM 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * http://www.apache.org/licenses/LICENSE-2.0 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an "AS IS" BASIS, 26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | *

30 | * Created by RapidPM - Team on 10.12.16. 31 | * 32 | * @author svenruppert 33 | * @version $Id: $Id 34 | */ 35 | public class Triple { 36 | private T1 t1; 37 | private T2 t2; 38 | private T3 t3; 39 | 40 | /** 41 | *

Constructor for Triple.

42 | * 43 | * @param t1 a T1 object. 44 | * @param t2 a T2 object. 45 | * @param t3 a T3 object. 46 | */ 47 | public Triple(final T1 t1, final T2 t2, final T3 t3) { 48 | this.t1 = t1; 49 | this.t2 = t2; 50 | this.t3 = t3; 51 | } 52 | 53 | /** 54 | *

Getter for the field t3.

55 | * 56 | * @return a T3 object. 57 | */ 58 | public T3 getT3() { 59 | return t3; 60 | } 61 | 62 | /** 63 | *

Getter for the field t1.

64 | * 65 | * @return a T1 object. 66 | */ 67 | public T1 getT1() { 68 | return t1; 69 | } 70 | 71 | /** 72 | *

Getter for the field t2.

73 | * 74 | * @return a T2 object. 75 | */ 76 | public T2 getT2() { 77 | return t2; 78 | } 79 | 80 | /** {@inheritDoc} */ 81 | @Override 82 | public boolean equals(Object o) { 83 | if (this == o) return true; 84 | if (! (o instanceof Triple)) return false; 85 | 86 | Triple triple = (Triple) o; 87 | 88 | if (t1 != null ? ! t1.equals(triple.t1) : triple.t1 != null) return false; 89 | if (t2 != null ? ! t2.equals(triple.t2) : triple.t2 != null) return false; 90 | return t3 != null ? t3.equals(triple.t3) : triple.t3 == null; 91 | } 92 | 93 | /** {@inheritDoc} */ 94 | @Override 95 | public int hashCode() { 96 | int result = t1 != null ? t1.hashCode() : 0; 97 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 98 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 99 | return result; 100 | } 101 | 102 | /** {@inheritDoc} */ 103 | @Override 104 | public String toString() { 105 | return "Triple{" + 106 | "t1=" + t1 + 107 | ", t2=" + t2 + 108 | ", t3=" + t3 + 109 | '}'; 110 | } 111 | 112 | /** 113 | *

next.

114 | * 115 | * @param t1 a T1 object. 116 | * @param t2 a T2 object. 117 | * @param t3 a T3 object. 118 | * @param a T1 object. 119 | * @param a T2 object. 120 | * @param a T3 object. 121 | * @return a {@link Triple} object. 122 | */ 123 | public static Triple next(final T1 t1, final T2 t2, final T3 t3) { 124 | return new Triple<>(t1, t2, t3); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | import java.util.Objects; 20 | 21 | /** 22 | * Copyright (C) 2010 RapidPM 23 | * Licensed under the Apache License, Version 2.0 (the "License"); 24 | * you may not use this file except in compliance with the License. 25 | * You may obtain a copy of the License at 26 | * http://www.apache.org/licenses/LICENSE-2.0 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, 29 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 30 | * See the License for the specific language governing permissions and 31 | * limitations under the License. 32 | *

33 | * Created by RapidPM - Team on 10.12.16. 34 | * 35 | * @author svenruppert 36 | * @version $Id: $Id 37 | */ 38 | public class Pair implements Serializable { 39 | private T1 t1; 40 | private T2 t2; 41 | 42 | /** 43 | *

Constructor for Pair.

44 | * 45 | * @param t1 a T1 object. 46 | * @param t2 a T2 object. 47 | */ 48 | public Pair(final T1 t1, final T2 t2) { 49 | this.t1 = t1; 50 | this.t2 = t2; 51 | } 52 | 53 | /** 54 | *

Getter for the field t1.

55 | * 56 | * @return a T1 object. 57 | */ 58 | public T1 getT1() { 59 | return t1; 60 | } 61 | 62 | /** 63 | *

Getter for the field t2.

64 | * 65 | * @return a T2 object. 66 | */ 67 | public T2 getT2() { 68 | return t2; 69 | } 70 | 71 | /** {@inheritDoc} */ 72 | @Override 73 | public String toString() { 74 | return "Pair{" + 75 | "t1=" + t1 + 76 | ", t2=" + t2 + 77 | '}'; 78 | } 79 | 80 | /** {@inheritDoc} */ 81 | @Override 82 | public boolean equals(final Object o) { 83 | if (this == o) return true; 84 | if (! (o instanceof Pair)) return false; 85 | final Pair pair = (Pair) o; 86 | return Objects.equals(t1, pair.t1) && 87 | Objects.equals(t2, pair.t2); 88 | } 89 | 90 | /** {@inheritDoc} */ 91 | @Override 92 | public int hashCode() { 93 | return Objects.hash(t1, t2); 94 | } 95 | 96 | /** 97 | *

next.

98 | * 99 | * @param a a T1 object. 100 | * @param b a T2 object. 101 | * @param a T1 object. 102 | * @param a T2 object. 103 | * @return a {@link com.svenruppert.functional.model.serial.Pair} object. 104 | */ 105 | public static Pair next(T1 a, T2 b) { 106 | return new Pair<>(a, b); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Quad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * Copyright (C) 2010 RapidPM 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * Unless required by applicable law or agreed to in writing, software 27 | * distributed under the License is distributed on an "AS IS" BASIS, 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | * See the License for the specific language governing permissions and 30 | * limitations under the License. 31 | *

32 | * Created by RapidPM - Team on 10.12.16. 33 | * 34 | * @author svenruppert 35 | * @version $Id: $Id 36 | */ 37 | public class Quad { 38 | 39 | private T1 t1; 40 | private T2 t2; 41 | private T3 t3; 42 | private T4 t4; 43 | 44 | /** 45 | *

Constructor for Quad.

46 | * 47 | * @param t1 a T1 object. 48 | * @param t2 a T2 object. 49 | * @param t3 a T3 object. 50 | * @param t4 a T4 object. 51 | */ 52 | public Quad(final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4) { 53 | this.t1 = t1; 54 | this.t2 = t2; 55 | this.t3 = t3; 56 | this.t4 = t4; 57 | } 58 | 59 | /** 60 | *

Getter for the field t4.

61 | * 62 | * @return a T4 object. 63 | */ 64 | public T4 getT4() { 65 | return t4; 66 | } 67 | 68 | /** 69 | *

Getter for the field t3.

70 | * 71 | * @return a T3 object. 72 | */ 73 | public T3 getT3() { 74 | return t3; 75 | } 76 | 77 | /** 78 | *

Getter for the field t1.

79 | * 80 | * @return a T1 object. 81 | */ 82 | public T1 getT1() { 83 | return t1; 84 | } 85 | 86 | /** 87 | *

Getter for the field t2.

88 | * 89 | * @return a T2 object. 90 | */ 91 | public T2 getT2() { 92 | return t2; 93 | } 94 | 95 | /** {@inheritDoc} */ 96 | @Override 97 | public boolean equals(Object o) { 98 | if (this == o) return true; 99 | if (! (o instanceof Quad)) return false; 100 | 101 | Quad quad = (Quad) o; 102 | 103 | if (t1 != null ? ! t1.equals(quad.t1) : quad.t1 != null) return false; 104 | if (t2 != null ? ! t2.equals(quad.t2) : quad.t2 != null) return false; 105 | if (t3 != null ? ! t3.equals(quad.t3) : quad.t3 != null) return false; 106 | return t4 != null ? t4.equals(quad.t4) : quad.t4 == null; 107 | } 108 | 109 | /** {@inheritDoc} */ 110 | @Override 111 | public int hashCode() { 112 | int result = t1 != null ? t1.hashCode() : 0; 113 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 114 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 115 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 116 | return result; 117 | } 118 | 119 | /** {@inheritDoc} */ 120 | @Override 121 | public String toString() { 122 | return "Quad{" + 123 | "t1=" + t1 + 124 | ", t2=" + t2 + 125 | ", t3=" + t3 + 126 | ", t4=" + t4 + 127 | '}'; 128 | } 129 | 130 | /** 131 | *

next.

132 | * 133 | * @param t1 a T1 object. 134 | * @param t2 a T2 object. 135 | * @param t3 a T3 object. 136 | * @param t4 a T4 object. 137 | * @param a T1 object. 138 | * @param a T2 object. 139 | * @param a T3 object. 140 | * @param a T4 object. 141 | * @return a {@link com.svenruppert.functional.model.serial.Quad} object. 142 | */ 143 | public static Quad next(final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4) { 147 | return new Quad<>(t1 , t2 , t3 , t4); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Quint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * Copyright (C) 2010 RapidPM 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * Unless required by applicable law or agreed to in writing, software 27 | * distributed under the License is distributed on an "AS IS" BASIS, 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | * See the License for the specific language governing permissions and 30 | * limitations under the License. 31 | *

32 | * Created by RapidPM - Team on 10.12.16. 33 | * 34 | * @author svenruppert 35 | * @version $Id: $Id 36 | */ 37 | public class Quint { 42 | 43 | private T1 t1; 44 | private T2 t2; 45 | private T3 t3; 46 | private T4 t4; 47 | private T5 t5; 48 | 49 | /** 50 | *

Constructor for Quint.

51 | * 52 | * @param t1 a T1 object. 53 | * @param t2 a T2 object. 54 | * @param t3 a T3 object. 55 | * @param t4 a T4 object. 56 | * @param t5 a T5 object. 57 | */ 58 | public Quint(final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4 , final T5 t5) { 59 | this.t1 = t1; 60 | this.t2 = t2; 61 | this.t3 = t3; 62 | this.t4 = t4; 63 | this.t5 = t5; 64 | } 65 | 66 | /** 67 | *

Getter for the field t5.

68 | * 69 | * @return a T5 object. 70 | */ 71 | public T5 getT5() { 72 | return t5; 73 | } 74 | 75 | /** 76 | *

Getter for the field t4.

77 | * 78 | * @return a T4 object. 79 | */ 80 | public T4 getT4() { 81 | return t4; 82 | } 83 | 84 | /** 85 | *

Getter for the field t3.

86 | * 87 | * @return a T3 object. 88 | */ 89 | public T3 getT3() { 90 | return t3; 91 | } 92 | 93 | /** 94 | *

Getter for the field t1.

95 | * 96 | * @return a T1 object. 97 | */ 98 | public T1 getT1() { 99 | return t1; 100 | } 101 | 102 | /** 103 | *

Getter for the field t2.

104 | * 105 | * @return a T2 object. 106 | */ 107 | public T2 getT2() { 108 | return t2; 109 | } 110 | 111 | 112 | /** {@inheritDoc} */ 113 | @Override 114 | public boolean equals(Object o) { 115 | if (this == o) return true; 116 | if (! (o instanceof Quint)) return false; 117 | 118 | Quint quint = (Quint) o; 119 | 120 | if (t1 != null ? ! t1.equals(quint.t1) : quint.t1 != null) return false; 121 | if (t2 != null ? ! t2.equals(quint.t2) : quint.t2 != null) return false; 122 | if (t3 != null ? ! t3.equals(quint.t3) : quint.t3 != null) return false; 123 | if (t4 != null ? ! t4.equals(quint.t4) : quint.t4 != null) return false; 124 | return t5 != null ? t5.equals(quint.t5) : quint.t5 == null; 125 | } 126 | 127 | /** {@inheritDoc} */ 128 | @Override 129 | public int hashCode() { 130 | int result = t1 != null ? t1.hashCode() : 0; 131 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 132 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 133 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 134 | result = 31 * result + (t5 != null ? t5.hashCode() : 0); 135 | return result; 136 | } 137 | 138 | /** {@inheritDoc} */ 139 | @Override 140 | public String toString() { 141 | return "Quint{" + 142 | "t1=" + t1 + 143 | ", t2=" + t2 + 144 | ", t3=" + t3 + 145 | ", t4=" + t4 + 146 | ", t5=" + t5 + 147 | '}'; 148 | } 149 | 150 | /** 151 | *

next.

152 | * 153 | * @param t1 a T1 object. 154 | * @param t2 a T2 object. 155 | * @param t3 a T3 object. 156 | * @param t4 a T4 object. 157 | * @param t5 a T5 object. 158 | * @param a T1 object. 159 | * @param a T2 object. 160 | * @param a T3 object. 161 | * @param a T4 object. 162 | * @param a T5 object. 163 | * @return a {@link com.svenruppert.functional.model.serial.Quint} object. 164 | */ 165 | public static Quint next(final T1 t1 , final T2 t2 , final T3 t3 , final T4 t4 , final T5 t5) { 170 | return new Quint<>(t1 , t2 , t3 , t4 , t5); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Sept.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | *

Sept class.

22 | * 23 | * @author svenruppert 24 | * @version $Id: $Id 25 | */ 26 | public class Sept { 28 | 29 | private T1 t1; 30 | private T2 t2; 31 | private T3 t3; 32 | private T4 t4; 33 | private T5 t5; 34 | private T6 t6; 35 | private T7 t7; 36 | 37 | /** 38 | *

Constructor for Sept.

39 | * 40 | * @param t1 a T1 object. 41 | * @param t2 a T2 object. 42 | * @param t3 a T3 object. 43 | * @param t4 a T4 object. 44 | * @param t5 a T5 object. 45 | * @param t6 a T6 object. 46 | * @param t7 a T7 object. 47 | */ 48 | public Sept(T1 t1 , T2 t2 , T3 t3 , T4 t4 , T5 t5 , T6 t6 , T7 t7) { 49 | this.t1 = t1; 50 | this.t2 = t2; 51 | this.t3 = t3; 52 | this.t4 = t4; 53 | this.t5 = t5; 54 | this.t6 = t6; 55 | this.t7 = t7; 56 | } 57 | 58 | /** {@inheritDoc} */ 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) return true; 62 | if (! (o instanceof Sept)) return false; 63 | 64 | Sept sept = (Sept) o; 65 | 66 | if (t1 != null ? ! t1.equals(sept.t1) : sept.t1 != null) return false; 67 | if (t2 != null ? ! t2.equals(sept.t2) : sept.t2 != null) return false; 68 | if (t3 != null ? ! t3.equals(sept.t3) : sept.t3 != null) return false; 69 | if (t4 != null ? ! t4.equals(sept.t4) : sept.t4 != null) return false; 70 | if (t5 != null ? ! t5.equals(sept.t5) : sept.t5 != null) return false; 71 | if (t6 != null ? ! t6.equals(sept.t6) : sept.t6 != null) return false; 72 | return t7 != null ? t7.equals(sept.t7) : sept.t7 == null; 73 | } 74 | 75 | /** {@inheritDoc} */ 76 | @Override 77 | public int hashCode() { 78 | int result = t1 != null ? t1.hashCode() : 0; 79 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 80 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 81 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 82 | result = 31 * result + (t5 != null ? t5.hashCode() : 0); 83 | result = 31 * result + (t6 != null ? t6.hashCode() : 0); 84 | result = 31 * result + (t7 != null ? t7.hashCode() : 0); 85 | return result; 86 | } 87 | 88 | /** {@inheritDoc} */ 89 | @Override 90 | public String toString() { 91 | return "Sept{" + 92 | "t1=" + t1 + 93 | ", t2=" + t2 + 94 | ", t3=" + t3 + 95 | ", t4=" + t4 + 96 | ", t5=" + t5 + 97 | ", t6=" + t6 + 98 | ", t7=" + t7 + 99 | '}'; 100 | } 101 | 102 | /** 103 | *

next.

104 | * 105 | * @param t1 a T1 object. 106 | * @param t2 a T2 object. 107 | * @param t3 a T3 object. 108 | * @param t4 a T4 object. 109 | * @param t5 a T5 object. 110 | * @param t6 a T6 object. 111 | * @param t7 a T7 object. 112 | * @param a T1 object. 113 | * @param a T2 object. 114 | * @param a T3 object. 115 | * @param a T4 object. 116 | * @param a T5 object. 117 | * @param a T6 object. 118 | * @param a T7 object. 119 | * @return a {@link com.svenruppert.functional.model.serial.Sept} object. 120 | */ 121 | public static Sept next(final T1 t1 , final T2 t2 , final T3 t3 , 123 | final T4 t4 , final T5 t5 , final T6 t6 , final T7 t7) { 124 | return new Sept<>(t1 , t2 , t3 , t4 , t5 , t6 , t7); 125 | } 126 | 127 | /** 128 | *

Getter for the field t1.

129 | * 130 | * @return a T1 object. 131 | */ 132 | public T1 getT1() { 133 | return t1; 134 | } 135 | 136 | /** 137 | *

Getter for the field t2.

138 | * 139 | * @return a T2 object. 140 | */ 141 | public T2 getT2() { 142 | return t2; 143 | } 144 | 145 | /** 146 | *

Getter for the field t3.

147 | * 148 | * @return a T3 object. 149 | */ 150 | public T3 getT3() { 151 | return t3; 152 | } 153 | 154 | /** 155 | *

Getter for the field t4.

156 | * 157 | * @return a T4 object. 158 | */ 159 | public T4 getT4() { 160 | return t4; 161 | } 162 | 163 | /** 164 | *

Getter for the field t5.

165 | * 166 | * @return a T5 object. 167 | */ 168 | public T5 getT5() { 169 | return t5; 170 | } 171 | 172 | /** 173 | *

Getter for the field t6.

174 | * 175 | * @return a T6 object. 176 | */ 177 | public T6 getT6() { 178 | return t6; 179 | } 180 | 181 | /** 182 | *

Getter for the field t7.

183 | * 184 | * @return a T7 object. 185 | */ 186 | public T7 getT7() { 187 | return t7; 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Sext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | *

Sext class.

22 | * 23 | * @author svenruppert 24 | * @version $Id: $Id 25 | */ 26 | public class Sext { 28 | 29 | private T1 t1; 30 | private T2 t2; 31 | private T3 t3; 32 | private T4 t4; 33 | private T5 t5; 34 | private T6 t6; 35 | 36 | /** 37 | *

Constructor for Sext.

38 | * 39 | * @param t1 a T1 object. 40 | * @param t2 a T2 object. 41 | * @param t3 a T3 object. 42 | * @param t4 a T4 object. 43 | * @param t5 a T5 object. 44 | * @param t6 a T6 object. 45 | */ 46 | public Sext(final T1 t1 , final T2 t2 , final T3 t3 , 47 | final T4 t4 , final T5 t5 , final T6 t6) { 48 | this.t1 = t1; 49 | this.t2 = t2; 50 | this.t3 = t3; 51 | this.t4 = t4; 52 | this.t5 = t5; 53 | this.t6 = t6; 54 | } 55 | 56 | /** 57 | *

Getter for the field t6.

58 | * 59 | * @return a T6 object. 60 | */ 61 | public T6 getT6() { 62 | return t6; 63 | } 64 | 65 | /** 66 | *

Getter for the field t5.

67 | * 68 | * @return a T5 object. 69 | */ 70 | public T5 getT5() { 71 | return t5; 72 | } 73 | 74 | /** 75 | *

Getter for the field t4.

76 | * 77 | * @return a T4 object. 78 | */ 79 | public T4 getT4() { 80 | return t4; 81 | } 82 | 83 | /** 84 | *

Getter for the field t3.

85 | * 86 | * @return a T3 object. 87 | */ 88 | public T3 getT3() { 89 | return t3; 90 | } 91 | 92 | /** 93 | *

Getter for the field t1.

94 | * 95 | * @return a T1 object. 96 | */ 97 | public T1 getT1() { 98 | return t1; 99 | } 100 | 101 | /** 102 | *

Getter for the field t2.

103 | * 104 | * @return a T2 object. 105 | */ 106 | public T2 getT2() { 107 | return t2; 108 | } 109 | 110 | 111 | /** {@inheritDoc} */ 112 | @Override 113 | public boolean equals(Object o) { 114 | if (this == o) return true; 115 | if (! (o instanceof Sext)) return false; 116 | 117 | Sext sext = (Sext) o; 118 | 119 | if (t1 != null ? ! t1.equals(sext.t1) : sext.t1 != null) return false; 120 | if (t2 != null ? ! t2.equals(sext.t2) : sext.t2 != null) return false; 121 | if (t3 != null ? ! t3.equals(sext.t3) : sext.t3 != null) return false; 122 | if (t4 != null ? ! t4.equals(sext.t4) : sext.t4 != null) return false; 123 | if (t5 != null ? ! t5.equals(sext.t5) : sext.t5 != null) return false; 124 | return t6 != null ? t6.equals(sext.t6) : sext.t6 == null; 125 | } 126 | 127 | /** {@inheritDoc} */ 128 | @Override 129 | public int hashCode() { 130 | int result = t1 != null ? t1.hashCode() : 0; 131 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 132 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 133 | result = 31 * result + (t4 != null ? t4.hashCode() : 0); 134 | result = 31 * result + (t5 != null ? t5.hashCode() : 0); 135 | result = 31 * result + (t6 != null ? t6.hashCode() : 0); 136 | return result; 137 | } 138 | 139 | /** {@inheritDoc} */ 140 | @Override 141 | public String toString() { 142 | return "Quint{" + 143 | "t1=" + t1 + 144 | ", t2=" + t2 + 145 | ", t3=" + t3 + 146 | ", t4=" + t4 + 147 | ", t5=" + t5 + 148 | '}'; 149 | } 150 | 151 | /** 152 | *

next.

153 | * 154 | * @param t1 a T1 object. 155 | * @param t2 a T2 object. 156 | * @param t3 a T3 object. 157 | * @param t4 a T4 object. 158 | * @param t5 a T5 object. 159 | * @param t6 a T6 object. 160 | * @param a T1 object. 161 | * @param a T2 object. 162 | * @param a T3 object. 163 | * @param a T4 object. 164 | * @param a T5 object. 165 | * @param a T6 object. 166 | * @return a {@link com.svenruppert.functional.model.serial.Sext} object. 167 | */ 168 | public static Sext next(final T1 t1 , final T2 t2 , final T3 t3 , 170 | final T4 t4 , final T5 t5 , final T6 t6) { 171 | return new Sext<>(t1 , t2 , t3 , t4 , t5 , t6); 172 | } 173 | 174 | 175 | } 176 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Single.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | import java.util.Objects; 20 | 21 | public class Single { 22 | private T1 t1; 23 | 24 | /** 25 | *

Constructor for Pair.

26 | * 27 | * @param t1 a T1 object. 28 | */ 29 | public Single(final T1 t1) { 30 | this.t1 = t1; 31 | } 32 | 33 | /** 34 | *

Getter for the field t1.

35 | * 36 | * @return a T1 object. 37 | */ 38 | public T1 getT1() { 39 | return t1; 40 | } 41 | 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public String toString() { 48 | return "Single{" + "t1=" + t1 + '}'; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) return true; 54 | if (!(o instanceof Single)) return false; 55 | Single single = (Single) o; 56 | return Objects.equals(t1, single.t1); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return Objects.hash(t1); 62 | } 63 | 64 | /** 65 | *

next.

66 | * 67 | * @param a a T1 object. 68 | * @param a T1 object. 69 | * @return a {@link com.svenruppert.functional.model.serial.Single} object. 70 | */ 71 | public static Single next(T1 a) { 72 | return new Single<>(a); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/model/serial/Triple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.model.serial; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * Copyright (C) 2010 RapidPM 22 | * Licensed under the Apache License, Version 2.0 (the "License"); 23 | * you may not use this file except in compliance with the License. 24 | * You may obtain a copy of the License at 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * Unless required by applicable law or agreed to in writing, software 27 | * distributed under the License is distributed on an "AS IS" BASIS, 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | * See the License for the specific language governing permissions and 30 | * limitations under the License. 31 | *

32 | * Created by RapidPM - Team on 10.12.16. 33 | * 34 | * @author svenruppert 35 | * @version $Id: $Id 36 | */ 37 | public class Triple { 38 | private T1 t1; 39 | private T2 t2; 40 | private T3 t3; 41 | 42 | /** 43 | *

Constructor for Triple.

44 | * 45 | * @param t1 a T1 object. 46 | * @param t2 a T2 object. 47 | * @param t3 a T3 object. 48 | */ 49 | public Triple(final T1 t1, final T2 t2, final T3 t3) { 50 | this.t1 = t1; 51 | this.t2 = t2; 52 | this.t3 = t3; 53 | } 54 | 55 | /** 56 | *

Getter for the field t3.

57 | * 58 | * @return a T3 object. 59 | */ 60 | public T3 getT3() { 61 | return t3; 62 | } 63 | 64 | /** 65 | *

Getter for the field t1.

66 | * 67 | * @return a T1 object. 68 | */ 69 | public T1 getT1() { 70 | return t1; 71 | } 72 | 73 | /** 74 | *

Getter for the field t2.

75 | * 76 | * @return a T2 object. 77 | */ 78 | public T2 getT2() { 79 | return t2; 80 | } 81 | 82 | /** {@inheritDoc} */ 83 | @Override 84 | public boolean equals(Object o) { 85 | if (this == o) return true; 86 | if (! (o instanceof Triple)) return false; 87 | 88 | Triple triple = (Triple) o; 89 | 90 | if (t1 != null ? ! t1.equals(triple.t1) : triple.t1 != null) return false; 91 | if (t2 != null ? ! t2.equals(triple.t2) : triple.t2 != null) return false; 92 | return t3 != null ? t3.equals(triple.t3) : triple.t3 == null; 93 | } 94 | 95 | /** {@inheritDoc} */ 96 | @Override 97 | public int hashCode() { 98 | int result = t1 != null ? t1.hashCode() : 0; 99 | result = 31 * result + (t2 != null ? t2.hashCode() : 0); 100 | result = 31 * result + (t3 != null ? t3.hashCode() : 0); 101 | return result; 102 | } 103 | 104 | /** {@inheritDoc} */ 105 | @Override 106 | public String toString() { 107 | return "Triple{" + 108 | "t1=" + t1 + 109 | ", t2=" + t2 + 110 | ", t3=" + t3 + 111 | '}'; 112 | } 113 | 114 | /** 115 | *

next.

116 | * 117 | * @param t1 a T1 object. 118 | * @param t2 a T2 object. 119 | * @param t3 a T3 object. 120 | * @param a T1 object. 121 | * @param a T2 object. 122 | * @param a T3 object. 123 | * @return a {@link Triple} object. 124 | */ 125 | public static Triple next(final T1 t1, final T2 t2, final T3 t3) { 126 | return new Triple<>(t1, t2, t3); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/svenruppert/functional/reactive/CompletableFutureQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.svenruppert.functional.reactive; 17 | 18 | import java.util.concurrent.CompletableFuture; 19 | import java.util.function.Function; 20 | 21 | import static java.util.concurrent.CompletableFuture.supplyAsync; 22 | 23 | /** 24 | *

CompletableFutureQueue class.

25 | * 26 | * @author svenruppert 27 | * @version $Id: $Id 28 | */ 29 | public class CompletableFutureQueue { 30 | 31 | private Function> resultFunction; 32 | 33 | private CompletableFutureQueue(Function> resultFunction) { 34 | this.resultFunction = resultFunction; 35 | } 36 | 37 | /** 38 | *

define.

39 | * 40 | * @param transformation a {@link java.util.function.Function} object. 41 | * @param a T object. 42 | * @param a R object. 43 | * @return a {@link com.svenruppert.functional.reactive.CompletableFutureQueue} object. 44 | */ 45 | public static CompletableFutureQueue define(Function transformation) { 46 | return new CompletableFutureQueue<>(t -> CompletableFuture.completedFuture(transformation.apply(t))); 47 | } 48 | 49 | /** 50 | *

thenCombineAsync.

51 | * 52 | * @param nextTransformation a {@link java.util.function.Function} object. 53 | * @param a N object. 54 | * @return a {@link com.svenruppert.functional.reactive.CompletableFutureQueue} object. 55 | */ 56 | public CompletableFutureQueue thenCombineAsync(Function nextTransformation) { 57 | final Function> f = this.resultFunction 58 | .andThen(before -> before.thenComposeAsync(v -> supplyAsync(() -> nextTransformation.apply(v)))); 59 | return new CompletableFutureQueue<>(f); 60 | } 61 | 62 | 63 | //TODO : how to combine a list of CF ? 64 | 65 | public CompletableFutureQueue thenCombineAsyncFromArray(Function[] nextTransformations) { 66 | CompletableFutureQueue cfq = this; 67 | for (Function nextTransformation : nextTransformations) { 68 | cfq = cfq.thenCombineAsync(nextTransformation); 69 | } 70 | return cfq; 71 | } 72 | 73 | // public CompletableFutureQueue thenCombineAsync(Collection> nextTransformations) { 74 | // 75 | // nextTransformations 76 | // .forEach(nextTransformation -> { 77 | // this.resultFunction = this.resultFunction 78 | // .andThen(before -> before.thenComposeAsync(v -> supplyAsync(() -> nextTransformation.apply(v)))); 79 | // }); 80 | // 81 | // 82 | // return new CompletableFutureQueue<>(this.resultFunction); 83 | // } 84 | // 85 | // 86 | // 87 | // 88 | // public CompletableFutureQueue thenCombineAsync(Function firstTransformation, Function... nextTransformations) { 89 | // final Function> f = this.resultFunction 90 | // .andThen(before -> before.thenComposeAsync(v -> supplyAsync(() -> firstTransformation.apply(v)))); 91 | // 92 | // if (nextTransformations != null) { 93 | // Arrays 94 | // .stream(nextTransformations) 95 | // .map(nf -> this.resultFunction.andThen(before -> before.thenComposeAsync(v -> supplyAsync(() -> nf.apply(v))))) 96 | // .forEach(nF -> { /** don something **/ }); 97 | // 98 | // } 99 | // return new CompletableFutureQueue<>(f); 100 | // } 101 | 102 | /** 103 | *

resultFunction.

104 | * 105 | * @return a {@link java.util.function.Function} object. 106 | */ 107 | public Function> resultFunction() { 108 | return this.resultFunction; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import com.svenruppert.functional.matcher.Case; 20 | import com.svenruppert.functional.model.Result; 21 | 22 | import static com.svenruppert.functional.matcher.Case.matchCase; 23 | 24 | public class DemoCase { 25 | 26 | 27 | @Test 28 | void test001() { 29 | 30 | String value = "A"; 31 | Result result 32 | = Case.match( 33 | matchCase(() -> Result.failure("nothing fit")), 34 | matchCase(() -> value.contains("A"), 35 | () -> Result.success("Got A")), 36 | matchCase(() -> value.contains("B"), 37 | () -> Result.success("Got B")) 38 | ); 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoCompletableFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.concurrent.CompletableFuture; 21 | import java.util.concurrent.ExecutorService; 22 | import java.util.concurrent.Executors; 23 | import java.util.function.Supplier; 24 | 25 | import static java.util.concurrent.CompletableFuture.supplyAsync; 26 | 27 | public class DemoCompletableFuture { 28 | 29 | 30 | @Test 31 | void test001() { 32 | ExecutorService exServ = Executors 33 | .newFixedThreadPool(2); 34 | 35 | Supplier dataSource = () -> "Hello World"; 36 | CompletableFuture cf = supplyAsync(dataSource, exServ); 37 | String result = cf.join(); 38 | System.out.println(result); 39 | exServ.shutdown(); 40 | } 41 | 42 | @Test 43 | void test002() { 44 | ExecutorService exServ = Executors 45 | .newFixedThreadPool(2); 46 | 47 | Supplier dataSource = () -> "Hello World"; 48 | supplyAsync(dataSource, exServ) 49 | .thenAcceptAsync(System.out::println, exServ) 50 | .join(); 51 | exServ.shutdown(); 52 | } 53 | 54 | @Test 55 | void test003() { 56 | ExecutorService exServ = Executors 57 | .newFixedThreadPool(2); 58 | 59 | CompletableFuture cfA = supplyAsync(() -> "A", exServ); 60 | CompletableFuture cfB = supplyAsync(() -> "B", exServ); 61 | CompletableFuture cfC = supplyAsync(() -> "C", exServ); 62 | 63 | cfA.thenCombineAsync(cfB, (a, b) -> a + b) 64 | .thenCombineAsync(cfC, (ab, c) -> ab + c) 65 | .thenAcceptAsync(System.out::println, exServ) 66 | .join(); 67 | exServ.shutdown(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoCompletableFutureQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import com.svenruppert.functional.reactive.CompletableFutureQueue; 20 | 21 | import java.util.concurrent.CompletableFuture; 22 | import java.util.function.Function; 23 | 24 | public class DemoCompletableFutureQueue { 25 | 26 | 27 | @Test 28 | void test001() { 29 | Function> f = CompletableFutureQueue 30 | .define((a) -> a + 10) 31 | .thenCombineAsync((b) -> b + 20) 32 | .thenCombineAsync((c) -> c + 30) 33 | .resultFunction(); 34 | 35 | f.apply(1) 36 | .thenAcceptAsync(System.out::println) 37 | .join(); 38 | } 39 | 40 | @Test 41 | void test002() { 42 | CompletableFutureQueue 43 | .define((a) -> a + 10) 44 | .thenCombineAsync((b) -> b + 20) 45 | .thenCombineAsync((c) -> c + 30) 46 | .resultFunction() 47 | .apply(1) 48 | .thenAcceptAsync(System.out::println) 49 | .join(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoExceptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import com.svenruppert.functional.functions.CheckedFunction; 20 | import com.svenruppert.functional.model.Result; 21 | 22 | import java.util.Optional; 23 | import java.util.stream.Stream; 24 | 25 | public class DemoExceptions { 26 | 27 | @Test 28 | void demo01() { 29 | try { 30 | int ups = Integer.parseInt("ups"); 31 | } catch (NumberFormatException e) { 32 | e.printStackTrace(); 33 | } 34 | 35 | Stream.of("1", "2", "3", "4", "ups") 36 | .map(Integer::parseInt) 37 | .count(); 38 | 39 | Stream.of("1", "2", "3", "4", "ups") 40 | .map(s -> { 41 | try { 42 | return Integer.parseInt(s); 43 | } catch (NumberFormatException e) { 44 | e.printStackTrace(); 45 | return -1; //oh no 46 | } 47 | }) 48 | .count(); 49 | 50 | Stream.of("1", "2", "3", "4", "ups") 51 | .map(s -> { 52 | try { 53 | return Optional.of(Integer.parseInt(s)); 54 | } catch (NumberFormatException e) { 55 | e.printStackTrace(); 56 | return Optional.empty(); //oh no 57 | } 58 | }) 59 | .filter(Optional::isPresent) 60 | // .flatMap(Optional::stream) 61 | .count(); 62 | 63 | 64 | Stream.of("1", "2", "3", "4", "ups") 65 | .map(new CheckedFunction() { 66 | @Override 67 | public Integer applyWithException(String s) throws Exception { 68 | return Integer.parseInt(s); 69 | } 70 | }) 71 | .count(); 72 | 73 | Stream.of("1", "2", "3", "4", "ups") 74 | .map((CheckedFunction) Integer::parseInt) 75 | .flatMap(Result::stream) 76 | .count(); 77 | 78 | 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoExtraction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.List; 21 | import java.util.function.BiFunction; 22 | import java.util.function.Consumer; 23 | import java.util.function.Function; 24 | import java.util.function.Predicate; 25 | 26 | import static java.util.Arrays.asList; 27 | 28 | public class DemoExtraction { 29 | 30 | 31 | @Test 32 | void test001() { 33 | List names = asList("Hugo", 34 | "Willy", 35 | "Lotta", 36 | "Maria"); 37 | names.stream() 38 | .filter(v -> v.contains("L")) 39 | .forEach(System.out::println); 40 | names.stream() 41 | .filter(v -> v.contains("H")) 42 | .forEach(System.out::println); 43 | } 44 | 45 | @Test 46 | void test002() { 47 | List names = asList("Hugo", 48 | "Willy", 49 | "Lotta", 50 | "Maria"); 51 | Consumer println = System.out::println; 52 | String l = "L";//final 53 | names.stream() 54 | .filter(v -> v.contains(l)) 55 | .forEach(println); 56 | 57 | String h = "H"; //final 58 | names.stream() 59 | .filter(v -> v.contains(h)) 60 | .forEach(println); 61 | } 62 | 63 | @Test 64 | void test003() { 65 | List names = asList("Hugo", 66 | "Willy", 67 | "Lotta", 68 | "Maria"); 69 | Consumer println = System.out::println; 70 | 71 | String l = "L";//final 72 | String h = "H"; //final 73 | 74 | Function> f 75 | = input -> s -> s.contains(input); 76 | 77 | names.stream() 78 | .filter(f.apply(l)) 79 | .forEach(println); 80 | 81 | names.stream() 82 | .filter(f.apply(h)) 83 | .forEach(println); 84 | 85 | 86 | BiFunction, String, Void> 87 | f2 = (list, input) -> { 88 | list.stream() 89 | .filter(f.apply(input)) 90 | .forEach(println); 91 | return null; 92 | }; 93 | 94 | f2.apply(names, l); 95 | f2.apply(names, h); 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoFunctionalInterfaces.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static java.lang.System.out; 21 | 22 | public class DemoFunctionalInterfaces { 23 | private static String doWorkStatic() {return null;} 24 | 25 | @FunctionalInterface 26 | interface InterfaceA { 27 | String doWork(); 28 | } 29 | 30 | @FunctionalInterface 31 | interface InterfaceB { 32 | String doWork(); 33 | 34 | default String doMoreWork() { 35 | return "useless"; 36 | } 37 | } 38 | 39 | @FunctionalInterface 40 | interface InterfaceC { 41 | String doWork(); 42 | 43 | default String doMoreWork() { 44 | return "useless"; 45 | } 46 | //with JDK9++ 47 | // private String doHiddenWork() { 48 | // return "useless"; 49 | // } 50 | } 51 | 52 | 53 | interface A { 54 | static void doStaticWork() {out.println("interface A");} 55 | default void doWork() {out.println("default A");} 56 | } 57 | 58 | interface B extends A { 59 | default void doWork() {out.println("default B");} 60 | } 61 | 62 | interface C { 63 | default void doWork() {out.println("default C");} 64 | } 65 | 66 | public static class ClassAB implements A , B { } 67 | public static class ClassAC implements A , C { 68 | @Override 69 | public void doWork() { 70 | out.println("default ClassAC"); 71 | } 72 | } 73 | 74 | 75 | @Test 76 | void demoA() { 77 | new ClassAB().doWork(); //"default B" 78 | //ClassAB.doStaticWork() 79 | 80 | A.doStaticWork(); 81 | 82 | new ClassAC().doWork(); //"default ClassAC" 83 | 84 | } 85 | 86 | 87 | public static class DemoClass{ 88 | public void consumeInterfaceA(InterfaceA a){ } 89 | } 90 | 91 | @Test 92 | void demoB() { 93 | DemoClass demoClass = new DemoClass(); 94 | 95 | demoClass.consumeInterfaceA(new InterfaceA() { 96 | @Override 97 | public String doWork() { 98 | return null; 99 | } 100 | }); 101 | 102 | demoClass.consumeInterfaceA(() -> { return null;}); 103 | demoClass.consumeInterfaceA(() -> null); 104 | //be careful !!! inheritance ?? 105 | demoClass.consumeInterfaceA(DemoFunctionalInterfaces::doWorkStatic); 106 | 107 | 108 | 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoMemoizingLegacy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.Assert; 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | import com.svenruppert.functional.memoizer.Memoizer; 22 | 23 | import java.util.function.Function; 24 | 25 | public class DemoMemoizingLegacy { 26 | 27 | @Test 28 | void test001() { 29 | 30 | class Legacy { 31 | public String doWork(Integer input) { 32 | return input.toString() 33 | + "-" 34 | + System.nanoTime(); 35 | } 36 | } 37 | 38 | Legacy legacy = new Legacy(); 39 | Function f = legacy::doWork; 40 | Function fMemo = Memoizer.memoize(f); 41 | String a1 = fMemo.apply(1); 42 | Assertions.assertEquals(fMemo.apply(1), a1); 43 | 44 | String aLegacy = f.apply(1); 45 | Assertions.assertNotEquals(f.apply(1), aLegacy); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoMigration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.function.Function; 21 | 22 | public class DemoMigration { 23 | 24 | 25 | @Test 26 | void test001() { 27 | 28 | 29 | Function plus2 = (i)-> i + 2; 30 | Function plus5 = (i)-> i + 5; 31 | Function plus10 = (i)-> i + 10; 32 | 33 | Function> 34 | adder = (con) -> (i) -> i+con; 35 | 36 | Function plusTwo 37 | = adder.apply(2); 38 | 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.concurrent.ConcurrentHashMap; 21 | import java.util.function.Consumer; 22 | 23 | import static java.lang.System.out; 24 | 25 | public class DemoObserver { 26 | 27 | 28 | @Test 29 | void test001() { 30 | 31 | class Observer { 32 | private ConcurrentHashMap> listener 33 | = new ConcurrentHashMap<>(); 34 | 35 | public void register(KEY key, 36 | Consumer consumer) { 37 | listener.put(key, consumer); 38 | } 39 | 40 | public void remove(KEY key) { 41 | listener.remove(key); 42 | } 43 | 44 | public void senEvent(VALUE value) { 45 | listener.values() 46 | .forEach(c -> c.accept(value)); 47 | } 48 | } 49 | 50 | 51 | Observer observer = new Observer<>(); 52 | 53 | observer.register("key1", out::println); 54 | observer.senEvent(2); 55 | observer.remove("key1"); 56 | observer.senEvent(2); 57 | 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoOptional.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.Optional; 21 | 22 | public class DemoOptional { 23 | 24 | @Test 25 | void demoOptionalA() { 26 | Optional.of("String"); 27 | Optional.ofNullable(null); 28 | Optional.empty(); 29 | 30 | Optional ofOne = Optional.of(1); 31 | // ofOne.or(() -> Optional.of(2)); //JDK9 32 | ofOne.orElse(2); 33 | // ofOne.orElseThrow(); //JDK10 34 | // ofOne.stream(); //JDK9 35 | ofOne.map(i -> i + 2); 36 | ofOne.filter(i -> i == 2); 37 | 38 | // ofOne.ifPresentOrElse( //JDK9 39 | // i -> {}, 40 | // ()->{}); 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.Set; 21 | import java.util.concurrent.ConcurrentHashMap; 22 | import java.util.function.Consumer; 23 | 24 | import static java.lang.System.out; 25 | 26 | public class DemoRegistration { 27 | 28 | interface Registration { 29 | void remove(); 30 | } 31 | 32 | @Test 33 | void test001() { 34 | 35 | class Observer { 36 | private Set> listener 37 | = ConcurrentHashMap.newKeySet(); 38 | 39 | public Registration register(Consumer consumer) { 40 | listener.add(consumer); 41 | return () -> listener.remove(consumer); 42 | } 43 | 44 | public void senEvent(VALUE value) { 45 | listener.forEach(c -> c.accept(value)); 46 | } 47 | } 48 | 49 | 50 | Observer observer = new Observer<>(); 51 | 52 | Registration reg = observer.register(out::println); 53 | observer.senEvent(2); 54 | reg.remove(); 55 | observer.senEvent(2); 56 | 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import com.svenruppert.functional.model.Result; 20 | 21 | import java.util.Optional; 22 | import java.util.concurrent.CompletableFuture; 23 | import java.util.function.BiFunction; 24 | import java.util.function.Function; 25 | 26 | public class DemoResult { 27 | 28 | 29 | @Test 30 | void demoA() { 31 | 32 | Result.fromOptional(Optional.empty()); 33 | Result.success("ok") 34 | .toOptional(); 35 | 36 | Result nullable = Result.ofNullable(null); 37 | Result success = Result.success("String"); 38 | Result ooops = Result.failure("Ooops"); 39 | 40 | 41 | Result a = Result.success("A"); 42 | a.isPresent(); 43 | a.isAbsent(); 44 | 45 | a.ifPresent(String::toUpperCase); 46 | a.ifFailed(f -> {}); 47 | 48 | a.ifPresentOrElse(String::toLowerCase, () -> {}); 49 | a.ifPresentOrElse(String::toLowerCase, (failed) -> {}); 50 | 51 | a.ifPresentOrElseAsync(String::toLowerCase, () -> {}); 52 | a.ifPresentOrElseAsync(String::toLowerCase, (failed) -> {}); 53 | 54 | BiFunction> fkt = (x, y) -> Result.ofNullable(x + y); 55 | Result r = a.thenCombine("B", fkt); 56 | 57 | CompletableFuture> rAsync = a.thenCombineAsync("B", fkt); 58 | 59 | 60 | Function f1 = (a1) -> a1 * -1; 61 | Function f2 = (a2) -> a2 * 10; 62 | 63 | 64 | BiFunction< 65 | Function, 66 | Function, 67 | Function> rF 68 | = Function::andThen; 69 | 70 | // var transform = rF.andThen(Result::ofNullable); 71 | 72 | // Result.success(f1) 73 | // .thenCombineAsync(f2, transform) 74 | // .join() 75 | // .map(f -> f.apply(10)) 76 | // .get(); 77 | 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/demo/OOversusFRP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.Optional; 21 | import java.util.function.Consumer; 22 | 23 | public class OOversusFRP { 24 | 25 | 26 | @Test 27 | void demo001() { 28 | 29 | final Optional o = Optional.of("HelloWorld"); 30 | final Optional upperCase = o.map(String::toUpperCase); 31 | 32 | o.ifPresent(System.out::println); 33 | o.ifPresent(new Consumer() { 34 | @Override 35 | public void accept(String x) {System.out.println(x);} 36 | }); 37 | 38 | o.orElseThrow(() -> new RuntimeException("Uuuuuppss")); 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/ConvertingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.DisplayName; 20 | import org.junit.jupiter.api.Test; 21 | import com.svenruppert.functional.Converting; 22 | 23 | public class ConvertingTest { 24 | 25 | @Test 26 | @DisplayName("convertToString") 27 | void test001() { 28 | final String result = Converting 29 | .convertToString() 30 | .apply(1) 31 | .get(); 32 | Assertions.assertEquals("1" , result); 33 | } 34 | 35 | @Test 36 | @DisplayName("convertToString(f)") 37 | void test002() { 38 | 39 | final String result = Converting 40 | .convertToString((i) -> "x" + 1) 41 | .apply(1) 42 | .get(); 43 | Assertions.assertEquals("x1" , result); 44 | } 45 | 46 | @Test 47 | @DisplayName("convertToString(f) - failed") 48 | void test003() { 49 | Converting 50 | .convertToString((i) -> { 51 | throw new RuntimeException("failed"); 52 | }) 53 | .apply(1) 54 | .ifPresentOrElse((s) -> Assertions.fail(), 55 | (failed) -> Assertions.assertEquals("RuntimeException - failed", failed)); 56 | } 57 | 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/StreamFunctionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional; 17 | 18 | import static java.util.stream.Collectors.toSet; 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.util.Set; 22 | import java.util.stream.Stream; 23 | 24 | import org.junit.jupiter.api.Test; 25 | import com.svenruppert.functional.StreamFunctions; 26 | 27 | /** 28 | * 29 | */ 30 | public class StreamFunctionsTest { 31 | 32 | @Test 33 | void test001() { 34 | 35 | final Set set = StreamFunctions.streamFilter() 36 | .apply(integer -> integer.equals(5)) 37 | .apply(Stream.of(1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9)) 38 | .collect(toSet()); 39 | 40 | 41 | assertEquals(1 , set.size()); 42 | set.forEach(i -> assertEquals(Long.valueOf(i) , Long.valueOf(5))); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/TransformationsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | import com.svenruppert.functional.Transformations; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | /** 25 | * 26 | */ 27 | public class TransformationsTest { 28 | 29 | 30 | @Test 31 | public void test001() { 32 | 33 | String helloWorld = Transformations 34 | .curryBiFunction() 35 | .apply((s1, s2) -> s1 + " " + s2) 36 | .apply("Hello").apply("World"); 37 | assertEquals("Hello World", helloWorld); 38 | } 39 | 40 | 41 | @Test 42 | public void test002() { 43 | String helloWorld = Transformations 44 | .unCurryBiFunction() 45 | .apply(inputA -> inputB -> inputA + " " + inputB) 46 | .apply("Hello", "World"); 47 | assertEquals("Hello World", helloWorld); 48 | } 49 | 50 | @Test 51 | public void test003() { 52 | 53 | String helloWorld = Transformations 54 | .curryTriFunction() 55 | .apply((s1, s2, s3) -> s1 + " " + s2 + " " + s3) 56 | .apply("Hello").apply("World").apply("!"); 57 | assertEquals("Hello World !", helloWorld); 58 | } 59 | 60 | 61 | @Test 62 | public void test004(){ 63 | String helloWorld = Transformations 64 | .unCurryTriFunction() 65 | .apply(inputA -> inputB -> inputC -> inputA + " " + inputB + " " + inputC) 66 | .apply("Hello", "World", "!"); 67 | assertEquals("Hello World !", helloWorld); 68 | } 69 | 70 | @Test 71 | public void test005(){ 72 | String helloWorld = Transformations 73 | .unCurryCheckedTriFunction() 74 | .apply(inputA -> inputB -> inputC -> inputA + " " + inputB + " " + inputC) 75 | .apply("Hello", "World", "!") 76 | .get(); 77 | assertEquals("Hello World !", helloWorld); 78 | } 79 | 80 | @Test 81 | public void test006() { 82 | Transformations 83 | .unCurryCheckedTriFunction() 84 | .apply(inputA -> inputB -> inputC -> { 85 | throw new RuntimeException(""); 86 | }) 87 | .apply("Hello", "World", "!") 88 | .ifPresent(e -> Assertions.fail("should be false")); 89 | } 90 | 91 | 92 | @Test 93 | public void test007() { 94 | 95 | String helloWorld = Transformations 96 | .curryCheckedTriFunction() 97 | .apply((s1, s2, s3) -> s1 + " " + s2 + " " + s3) 98 | .apply("Hello").apply("World").apply("!") 99 | .get(); 100 | assertEquals("Hello World !", helloWorld); 101 | } 102 | 103 | @Test 104 | public void test008(){ 105 | Transformations 106 | .curryCheckedTriFunction() 107 | .apply((s1, s2, s3) -> {throw new RuntimeException("");}) 108 | .apply("Hello").apply("World").apply("!") 109 | .ifPresent(e -> Assertions.fail("should be false")); 110 | } 111 | 112 | @Test 113 | public void test009() { 114 | String helloWorld = Transformations 115 | .curryCheckedBiFunction() 116 | .apply((s1, s2) -> s1 + " " + s2) 117 | .apply("Hello").apply("World") 118 | .get(); 119 | assertEquals("Hello World", helloWorld); 120 | } 121 | 122 | @Test 123 | public void test010() { 124 | Transformations 125 | .curryCheckedBiFunction() 126 | .apply((s1, s2) -> {throw new RuntimeException("");}) 127 | .apply("Hello").apply("World") 128 | .ifPresent(e -> Assertions.fail("should be false")); 129 | } 130 | 131 | @Test 132 | public void test011() { 133 | String helloWorld = Transformations 134 | .unCurryCheckedBiFunction() 135 | .apply(inputA -> inputB -> inputA + " " + inputB) 136 | .apply("Hello", "World") 137 | .get(); 138 | assertEquals("Hello World", helloWorld); 139 | } 140 | 141 | @Test 142 | public void test012() { 143 | Transformations 144 | .unCurryCheckedBiFunction() 145 | .apply(inputA -> inputB -> {throw new RuntimeException("");}) 146 | .apply("Hello", "World") 147 | .ifPresent(e -> Assertions.fail("should be false")); 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/functions/CheckedBiFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.functions; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import com.svenruppert.functional.functions.CheckedBiFunction; 24 | import com.svenruppert.functional.model.Result; 25 | 26 | /** 27 | * 28 | */ 29 | public class CheckedBiFunctionTest { 30 | 31 | @Test 32 | public void test001() { 33 | 34 | final Result result = ((CheckedBiFunction) (s1 , s2) -> "ok") 35 | .apply("Hello" , "World"); 36 | 37 | assertNotNull(result); 38 | assertTrue(result.isPresent()); 39 | assertEquals("ok" , result.get()); 40 | 41 | } 42 | 43 | @Test 44 | public void test002() throws Exception { 45 | 46 | final Result result = ((CheckedBiFunction) (s1 , s2) -> { 47 | throw new RuntimeException("noop"); 48 | }) 49 | .apply("Hello" , "World"); 50 | 51 | assertNotNull(result); 52 | assertTrue(result.isAbsent()); 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/functions/CheckedExecutorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.functions; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertFalse; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import com.svenruppert.functional.functions.CheckedExecutor; 24 | import com.svenruppert.functional.model.Result; 25 | 26 | /** 27 | * Created by svenruppert on 26.04.17. 28 | */ 29 | public class CheckedExecutorTest { 30 | 31 | 32 | @Test 33 | public void test001() throws Exception { 34 | 35 | final CheckedExecutor e = () -> { /* do magic here */}; 36 | final Result result = e.execute(); 37 | assertNotNull(result); 38 | 39 | assertFalse(result.isPresent()); 40 | assertTrue(result.isAbsent()); 41 | 42 | assertTrue(result instanceof Result.Success); 43 | 44 | } 45 | 46 | @Test 47 | public void test002() throws Exception { 48 | 49 | final CheckedExecutor e = () -> { 50 | throw new RuntimeException("noop"); 51 | }; 52 | final Result result = e.execute(); 53 | assertNotNull(result); 54 | 55 | assertFalse(result.isPresent()); 56 | assertTrue(result.isAbsent()); 57 | 58 | assertTrue(result instanceof Result.Failure); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/functions/CheckedFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.functions; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import com.svenruppert.functional.functions.CheckedFunction; 24 | import com.svenruppert.functional.model.Result; 25 | 26 | /** 27 | * 28 | */ 29 | public class CheckedFunctionTest { 30 | 31 | @Test 32 | public void test001() throws Exception { 33 | 34 | final Result result = ((CheckedFunction) s -> "ok") 35 | .apply("Hello World"); 36 | 37 | assertNotNull(result); 38 | assertTrue(result.isPresent()); 39 | assertEquals("ok" , result.get()); 40 | 41 | } 42 | 43 | @Test 44 | public void test002() throws Exception { 45 | 46 | final Result result = ((CheckedFunction) s -> { 47 | throw new RuntimeException("noop"); 48 | }) 49 | .apply("Hello World"); 50 | 51 | assertNotNull(result); 52 | assertTrue(result.isAbsent()); 53 | 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/functions/CheckedPredicateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.functions; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertFalse; 19 | import static org.junit.jupiter.api.Assertions.assertTrue; 20 | 21 | import java.io.IOException; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.functions.CheckedPredicate; 25 | 26 | /** 27 | * 28 | */ 29 | public class CheckedPredicateTest { 30 | 31 | @Test 32 | public void test001() { 33 | CheckedPredicate p = s -> { 34 | throw new RuntimeException("foo"); 35 | }; 36 | assertFalse(p.test("")); 37 | } 38 | 39 | @Test 40 | public void test002() { 41 | CheckedPredicate p = s -> { 42 | throw new IOException("foo"); 43 | }; 44 | assertFalse(p.test("")); 45 | } 46 | 47 | @Test 48 | public void test003() { 49 | CheckedPredicate p = s -> s.equals("foo"); 50 | assertFalse(p.test("")); 51 | assertTrue(p.test("foo")); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/functions/CheckedSupplierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.functions; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import org.junit.jupiter.api.Test; 23 | import com.svenruppert.functional.functions.CheckedSupplier; 24 | import com.svenruppert.functional.model.Result; 25 | 26 | /** 27 | * 28 | */ 29 | public class CheckedSupplierTest { 30 | 31 | @Test 32 | public void test001() throws Exception { 33 | Result result = ((CheckedSupplier) () -> "Hello").get(); 34 | assertNotNull(result); 35 | assertTrue(result.isPresent()); 36 | assertEquals("Hello", result.get()); 37 | } 38 | 39 | @Test 40 | public void test002() throws Exception { 41 | Result result = ((CheckedSupplier) () -> { 42 | throw new RuntimeException("Hello"); 43 | }) 44 | .get(); 45 | assertNotNull(result); 46 | assertTrue(result.isAbsent()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/matcher/CaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.matcher; 17 | 18 | import static java.util.Objects.isNull; 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.fail; 21 | import static com.svenruppert.functional.matcher.Case.match; 22 | import static com.svenruppert.functional.matcher.Case.matchCase; 23 | 24 | import java.util.stream.IntStream; 25 | 26 | import org.junit.jupiter.api.Test; 27 | import com.svenruppert.functional.model.Result; 28 | 29 | /** 30 | * 31 | */ 32 | public class CaseTest { 33 | 34 | 35 | @Test 36 | void test000() { 37 | String value = "OK"; 38 | 39 | match( 40 | matchCase(() -> Result.success(value)) 41 | ) 42 | .ifPresentOrElse( 43 | s -> assertEquals(value , s) , 44 | s -> fail("not good") 45 | ); 46 | } 47 | 48 | @Test 49 | void test001() { 50 | final String error_message = "error message"; 51 | String value = null; 52 | 53 | match( 54 | matchCase(() -> Result.success(value)) , 55 | matchCase(() -> isNull(value) , () -> Result.failure(error_message)) 56 | ) 57 | .ifPresentOrElse( 58 | s -> fail("not good") , 59 | s -> assertEquals(error_message , s) 60 | ); 61 | } 62 | 63 | @Test 64 | void test002() { 65 | final String error_message = "error message"; 66 | String value = "OK"; 67 | 68 | match( 69 | matchCase(() -> Result.success(value)) , 70 | matchCase(() -> isNull(value) , () -> Result.failure(error_message)) 71 | ) 72 | .ifPresentOrElse( 73 | s -> assertEquals(value , s) , 74 | s -> fail("not good") 75 | ); 76 | } 77 | 78 | @Test 79 | void test003() { 80 | final String error_message = "error message"; 81 | 82 | 83 | IntStream 84 | .range(0 , 10) 85 | .boxed() 86 | .forEach(value -> match( 87 | matchCase(() -> Result.success(value)) , 88 | matchCase(() -> value == null , () -> Result.failure(error_message)) , 89 | matchCase(() -> value == 1 , () -> Result.success(100)) , 90 | matchCase(() -> value == 2 , () -> Result.success(200)) 91 | ) 92 | .ifPresentOrElse( 93 | s -> { 94 | if (value == 1) assertEquals(Long.valueOf(100) , Long.valueOf(s)); 95 | else if (value == 2) assertEquals(Long.valueOf(200) , Long.valueOf(s)); 96 | else assertEquals(Long.valueOf(value) , Long.valueOf(s)); 97 | } , 98 | s -> fail("not good") 99 | )); 100 | 101 | 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/PairTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.model.Pair; 25 | 26 | public class PairTest { 27 | 28 | @Test 29 | public void testEquals() { 30 | final Pair pair = new Pair(0, 1); 31 | 32 | assertFalse(pair.equals(null)); 33 | assertFalse(pair.equals(new Pair(null, 1))); 34 | assertFalse(pair.equals(new Pair(0, null))); 35 | assertTrue(pair.equals(pair)); 36 | assertTrue(pair.equals(new Pair(0, 1))); 37 | } 38 | 39 | @Test 40 | public void testHashCode() { 41 | final Pair pair = new Pair(0, 1); 42 | 43 | assertEquals(962, pair.hashCode()); 44 | } 45 | 46 | @Test 47 | public void testNext() { 48 | final Pair pair = Pair.next(0, 1); 49 | 50 | assertNotNull(pair); 51 | assertEquals(0, pair.getT1()); 52 | assertEquals(1, pair.getT2()); 53 | } 54 | 55 | @Test 56 | public void testToString() { 57 | final Pair pair = new Pair(0, 1); 58 | 59 | assertEquals("Pair{t1=0, t2=1}", pair.toString()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/QuadTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.model.Quad; 25 | 26 | public class QuadTest { 27 | 28 | @Test 29 | public void testEquals() { 30 | final Quad quad = new Quad(0, 1, 2, 3); 31 | 32 | assertTrue(quad.equals(quad)); 33 | assertFalse(quad.equals(null)); 34 | assertFalse(quad.equals(new Quad(null, 1, 2, 3))); 35 | assertFalse(quad.equals(new Quad(0, null, 2, 3))); 36 | assertFalse(quad.equals(new Quad(0, 1, null, 3))); 37 | } 38 | 39 | @Test 40 | public void testEqualsT1() { 41 | final Quad quad = new Quad(null, 1, 2, 3); 42 | 43 | assertTrue(quad.equals(new Quad(null, 1, 2, 3))); 44 | assertFalse(quad.equals(new Quad(0, 1, 2, 3))); 45 | } 46 | 47 | @Test 48 | public void testEqualsT2() { 49 | final Quad quad = new Quad(0, null, 2, 3); 50 | 51 | assertTrue(quad.equals(new Quad(0, null, 2, 3))); 52 | assertFalse(quad.equals(new Quad(0, 1, 2, 3))); 53 | } 54 | 55 | @Test 56 | public void testEqualsT3() { 57 | final Quad quad = new Quad(0, 1, null, 3); 58 | 59 | assertTrue(quad.equals(new Quad(0, 1, null, 3))); 60 | assertFalse(quad.equals(new Quad(0, 1, 2, 3))); 61 | } 62 | 63 | @Test 64 | public void testEqualsT4() { 65 | final Quad quad = new Quad(0, 1, 2, null); 66 | 67 | assertTrue(quad.equals(new Quad(0, 1, 2, null))); 68 | assertFalse(quad.equals(new Quad(0, 1, 2, 3))); 69 | } 70 | 71 | @Test 72 | public void testHashCode() { 73 | final Quad quad = new Quad(0, 1, 2, 3); 74 | 75 | assertEquals(1026, quad.hashCode()); 76 | } 77 | 78 | @Test 79 | public void testHashCodeT1() { 80 | final Quad quad = new Quad(null, 1, 2, 3); 81 | 82 | assertEquals(1026, quad.hashCode()); 83 | } 84 | 85 | @Test 86 | public void testHashCodeT2() { 87 | final Quad quad = new Quad(0, null, 2, 3); 88 | 89 | assertEquals(65, quad.hashCode()); 90 | } 91 | 92 | @Test 93 | public void testHashCodeT3() { 94 | final Quad quad = new Quad(0, 1, null, 3); 95 | 96 | assertEquals(964, quad.hashCode()); 97 | } 98 | 99 | @Test 100 | public void testHashCodeT4() { 101 | final Quad quad = new Quad(0, 1, 2, null); 102 | 103 | assertEquals(1023, quad.hashCode()); 104 | } 105 | 106 | 107 | @Test 108 | public void testNext() { 109 | final Quad quad = Quad.next(0, 1, 2, 3); 110 | 111 | assertNotNull(quad); 112 | assertEquals(0, quad.getT1()); 113 | assertEquals(1, quad.getT2()); 114 | assertEquals(2, quad.getT3()); 115 | assertEquals(3, quad.getT4()); 116 | } 117 | 118 | @Test 119 | public void testToString() { 120 | final Quad quad = new Quad(0, 1, 2, 3); 121 | 122 | assertEquals("Quad{t1=0, t2=1, t3=2, t4=3}", quad.toString()); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/QuintTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.model.Quint; 25 | 26 | public class QuintTest { 27 | 28 | @Test 29 | public void testEquals() { 30 | final Quint quint = new Quint(0, 1, 2, 3, 4); 31 | 32 | // assertTrue(quint.equals(quint)); 33 | assertEquals(quint, quint); 34 | assertFalse(quint.equals(null)); 35 | assertFalse(quint.equals(new Quint(null, 1, 2, 3, 4))); 36 | assertFalse(quint.equals(new Quint(0, null, 2, 3, 4))); 37 | assertFalse(quint.equals(new Quint(0, 1, null, 3, 4))); 38 | assertFalse(quint.equals(new Quint(0, 1, 2, null, 4))); 39 | } 40 | 41 | @Test 42 | public void testEqualsT1() { 43 | final Quint quint = new Quint(null, 1, 2, 3, 4); 44 | 45 | assertTrue(quint.equals(new Quint(null, 1, 2, 3, 4))); 46 | assertFalse(quint.equals(new Quint(0, 1, 2, 3, 4))); 47 | } 48 | 49 | @Test 50 | public void testEqualsT2() { 51 | final Quint quint = new Quint(0, null, 2, 3, 4); 52 | 53 | assertTrue(quint.equals(new Quint(0, null, 2, 3, 4))); 54 | assertFalse(quint.equals(new Quint(0, 1, 2, 3, 4))); 55 | } 56 | 57 | @Test 58 | public void testEqualsT3() { 59 | final Quint quint = new Quint(0, 1, null, 3, 4); 60 | 61 | assertTrue(quint.equals(new Quint(0, 1, null, 3, 4))); 62 | assertFalse(quint.equals(new Quint(0, 1, 2, 3, 4))); 63 | } 64 | 65 | @Test 66 | public void testEqualsT4() { 67 | final Quint quint = new Quint(0, 1, 2, null, 4); 68 | 69 | assertTrue(quint.equals(new Quint(0, 1, 2, null, 4))); 70 | assertFalse(quint.equals(new Quint(0, 1, 2, 3, 4))); 71 | } 72 | 73 | @Test 74 | public void testEqualsT5() { 75 | final Quint quint = new Quint(0, 1, 2, 3, null); 76 | 77 | assertTrue(quint.equals(new Quint(0, 1, 2, 3, null))); 78 | assertFalse(quint.equals(new Quint(0, 1, 2, 3, 4))); 79 | } 80 | 81 | @Test 82 | public void testHashCode() { 83 | final Quint quint = new Quint(0, 1, 2, 3, 4); 84 | 85 | assertEquals(31810, quint.hashCode()); 86 | } 87 | 88 | @Test 89 | public void testHashCodeT1() { 90 | final Quint quint = new Quint(null, 1, 2, 3, 4); 91 | 92 | assertEquals(31810, quint.hashCode()); 93 | } 94 | 95 | @Test 96 | public void testHashCodeT2() { 97 | final Quint quint = new Quint(0, null, 2, 3, 4); 98 | 99 | assertEquals(2019, quint.hashCode()); 100 | } 101 | 102 | @Test 103 | public void testHashCodeT3() { 104 | final Quint quint = new Quint(0, 1, null, 3, 4); 105 | 106 | assertEquals(29888, quint.hashCode()); 107 | } 108 | 109 | @Test 110 | public void testHashCodeT4() { 111 | final Quint quint = new Quint(0, 1, 2, null, 4); 112 | 113 | assertEquals(31717, quint.hashCode()); 114 | } 115 | 116 | @Test 117 | public void testHashCodeT5() throws Exception { 118 | final Quint quint = new Quint(0, 1, 2, 3, null); 119 | 120 | assertEquals(31806, quint.hashCode()); 121 | } 122 | 123 | @Test 124 | public void testNext() { 125 | final Quint quint = Quint.next(0, 1, 2, 3, 4); 126 | 127 | assertNotNull(quint); 128 | assertEquals(0, quint.getT1()); 129 | assertEquals(1, quint.getT2()); 130 | assertEquals(2, quint.getT3()); 131 | assertEquals(3, quint.getT4()); 132 | assertEquals(4, quint.getT5()); 133 | } 134 | 135 | @Test 136 | public void testToString() { 137 | final Quint quint = new Quint(0, 1, 2, 3, 4); 138 | 139 | assertEquals("Quint{t1=0, t2=1, t3=2, t4=3, t5=4}", quint.toString()); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/ResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import java.util.concurrent.CompletableFuture; 23 | 24 | import org.junit.jupiter.api.Assertions; 25 | import org.junit.jupiter.api.Test; 26 | import com.svenruppert.functional.model.Result; 27 | 28 | /** 29 | * 30 | */ 31 | public class ResultTest { 32 | 33 | @Test 34 | public void test001() throws Exception { 35 | Result hello = Result.success("Hello"); 36 | Result world = hello.thenCombine("World" , (s , s2) -> Result.success(s + " - " + s2)); 37 | assertEquals("Hello - World" , world.get()); 38 | } 39 | 40 | 41 | @Test 42 | public void test002() throws Exception { 43 | Result hello = Result.success("Hello"); 44 | CompletableFuture> world = hello 45 | .thenCombineAsync("World" , (s , s2) -> Result.success(s + " - " + s2)); 46 | 47 | Result result = world.join(); 48 | assertNotNull(result); 49 | assertTrue(result.isPresent()); 50 | assertEquals("Hello - World" , result.get()); 51 | } 52 | 53 | 54 | @Test 55 | public void test003() throws Exception { 56 | final Result asFailure = Result.success("Hello").asFailure(); 57 | assertTrue(asFailure.isAbsent()); 58 | asFailure.ifPresent(v -> Assertions.fail("not good")); 59 | } 60 | 61 | @Test 62 | public void test004() throws Exception { 63 | final Result asFailure = Result.failure("Hello").asFailure(); 64 | assertTrue(asFailure.isAbsent()); 65 | asFailure.ifPresent(v -> Assertions.fail("not good")); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/SeptTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.model.Sept; 25 | 26 | public class SeptTest { 27 | 28 | @Test 29 | public void testEquals() { 30 | final Sept sept = new Sept(0, 1, 2, 3, 4, 5, 6); 31 | 32 | assertTrue(sept.equals(sept)); 33 | assertFalse(sept.equals(null)); 34 | assertFalse(sept.equals(new Sept(null, 1, 2, 3, 4, 5, 6))); 35 | assertFalse(sept.equals(new Sept(0, null, 2, 3, 4, 5, 6))); 36 | assertFalse(sept.equals(new Sept(0, 1, null, 3, 4, 5, 6))); 37 | assertFalse(sept.equals(new Sept(0, 1, 2, null, 4, 5, 6))); 38 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, null, 5, 6))); 39 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, null, 6))); 40 | } 41 | 42 | @Test 43 | public void testEqualsT1() { 44 | final Sept sept = new Sept(null, 1, 2, 3, 4, 5, 6); 45 | 46 | assertTrue(sept.equals(new Sept(null, 1, 2, 3, 4, 5, 6))); 47 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 48 | } 49 | 50 | @Test 51 | public void testEqualsT2() { 52 | final Sept sept = new Sept(0, null, 2, 3, 4, 5, 6); 53 | 54 | assertTrue(sept.equals(new Sept(0, null, 2, 3, 4, 5, 6))); 55 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 56 | } 57 | 58 | @Test 59 | public void testEqualsT3() { 60 | final Sept sept = new Sept(0, 1, null, 3, 4, 5, 6); 61 | 62 | assertTrue(sept.equals(new Sept(0, 1, null, 3, 4, 5, 6))); 63 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 64 | } 65 | 66 | @Test 67 | public void testEqualsT4() { 68 | final Sept sept = new Sept(0, 1, 2, null, 4, 5, 6); 69 | 70 | assertTrue(sept.equals(new Sept(0, 1, 2, null, 4, 5, 6))); 71 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 72 | } 73 | 74 | @Test 75 | public void testEqualsT5() { 76 | final Sept sept = new Sept(0, 1, 2, 3, null, 5, 6); 77 | 78 | assertTrue(sept.equals(new Sept(0, 1, 2, 3, null, 5, 6))); 79 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 80 | } 81 | 82 | @Test 83 | public void testEqualsT6() { 84 | final Sept sept = new Sept(0, 1, 2, 3, 4, null, 6); 85 | 86 | assertTrue(sept.equals(new Sept(0, 1, 2, 3, 4, null, 6))); 87 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 88 | } 89 | 90 | @Test 91 | public void testEqualsT7() { 92 | final Sept sept = new Sept(0, 1, 2, 3, 4, 5, null); 93 | 94 | assertTrue(sept.equals(new Sept(0, 1, 2, 3, 4, 5, null))); 95 | assertFalse(sept.equals(new Sept(0, 1, 2, 3, 4, 5, 6))); 96 | } 97 | 98 | @Test 99 | public void testHashCode() { 100 | final Sept sept = new Sept(0, 1, 2, 3, 4, 5, 6); 101 | 102 | assertEquals(30569571, sept.hashCode()); 103 | } 104 | 105 | @Test 106 | public void testHashCodeT1() { 107 | final Sept sept = new Sept(null, 1, 2, 3, 4, 5, 6); 108 | 109 | assertEquals(30569571, sept.hashCode()); 110 | } 111 | 112 | @Test 113 | public void testHashCodeT2() { 114 | final Sept sept = new Sept(0, null, 2, 3, 4, 5, 6); 115 | 116 | assertEquals(1940420, sept.hashCode()); 117 | } 118 | 119 | @Test 120 | public void testHashCodeT3() { 121 | final Sept sept = new Sept(0, 1, null, 3, 4, 5, 6); 122 | 123 | assertEquals(28722529, sept.hashCode()); 124 | } 125 | 126 | @Test 127 | public void testHashCodeT4() { 128 | final Sept sept = new Sept(0, 1, 2, null, 4, 5, 6); 129 | 130 | assertEquals(30480198, sept.hashCode()); 131 | } 132 | 133 | @Test 134 | public void testHashCodeT5() { 135 | final Sept sept = new Sept(0, 1, 2, 3, null, 5, 6); 136 | 137 | assertEquals(30565727, sept.hashCode()); 138 | } 139 | 140 | @Test 141 | public void testHashCodeT6() { 142 | final Sept sept = new Sept(0, 1, 2, 3, 4, null, 6); 143 | 144 | assertEquals(30569416, sept.hashCode()); 145 | } 146 | 147 | @Test 148 | public void testHashCodeT7() { 149 | final Sept sept = new Sept(0, 1, 2, 3, 4, 5, null); 150 | 151 | assertEquals(30569565, sept.hashCode()); 152 | } 153 | 154 | @Test 155 | public void testNext() { 156 | final Sept sept = Sept.next(0, 1, 2, 3, 4, 5, 6); 157 | 158 | assertNotNull(sept); 159 | assertEquals(0, sept.getT1()); 160 | assertEquals(1, sept.getT2()); 161 | assertEquals(2, sept.getT3()); 162 | assertEquals(3, sept.getT4()); 163 | assertEquals(4, sept.getT5()); 164 | assertEquals(5, sept.getT6()); 165 | assertEquals(6, sept.getT7()); 166 | } 167 | 168 | @Test 169 | public void testToString() { 170 | final Sept sept = new Sept(0, 1, 2, 3, 4, 5, 6); 171 | 172 | assertEquals("Sept{t1=0, t2=1, t3=2, t4=3, t5=4, t6=5, t7=6}", sept.toString()); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/SextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.model.Sext; 25 | 26 | public class SextTest { 27 | 28 | @Test 29 | public void testEquals() { 30 | final Sext sext = new Sext(0, 1, 2, 3, 4, 5); 31 | 32 | assertTrue(sext.equals(sext)); 33 | assertFalse(sext.equals(null)); 34 | assertFalse(sext.equals(new Sext(null, 1, 2, 3, 4, 5))); 35 | assertFalse(sext.equals(new Sext(0, null, 2, 3, 4, 5))); 36 | assertFalse(sext.equals(new Sext(0, 1, null, 3, 4, 5))); 37 | assertFalse(sext.equals(new Sext(0, 1, 2, null, 4, 5))); 38 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, null, 5))); 39 | } 40 | 41 | @Test 42 | public void testEqualsT1() { 43 | final Sext sext = new Sext(null, 1, 2, 3, 4, 5); 44 | 45 | assertTrue(sext.equals(new Sext(null, 1, 2, 3, 4, 5))); 46 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, 4, 5))); 47 | } 48 | 49 | @Test 50 | public void testEqualsT2() { 51 | final Sext sext = new Sext(0, null, 2, 3, 4, 5); 52 | 53 | assertTrue(sext.equals(new Sext(0, null, 2, 3, 4, 5))); 54 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, 4, 5))); 55 | } 56 | 57 | @Test 58 | public void testEqualsT3() { 59 | final Sext sext = new Sext(0, 1, null, 3, 4, 5); 60 | 61 | assertTrue(sext.equals(new Sext(0, 1, null, 3, 4, 5))); 62 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, 4, 5))); 63 | } 64 | 65 | @Test 66 | public void testEqualsT4() { 67 | final Sext sext = new Sext(0, 1, 2, null, 4, 5); 68 | 69 | assertTrue(sext.equals(new Sext(0, 1, 2, null, 4, 5))); 70 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, 4, 5))); 71 | } 72 | 73 | @Test 74 | public void testEqualsT5() { 75 | final Sext sext = new Sext(0, 1, 2, 3, null, 5); 76 | 77 | assertTrue(sext.equals(new Sext(0, 1, 2, 3, null, 5))); 78 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, 4, 5))); 79 | } 80 | 81 | @Test 82 | public void testEqualsT6() { 83 | final Sext sext = new Sext(0, 1, 2, 3, 4, null); 84 | 85 | assertTrue(sext.equals(new Sext(0, 1, 2, 3, 4, null))); 86 | assertFalse(sext.equals(new Sext(0, 1, 2, 3, 4, 5))); 87 | } 88 | 89 | @Test 90 | public void testHashCode() { 91 | final Sext sext = new Sext(0, 1, 2, 3, 4, 5); 92 | 93 | assertEquals(986115, sext.hashCode()); 94 | } 95 | 96 | @Test 97 | public void testHashCodeT1() { 98 | final Sext sext = new Sext(null, 1, 2, 3, 4, 5); 99 | 100 | assertEquals(986115, sext.hashCode()); 101 | } 102 | 103 | @Test 104 | public void testHashCodeT2() { 105 | final Sext sext = new Sext(0, null, 2, 3, 4, 5); 106 | 107 | assertEquals(62594, sext.hashCode()); 108 | } 109 | 110 | @Test 111 | public void testHashCodeT3() { 112 | final Sext sext = new Sext(0, 1, null, 3, 4, 5); 113 | 114 | assertEquals(926533, sext.hashCode()); 115 | } 116 | 117 | @Test 118 | public void testHashCodeT4(){ 119 | final Sext sext = new Sext(0, 1, 2, null, 4, 5); 120 | 121 | assertEquals(983232, sext.hashCode()); 122 | } 123 | 124 | @Test 125 | public void testHashCodeT5() { 126 | final Sext sext = new Sext(0, 1, 2, 3, null, 5); 127 | 128 | assertEquals(985991, sext.hashCode()); 129 | } 130 | 131 | @Test 132 | public void testHashCodeT6() { 133 | final Sext sext = new Sext(0, 1, 2, 3, 4, null); 134 | 135 | assertEquals(986110, sext.hashCode()); 136 | } 137 | 138 | @Test 139 | public void testNext() { 140 | final Sext sext = Sext.next(0, 1, 2, 3, 4, 5); 141 | 142 | assertNotNull(sext); 143 | assertEquals(0, sext.getT1()); 144 | assertEquals(1, sext.getT2()); 145 | assertEquals(2, sext.getT3()); 146 | assertEquals(3, sext.getT4()); 147 | assertEquals(4, sext.getT5()); 148 | assertEquals(5, sext.getT6()); 149 | } 150 | 151 | @Test 152 | public void testToString() { 153 | final Sext sext = new Sext(0, 1, 2, 3, 4, 5); 154 | 155 | assertEquals("Sext{t1=0, t2=1, t3=2, t4=3, t5=4, t6=5}", sext.toString()); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/SingleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import com.svenruppert.functional.model.Single; 25 | 26 | public class SingleTest { 27 | 28 | @Test 29 | public void testEquals() { 30 | final Single single = new Single(0); 31 | 32 | assertFalse(single.equals(null)); 33 | assertTrue(single.equals(single)); 34 | assertTrue(single.equals(new Single(0))); 35 | } 36 | 37 | @Test 38 | public void testHashCode() { 39 | final Single single = new Single(0); 40 | 41 | assertEquals(31, single.hashCode()); 42 | } 43 | 44 | @Test 45 | public void testNext() { 46 | final Single single = Single.next(0); 47 | 48 | assertNotNull(single); 49 | assertEquals(0, single.getT1()); 50 | } 51 | 52 | @Test 53 | public void testToString() { 54 | final Single single = new Single(0); 55 | 56 | assertEquals("Single{t1=0}", single.toString()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/junit/com/svenruppert/functional/model/TripleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Sven Ruppert (sven.ruppert@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package junit.com.svenruppert.functional.model; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertFalse; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertNull; 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | import org.junit.jupiter.api.Test; 25 | import com.svenruppert.functional.model.Triple; 26 | 27 | public class TripleTest { 28 | 29 | @Test 30 | public void testEquals() { 31 | final Triple triple = new Triple(0, 1, 2); 32 | 33 | assertTrue(triple.equals(triple)); 34 | assertFalse(triple.equals(null)); 35 | assertFalse(triple.equals(new Triple(null, 1, 2))); 36 | assertFalse(triple.equals(new Triple(0, null, 2))); 37 | } 38 | 39 | @Test 40 | public void testEqualsT1() { 41 | final Triple triple = new Triple(null, 1, 2); 42 | 43 | assertTrue(triple.equals(new Triple(null, 1, 2))); 44 | assertFalse(triple.equals(new Triple(0, 1, 2))); 45 | } 46 | 47 | @Test 48 | public void testEqualsT2() { 49 | final Triple triple = new Triple(0, null, 2); 50 | 51 | assertTrue(triple.equals(new Triple(0, null, 2))); 52 | assertFalse(triple.equals(new Triple(0, 1, 2))); 53 | } 54 | 55 | @Test 56 | public void testEqualsT3() { 57 | final Triple triple = new Triple(0, 1, null); 58 | 59 | assertTrue(triple.equals(new Triple(0, 1, null))); 60 | assertFalse(triple.equals(new Triple(0, 1, 2))); 61 | } 62 | 63 | @Test 64 | public void testHashCode() { 65 | final Triple triple = new Triple(0, 1, 2); 66 | 67 | assertEquals(33, triple.hashCode()); 68 | } 69 | 70 | @Test 71 | public void testHashCodeT1() { 72 | final Triple triple = new Triple(null, 1, 2); 73 | 74 | assertEquals(33, triple.hashCode()); 75 | } 76 | 77 | @Test 78 | public void testHashCodeT2() { 79 | final Triple triple = new Triple(0, null, 2); 80 | 81 | assertEquals(2, triple.hashCode()); 82 | } 83 | 84 | @Test 85 | public void testHashCodeT3() { 86 | final Triple triple = new Triple(0, 1, null); 87 | 88 | assertEquals(31, triple.hashCode()); 89 | } 90 | 91 | @Test 92 | public void testNext() { 93 | final Triple triple = Triple.next(0, 1, 2); 94 | 95 | assertNotNull(triple); 96 | assertEquals(0, triple.getT1()); 97 | assertEquals(1, triple.getT2()); 98 | assertEquals(2, triple.getT3()); 99 | } 100 | 101 | @Test 102 | public void testToString() { 103 | final Triple triple = new Triple(0, 1, 2); 104 | 105 | assertEquals("Triple{t1=0, t2=1, t3=2}", triple.toString()); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /version-number-rules.xml: -------------------------------------------------------------------------------- 1 | 18 | 21 | 22 | (?i).*[-_\.]CR[0-9\.]* 23 | (?i).*[-_\.]rc[0-9\.]* 24 | (?i).*[-_\.]beta[0-9\.-]* 25 | (?i).*[-_\.]alpha[0-9\.-]* 26 | (?i).*[-_\.]nightly[0-9\.]* 27 | (?i).*[-_\.]jboss[0-9\.]* 28 | (?i).*-atlassian-[0-9\.]* 29 | (?i).*-jenkins-[0-9\.]* 30 | .*[-\.]redhat-[0-9]+ 31 | \d{4,}.* 32 | 33 | 34 | 35 | 36 | .*-xwiki 37 | 38 | 39 | 40 | 41 | 9c6abc2 42 | 43 | 44 | 45 | 46 | .*-tc 47 | 48 | 49 | 50 | 51 | .*-r\d+ 52 | .*-Draft\d+ 53 | 54 | 55 | 56 | --------------------------------------------------------------------------------