From 1d45cd4d2bc12dab74e93b3ee997697c865b8285 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sat, 1 Aug 2015 21:54:47 +0300 Subject: [PATCH] java.util.function --- teavm-classlib/pom.xml | 3 +- .../java/lang/TFunctionalInterface.java | 32 +++++ .../teavm/classlib/java/util/TComparator.java | 111 ++++++++++++++++++ .../java/util/function/TBiConsumer.java | 32 +++++ .../java/util/function/TBiFunction.java | 29 +++++ .../java/util/function/TBiPredicate.java | 39 ++++++ .../java/util/function/TBinaryOperator.java | 33 ++++++ .../java/util/function/TBooleanSupplier.java | 25 ++++ .../java/util/function/TConsumer.java | 32 +++++ .../util/function/TDoubleBinaryOperator.java | 25 ++++ .../java/util/function/TDoubleConsumer.java | 32 +++++ .../java/util/function/TDoubleFunction.java | 25 ++++ .../java/util/function/TDoublePredicate.java | 37 ++++++ .../java/util/function/TDoubleSupplier.java | 25 ++++ .../util/function/TDoubleToIntFunction.java | 25 ++++ .../util/function/TDoubleToLongFunction.java | 25 ++++ .../util/function/TDoubleUnaryOperator.java | 37 ++++++ .../java/util/function/TFunction.java | 37 ++++++ .../util/function/TIntBinaryOperator.java | 25 ++++ .../java/util/function/TIntConsumer.java | 32 +++++ .../java/util/function/TIntFunction.java | 25 ++++ .../java/util/function/TIntPredicate.java | 37 ++++++ .../java/util/function/TIntSupplier.java | 25 ++++ .../util/function/TIntToDoubleFunction.java | 25 ++++ .../util/function/TIntToLongFunction.java | 25 ++++ .../java/util/function/TIntUnaryOperator.java | 37 ++++++ .../java/util/function/TPredicate.java | 43 +++++++ .../java/util/function/TSupplier.java | 25 ++++ .../java/util/function/TToDoubleFunction.java | 25 ++++ .../java/util/function/TToIntFunction.java | 25 ++++ .../java/util/function/TToLongFunction.java | 25 ++++ .../java/util/function/TUnaryOperator.java | 27 +++++ 32 files changed, 1004 insertions(+), 1 deletion(-) create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFunctionalInterface.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiPredicate.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBinaryOperator.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBooleanSupplier.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TConsumer.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleBinaryOperator.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleConsumer.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoublePredicate.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleSupplier.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToIntFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToLongFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleUnaryOperator.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntBinaryOperator.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntConsumer.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntPredicate.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntSupplier.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToDoubleFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToLongFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntUnaryOperator.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TPredicate.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TSupplier.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToDoubleFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToIntFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToLongFunction.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TUnaryOperator.java diff --git a/teavm-classlib/pom.xml b/teavm-classlib/pom.xml index 2b389ecb2..3697a4730 100644 --- a/teavm-classlib/pom.xml +++ b/teavm-classlib/pom.xml @@ -122,8 +122,9 @@ java.nio.charset java.text java.util - java.util.logging java.util.concurrent + java.util.function + java.util.logging java.util.regex java.util.zip -output diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFunctionalInterface.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFunctionalInterface.java new file mode 100644 index 000000000..8a64986e9 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFunctionalInterface.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.lang; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author Alexey Andreev + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface TFunctionalInterface { +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java index fe591fde9..dac75c6a7 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TComparator.java @@ -15,11 +15,122 @@ */ package org.teavm.classlib.java.util; +import org.teavm.classlib.java.lang.TComparable; +import org.teavm.classlib.java.util.function.TFunction; +import org.teavm.classlib.java.util.function.TToDoubleFunction; +import org.teavm.classlib.java.util.function.TToIntFunction; +import org.teavm.classlib.java.util.function.TToLongFunction; + /** * * @author Alexey Andreev * @param */ +@FunctionalInterface public interface TComparator { int compare(T o1, T o2); + + default TComparator reversed() { + return (a, b) -> compare(b, a); + } + + default TComparator thenComparing(TComparator other) { + return (a, b) -> { + int r = compare(a, b); + if (r == 0) { + r = other.compare(a, b); + } + return r; + }; + } + + default TComparator thenComparing(TFunction keyExtractor, + TComparator keyComparator) { + return thenComparing(comparing(keyExtractor, keyComparator)); + } + + default > TComparator thenComparing( + TFunction keyExtractor) { + return (a, b) -> { + int r = compare(a, b); + if (r == 0) { + U k = keyExtractor.apply(a); + U m = keyExtractor.apply(b); + r = k != null ? k.compareTo(m) : -m.compareTo(k); + } + return r; + }; + } + + default TComparator thenComparingInt(TToIntFunction keyExtractor) { + return (a, b) -> { + int r = compare(a, b); + if (r == 0) { + r = Integer.compare(keyExtractor.applyAsInt(a), keyExtractor.applyAsInt(b)); + } + return r; + }; + } + + default TComparator thenComparingLong(TToLongFunction keyExtractor) { + return (a, b) -> { + int r = compare(a, b); + if (r == 0) { + r = Long.compare(keyExtractor.applyAsLong(a), keyExtractor.applyAsLong(b)); + } + return r; + }; + } + + default TComparator thenComparingDouble(TToDoubleFunction keyExtractor) { + return (a, b) -> { + int r = compare(a, b); + if (r == 0) { + r = Double.compare(keyExtractor.applyAsDouble(a), keyExtractor.applyAsDouble(b)); + } + return r; + }; + } + + static TComparator comparing(TFunction keyExtractor, + TComparator keyComparator) { + return (a, b) -> keyComparator.compare(keyExtractor.apply(a), keyExtractor.apply(b)); + } + + static > TComparator comparing( + TFunction keyExtractor) { + return (a, b) -> { + U k = keyExtractor.apply(a); + U m = keyExtractor.apply(b); + return k != null ? k.compareTo(m) : -m.compareTo(k); + }; + } + + static > TComparator naturalOrder() { + return (o1, o2) -> o1 != null ? o1.compareTo(o2) : o2.compareTo(o1); + } + + static > TComparator reverseOrder() { + return (o1, o2) -> o2 != null ? o2.compareTo(o1) : o1.compareTo(o2); + } + + static TComparator nullsFirst(TComparator comparator) { + return (a, b) -> a == null && b == null ? 0 : a == null ? -1 : b == null ? 1 : comparator.compare(a, b); + } + + static TComparator nullsLast(TComparator comparator) { + return (a, b) -> a == null && b == null ? 0 : a == null ? 1 : b == null ? -1 : comparator.compare(a, b); + } + + static TComparator comparingInt(TToIntFunction keyExtractor) { + return (a, b) -> Integer.compare(keyExtractor.applyAsInt(a), keyExtractor.applyAsInt(b)); + } + + static TComparator comparingLong(TToLongFunction keyExtractor) { + return (a, b) -> Long.compare(keyExtractor.applyAsLong(a), keyExtractor.applyAsLong(b)); + } + + static TComparator comparingDouble(TToDoubleFunction keyExtractor) { + return (a, b) -> Double.compare(keyExtractor.applyAsDouble(a), keyExtractor.applyAsDouble(b)); + } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java new file mode 100644 index 000000000..af92ad87b --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiConsumer.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TBiConsumer { + void accept(T t, U u); + + default TBiConsumer andThen(TBiConsumer after) { + return (t, u) -> { + this.accept(t, u); + after.accept(t, u); + }; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java new file mode 100644 index 000000000..8255a7d8a --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiFunction.java @@ -0,0 +1,29 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TBiFunction { + R apply(T t, U u); + + default TBiFunction andThen(TFunction after) { + return (t, u) -> after.apply(apply(t, u)); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiPredicate.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiPredicate.java new file mode 100644 index 000000000..c4fb3d4c3 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBiPredicate.java @@ -0,0 +1,39 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +import java.util.function.BiPredicate; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TBiPredicate { + boolean test(T t, U u); + + default TBiPredicate and(TBiPredicate other) { + return (t, u) -> test(t, u) && other.test(t, u); + } + + default BiPredicate negate() { + return (t, u) -> !test(t, u); + } + + default TBiPredicate or(TBiPredicate other) { + return (t, u) -> test(t, u) || other.test(t, u); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBinaryOperator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBinaryOperator.java new file mode 100644 index 000000000..e0e95f7cc --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBinaryOperator.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +import org.teavm.classlib.java.util.TComparator; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TBinaryOperator extends TBiFunction { + static TBinaryOperator minBy(TComparator comparator) { + return (a, b) -> comparator.compare(a, b) <= 0 ? a : b; + } + + static TBinaryOperator maxBy(TComparator comparator) { + return (a, b) -> comparator.compare(a, b) >= 0 ? a : b; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBooleanSupplier.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBooleanSupplier.java new file mode 100644 index 000000000..7db80a9ed --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TBooleanSupplier.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TBooleanSupplier { + boolean getAsBoolean(); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TConsumer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TConsumer.java new file mode 100644 index 000000000..b4d5cd7c7 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TConsumer.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TConsumer { + void accept(T t); + + default TConsumer andThen(TConsumer after) { + return t -> { + accept(t); + after.accept(t); + }; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleBinaryOperator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleBinaryOperator.java new file mode 100644 index 000000000..b67df85d0 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleBinaryOperator.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleBinaryOperator { + double applyAsDouble(double left, double right); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleConsumer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleConsumer.java new file mode 100644 index 000000000..77182276d --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleConsumer.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleConsumer { + void accept(double value); + + default TDoubleConsumer andThen(TDoubleConsumer after) { + return e -> { + accept(e); + after.accept(e); + }; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleFunction.java new file mode 100644 index 000000000..2f7da6143 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleFunction { + R apply(double value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoublePredicate.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoublePredicate.java new file mode 100644 index 000000000..6174312cf --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoublePredicate.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoublePredicate { + boolean test(double value); + + default TDoublePredicate and(TDoublePredicate other) { + return v -> test(v) && other.test(v); + } + + default TDoublePredicate negate() { + return v -> !test(v); + } + + default TDoublePredicate or(TDoublePredicate other) { + return v -> test(v) || other.test(v); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleSupplier.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleSupplier.java new file mode 100644 index 000000000..3e8aa8745 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleSupplier.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleSupplier { + double getAsDouble(); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToIntFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToIntFunction.java new file mode 100644 index 000000000..64514973e --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToIntFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleToIntFunction { + int applyAsInt(double value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToLongFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToLongFunction.java new file mode 100644 index 000000000..af6c424ae --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleToLongFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleToLongFunction { + long applyAsLong(double value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleUnaryOperator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleUnaryOperator.java new file mode 100644 index 000000000..b6be9eddf --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TDoubleUnaryOperator.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TDoubleUnaryOperator { + double applyAsDouble(double operand); + + default TDoubleUnaryOperator compose(TDoubleUnaryOperator before) { + return v -> applyAsDouble(before.applyAsDouble(v)); + } + + default TDoubleUnaryOperator andThen(TDoubleUnaryOperator after) { + return v -> after.applyAsDouble(applyAsDouble(v)); + } + + static TDoubleUnaryOperator identity() { + return v -> v; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TFunction.java new file mode 100644 index 000000000..26236afe9 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TFunction.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TFunction { + R apply(T t); + + default TFunction compose(TFunction before) { + return v -> apply(before.apply(v)); + } + + default TFunction andThen(TFunction after) { + return t -> after.apply(apply(t)); + } + + static TFunction identity() { + return t -> t; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntBinaryOperator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntBinaryOperator.java new file mode 100644 index 000000000..801e7e6aa --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntBinaryOperator.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntBinaryOperator { + int applyAsInt(int left, int right); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntConsumer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntConsumer.java new file mode 100644 index 000000000..3ebf78c21 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntConsumer.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntConsumer { + void accept(int value); + + default TIntConsumer andThen(TIntConsumer after) { + return v -> { + accept(v); + after.accept(v); + }; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntFunction.java new file mode 100644 index 000000000..1b9d62d03 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntFunction { + R apply(int value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntPredicate.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntPredicate.java new file mode 100644 index 000000000..ab09e6fe4 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntPredicate.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntPredicate { + boolean test(int value); + + default TIntPredicate and(TIntPredicate other) { + return v -> test(v) && other.test(v); + } + + default TIntPredicate negate() { + return v -> !test(v); + } + + default TIntPredicate or(TIntPredicate other) { + return v -> test(v) || other.test(v); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntSupplier.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntSupplier.java new file mode 100644 index 000000000..db77886a0 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntSupplier.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntSupplier { + int getAsInt(); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToDoubleFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToDoubleFunction.java new file mode 100644 index 000000000..6e7d7eb7b --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToDoubleFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntToDoubleFunction { + double applyAsDouble(int value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToLongFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToLongFunction.java new file mode 100644 index 000000000..31d0f181f --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntToLongFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntToLongFunction { + long applyAsLong(int value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntUnaryOperator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntUnaryOperator.java new file mode 100644 index 000000000..fd692371b --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TIntUnaryOperator.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TIntUnaryOperator { + int applyAsInt(int operand); + + default TIntUnaryOperator compose(TIntUnaryOperator before) { + return v -> applyAsInt(before.applyAsInt(v)); + } + + default TIntUnaryOperator andThen(TIntUnaryOperator after) { + return v -> after.applyAsInt(applyAsInt(v)); + } + + static TIntUnaryOperator identity() { + return v -> v; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TPredicate.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TPredicate.java new file mode 100644 index 000000000..6a8284938 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TPredicate.java @@ -0,0 +1,43 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +import org.teavm.classlib.java.util.TObjects; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TPredicate { + boolean test(T t); + + default TPredicate and(TPredicate other) { + return t -> test(t) && other.test(t); + } + + default TPredicate negate() { + return t -> !test(t); + } + + default TPredicate or(TPredicate other) { + return t -> test(t) || other.test(t); + } + + default TPredicate isEqual(Object targetRef) { + return t -> TObjects.equals(t, targetRef); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TSupplier.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TSupplier.java new file mode 100644 index 000000000..8033863c9 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TSupplier.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TSupplier { + T get(); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToDoubleFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToDoubleFunction.java new file mode 100644 index 000000000..a25548ede --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToDoubleFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TToDoubleFunction { + double applyAsDouble(T value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToIntFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToIntFunction.java new file mode 100644 index 000000000..e97a65ead --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToIntFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TToIntFunction { + int applyAsInt(T value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToLongFunction.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToLongFunction.java new file mode 100644 index 000000000..3f4ee8c57 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TToLongFunction.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TToLongFunction { + long applyAsLong(T value); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TUnaryOperator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TUnaryOperator.java new file mode 100644 index 000000000..bf5fbcd56 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/function/TUnaryOperator.java @@ -0,0 +1,27 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util.function; + +/** + * + * @author Alexey Andreev + */ +@FunctionalInterface +public interface TUnaryOperator extends TFunction { + static TUnaryOperator identity() { + return t -> t; + } +}