mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
java.util.function
This commit is contained in:
parent
afac931c62
commit
1d45cd4d2b
|
@ -122,8 +122,9 @@
|
|||
<argument>java.nio.charset</argument>
|
||||
<argument>java.text</argument>
|
||||
<argument>java.util</argument>
|
||||
<argument>java.util.logging</argument>
|
||||
<argument>java.util.concurrent</argument>
|
||||
<argument>java.util.function</argument>
|
||||
<argument>java.util.logging</argument>
|
||||
<argument>java.util.regex</argument>
|
||||
<argument>java.util.zip</argument>
|
||||
<argument>-output</argument>
|
||||
|
|
|
@ -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 {
|
||||
}
|
|
@ -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 <T>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TComparator<T> {
|
||||
int compare(T o1, T o2);
|
||||
|
||||
default TComparator<T> reversed() {
|
||||
return (a, b) -> compare(b, a);
|
||||
}
|
||||
|
||||
default TComparator<T> thenComparing(TComparator<? super T> other) {
|
||||
return (a, b) -> {
|
||||
int r = compare(a, b);
|
||||
if (r == 0) {
|
||||
r = other.compare(a, b);
|
||||
}
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
default <U> TComparator<T> thenComparing(TFunction<? super T, ? extends U> keyExtractor,
|
||||
TComparator<? super U> keyComparator) {
|
||||
return thenComparing(comparing(keyExtractor, keyComparator));
|
||||
}
|
||||
|
||||
default <U extends Comparable<? super U>> TComparator<T> thenComparing(
|
||||
TFunction<? super T,? extends U> 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<T> thenComparingInt(TToIntFunction<? super T> 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<T> thenComparingLong(TToLongFunction<? super T> 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<T> thenComparingDouble(TToDoubleFunction<? super T> keyExtractor) {
|
||||
return (a, b) -> {
|
||||
int r = compare(a, b);
|
||||
if (r == 0) {
|
||||
r = Double.compare(keyExtractor.applyAsDouble(a), keyExtractor.applyAsDouble(b));
|
||||
}
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
static <T, U> TComparator<T> comparing(TFunction<? super T, ? extends U> keyExtractor,
|
||||
TComparator<? super U> keyComparator) {
|
||||
return (a, b) -> keyComparator.compare(keyExtractor.apply(a), keyExtractor.apply(b));
|
||||
}
|
||||
|
||||
static <T, U extends TComparable<? super U>> TComparator<T> comparing(
|
||||
TFunction<? super T, ? extends U> keyExtractor) {
|
||||
return (a, b) -> {
|
||||
U k = keyExtractor.apply(a);
|
||||
U m = keyExtractor.apply(b);
|
||||
return k != null ? k.compareTo(m) : -m.compareTo(k);
|
||||
};
|
||||
}
|
||||
|
||||
static <T extends TComparable<? super T>> TComparator<T> naturalOrder() {
|
||||
return (o1, o2) -> o1 != null ? o1.compareTo(o2) : o2.compareTo(o1);
|
||||
}
|
||||
|
||||
static <T extends TComparable<? super T>> TComparator<T> reverseOrder() {
|
||||
return (o1, o2) -> o2 != null ? o2.compareTo(o1) : o1.compareTo(o2);
|
||||
}
|
||||
|
||||
static <T> TComparator<T> nullsFirst(TComparator<? super T> comparator) {
|
||||
return (a, b) -> a == null && b == null ? 0 : a == null ? -1 : b == null ? 1 : comparator.compare(a, b);
|
||||
}
|
||||
|
||||
static <T> TComparator<T> nullsLast(TComparator<? super T> comparator) {
|
||||
return (a, b) -> a == null && b == null ? 0 : a == null ? 1 : b == null ? -1 : comparator.compare(a, b);
|
||||
}
|
||||
|
||||
static <T> TComparator<T> comparingInt(TToIntFunction<? super T> keyExtractor) {
|
||||
return (a, b) -> Integer.compare(keyExtractor.applyAsInt(a), keyExtractor.applyAsInt(b));
|
||||
}
|
||||
|
||||
static <T> TComparator<T> comparingLong(TToLongFunction<? super T> keyExtractor) {
|
||||
return (a, b) -> Long.compare(keyExtractor.applyAsLong(a), keyExtractor.applyAsLong(b));
|
||||
}
|
||||
|
||||
static <T> TComparator<T> comparingDouble(TToDoubleFunction<? super T> keyExtractor) {
|
||||
return (a, b) -> Double.compare(keyExtractor.applyAsDouble(a), keyExtractor.applyAsDouble(b));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T, U> {
|
||||
void accept(T t, U u);
|
||||
|
||||
default TBiConsumer<T,U> andThen(TBiConsumer<? super T,? super U> after) {
|
||||
return (t, u) -> {
|
||||
this.accept(t, u);
|
||||
after.accept(t, u);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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<T, U, R> {
|
||||
R apply(T t, U u);
|
||||
|
||||
default <V> TBiFunction<T,U,V> andThen(TFunction<? super R, ? extends V> after) {
|
||||
return (t, u) -> after.apply(apply(t, u));
|
||||
}
|
||||
}
|
|
@ -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<T, U> {
|
||||
boolean test(T t, U u);
|
||||
|
||||
default TBiPredicate<T, U> and(TBiPredicate<? super T, ? super U> other) {
|
||||
return (t, u) -> test(t, u) && other.test(t, u);
|
||||
}
|
||||
|
||||
default BiPredicate<T, U> negate() {
|
||||
return (t, u) -> !test(t, u);
|
||||
}
|
||||
|
||||
default TBiPredicate<T, U> or(TBiPredicate<? super T, ? super U> other) {
|
||||
return (t, u) -> test(t, u) || other.test(t, u);
|
||||
}
|
||||
}
|
|
@ -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<T> extends TBiFunction<T, T, T> {
|
||||
static <T> TBinaryOperator<T> minBy(TComparator<? super T> comparator) {
|
||||
return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
|
||||
}
|
||||
|
||||
static <T> TBinaryOperator<T> maxBy(TComparator<? super T> comparator) {
|
||||
return (a, b) -> comparator.compare(a, b) >= 0 ? a : b;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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<T> {
|
||||
void accept(T t);
|
||||
|
||||
default TConsumer<T> andThen(TConsumer<? super T> after) {
|
||||
return t -> {
|
||||
accept(t);
|
||||
after.accept(t);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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> {
|
||||
R apply(double value);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<T, R> {
|
||||
R apply(T t);
|
||||
|
||||
default <V> TFunction<V, R> compose(TFunction<? super V, ? extends T> before) {
|
||||
return v -> apply(before.apply(v));
|
||||
}
|
||||
|
||||
default <V> TFunction<T, V> andThen(TFunction<? super R, ? extends V> after) {
|
||||
return t -> after.apply(apply(t));
|
||||
}
|
||||
|
||||
static <T> TFunction<T, T> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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> {
|
||||
R apply(int value);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<T> {
|
||||
boolean test(T t);
|
||||
|
||||
default TPredicate<T> and(TPredicate<? super T> other) {
|
||||
return t -> test(t) && other.test(t);
|
||||
}
|
||||
|
||||
default TPredicate<T> negate() {
|
||||
return t -> !test(t);
|
||||
}
|
||||
|
||||
default TPredicate<T> or(TPredicate<? super T> other) {
|
||||
return t -> test(t) || other.test(t);
|
||||
}
|
||||
|
||||
default TPredicate<T> isEqual(Object targetRef) {
|
||||
return t -> TObjects.equals(t, targetRef);
|
||||
}
|
||||
}
|
|
@ -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> {
|
||||
T get();
|
||||
}
|
|
@ -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<T> {
|
||||
double applyAsDouble(T value);
|
||||
}
|
|
@ -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<T> {
|
||||
int applyAsInt(T value);
|
||||
}
|
|
@ -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<T> {
|
||||
long applyAsLong(T value);
|
||||
}
|
|
@ -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<T> extends TFunction<T, T> {
|
||||
static <T> TUnaryOperator<T> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user