├── .gitignore ├── LICENSE ├── README.md ├── bnd.bnd ├── pom.xml └── src └── main └── java ├── module-info.java └── org └── danekja └── java ├── misc └── serializable │ ├── SerializableCallable.java │ ├── SerializableComparator.java │ ├── SerializableComparatorWrapperClass.java │ ├── SerializableRunnable.java │ └── package-info.java └── util └── function └── serializable ├── SerializableBiConsumer.java ├── SerializableBiFunction.java ├── SerializableBiPredicate.java ├── SerializableBinaryOperator.java ├── SerializableBooleanSupplier.java ├── SerializableConsumer.java ├── SerializableDoubleBinaryOperator.java ├── SerializableDoubleConsumer.java ├── SerializableDoubleFunction.java ├── SerializableDoublePredicate.java ├── SerializableDoubleSupplier.java ├── SerializableDoubleToIntFunction.java ├── SerializableDoubleToLongFunction.java ├── SerializableDoubleUnaryOperator.java ├── SerializableFunction.java ├── SerializableIntBinaryOperator.java ├── SerializableIntConsumer.java ├── SerializableIntFunction.java ├── SerializableIntPredicate.java ├── SerializableIntSupplier.java ├── SerializableIntToDoubleFunction.java ├── SerializableIntToLongFunction.java ├── SerializableIntUnaryOperator.java ├── SerializableLongBinaryOperator.java ├── SerializableLongConsumer.java ├── SerializableLongFunction.java ├── SerializableLongPredicate.java ├── SerializableLongSupplier.java ├── SerializableLongToDoubleFunction.java ├── SerializableLongToIntFunction.java ├── SerializableLongUnaryOperator.java ├── SerializableObjDoubleConsumer.java ├── SerializableObjIntConsumer.java ├── SerializableObjLongConsumer.java ├── SerializablePredicate.java ├── SerializableSupplier.java ├── SerializableToDoubleBiFunction.java ├── SerializableToDoubleFunction.java ├── SerializableToIntBiFunction.java ├── SerializableToIntFunction.java ├── SerializableToLongBiFunction.java ├── SerializableToLongFunction.java ├── SerializableUnaryOperator.java └── package-info.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | *.class 4 | 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | # Package Files # 9 | *.jar 10 | *.war 11 | *.ear 12 | 13 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 14 | hs_err_pid* 15 | 16 | 17 | ### NetBeans template 18 | nbproject/private/ 19 | build/ 20 | nbbuild/ 21 | dist/ 22 | nbdist/ 23 | nbactions.xml 24 | nb-configuration.xml 25 | .nb-gradle/ 26 | 27 | 28 | ### Eclipse template 29 | *.pydevproject 30 | .metadata 31 | .gradle 32 | bin/ 33 | tmp/ 34 | *.tmp 35 | *.bak 36 | *.swp 37 | *~.nib 38 | local.properties 39 | .settings/ 40 | .loadpath 41 | 42 | # Eclipse Core 43 | .project 44 | 45 | # External tool builders 46 | .externalToolBuilders/ 47 | 48 | # Locally stored "Eclipse launch configurations" 49 | *.launch 50 | 51 | # CDT-specific 52 | .cproject 53 | 54 | # JDT-specific (Eclipse Java Development Tools) 55 | .classpath 56 | 57 | # Java annotation processor (APT) 58 | .factorypath 59 | 60 | # PDT-specific 61 | .buildpath 62 | 63 | # sbteclipse plugin 64 | .target 65 | 66 | # TeXlipse plugin 67 | .texlipse 68 | 69 | 70 | ### JetBrains template 71 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion 72 | 73 | *.iml 74 | 75 | ## Directory-based project format: 76 | .idea/ 77 | # if you remove the above rule, at least ignore the following: 78 | 79 | # User-specific stuff: 80 | # .idea/workspace.xml 81 | # .idea/tasks.xml 82 | # .idea/dictionaries 83 | 84 | # Sensitive or high-churn files: 85 | # .idea/dataSources.ids 86 | # .idea/dataSources.xml 87 | # .idea/sqlDataSources.xml 88 | # .idea/dynamic.xml 89 | # .idea/uiDesigner.xml 90 | 91 | # Gradle: 92 | # .idea/gradle.xml 93 | # .idea/libraries 94 | 95 | # Mongo Explorer plugin: 96 | # .idea/mongoSettings.xml 97 | 98 | ## File-based project format: 99 | *.ipr 100 | *.iws 101 | 102 | ## Plugin-specific files: 103 | 104 | # IntelliJ 105 | /out/ 106 | 107 | # mpeltonen/sbt-idea plugin 108 | .idea_modules/ 109 | 110 | # JIRA plugin 111 | atlassian-ide-plugin.xml 112 | 113 | # Crashlytics plugin (for Android Studio and IntelliJ) 114 | com_crashlytics_export_strings.xml 115 | crashlytics.properties 116 | crashlytics-build.properties 117 | 118 | 119 | ### Maven template 120 | target/ 121 | pom.xml.tag 122 | pom.xml.releaseBackup 123 | pom.xml.versionsBackup 124 | pom.xml.next 125 | release.properties 126 | dependency-reduced-pom.xml 127 | buildNumber.properties 128 | .mvn/timing.properties 129 | 130 | 131 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jakub Danek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Serializable java.util.function Interfaces 2 | This library contains serializable versions of generic functional interface introduced in JDK 8. 3 | 4 | Interfaces in this library follow simple naming convention: 5 | ``` 6 | Serializable 7 | ``` 8 | 9 | ## Maven 10 | 11 | The library has been deployed to Maven Central. Add the following dependency to you project: 12 | 13 | ### JDK 9 14 | ``` 15 | 16 | 17 | org.danekja 18 | jdk-serializable-functional 19 | 1.9.0 20 | 21 | 22 | ``` 23 | 24 | ### JDK 8 25 | ``` 26 | 27 | 28 | org.danekja 29 | jdk-serializable-functional 30 | 1.8.6 31 | 32 | 33 | ``` 34 | 35 | ## Component Model 36 | 37 | Starting with version 1.9.0, the library is also a Java module. 38 | Starting with version 1.8.4, the library is also an OSGi bundle. 39 | 40 | ## Versioning 41 | The version identifier follows semantic scheme *major.minor.micro*, where *major* and *minor* portions 42 | identify JDK version and micro is used for this library versioning (documentation/build modifications, etc.). 43 | 44 | i.e. version **1.8.1** is the second release of this library based on JDK 1.8. 45 | 46 | ## Licensing 47 | The library is licensed under the MIT License. -------------------------------------------------------------------------------- /bnd.bnd: -------------------------------------------------------------------------------- 1 | Bundle-Name Serializable JDK Functional Interfaces 2 | Bundle-SymbolicName ${project.groupId}.${project.artifactId} 3 | Bundle-Version ${project.version} 4 | Bundle-Developers Jakub Danek 5 | Bundle-Contributors Emond Papegaaij,\ 6 | Jezza 7 | Bundle-Description A library containing Serializable versions of functional interfaces from java.util.function package. 8 | Bundle-License MIT 9 | -exportcontents: \ 10 | org.danekja.java.misc.serializable,\ 11 | org.danekja.java.util.function.serializable 12 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.danekja 6 | jdk-serializable-functional 7 | 1.9.1-SNAPSHOT 8 | jar 9 | 10 | ${project.groupId}.${project.artifactId} 11 | 12 | A library containing Serializable versions of functional interfaces from 13 | java.util.function package. 14 | 15 | https://github.com/danekja/jdk-serializable-functional 16 | 17 | 18 | 19 | MIT License 20 | http://www.opensource.org/licenses/mit-license.php 21 | 22 | 23 | 24 | 25 | 26 | Jakub Daněk 27 | danek.ja@gmail.com 28 | Jakub Daněk 29 | http://www.danekja.org/ 30 | 31 | 32 | 33 | 34 | scm:git:ssh://git@github.com/danekja/jdk-serializable-functional.git 35 | scm:git:ssh://git@github.com/danekja/jdk-serializable-functional.git 36 | https://github.com/danekja/jdk-serializable-functional/tree/master 37 | v1.9.0 38 | 39 | 40 | 41 | 42 | ossrh 43 | https://oss.sonatype.org/content/repositories/snapshots 44 | 45 | 46 | ossrh 47 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-compiler-plugin 57 | 3.8.1 58 | 59 | 9 60 | 9 61 | 9 62 | UTF-8 63 | 64 | 65 | 66 | 70 | 71 | org.apache.maven.plugins 72 | maven-jar-plugin 73 | 74 | true 75 | 76 | 77 | org.danekja.jdk.serializable.functional 78 | 79 | 80 | 81 | 82 | 83 | biz.aQute.bnd 84 | bnd-maven-plugin 85 | 3.5.0 86 | 87 | 88 | 89 | bnd-process 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | org.apache.maven.plugins 98 | maven-release-plugin 99 | 2.5.2 100 | 101 | v@{project.version} 102 | false 103 | release 104 | deploy 105 | 106 | 107 | 108 | org.apache.maven.scm 109 | maven-scm-api 110 | 1.9.1 111 | 112 | 113 | org.apache.maven.scm 114 | maven-scm-provider-gitexe 115 | 1.9.1 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | release 125 | 126 | 127 | 128 | org.apache.maven.plugins 129 | maven-source-plugin 130 | 2.2.1 131 | 132 | 133 | attach-sources 134 | 135 | jar-no-fork 136 | 137 | 138 | 139 | 140 | 141 | org.apache.maven.plugins 142 | maven-javadoc-plugin 143 | 2.10.1 144 | 145 | 146 | attach-javadocs 147 | 148 | jar 149 | 150 | 151 | 152 | 153 | 157 | 158 | 159 | apiNote 160 | a 161 | API Note: 162 | 163 | 164 | implSpec 165 | a 166 | Implementation Requirements: 167 | 168 | 169 | implNote 170 | a 171 | Implementation Note: 172 | 173 | 174 | 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-gpg-plugin 179 | 1.5 180 | 181 | 182 | sign-artifacts 183 | verify 184 | 185 | sign 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module org.danekja.jdk.serializable.functional 2 | { 3 | exports org.danekja.java.misc.serializable; 4 | 5 | exports org.danekja.java.util.function.serializable; 6 | 7 | requires java.base; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/misc/serializable/SerializableCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.misc.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.concurrent.Callable; 35 | 36 | /** 37 | * Serializable version of {@link Callable}. 38 | * 39 | * @author Emond Papegaaij 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableCallable extends Callable, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/misc/serializable/SerializableComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.misc.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Collections; 35 | import java.util.Comparator; 36 | import java.util.Objects; 37 | 38 | import org.danekja.java.util.function.serializable.SerializableFunction; 39 | import org.danekja.java.util.function.serializable.SerializableToDoubleFunction; 40 | import org.danekja.java.util.function.serializable.SerializableToIntFunction; 41 | import org.danekja.java.util.function.serializable.SerializableToLongFunction; 42 | 43 | /** 44 | * Serializable version of {@link Comparator}. 45 | * 46 | * @author Emond Papegaaij 47 | */ 48 | @FunctionalInterface 49 | public interface SerializableComparator extends Comparator, Serializable { 50 | 51 | /** 52 | * Returns a comparator that imposes the reverse ordering of this 53 | * comparator. 54 | * 55 | * @return a comparator that imposes the reverse ordering of this 56 | * comparator. 57 | * @since 1.8 58 | */ 59 | default SerializableComparator reversed() { 60 | return Collections.reverseOrder(this)::compare; 61 | } 62 | 63 | /** 64 | * Returns a lexicographic-order comparator with another comparator. 65 | * If this {@code SerializableComparator} considers two elements equal, i.e. 66 | * {@code compare(a, b) == 0}, {@code other} is used to determine the order. 67 | * 68 | * @apiNote 69 | * For example, to sort a collection of {@code String} based on the length 70 | * and then case-insensitive natural ordering, the comparator can be 71 | * composed using following code, 72 | * 73 | *
{@code
 74 | 	 *     SerializableComparator cmp = SerializableComparator.comparingInt(String::length)
 75 | 	 *             .thenComparing(String.CASE_INSENSITIVE_ORDER);
 76 | 	 * }
77 | * 78 | * @param other the other comparator to be used when this comparator 79 | * compares two objects that are equal. 80 | * @return a lexicographic-order comparator composed of this and then the 81 | * other comparator 82 | * @throws NullPointerException if the argument is null. 83 | * @since 1.8 84 | */ 85 | default SerializableComparator thenComparing(SerializableComparator other) { 86 | Objects.requireNonNull(other); 87 | return (c1, c2) -> { 88 | int res = compare(c1, c2); 89 | return (res != 0) ? res : other.compare(c1, c2); 90 | }; 91 | } 92 | 93 | /** 94 | * Returns a lexicographic-order comparator with a function that 95 | * extracts a key to be compared with the given {@code SerializableComparator}. 96 | * 97 | * @implSpec This default implementation behaves as if {@code 98 | * thenComparing(comparing(keyExtractor, cmp))}. 99 | * 100 | * @param the type of the sort key 101 | * @param keyExtractor the function used to extract the sort key 102 | * @param keyComparator the {@code SerializableComparator} used to compare the sort key 103 | * @return a lexicographic-order comparator composed of this comparator 104 | * and then comparing on the key extracted by the keyExtractor function 105 | * @throws NullPointerException if either argument is null. 106 | * @see #comparing(SerializableFunction, SerializableComparator) 107 | * @see #thenComparing(SerializableComparator) 108 | * @since 1.8 109 | */ 110 | default SerializableComparator thenComparing( 111 | SerializableFunction keyExtractor, 112 | SerializableComparator keyComparator) 113 | { 114 | return thenComparing(comparing(keyExtractor, keyComparator)); 115 | } 116 | 117 | /** 118 | * Returns a lexicographic-order comparator with a function that 119 | * extracts a {@code Comparable} sort key. 120 | * 121 | * @implSpec This default implementation behaves as if {@code 122 | * thenComparing(comparing(keyExtractor))}. 123 | * 124 | * @param the type of the {@link Comparable} sort key 125 | * @param keyExtractor the function used to extract the {@link 126 | * Comparable} sort key 127 | * @return a lexicographic-order comparator composed of this and then the 128 | * {@link Comparable} sort key. 129 | * @throws NullPointerException if the argument is null. 130 | * @see #comparing(SerializableFunction) 131 | * @see #thenComparing(SerializableComparator) 132 | * @since 1.8 133 | */ 134 | default > SerializableComparator thenComparing( 135 | SerializableFunction keyExtractor) 136 | { 137 | return thenComparing(comparing(keyExtractor)); 138 | } 139 | 140 | /** 141 | * Returns a lexicographic-order comparator with a function that 142 | * extracts an {@code int} sort key. 143 | * 144 | * @implSpec This default implementation behaves as if {@code 145 | * thenComparing(comparingInt(keyExtractor))}. 146 | * 147 | * @param keyExtractor the function used to extract the integer sort key 148 | * @return a lexicographic-order comparator composed of this and then the 149 | * {@code int} sort key 150 | * @throws NullPointerException if the argument is null. 151 | * @see #comparingInt(SerializableToIntFunction) 152 | * @see #thenComparing(SerializableComparator) 153 | * @since 1.8 154 | */ 155 | default SerializableComparator thenComparingInt( 156 | SerializableToIntFunction keyExtractor) { 157 | return thenComparing(comparingInt(keyExtractor)); 158 | } 159 | 160 | /** 161 | * Returns a lexicographic-order comparator with a function that 162 | * extracts a {@code long} sort key. 163 | * 164 | * @implSpec This default implementation behaves as if {@code 165 | * thenComparing(comparingLong(keyExtractor))}. 166 | * 167 | * @param keyExtractor the function used to extract the long sort key 168 | * @return a lexicographic-order comparator composed of this and then the 169 | * {@code long} sort key 170 | * @throws NullPointerException if the argument is null. 171 | * @see #comparingLong(SerializableToLongFunction) 172 | * @see #thenComparing(SerializableComparator) 173 | * @since 1.8 174 | */ 175 | default SerializableComparator thenComparingLong( 176 | SerializableToLongFunction keyExtractor) { 177 | return thenComparing(comparingLong(keyExtractor)); 178 | } 179 | 180 | /** 181 | * Returns a lexicographic-order comparator with a function that 182 | * extracts a {@code double} sort key. 183 | * 184 | * @implSpec This default implementation behaves as if {@code 185 | * thenComparing(comparingDouble(keyExtractor))}. 186 | * 187 | * @param keyExtractor the function used to extract the double sort key 188 | * @return a lexicographic-order comparator composed of this and then the 189 | * {@code double} sort key 190 | * @throws NullPointerException if the argument is null. 191 | * @see #comparingDouble(SerializableToDoubleFunction) 192 | * @see #thenComparing(SerializableComparator) 193 | * @since 1.8 194 | */ 195 | default SerializableComparator thenComparingDouble( 196 | SerializableToDoubleFunction keyExtractor) { 197 | return thenComparing(comparingDouble(keyExtractor)); 198 | } 199 | 200 | /** 201 | * Returns a comparator that imposes the reverse of the natural 202 | * ordering. 203 | * 204 | *

The returned comparator throws {@link NullPointerException} when 205 | * comparing {@code null}. 206 | * 207 | * @param the {@link Comparable} type of element to be compared 208 | * @return a comparator that imposes the reverse of the natural 209 | * ordering on {@code Comparable} objects. 210 | * @see Comparable 211 | * @since 1.8 212 | */ 213 | public static > SerializableComparator reverseOrder() { 214 | return Collections.reverseOrder()::compare; 215 | } 216 | 217 | /** 218 | * Returns a comparator that compares {@link Comparable} objects in natural 219 | * order. 220 | * 221 | *

The returned comparator throws {@link NullPointerException} when 222 | * comparing {@code null}. 223 | * 224 | * @param the {@link Comparable} type of element to be compared 225 | * @return a comparator that imposes the natural ordering on {@code 226 | * Comparable} objects. 227 | * @see Comparable 228 | * @since 1.8 229 | */ 230 | public static > SerializableComparator naturalOrder() { 231 | return Comparator.naturalOrder()::compare; 232 | } 233 | 234 | /** 235 | * Returns a null-friendly comparator that considers {@code null} to be 236 | * less than non-null. When both are {@code null}, they are considered 237 | * equal. If both are non-null, the specified {@code Comparator} is used 238 | * to determine the order. If the specified comparator is {@code null}, 239 | * then the returned comparator considers all non-null values to be equal. 240 | * 241 | * @param the type of the elements to be compared 242 | * @param comparator a {@code SerializableComparator} for comparing non-null values 243 | * @return a comparator that considers {@code null} to be less than 244 | * non-null, and compares non-null objects with the supplied 245 | * {@code SerializableComparator}. 246 | * @since 1.8 247 | */ 248 | public static SerializableComparator nullsFirst( 249 | SerializableComparator comparator) { 250 | return Comparator.nullsFirst(comparator)::compare; 251 | } 252 | 253 | /** 254 | * Returns a null-friendly comparator that considers {@code null} to be 255 | * greater than non-null. When both are {@code null}, they are considered 256 | * equal. If both are non-null, the specified {@code Comparator} is used 257 | * to determine the order. If the specified comparator is {@code null}, 258 | * then the returned comparator considers all non-null values to be equal. 259 | * 260 | * @param the type of the elements to be compared 261 | * @param comparator a {@code SerializableComparator} for comparing non-null values 262 | * @return a comparator that considers {@code null} to be greater than 263 | * non-null, and compares non-null objects with the supplied 264 | * {@code SerializableComparator}. 265 | * @since 1.8 266 | */ 267 | public static SerializableComparator nullsLast( 268 | SerializableComparator comparator) { 269 | return Comparator.nullsLast(comparator)::compare; 270 | } 271 | 272 | /** 273 | * Accepts a function that extracts a sort key from a type {@code T}, and 274 | * returns a {@code SerializableComparator} that compares by that sort 275 | * key using the specified {@link SerializableComparator}. 276 | * 277 | *

The returned comparator is serializable. 278 | * 279 | * @apiNote 280 | * For example, to obtain a {@code SerializableComparator} that compares 281 | * {@code Person} objects by their last name ignoring case differences, 282 | * 283 | *

{@code
284 | 	 *     SerializableComparator cmp = SerializableComparator.comparing(
285 | 	 *             Person::getLastName,
286 | 	 *             String.CASE_INSENSITIVE_ORDER);
287 | 	 * }
288 | * 289 | * @param the type of element to be compared 290 | * @param the type of the sort key 291 | * @param keyExtractor the function used to extract the sort key 292 | * @param keyComparator the {@code SerializableComparator} used to compare the sort key 293 | * @return a comparator that compares by an extracted key using the 294 | * specified {@code SerializableComparator} 295 | * @throws NullPointerException if either argument is null 296 | * @since 1.8 297 | */ 298 | public static SerializableComparator comparing( 299 | SerializableFunction keyExtractor, 300 | SerializableComparator keyComparator) 301 | { 302 | Objects.requireNonNull(keyExtractor); 303 | Objects.requireNonNull(keyComparator); 304 | return 305 | (c1, c2) -> keyComparator.compare(keyExtractor.apply(c1), 306 | keyExtractor.apply(c2)); 307 | } 308 | 309 | /** 310 | * Accepts a function that extracts a {@link java.lang.Comparable 311 | * Comparable} sort key from a type {@code T}, and returns a {@code 312 | * Comparator} that compares by that sort key. 313 | * 314 | * @apiNote 315 | * For example, to obtain a {@code SerializableComparator} that compares 316 | * {@code Person} objects by their last name, 317 | * 318 | *
{@code
319 | 	 *     Comparator byLastName = Comparator.comparing(Person::getLastName);
320 | 	 * }
321 | * 322 | * @param the type of element to be compared 323 | * @param the type of the {@code Comparable} sort key 324 | * @param keyExtractor the function used to extract the {@link 325 | * Comparable} sort key 326 | * @return a comparator that compares by an extracted key 327 | * @throws NullPointerException if the argument is null 328 | * @since 1.8 329 | */ 330 | public static > SerializableComparator comparing( 331 | SerializableFunction keyExtractor) 332 | { 333 | Objects.requireNonNull(keyExtractor); 334 | return (c1, c2) -> keyExtractor.apply(c1).compareTo(keyExtractor.apply(c2)); 335 | } 336 | 337 | /** 338 | * Accepts a function that extracts an {@code int} sort key from a type 339 | * {@code T}, and returns a {@code Comparator} that compares by that 340 | * sort key. 341 | * 342 | * @param the type of element to be compared 343 | * @param keyExtractor the function used to extract the integer sort key 344 | * @return a comparator that compares by an extracted key 345 | * @see #comparing(SerializableFunction) 346 | * @throws NullPointerException if the argument is null 347 | * @since 1.8 348 | */ 349 | public static SerializableComparator comparingInt( 350 | SerializableToIntFunction keyExtractor) { 351 | Objects.requireNonNull(keyExtractor); 352 | return (c1, c2) -> Integer.compare(keyExtractor.applyAsInt(c1), keyExtractor.applyAsInt(c2)); 353 | } 354 | 355 | /** 356 | * Accepts a function that extracts a {@code long} sort key from a type 357 | * {@code T}, and returns a {@code Comparator} that compares by that 358 | * sort key. 359 | * 360 | * @param the type of element to be compared 361 | * @param keyExtractor the function used to extract the long sort key 362 | * @return a comparator that compares by an extracted key 363 | * @see #comparing(SerializableFunction) 364 | * @throws NullPointerException if the argument is null 365 | * @since 1.8 366 | */ 367 | public static SerializableComparator comparingLong( 368 | SerializableToLongFunction keyExtractor) { 369 | Objects.requireNonNull(keyExtractor); 370 | return (c1, c2) -> Long.compare(keyExtractor.applyAsLong(c1), keyExtractor.applyAsLong(c2)); 371 | } 372 | 373 | /** 374 | * Accepts a function that extracts a {@code double} sort key from a type 375 | * {@code T}, and returns a {@code SerializableComparator} that compares 376 | * by that sort key. 377 | * 378 | * @param the type of element to be compared 379 | * @param keyExtractor the function used to extract the double sort key 380 | * @return a comparator that compares by an extracted key 381 | * @see #comparing(SerializableFunction) 382 | * @throws NullPointerException if the argument is null 383 | * @since 1.8 384 | */ 385 | public static SerializableComparator comparingDouble( 386 | SerializableToDoubleFunction keyExtractor) { 387 | Objects.requireNonNull(keyExtractor); 388 | return (c1, c2) -> Double.compare(keyExtractor.applyAsDouble(c1), keyExtractor.applyAsDouble(c2)); 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/misc/serializable/SerializableComparatorWrapperClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | package org.danekja.java.misc.serializable; 31 | 32 | import java.text.Collator; 33 | import java.util.Comparator; 34 | 35 | import org.danekja.java.util.function.serializable.SerializableSupplier; 36 | 37 | /** 38 | * Wrapper for a non-serializable subclass of {@link Comparator}, such as {@link Collator}. 39 | * This way you can still use such comparators in a serializable way. 40 | * 41 | * This wrapper calls the given {@link SerializableSupplier} to retrieve a delegate {@link Comparator} which it 42 | * uses for all calls to its {@link #compare(Object, Object)}-method. It caches the retrieved {@link Comparator} 43 | * in a transient field for efficiency. 44 | * 45 | * Usage example: 46 | * 47 | *
48 |  * SerializableComparator<Object> collator = new SerializableComparatorWrapper<>(() -> Collator.getInstance(Locale.UK));
49 |  * SerializableComparator<Object> objectComparator = SerializableComparator.comparing(Object::toString, collator);
50 |  * 
51 | * 52 | * (Note that Collator is an instance of Comparator typed with Object, not with a generic type variable.) 53 | * 54 | * @author haster 55 | * 56 | * @param comparable type 57 | */ 58 | public class SerializableComparatorWrapperClass implements SerializableComparator 59 | { 60 | private static final long serialVersionUID = 1L; 61 | 62 | private SerializableSupplier> comparatorSupplier; 63 | 64 | private transient Comparator delegate; 65 | 66 | public SerializableComparatorWrapperClass(SerializableSupplier> comparatorSupplier) 67 | { 68 | this.comparatorSupplier = comparatorSupplier; 69 | } 70 | 71 | @Override 72 | public int compare(T o1, T o2) 73 | { 74 | if (delegate == null) 75 | delegate = comparatorSupplier.get(); 76 | return delegate.compare(o1, o2); 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/misc/serializable/SerializableRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.misc.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | 36 | /** 37 | * Serializable version of {@link Runnable}. 38 | * 39 | * @author Emond Papegaaij 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableRunnable extends Runnable, Serializable { 43 | /** 44 | * Returns a composed {@code SerializableRunnable} that performs, in sequence, 45 | * this operation followed by the {@code next} operation. If performing either 46 | * operation throws an exception, it is relayed to the caller of the 47 | * composed operation. If performing this operation throws an exception, 48 | * the {@code after} operation will not be performed. 49 | * 50 | * @param next the operation to perform after this operation 51 | * @return a composed {@code SerializableRunnable} that performs in sequence 52 | * this operation followed by the {@code next} operation 53 | * @throws NullPointerException if {@code next} is null 54 | */ 55 | default SerializableRunnable andThen(final SerializableRunnable next) { 56 | Objects.requireNonNull(next); 57 | 58 | return () -> { 59 | run(); 60 | next.run(); 61 | }; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/misc/serializable/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | /** 32 | * This package contains serializable versions of 33 | * {@code FunctionalInterface}s from the JDK not in 34 | * {@code java.util.function} 35 | * 36 | * @see java.lang.FunctionalInterface 37 | * @since 1.8 38 | */ 39 | package org.danekja.java.misc.serializable; 40 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableBiConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.BiConsumer; 36 | 37 | /** 38 | * Serializable version of {@link BiConsumer}. 39 | * 40 | * @author Jakub Danek 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableBiConsumer extends BiConsumer, Serializable { 44 | /** 45 | * Returns a composed {@code SerializableBiConsumer} that performs, in sequence, 46 | * this operation followed by the {@code after} operation. If performing either 47 | * operation throws an exception, it is relayed to the caller of the 48 | * composed operation. If performing this operation throws an exception, 49 | * the {@code after} operation will not be performed. 50 | * 51 | * @param after the operation to perform after this operation 52 | * @return a composed {@code SerializableBiConsumer} that performs in sequence 53 | * this operation followed by the {@code after} operation 54 | * @throws NullPointerException if {@code after} is null 55 | */ 56 | default SerializableBiConsumer andThen(SerializableBiConsumer after) { 57 | Objects.requireNonNull(after); 58 | 59 | return (l, r) -> { 60 | accept(l, r); 61 | after.accept(l, r); 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.BiFunction; 36 | 37 | /** 38 | * Serializable version of {@link BiFunction} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableBiFunction extends BiFunction, Serializable { 44 | /** 45 | * Returns a composed function that first applies this function to 46 | * its input, and then applies the {@code after} function to the result. 47 | * If evaluation of either function throws an exception, it is relayed to 48 | * the caller of the composed function. 49 | * 50 | * @param the type of output of the {@code after} function, and of the 51 | * composed function 52 | * @param after the function to apply after this function is applied 53 | * @return a composed function that first applies this function and then 54 | * applies the {@code after} function 55 | * @throws NullPointerException if after is null 56 | */ 57 | default SerializableBiFunction andThen(SerializableFunction after) { 58 | Objects.requireNonNull(after); 59 | return (T t, U u) -> after.apply(apply(t, u)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableBiPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.BiPredicate; 36 | 37 | /** 38 | * Serializable version of {@link BiPredicate} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableBiPredicate extends BiPredicate, Serializable { 44 | /** 45 | * Returns a composed predicate that represents a short-circuiting logical 46 | * AND of this predicate and another. When evaluating the composed 47 | * predicate, if this predicate is {@code false}, then the {@code other} 48 | * predicate is not evaluated. 49 | * 50 | *

Any exceptions thrown during evaluation of either predicate are relayed 51 | * to the caller; if evaluation of this predicate throws an exception, the 52 | * {@code other} predicate will not be evaluated. 53 | * 54 | * @param other a predicate that will be logically-ANDed with this 55 | * predicate 56 | * @return a composed predicate that represents the short-circuiting logical 57 | * AND of this predicate and the {@code other} predicate 58 | * @throws NullPointerException if other is null 59 | */ 60 | default SerializableBiPredicate and(SerializableBiPredicate other) { 61 | Objects.requireNonNull(other); 62 | return (T t, U u) -> test(t, u) && other.test(t, u); 63 | } 64 | 65 | /** 66 | * Returns a predicate that represents the logical negation of this 67 | * predicate. 68 | * 69 | * @return a predicate that represents the logical negation of this 70 | * predicate 71 | */ 72 | default SerializableBiPredicate negate() { 73 | return (T t, U u) -> !test(t, u); 74 | } 75 | 76 | /** 77 | * Returns a composed predicate that represents a short-circuiting logical 78 | * OR of this predicate and another. When evaluating the composed 79 | * predicate, if this predicate is {@code true}, then the {@code other} 80 | * predicate is not evaluated. 81 | * 82 | *

Any exceptions thrown during evaluation of either predicate are relayed 83 | * to the caller; if evaluation of this predicate throws an exception, the 84 | * {@code other} predicate will not be evaluated. 85 | * 86 | * @param other a predicate that will be logically-ORed with this 87 | * predicate 88 | * @return a composed predicate that represents the short-circuiting logical 89 | * OR of this predicate and the {@code other} predicate 90 | * @throws NullPointerException if other is null 91 | */ 92 | default SerializableBiPredicate or(SerializableBiPredicate other) { 93 | Objects.requireNonNull(other); 94 | return (T t, U u) -> test(t, u) || other.test(t, u); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Comparator; 35 | import java.util.Objects; 36 | import java.util.function.BinaryOperator; 37 | 38 | /** 39 | * Serializable version of {@link SerializableBinaryOperator} 40 | * 41 | * @author Jakub Danek (www.danekja.org) 42 | * 43 | */ 44 | @FunctionalInterface 45 | public interface SerializableBinaryOperator extends BinaryOperator, Serializable { 46 | /** 47 | * Returns a {@link SerializableBinaryOperator} which returns the lesser of 48 | * two elements according to the specified {@code Comparator}. 49 | * 50 | * @param the type of the input arguments of the comparator 51 | * @param comparator a {@code Comparator} for comparing the two values 52 | * @return a {@code SerializableBinaryOperator} which returns the lesser of 53 | * its operands, according to the supplied {@code Comparator} 54 | * @throws NullPointerException if the argument is null 55 | */ 56 | public static SerializableBinaryOperator minBy(Comparator comparator) { 57 | Objects.requireNonNull(comparator); 58 | return (a, b) -> comparator.compare(a, b) <= 0 ? a : b; 59 | } 60 | 61 | /** 62 | * Returns a {@link SerializableBinaryOperator} which returns the greater of 63 | * two elements according to the specified {@code Comparator}. 64 | * 65 | * @param the type of the input arguments of the comparator 66 | * @param comparator a {@code Comparator} for comparing the two values 67 | * @return a {@code SerializableBinaryOperator} which returns the greater of 68 | * its operands, according to the supplied {@code Comparator} 69 | * @throws NullPointerException if the argument is null 70 | */ 71 | public static SerializableBinaryOperator maxBy(Comparator comparator) { 72 | Objects.requireNonNull(comparator); 73 | return (a, b) -> comparator.compare(a, b) >= 0 ? a : b; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableBooleanSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.BooleanSupplier; 35 | 36 | /** 37 | * Serializable version of {@link BooleanSupplier} 38 | * 39 | * 40 | * @author Jakub Danek 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableBooleanSupplier extends BooleanSupplier, Serializable { 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.Consumer; 36 | 37 | /** 38 | * Serializable version of {@link Consumer} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableConsumer extends Consumer, Serializable { 44 | 45 | /** 46 | * Returns a composed {@code SerializableConsumer} that performs, in sequence, 47 | * this operation followed by the {@code after} operation. If performing either 48 | * operation throws an exception, it is relayed to the caller of the 49 | * composed operation. If performing this operation throws an exception, 50 | * the {@code after} operation will not be performed. 51 | * 52 | * @param after the operation to perform after this operation 53 | * @return a composed {@code SerializableConsumer} that performs in sequence 54 | * this operation followed by the {@code after} operation 55 | * @throws NullPointerException if {@code after} is null 56 | */ 57 | default SerializableConsumer andThen(SerializableConsumer after) { 58 | Objects.requireNonNull(after); 59 | return (T t) -> { 60 | accept(t); 61 | after.accept(t); 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.DoubleBinaryOperator; 35 | 36 | /** 37 | * Serializable version of {@link DoubleBinaryOperator} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableDoubleBinaryOperator extends DoubleBinaryOperator, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.DoubleConsumer; 36 | 37 | /** 38 | * Serializable version of {@link DoubleConsumer} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableDoubleConsumer extends DoubleConsumer, Serializable { 44 | /** 45 | * Returns a composed {@code SerializableDoubleConsumer} that performs, in sequence, 46 | * this operation followed by the {@code after} operation. If performing either 47 | * operation throws an exception, it is relayed to the caller of the 48 | * composed operation. If performing this operation throws an exception, 49 | * the {@code after} operation will not be performed. 50 | * 51 | * @param after the operation to perform after this operation 52 | * @return a composed {@code SerializableDoubleConsumer} that performs in sequence 53 | * this operation followed by the {@code after} operation 54 | * @throws NullPointerException if {@code after} is null 55 | */ 56 | default SerializableDoubleConsumer andThen(SerializableDoubleConsumer after) { 57 | Objects.requireNonNull(after); 58 | return (double t) -> { 59 | accept(t); 60 | after.accept(t); 61 | }; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.DoubleFunction; 35 | 36 | /** 37 | * Serializable version of {@link DoubleFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableDoubleFunction extends DoubleFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoublePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.DoublePredicate; 36 | 37 | /** 38 | * Serializable version of {@link DoublePredicate} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableDoublePredicate extends DoublePredicate, Serializable { 44 | /** 45 | * Returns a composed predicate that represents a short-circuiting logical 46 | * AND of this predicate and another. When evaluating the composed 47 | * predicate, if this predicate is {@code false}, then the {@code other} 48 | * predicate is not evaluated. 49 | * 50 | *

Any exceptions thrown during evaluation of either predicate are relayed 51 | * to the caller; if evaluation of this predicate throws an exception, the 52 | * {@code other} predicate will not be evaluated. 53 | * 54 | * @param other a predicate that will be logically-ANDed with this 55 | * predicate 56 | * @return a composed predicate that represents the short-circuiting logical 57 | * AND of this predicate and the {@code other} predicate 58 | * @throws NullPointerException if other is null 59 | */ 60 | default SerializableDoublePredicate and(SerializableDoublePredicate other) { 61 | Objects.requireNonNull(other); 62 | return (value) -> test(value) && other.test(value); 63 | } 64 | 65 | /** 66 | * Returns a predicate that represents the logical negation of this 67 | * predicate. 68 | * 69 | * @return a predicate that represents the logical negation of this 70 | * predicate 71 | */ 72 | default SerializableDoublePredicate negate() { 73 | return (value) -> !test(value); 74 | } 75 | 76 | /** 77 | * Returns a composed predicate that represents a short-circuiting logical 78 | * OR of this predicate and another. When evaluating the composed 79 | * predicate, if this predicate is {@code true}, then the {@code other} 80 | * predicate is not evaluated. 81 | * 82 | *

Any exceptions thrown during evaluation of either predicate are relayed 83 | * to the caller; if evaluation of this predicate throws an exception, the 84 | * {@code other} predicate will not be evaluated. 85 | * 86 | * @param other a predicate that will be logically-ORed with this 87 | * predicate 88 | * @return a composed predicate that represents the short-circuiting logical 89 | * OR of this predicate and the {@code other} predicate 90 | * @throws NullPointerException if other is null 91 | */ 92 | default SerializableDoublePredicate or(SerializableDoublePredicate other) { 93 | Objects.requireNonNull(other); 94 | return (value) -> test(value) || other.test(value); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.DoubleSupplier; 35 | 36 | /** 37 | * Serializable version of {@link DoubleSupplier} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableDoubleSupplier extends DoubleSupplier, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.DoubleToIntFunction; 35 | 36 | /** 37 | * Serializable version of {@link DoubleToIntFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableDoubleToIntFunction extends DoubleToIntFunction, Serializable{ 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.DoubleToLongFunction; 35 | 36 | /** 37 | * Serializable version of {@link DoubleToLongFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableDoubleToLongFunction extends DoubleToLongFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableDoubleUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.DoubleUnaryOperator; 36 | 37 | /** 38 | * Serializable version of {@link DoubleUnaryOperator} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableDoubleUnaryOperator extends DoubleUnaryOperator, Serializable { 44 | /** 45 | * Returns a composed operator that first applies the {@code before} 46 | * operator to its input, and then applies this operator to the result. 47 | * If evaluation of either operator throws an exception, it is relayed to 48 | * the caller of the composed operator. 49 | * 50 | * @param before the operator to apply before this operator is applied 51 | * @return a composed operator that first applies the {@code before} 52 | * operator and then applies this operator 53 | * @throws NullPointerException if before is null 54 | * 55 | * @see #andThen(SerializableDoubleUnaryOperator) 56 | */ 57 | default SerializableDoubleUnaryOperator compose(SerializableDoubleUnaryOperator before) { 58 | Objects.requireNonNull(before); 59 | return (double v) -> applyAsDouble(before.applyAsDouble(v)); 60 | } 61 | 62 | /** 63 | * Returns a composed operator that first applies this operator to 64 | * its input, and then applies the {@code after} operator to the result. 65 | * If evaluation of either operator throws an exception, it is relayed to 66 | * the caller of the composed operator. 67 | * 68 | * @param after the operator to apply after this operator is applied 69 | * @return a composed operator that first applies this operator and then 70 | * applies the {@code after} operator 71 | * @throws NullPointerException if after is null 72 | * 73 | * @see #compose(SerializableDoubleUnaryOperator) 74 | */ 75 | default SerializableDoubleUnaryOperator andThen(SerializableDoubleUnaryOperator after) { 76 | Objects.requireNonNull(after); 77 | return (double t) -> after.applyAsDouble(applyAsDouble(t)); 78 | } 79 | 80 | /** 81 | * Returns a unary operator that always returns its input argument. 82 | * 83 | * @return a unary operator that always returns its input argument 84 | */ 85 | static SerializableDoubleUnaryOperator identity() { 86 | return t -> t; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.Function; 36 | 37 | /** 38 | * Serializable version of {@link Function} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableFunction extends Function, Serializable { 44 | /** 45 | * Returns a composed function that first applies the {@code before} 46 | * function to its input, and then applies this function to the result. 47 | * If evaluation of either function throws an exception, it is relayed to 48 | * the caller of the composed function. 49 | * 50 | * @param the type of input to the {@code before} function, and to the 51 | * composed function 52 | * @param before the function to apply before this function is applied 53 | * @return a composed function that first applies the {@code before} 54 | * function and then applies this function 55 | * @throws NullPointerException if before is null 56 | * 57 | * @see #andThen(Function) 58 | */ 59 | default SerializableFunction compose(SerializableFunction before) { 60 | Objects.requireNonNull(before); 61 | return (V v) -> apply(before.apply(v)); 62 | } 63 | 64 | /** 65 | * Returns a composed function that first applies this function to 66 | * its input, and then applies the {@code after} function to the result. 67 | * If evaluation of either function throws an exception, it is relayed to 68 | * the caller of the composed function. 69 | * 70 | * @param the type of output of the {@code after} function, and of the 71 | * composed function 72 | * @param after the function to apply after this function is applied 73 | * @return a composed function that first applies this function and then 74 | * applies the {@code after} function 75 | * @throws NullPointerException if after is null 76 | * 77 | * @see #compose(Function) 78 | */ 79 | default SerializableFunction andThen(SerializableFunction after) { 80 | Objects.requireNonNull(after); 81 | return (T t) -> after.apply(apply(t)); 82 | } 83 | 84 | /** 85 | * Returns a function that always returns its input argument. 86 | * 87 | * @param the type of the input and output objects to the function 88 | * @return a function that always returns its input argument 89 | */ 90 | static SerializableFunction identity() { 91 | return t -> t; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.IntBinaryOperator; 35 | 36 | /** 37 | * Serializable version of {@link IntBinaryOperator} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableIntBinaryOperator extends IntBinaryOperator, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.IntConsumer; 36 | 37 | /** 38 | * Serializable version of {@link IntConsumer} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableIntConsumer extends IntConsumer, Serializable { 44 | /** 45 | * Returns a composed {@code SerializableIntConsumer} that performs, in sequence, 46 | * this operation followed by the {@code after} operation. If performing either 47 | * operation throws an exception, it is relayed to the caller of the 48 | * composed operation. If performing this operation throws an exception, 49 | * the {@code after} operation will not be performed. 50 | * 51 | * @param after the operation to perform after this operation 52 | * @return a composed {@code SerializableIntConsumer} that performs in sequence 53 | * this operation followed by the {@code after} operation 54 | * @throws NullPointerException if {@code after} is null 55 | */ 56 | default SerializableIntConsumer andThen(SerializableIntConsumer after) { 57 | Objects.requireNonNull(after); 58 | return (int t) -> { 59 | accept(t); 60 | after.accept(t); 61 | }; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.IntFunction; 35 | 36 | /** 37 | * Serializable version of {@link IntFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableIntFunction extends IntFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.IntPredicate; 36 | 37 | /** 38 | * Serializable version of {@link IntPredicate} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableIntPredicate extends IntPredicate, Serializable { 44 | /** 45 | * Returns a composed predicate that represents a short-circuiting logical 46 | * AND of this predicate and another. When evaluating the composed 47 | * predicate, if this predicate is {@code false}, then the {@code other} 48 | * predicate is not evaluated. 49 | * 50 | *

Any exceptions thrown during evaluation of either predicate are relayed 51 | * to the caller; if evaluation of this predicate throws an exception, the 52 | * {@code other} predicate will not be evaluated. 53 | * 54 | * @param other a predicate that will be logically-ANDed with this 55 | * predicate 56 | * @return a composed predicate that represents the short-circuiting logical 57 | * AND of this predicate and the {@code other} predicate 58 | * @throws NullPointerException if other is null 59 | */ 60 | default SerializableIntPredicate and(SerializableIntPredicate other) { 61 | Objects.requireNonNull(other); 62 | return (value) -> test(value) && other.test(value); 63 | } 64 | 65 | /** 66 | * Returns a predicate that represents the logical negation of this 67 | * predicate. 68 | * 69 | * @return a predicate that represents the logical negation of this 70 | * predicate 71 | */ 72 | default SerializableIntPredicate negate() { 73 | return (value) -> !test(value); 74 | } 75 | 76 | /** 77 | * Returns a composed predicate that represents a short-circuiting logical 78 | * OR of this predicate and another. When evaluating the composed 79 | * predicate, if this predicate is {@code true}, then the {@code other} 80 | * predicate is not evaluated. 81 | * 82 | *

Any exceptions thrown during evaluation of either predicate are relayed 83 | * to the caller; if evaluation of this predicate throws an exception, the 84 | * {@code other} predicate will not be evaluated. 85 | * 86 | * @param other a predicate that will be logically-ORed with this 87 | * predicate 88 | * @return a composed predicate that represents the short-circuiting logical 89 | * OR of this predicate and the {@code other} predicate 90 | * @throws NullPointerException if other is null 91 | */ 92 | default SerializableIntPredicate or(SerializableIntPredicate other) { 93 | Objects.requireNonNull(other); 94 | return (value) -> test(value) || other.test(value); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.IntSupplier; 35 | 36 | /** 37 | * Serializable version of {@link IntSupplier} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableIntSupplier extends IntSupplier, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.IntToDoubleFunction; 35 | 36 | /** 37 | * Serializable version of {@link IntToDoubleFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableIntToDoubleFunction extends IntToDoubleFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.IntToLongFunction; 35 | 36 | /** 37 | * Serializable version of {@link IntToLongFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableIntToLongFunction extends IntToLongFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableIntUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.IntUnaryOperator; 36 | 37 | /** 38 | * Serializable version of {@link IntUnaryOperator} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableIntUnaryOperator extends IntUnaryOperator, Serializable { 44 | /** 45 | * Returns a composed operator that first applies the {@code before} 46 | * operator to its input, and then applies this operator to the result. 47 | * If evaluation of either operator throws an exception, it is relayed to 48 | * the caller of the composed operator. 49 | * 50 | * @param before the operator to apply before this operator is applied 51 | * @return a composed operator that first applies the {@code before} 52 | * operator and then applies this operator 53 | * @throws NullPointerException if before is null 54 | * 55 | * @see #andThen(IntUnaryOperator) 56 | */ 57 | default SerializableIntUnaryOperator compose(SerializableIntUnaryOperator before) { 58 | Objects.requireNonNull(before); 59 | return (int v) -> applyAsInt(before.applyAsInt(v)); 60 | } 61 | 62 | /** 63 | * Returns a composed operator that first applies this operator to 64 | * its input, and then applies the {@code after} operator to the result. 65 | * If evaluation of either operator throws an exception, it is relayed to 66 | * the caller of the composed operator. 67 | * 68 | * @param after the operator to apply after this operator is applied 69 | * @return a composed operator that first applies this operator and then 70 | * applies the {@code after} operator 71 | * @throws NullPointerException if after is null 72 | * 73 | * @see #compose(IntUnaryOperator) 74 | */ 75 | default SerializableIntUnaryOperator andThen(SerializableIntUnaryOperator after) { 76 | Objects.requireNonNull(after); 77 | return (int t) -> after.applyAsInt(applyAsInt(t)); 78 | } 79 | 80 | /** 81 | * Returns a unary operator that always returns its input argument. 82 | * 83 | * @return a unary operator that always returns its input argument 84 | */ 85 | static SerializableIntUnaryOperator identity() { 86 | return t -> t; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.LongBinaryOperator; 35 | 36 | /** 37 | * Serializable version of {@link LongBinaryOperator} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableLongBinaryOperator extends LongBinaryOperator, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.LongConsumer; 36 | 37 | /** 38 | * Serializable version of {@link LongConsumer} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableLongConsumer extends LongConsumer, Serializable { 44 | /** 45 | * Returns a composed {@code SerializableLongConsumer} that performs, in sequence, 46 | * this operation followed by the {@code after} operation. If performing either 47 | * operation throws an exception, it is relayed to the caller of the 48 | * composed operation. If performing this operation throws an exception, 49 | * the {@code after} operation will not be performed. 50 | * 51 | * @param after the operation to perform after this operation 52 | * @return a composed {@code SerializableLongConsumer} that performs in sequence 53 | * this operation followed by the {@code after} operation 54 | * @throws NullPointerException if {@code after} is null 55 | */ 56 | default SerializableLongConsumer andThen(SerializableLongConsumer after) { 57 | Objects.requireNonNull(after); 58 | return (long t) -> { accept(t); after.accept(t); }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.LongFunction; 35 | 36 | /** 37 | * Serializable version of {@link LongFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableLongFunction extends LongFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.LongPredicate; 36 | 37 | /** 38 | * Serializable version of {@link LongPredicate} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableLongPredicate extends LongPredicate, Serializable { 44 | /** 45 | * Returns a composed predicate that represents a short-circuiting logical 46 | * AND of this predicate and another. When evaluating the composed 47 | * predicate, if this predicate is {@code false}, then the {@code other} 48 | * predicate is not evaluated. 49 | * 50 | *

Any exceptions thrown during evaluation of either predicate are relayed 51 | * to the caller; if evaluation of this predicate throws an exception, the 52 | * {@code other} predicate will not be evaluated. 53 | * 54 | * @param other a predicate that will be logically-ANDed with this 55 | * predicate 56 | * @return a composed predicate that represents the short-circuiting logical 57 | * AND of this predicate and the {@code other} predicate 58 | * @throws NullPointerException if other is null 59 | */ 60 | default SerializableLongPredicate and(SerializableLongPredicate other) { 61 | Objects.requireNonNull(other); 62 | return (value) -> test(value) && other.test(value); 63 | } 64 | 65 | /** 66 | * Returns a predicate that represents the logical negation of this 67 | * predicate. 68 | * 69 | * @return a predicate that represents the logical negation of this 70 | * predicate 71 | */ 72 | default SerializableLongPredicate negate() { 73 | return (value) -> !test(value); 74 | } 75 | 76 | /** 77 | * Returns a composed predicate that represents a short-circuiting logical 78 | * OR of this predicate and another. When evaluating the composed 79 | * predicate, if this predicate is {@code true}, then the {@code other} 80 | * predicate is not evaluated. 81 | * 82 | *

Any exceptions thrown during evaluation of either predicate are relayed 83 | * to the caller; if evaluation of this predicate throws an exception, the 84 | * {@code other} predicate will not be evaluated. 85 | * 86 | * @param other a predicate that will be logically-ORed with this 87 | * predicate 88 | * @return a composed predicate that represents the short-circuiting logical 89 | * OR of this predicate and the {@code other} predicate 90 | * @throws NullPointerException if other is null 91 | */ 92 | default SerializableLongPredicate or(SerializableLongPredicate other) { 93 | Objects.requireNonNull(other); 94 | return (value) -> test(value) || other.test(value); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.LongSupplier; 35 | 36 | /** 37 | * Serializable version of {@link LongSupplier} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableLongSupplier extends LongSupplier, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.LongToDoubleFunction; 35 | 36 | /** 37 | * Serializable version of {@link LongToDoubleFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableLongToDoubleFunction extends LongToDoubleFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.LongToIntFunction; 35 | 36 | /** 37 | * Serializable version of {@link LongToIntFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableLongToIntFunction extends LongToIntFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableLongUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.LongUnaryOperator; 36 | 37 | /** 38 | * Serializable version of {@link LongUnaryOperator} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializableLongUnaryOperator extends LongUnaryOperator, Serializable { 44 | /** 45 | * Returns a composed operator that first applies the {@code before} 46 | * operator to its input, and then applies this operator to the result. 47 | * If evaluation of either operator throws an exception, it is relayed to 48 | * the caller of the composed operator. 49 | * 50 | * @param before the operator to apply before this operator is applied 51 | * @return a composed operator that first applies the {@code before} 52 | * operator and then applies this operator 53 | * @throws NullPointerException if before is null 54 | * 55 | * @see #andThen(LongUnaryOperator) 56 | */ 57 | default SerializableLongUnaryOperator compose(SerializableLongUnaryOperator before) { 58 | Objects.requireNonNull(before); 59 | return (long v) -> applyAsLong(before.applyAsLong(v)); 60 | } 61 | 62 | /** 63 | * Returns a composed operator that first applies this operator to 64 | * its input, and then applies the {@code after} operator to the result. 65 | * If evaluation of either operator throws an exception, it is relayed to 66 | * the caller of the composed operator. 67 | * 68 | * @param after the operator to apply after this operator is applied 69 | * @return a composed operator that first applies this operator and then 70 | * applies the {@code after} operator 71 | * @throws NullPointerException if after is null 72 | * 73 | * @see #compose(LongUnaryOperator) 74 | */ 75 | default SerializableLongUnaryOperator andThen(SerializableLongUnaryOperator after) { 76 | Objects.requireNonNull(after); 77 | return (long t) -> after.applyAsLong(applyAsLong(t)); 78 | } 79 | 80 | /** 81 | * Returns a unary operator that always returns its input argument. 82 | * 83 | * @return a unary operator that always returns its input argument 84 | */ 85 | static SerializableLongUnaryOperator identity() { 86 | return t -> t; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableObjDoubleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ObjDoubleConsumer; 35 | 36 | /** 37 | * Serializable version of {@link ObjDoubleConsumer} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableObjDoubleConsumer extends ObjDoubleConsumer, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableObjIntConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ObjIntConsumer; 35 | 36 | /** 37 | * Serializable version of {@link ObjIntConsumer} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableObjIntConsumer extends ObjIntConsumer, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableObjLongConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ObjLongConsumer; 35 | 36 | /** 37 | * Serializable version of {@link ObjLongConsumer} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableObjLongConsumer extends ObjLongConsumer, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializablePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.Objects; 35 | import java.util.function.Predicate; 36 | 37 | /** 38 | * Serializable version of {@link Predicate} 39 | * 40 | * @author Jakub Danek (www.danekja.org) 41 | */ 42 | @FunctionalInterface 43 | public interface SerializablePredicate extends Predicate, Serializable { 44 | /** 45 | * Returns a composed predicate that represents a short-circuiting logical 46 | * AND of this predicate and another. When evaluating the composed 47 | * predicate, if this predicate is {@code false}, then the {@code other} 48 | * predicate is not evaluated. 49 | * 50 | *

Any exceptions thrown during evaluation of either predicate are relayed 51 | * to the caller; if evaluation of this predicate throws an exception, the 52 | * {@code other} predicate will not be evaluated. 53 | * 54 | * @param other a predicate that will be logically-ANDed with this 55 | * predicate 56 | * @return a composed predicate that represents the short-circuiting logical 57 | * AND of this predicate and the {@code other} predicate 58 | * @throws NullPointerException if other is null 59 | */ 60 | default SerializablePredicate and(SerializablePredicate other) { 61 | Objects.requireNonNull(other); 62 | return (t) -> test(t) && other.test(t); 63 | } 64 | 65 | /** 66 | * Returns a predicate that represents the logical negation of this 67 | * predicate. 68 | * 69 | * @return a predicate that represents the logical negation of this 70 | * predicate 71 | */ 72 | default SerializablePredicate negate() { 73 | return (t) -> !test(t); 74 | } 75 | 76 | /** 77 | * Returns a composed predicate that represents a short-circuiting logical 78 | * OR of this predicate and another. When evaluating the composed 79 | * predicate, if this predicate is {@code true}, then the {@code other} 80 | * predicate is not evaluated. 81 | * 82 | *

Any exceptions thrown during evaluation of either predicate are relayed 83 | * to the caller; if evaluation of this predicate throws an exception, the 84 | * {@code other} predicate will not be evaluated. 85 | * 86 | * @param other a predicate that will be logically-ORed with this 87 | * predicate 88 | * @return a composed predicate that represents the short-circuiting logical 89 | * OR of this predicate and the {@code other} predicate 90 | * @throws NullPointerException if other is null 91 | */ 92 | default SerializablePredicate or(SerializablePredicate other) { 93 | Objects.requireNonNull(other); 94 | return (t) -> test(t) || other.test(t); 95 | } 96 | 97 | static SerializablePredicate isEqual(Object targetRef) { 98 | return (null == targetRef) ? Objects::isNull : object -> targetRef.equals(object); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.Supplier; 35 | 36 | /** 37 | * Serializable version of {@link Supplier} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableSupplier extends Supplier, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableToDoubleBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ToDoubleBiFunction; 35 | 36 | /** 37 | * Serializable version of {@link ToDoubleBiFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableToDoubleBiFunction extends ToDoubleBiFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ToDoubleFunction; 35 | 36 | /** 37 | * Serializable version of {@link ToDoubleFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableToDoubleFunction extends ToDoubleFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableToIntBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ToIntBiFunction; 35 | 36 | /** 37 | * Serializable version of {@link ToIntBiFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableToIntBiFunction extends ToIntBiFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ToIntFunction; 35 | 36 | /** 37 | * Serializable version of {@link ToIntFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableToIntFunction extends ToIntFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableToLongBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ToLongBiFunction; 35 | 36 | /** 37 | * Serializable version of {@link ToLongBiFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableToLongBiFunction extends ToLongBiFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.ToLongFunction; 35 | 36 | /** 37 | * Serializable version of {@link ToLongFunction} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableToLongFunction extends ToLongFunction, Serializable { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/SerializableUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | package org.danekja.java.util.function.serializable; 32 | 33 | import java.io.Serializable; 34 | import java.util.function.UnaryOperator; 35 | 36 | /** 37 | * Serializable version of {@link UnaryOperator} 38 | * 39 | * @author Jakub Danek (www.danekja.org) 40 | */ 41 | @FunctionalInterface 42 | public interface SerializableUnaryOperator extends UnaryOperator, Serializable { 43 | /** 44 | * Returns a unary operator that always returns its input argument. 45 | * 46 | * @param the type of the input and output of the operator 47 | * @return a unary operator that always returns its input argument 48 | */ 49 | static SerializableUnaryOperator identity() { 50 | return t -> t; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/danekja/java/util/function/serializable/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Copyright (c) 2015 Jakub Danek 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * 26 | * Please visit https://github.com/danekja/jdk-function-serializable if you need additional information or have any 27 | * questions. 28 | * 29 | */ 30 | 31 | /** 32 | * This package contains serializable versions of JDK's 33 | * {@link java.util.function} package 34 | * 35 | * @see java.lang.FunctionalInterface 36 | * @since 1.8 37 | */ 38 | package org.danekja.java.util.function.serializable; 39 | --------------------------------------------------------------------------------