text
stringlengths
9
39.2M
dir
stringlengths
25
226
lang
stringclasses
163 values
created_date
timestamp[s]
updated_date
timestamp[s]
repo_name
stringclasses
751 values
repo_full_name
stringclasses
752 values
star
int64
1.01k
183k
len_tokens
int64
1
18.5M
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional; import androidx.annotation.CheckResult; import java.util.ArrayList; import java.util.Collection; import java.util.List; import me.zhanghai.android.douya.functional.compat.BiConsumer; import me.zhanghai.android.douya.functional.compat.BiFunction; import me.zhanghai.android.douya.functional.compat.BiPredicate; import me.zhanghai.android.douya.functional.compat.Consumer; import me.zhanghai.android.douya.functional.compat.Function; import me.zhanghai.android.douya.functional.compat.Predicate; import me.zhanghai.android.douya.functional.extension.QuadFunction; import me.zhanghai.android.douya.functional.extension.TriConsumer; import me.zhanghai.android.douya.functional.extension.TriFunction; import me.zhanghai.android.douya.functional.extension.TriPredicate; @SuppressWarnings("unused") public class Functional { private Functional() {} public static <T> boolean every(Iterable<T> iterable, Predicate<T> predicate) { return FunctionalIterator.everyRemaining(iterable.iterator(), predicate); } public static <T> boolean every(Iterable<T> iterable, BiPredicate<T, Integer> predicate) { return FunctionalIterator.everyRemaining(iterable.iterator(), predicate); } public static <I extends Iterable<T>, T> boolean every(I iterable, TriPredicate<T, Integer, I> predicate) { return FunctionalIterator.everyRemaining(iterable.iterator(), (t, index, iterator) -> predicate.test(t, index, iterable)); } public static <T, J extends Collection<? super T>> J filter(Iterable<T> iterable, Predicate<T> predicate, J collector) { return FunctionalIterator.filterRemaining(iterable.iterator(), predicate, collector); } @CheckResult public static <T, J extends Collection<? super T>> ArrayList<T> filter(Iterable<T> iterable, Predicate<T> predicate) { return FunctionalIterator.filterRemaining(iterable.iterator(), predicate); } public static <T, J extends Collection<? super T>> J filter(Iterable<T> iterable, BiPredicate<T, Integer> predicate, J collector) { return FunctionalIterator.filterRemaining(iterable.iterator(), predicate, collector); } @CheckResult public static <T, J extends Collection<? super T>> ArrayList<T> filter( Iterable<T> iterable, BiPredicate<T, Integer> predicate) { return FunctionalIterator.filterRemaining(iterable.iterator(), predicate); } public static <I extends Iterable<T>, T, J extends Collection<? super T>> J filter( I iterable, TriPredicate<T, Integer, I> predicate, J collector) { return FunctionalIterator.filterRemaining(iterable.iterator(), (t, index, iterator) -> predicate.test(t, index, iterable), collector); } @CheckResult public static <I extends Iterable<T>, T, J extends Collection<? super T>> ArrayList<T> filter( I iterable, TriPredicate<T, Integer, I> predicate) { return FunctionalIterator.filterRemaining(iterable.iterator(), (t, index, iterator) -> predicate.test(t, index, iterable)); } public static <T> T find(Iterable<T> iterable, Predicate<T> predicate) { return FunctionalIterator.findRemaining(iterable.iterator(), predicate); } public static <T> T find(Iterable<T> iterable, BiPredicate<T, Integer> predicate) { return FunctionalIterator.findRemaining(iterable.iterator(), predicate); } public static <I extends Iterable<T>, T> T find(I iterable, TriPredicate<T, Integer, I> predicate) { return FunctionalIterator.findRemaining(iterable.iterator(), (t, index, iterator) -> predicate.test(t, index, iterable)); } public static <T> int findIndex(Iterable<T> iterable, Predicate<T> predicate) { return FunctionalIterator.findIndexRemaining(iterable.iterator(), predicate); } public static <T> int findIndex(Iterable<T> iterable, BiPredicate<T, Integer> predicate) { return FunctionalIterator.findIndexRemaining(iterable.iterator(), predicate); } public static <I extends Iterable<T>, T> int findIndex(I iterable, TriPredicate<T, Integer, I> predicate) { return FunctionalIterator.findIndexRemaining(iterable.iterator(), (t, index, iterator) -> predicate.test(t, index, iterable)); } public static <T> void forEach(Iterable<T> iterable, Consumer<T> consumer) { FunctionalIterator.forEachRemaining(iterable.iterator(), consumer); } public static <T> void forEach(Iterable<T> iterable, BiConsumer<T, Integer> consumer) { FunctionalIterator.forEachRemaining(iterable.iterator(), consumer); } public static <I extends Iterable<T>, T> void forEach(I iterable, TriConsumer<T, Integer, I> consumer) { FunctionalIterator.forEachRemaining(iterable.iterator(), (t, index, iterator) -> consumer.accept(t, index, iterable)); } public static <T, U, J extends Collection<? super U>> J map(Iterable<T> iterable, Function<T, U> function, J collector) { return FunctionalIterator.mapRemaining(iterable.iterator(), function, collector); } @CheckResult public static <T, U, J extends Collection<? super U>> ArrayList<U> map( Iterable<T> iterable, Function<T, U> function) { return FunctionalIterator.mapRemaining(iterable.iterator(), function); } public static <T, U, J extends Collection<? super U>> J map(Iterable<T> iterable, BiFunction<T, Integer, U> function, J collector) { return FunctionalIterator.mapRemaining(iterable.iterator(), function, collector); } @CheckResult public static <T, U, J extends Collection<? super U>> ArrayList<U> map( Iterable<T> iterable, BiFunction<T, Integer, U> function) { return FunctionalIterator.mapRemaining(iterable.iterator(), function); } public static <I extends Iterable<T>, T, U, J extends Collection<? super U>> J map( I iterable, TriFunction<T, Integer, I, U> function, J collector) { return FunctionalIterator.mapRemaining(iterable.iterator(), (t, index, iterator) -> function.apply(t, index, iterable), collector); } @CheckResult public static <I extends Iterable<T>, T, U, J extends Collection<? super U>> ArrayList<U> map( I iterable, TriFunction<T, Integer, I, U> function) { return FunctionalIterator.mapRemaining(iterable.iterator(), (t, index, iterator) -> function.apply(t, index, iterable)); } public static <T, U> U reduce(Iterable<T> iterable, BiFunction<U, T, U> function, U initialValue) { return FunctionalIterator.reduceRemaining(iterable.iterator(), function, initialValue); } public static <T, U> U reduce(Iterable<T> iterable, TriFunction<U, T, Integer, U> function, U initialValue) { return FunctionalIterator.reduceRemaining(iterable.iterator(), function, initialValue); } public static <I extends Iterable<T>, T, U> U reduce(I iterable, QuadFunction<U, T, Integer, I, U> function, U initialValue) { return FunctionalIterator.reduceRemaining(iterable.iterator(), (accumulator, t, index, iterator) -> function.apply(accumulator, t, index, iterable), initialValue); } public static <T> T reduce(Iterable<T> iterable, BiFunction<T, T, T> function) { return FunctionalIterator.reduceRemaining(iterable.iterator(), function); } public static <T> T reduce(Iterable<T> iterable, TriFunction<T, T, Integer, T> function) { return FunctionalIterator.reduceRemaining(iterable.iterator(), function); } public static <I extends Iterable<T>, T> T reduce(I iterable, QuadFunction<T, T, Integer, I, T> function) { return FunctionalIterator.reduceRemaining(iterable.iterator(), (accumulator, t, index, iterator) -> function.apply(accumulator, t, index, iterable)); } public static <T> T reduceRight(List<T> iterable, BiFunction<T, T, T> function) { return FunctionalIterator.reduceRemaining(new FunctionalIterator.ReverseIterator<>( iterable), function); } public static <T> T reduceRight(List<T> list, TriFunction<T, T, Integer, T> function) { return FunctionalIterator.reduceRemaining(new FunctionalIterator.ReverseIterator<>(list), (previousValue, t, index, iterator) -> function.apply(previousValue, t, list.size() - 1 - index)); } public static <I extends List<T>, T> T reduceRight(I list, QuadFunction<T, T, Integer, I, T> function) { return FunctionalIterator.reduceRemaining(new FunctionalIterator.ReverseIterator<>(list), (previousValue, t, index, iterator) -> function.apply(previousValue, t, list.size() - 1 - index, list)); } public static <T> boolean some(Iterable<T> iterable, Predicate<T> predicate) { return FunctionalIterator.someRemaining(iterable.iterator(), predicate); } public static <T> boolean some(Iterable<T> iterable, BiPredicate<T, Integer> predicate) { return FunctionalIterator.someRemaining(iterable.iterator(), predicate); } public static <I extends Iterable<T>, T> boolean some(I iterable, TriPredicate<T, Integer, I> predicate) { return FunctionalIterator.someRemaining(iterable.iterator(), (t, index, iterator) -> predicate.test(t, index, iterable)); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/Functional.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
2,060
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.profile.content; import android.content.Context; import android.os.Bundle; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import java.util.List; import me.zhanghai.android.douya.app.TargetedRetainedFragment; import me.zhanghai.android.douya.broadcast.content.TimelineBroadcastListResource; import me.zhanghai.android.douya.diary.content.UserDiaryListResource; import me.zhanghai.android.douya.followship.content.FollowingListResource; import me.zhanghai.android.douya.network.api.ApiError; import me.zhanghai.android.douya.network.api.info.frodo.Broadcast; import me.zhanghai.android.douya.network.api.info.apiv2.User; import me.zhanghai.android.douya.network.api.info.frodo.Diary; import me.zhanghai.android.douya.network.api.info.frodo.SimpleReview; import me.zhanghai.android.douya.network.api.info.frodo.SimpleUser; import me.zhanghai.android.douya.network.api.info.frodo.UserItems; import me.zhanghai.android.douya.review.content.UserReviewListResource; import me.zhanghai.android.douya.user.content.UserResource; import me.zhanghai.android.douya.util.FragmentUtils; public class ProfileResource extends TargetedRetainedFragment implements UserResource.Listener, TimelineBroadcastListResource.Listener, FollowingListResource.Listener, UserDiaryListResource.Listener, UserItemListResource.Listener, UserReviewListResource.Listener { private static final String KEY_PREFIX = ProfileResource.class.getName() + '.'; private static final String EXTRA_USER_ID_OR_UID = KEY_PREFIX + "user_id_or_uid"; private static final String EXTRA_SIMPLE_USER = KEY_PREFIX + "simple_user"; private static final String EXTRA_USER = KEY_PREFIX + "user"; private String mUserIdOrUid; private me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser mSimpleUser; private User mUser; private UserResource mUserResource; private TimelineBroadcastListResource mBroadcastListResource; private FollowingListResource mFollowingListResource; private UserDiaryListResource mDiaryListResource; private UserItemListResource mUserItemListResource; private UserReviewListResource mReviewListResource; private boolean mHasError; private static final String FRAGMENT_TAG_DEFAULT = ProfileResource.class.getName(); private static ProfileResource newInstance( String userIdOrUid, me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser simpleUser, User user) { //noinspection deprecation return new ProfileResource().setArguments(userIdOrUid, simpleUser, user); } public static ProfileResource attachTo( String userIdOrUid, me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser simpleUser, User user, Fragment fragment, String tag, int requestCode) { FragmentActivity activity = fragment.getActivity(); ProfileResource instance = FragmentUtils.findByTag(activity, tag); if (instance == null) { instance = newInstance(userIdOrUid, simpleUser, user); FragmentUtils.add(instance, activity, tag); } instance.setTarget(fragment, requestCode); return instance; } public static ProfileResource attachTo( String userIdOrUid, me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser simpleUser, User user, Fragment fragment) { return attachTo(userIdOrUid, simpleUser, user, fragment, FRAGMENT_TAG_DEFAULT, REQUEST_CODE_INVALID); } /** * @deprecated Use {@code attachTo()} instead. */ public ProfileResource() {} protected ProfileResource setArguments( String userIdOrUid, me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser simpleUser, User user) { FragmentUtils.getArgumentsBuilder(this) .putString(EXTRA_USER_ID_OR_UID, userIdOrUid) .putParcelable(EXTRA_SIMPLE_USER, simpleUser) .putParcelable(EXTRA_USER, user); return this; } public String getUserIdOrUid() { // Can be called before onCreate() is called. ensureArguments(); return mUserIdOrUid; } public me.zhanghai.android.douya.network.api.info.apiv2.SimpleUser getSimpleUser() { // Can be called before onCreate() is called. ensureArguments(); return mSimpleUser; } public boolean hasSimpleUser() { // Can be called before onCreate() is called. ensureArguments(); return mSimpleUser != null; } public User getUser() { // Can be called before onCreate() is called. ensureArguments(); return mUser; } public boolean hasUser() { // Can be called before onCreate() is called. ensureArguments(); return mUser != null; } @Override public void onAttach(Context context) { super.onAttach(context); ensureResourcesTarget(); } private void ensureResourcesTarget() { if (mUserResource != null) { mUserResource.setTarget(this); } if (mBroadcastListResource != null) { mBroadcastListResource.setTarget(this); } if (mFollowingListResource != null) { mFollowingListResource.setTarget(this); } if (mDiaryListResource != null) { mDiaryListResource.setTarget(this); } if (mUserItemListResource != null) { mUserItemListResource.setTarget(this); } if (mReviewListResource != null) { mReviewListResource.setTarget(this); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ensureArguments(); mUserResource = UserResource.attachTo(mUserIdOrUid, mSimpleUser, mUser, this); ensureResourcesIfHasSimpleUser(); } private void ensureArguments() { if (mUserIdOrUid != null) { return; } Bundle arguments = getArguments(); mUser = arguments.getParcelable(EXTRA_USER); if (mUser != null) { mSimpleUser = mUser; mUserIdOrUid = mUser.getIdOrUid(); } else { mSimpleUser = arguments.getParcelable(EXTRA_SIMPLE_USER); if (mSimpleUser != null) { mUserIdOrUid = mSimpleUser.getIdOrUid(); } else { mUserIdOrUid = arguments.getString(EXTRA_USER_ID_OR_UID); } } } @Override public void onDestroy() { super.onDestroy(); mUserResource.detach(); if (mBroadcastListResource != null) { mBroadcastListResource.detach(); } if (mFollowingListResource != null) { mFollowingListResource.detach(); } if (mDiaryListResource != null) { mDiaryListResource.detach(); } if (mUserItemListResource != null) { mUserItemListResource.detach(); } if (mReviewListResource != null) { mReviewListResource.detach(); } Bundle arguments = getArguments(); arguments.putString(EXTRA_USER_ID_OR_UID, mUserIdOrUid); arguments.putParcelable(EXTRA_SIMPLE_USER, mSimpleUser); arguments.putParcelable(EXTRA_USER, mUser); } @Override public void onLoadUserStarted(int requestCode) {} @Override public void onLoadUserFinished(int requestCode) {} @Override public void onLoadUserError(int requestCode, ApiError error) { notifyError(error); } @Override public void onUserChanged(int requestCode, User newUser) { mUser = newUser; mSimpleUser = newUser; mUserIdOrUid = newUser.getIdOrUid(); getListener().onUserChanged(getRequestCode(), newUser); notifyChangedIfLoaded(); ensureResourcesIfHasSimpleUser(); } @Override public void onUserWriteStarted(int requestCode) { getListener().onUserWriteStarted(getRequestCode()); } @Override public void onUserWriteFinished(int requestCode) { getListener().onUserWriteFinished(getRequestCode()); } private void ensureResourcesIfHasSimpleUser() { if (mBroadcastListResource != null || mFollowingListResource != null || mDiaryListResource != null || mUserItemListResource != null || mReviewListResource != null) { return; } if (mSimpleUser == null) { return; } mBroadcastListResource = TimelineBroadcastListResource.attachTo(mSimpleUser.getIdOrUid(), null, this); mFollowingListResource = FollowingListResource.attachTo(mSimpleUser.getIdOrUid(), this); mDiaryListResource = UserDiaryListResource.attachTo(mSimpleUser.getIdOrUid(), this); mUserItemListResource = UserItemListResource.attachTo(mSimpleUser.getIdOrUid(), this); mReviewListResource = UserReviewListResource.attachTo(mSimpleUser.getIdOrUid(), this); } @Override public void onLoadBroadcastListStarted(int requestCode) {} @Override public void onLoadBroadcastListFinished(int requestCode) {} @Override public void onLoadBroadcastListError(int requestCode, ApiError error) { notifyError(error); } @Override public void onBroadcastListChanged(int requestCode, List<Broadcast> newBroadcastList) { notifyChangedIfLoaded(); } @Override public void onBroadcastListAppended(int requestCode, List<Broadcast> appendedBroadcastList) { notifyChangedIfLoaded(); } @Override public void onBroadcastChanged(int requestCode, int position, Broadcast newBroadcast) { notifyChangedIfLoaded(); } @Override public void onBroadcastRemoved(int requestCode, int position) { notifyChangedIfLoaded(); } @Override public void onBroadcastWriteStarted(int requestCode, int position) {} @Override public void onBroadcastWriteFinished(int requestCode, int position) {} @Override public void onLoadUserListStarted(int requestCode) {} @Override public void onLoadUserListFinished(int requestCode) {} @Override public void onLoadUserListError(int requestCode, ApiError error) { notifyError(error); } @Override public void onUserListChanged(int requestCode, List<SimpleUser> newUserList) { notifyChangedIfLoaded(); } @Override public void onUserListAppended(int requestCode, List<SimpleUser> appendedUserList) { notifyChangedIfLoaded(); } @Override public void onLoadDiaryListStarted(int requestCode) {} @Override public void onLoadDiaryListFinished(int requestCode) {} @Override public void onLoadDiaryListError(int requestCode, ApiError error) { notifyError(error); } @Override public void onDiaryListChanged(int requestCode, List<Diary> newDiaryList) { notifyChangedIfLoaded(); } @Override public void onDiaryListAppended(int requestCode, List<Diary> appendedDiaryList) { notifyChangedIfLoaded(); } @Override public void onDiaryChanged(int requestCode, int position, Diary newDiary) { notifyChangedIfLoaded(); } @Override public void onDiaryRemoved(int requestCode, int position) { notifyChangedIfLoaded(); } @Override public void onLoadUserItemListStarted(int requestCode) {} @Override public void onLoadUserItemListFinished(int requestCode) {} @Override public void onLoadUserItemListError(int requestCode, ApiError error) { notifyError(error); } @Override public void onUserItemListChanged(int requestCode, List<UserItems> newUserItemList) { notifyChangedIfLoaded(); } @Override public void onLoadReviewListStarted(int requestCode) {} @Override public void onLoadReviewListFinished(int requestCode) {} @Override public void onLoadReviewListError(int requestCode, ApiError error) { notifyError(error); } @Override public void onReviewListChanged(int requestCode, List<SimpleReview> newReviewList) { notifyChangedIfLoaded(); } @Override public void onReviewListAppended(int requestCode, List<SimpleReview> appendedReviewList) { notifyChangedIfLoaded(); } @Override public void onReviewChanged(int requestCode, int position, SimpleReview newReview) { notifyChangedIfLoaded(); } @Override public void onReviewRemoved(int requestCode, int position) { notifyChangedIfLoaded(); } public boolean isAnyLoaded() { return hasUser() || (mBroadcastListResource != null && mBroadcastListResource.has()) || (mFollowingListResource != null && mFollowingListResource.has()) || (mDiaryListResource != null && mDiaryListResource.has()) || (mUserItemListResource != null && mUserItemListResource.has()) || (mReviewListResource != null && mReviewListResource.has()); } public void notifyChangedIfLoaded() { getListener().onChanged(getRequestCode(), getUser(), mBroadcastListResource != null ? mBroadcastListResource.get() : null, mFollowingListResource != null ? mFollowingListResource.get() : null, mDiaryListResource != null ? mDiaryListResource.get() : null, mUserItemListResource != null ? mUserItemListResource.get() : null, mReviewListResource != null ? mReviewListResource.get() : null); } private void notifyError(ApiError error) { if (!mHasError) { mHasError = true; getListener().onLoadError(getRequestCode(), error); } } private Listener getListener() { return (Listener) getTarget(); } public interface Listener { void onLoadError(int requestCode, ApiError error); void onUserChanged(int requestCode, User newUser); void onUserWriteStarted(int requestCode); void onUserWriteFinished(int requestCode); void onChanged(int requestCode, User newUser, List<Broadcast> newBroadcastList, List<SimpleUser> newFollowingList, List<Diary> newDiaryList, List<UserItems> newUserItemList, List<SimpleReview> newReviewList); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/profile/content/ProfileResource.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
3,076
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional; import java.util.Objects; import me.zhanghai.android.douya.functional.compat.Consumer; public class IterableCompat { private IterableCompat() {} public static <T> void forEach(Iterable<T> iterable, Consumer<T> action) { Objects.requireNonNull(iterable); for (T t : iterable) { action.accept(t); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/IterableCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
93
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional; public class FunctionalException extends RuntimeException { public FunctionalException(Throwable cause) { super(cause); } public <T extends Throwable> T getCauseAs(Class<T> classOfCause) { //noinspection unchecked return (T) super.getCause(); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/FunctionalException.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
77
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional; import java.util.Objects; public class ObjectsCompat { private ObjectsCompat() {} /** * @see Objects#isNull */ public static boolean isNull(Object object) { return object == null; } /** * @see Objects#nonNull */ public static boolean nonNull(Object object) { return object != null; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/ObjectsCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
97
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional; import java.io.Serializable; import java.util.Collections; import java.util.Comparator; import java.util.Objects; import me.zhanghai.android.douya.functional.compat.Function; import me.zhanghai.android.douya.functional.compat.ToDoubleFunction; import me.zhanghai.android.douya.functional.compat.ToIntFunction; import me.zhanghai.android.douya.functional.compat.ToLongFunction; @SuppressWarnings("unused") public class ComparatorCompat { private ComparatorCompat() {} public static <T> Comparator<T> reversed(Comparator<T> comparator) { return Collections.reverseOrder(comparator); } public static <T> Comparator<T> thenComparing(Comparator<T> comparator, Comparator<? super T> other) { Objects.requireNonNull(other); return (Comparator<T> & Serializable) (object1, object2) -> { int result = comparator.compare(object1, object2); return (result != 0) ? result : other.compare(object1, object2); }; } public static <T, U> Comparator<T> thenComparing(Comparator<T> comparator, Function<? super T, ? extends U> keyExtractor, Comparator<? super U> keyComparator) { return thenComparing(comparator, comparing(keyExtractor, keyComparator)); } public static <T, U extends Comparable<? super U>> Comparator<T> thenComparing( Comparator<T> comparator, Function<? super T, ? extends U> keyExtractor) { return thenComparing(comparator, comparing(keyExtractor)); } public static <T> Comparator<T> thenComparingInt(Comparator<T> comparator, ToIntFunction<? super T> keyExtractor) { return thenComparing(comparator, comparingInt(keyExtractor)); } public static <T> Comparator<T> thenComparingLong(Comparator<T> comparator, ToLongFunction<? super T> keyExtractor) { return thenComparing(comparator, comparingLong(keyExtractor)); } public static <T> Comparator<T> thenComparingDouble(Comparator<T> comparator, ToDoubleFunction<? super T> keyExtractor) { return thenComparing(comparator, comparingDouble(keyExtractor)); } public static <T extends Comparable<? super T>> Comparator<T> reverseOrder() { return Collections.reverseOrder(); } @SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() { return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE; } public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(true, comparator); } public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) { return new Comparators.NullComparator<>(false, comparator); } public static <T, U> Comparator<T> comparing(Function<? super T, ? extends U> keyExtractor, Comparator<? super U> keyComparator) { Objects.requireNonNull(keyExtractor); Objects.requireNonNull(keyComparator); return (Comparator<T> & Serializable) (object1, object2) -> keyComparator.compare(keyExtractor.apply(object1), keyExtractor.apply(object2)); } public static <T, U extends Comparable<? super U>> Comparator<T> comparing( Function<? super T, ? extends U> keyExtractor) { Objects.requireNonNull(keyExtractor); return (Comparator<T> & Serializable) (object1, object2) -> keyExtractor.apply(object1).compareTo(keyExtractor.apply(object2)); } public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor) { Objects.requireNonNull(keyExtractor); return (Comparator<T> & Serializable) (object1, object2) -> Integer.compare(keyExtractor.applyAsInt(object1), keyExtractor.applyAsInt(object2)); } public static <T> Comparator<T> comparingLong(ToLongFunction<? super T> keyExtractor) { Objects.requireNonNull(keyExtractor); return (Comparator<T> & Serializable) (object1, object2) -> Long.compare(keyExtractor.applyAsLong(object1), keyExtractor.applyAsLong(object2)); } public static<T> Comparator<T> comparingDouble(ToDoubleFunction<? super T> keyExtractor) { Objects.requireNonNull(keyExtractor); return (Comparator<T> & Serializable) (object1, object2) -> Double.compare(keyExtractor.applyAsDouble(object1), keyExtractor.applyAsDouble(object2)); } private static class Comparators { private Comparators() {} public enum NaturalOrderComparator implements Comparator<Comparable<Object>> { INSTANCE; @Override public int compare(Comparable<Object> object1, Comparable<Object> object2) { return object1.compareTo(object2); } @Override public Comparator<Comparable<Object>> reversed() { return ComparatorCompat.reverseOrder(); } } public static class NullComparator<T> implements Comparator<T>, Serializable { private static final long serialVersionUID = -7569533591570686392L; private final boolean nullFirst; private final Comparator<T> real; @SuppressWarnings("unchecked") public NullComparator(boolean nullFirst, Comparator<? super T> real) { this.nullFirst = nullFirst; this.real = (Comparator<T>) real; } @Override public int compare(T object1, T object2) { if (object1 == null) { return object2 == null ? 0 : nullFirst ? -1 : 1; } else if (object2 == null) { return nullFirst ? 1: -1; } else { return real == null ? 0 : real.compare(object1, object2); } } @Override public Comparator<T> thenComparing(Comparator<? super T> other) { Objects.requireNonNull(other); return new NullComparator<>(nullFirst, real == null ? other : ComparatorCompat.thenComparing(real, other)); } @Override public Comparator<T> reversed() { return new NullComparator<>(!nullFirst, real == null ? null : ComparatorCompat.reversed(real)); } } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/ComparatorCompat.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,324
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ToDoubleFunction; /** * Represents a function that produces a double-valued result. This is the * {@code double}-producing primitive specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(Object)}. * * @param <T> the type of the input to the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingToDoubleFunction<T> extends ToDoubleFunction<T> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ double applyAsDoubleThrows(T value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default double applyAsDouble(T value) { try { return applyAsDoubleThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingToDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
491
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ToIntBiFunction; /** * Represents a function that accepts two arguments and produces an int-valued * result. This is the {@code int}-producing primitive specialization for * {@link ThrowingBiFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * * @see ThrowingBiFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingToIntBiFunction<T, U> extends ToIntBiFunction<T, U> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ int applyAsIntThrows(T t, U u) throws Exception; /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ default int applyAsInt(T t, U u) { try { return applyAsIntThrows(t, u); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingToIntBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
554
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional; import androidx.annotation.CheckResult; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import me.zhanghai.android.douya.functional.compat.BiConsumer; import me.zhanghai.android.douya.functional.compat.BiFunction; import me.zhanghai.android.douya.functional.compat.BiPredicate; import me.zhanghai.android.douya.functional.compat.Consumer; import me.zhanghai.android.douya.functional.compat.Function; import me.zhanghai.android.douya.functional.compat.Predicate; import me.zhanghai.android.douya.functional.extension.QuadFunction; import me.zhanghai.android.douya.functional.extension.TriConsumer; import me.zhanghai.android.douya.functional.extension.TriFunction; import me.zhanghai.android.douya.functional.extension.TriPredicate; @SuppressWarnings("unused") public class FunctionalIterator { private FunctionalIterator() {} public static <T> boolean everyRemaining(Iterator<T> iterator, Predicate<T> predicate) { while (iterator.hasNext()) { T t = iterator.next(); if (!predicate.test(t)) { return false; } } return true; } public static <T> boolean everyRemaining(Iterator<T> iterator, BiPredicate<T, Integer> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (!predicate.test(t, index)) { return false; } ++index; } return true; } public static <I extends Iterator<T>, T> boolean everyRemaining( I iterator, TriPredicate<T, Integer, I> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (!predicate.test(t, index, iterator)) { return false; } ++index; } return true; } public static <T, J extends Collection<? super T>> J filterRemaining(Iterator<T> iterator, Predicate<T> predicate, J collector) { while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t)) { collector.add(t); } } return collector; } @CheckResult public static <T, J extends Collection<? super T>> ArrayList<T> filterRemaining( Iterator<T> iterator, Predicate<T> predicate) { return filterRemaining(iterator, predicate, new ArrayList<>()); } public static <T, J extends Collection<? super T>> J filterRemaining( Iterator<T> iterator, BiPredicate<T, Integer> predicate, J collector) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index)) { collector.add(t); } ++index; } return collector; } @CheckResult public static <T, J extends Collection<? super T>> ArrayList<T> filterRemaining( Iterator<T> iterator, BiPredicate<T, Integer> predicate) { return filterRemaining(iterator, predicate, new ArrayList<>()); } public static <I extends Iterator<T>, T, J extends Collection<? super T>> J filterRemaining( I iterator, TriPredicate<T, Integer, I> predicate, J collector) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index, iterator)) { collector.add(t); } ++index; } return collector; } @CheckResult public static <I extends Iterator<T>, T, J extends Collection<? super T>> ArrayList<T> filterRemaining(I iterator, TriPredicate<T, Integer, I> predicate) { return filterRemaining(iterator, predicate, new ArrayList<>()); } public static <T> T findRemaining(Iterator<T> iterator, Predicate<T> predicate) { while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t)) { return t; } } return null; } public static <T> T findRemaining(Iterator<T> iterator, BiPredicate<T, Integer> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index)) { return t; } ++index; } return null; } public static <I extends Iterator<T>, T> T findRemaining( I iterator, TriPredicate<T, Integer, I> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index, iterator)) { return t; } ++index; } return null; } public static <T> int findIndexRemaining(Iterator<T> iterator, Predicate<T> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t)) { return index; } ++index; } return -1; } public static <T> int findIndexRemaining(Iterator<T> iterator, BiPredicate<T, Integer> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index)) { return index; } ++index; } return -1; } public static <I extends Iterator<T>, T> int findIndexRemaining( I iterator, TriPredicate<T, Integer, I> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index, iterator)) { return index; } ++index; } return -1; } public static <T> void forEachRemaining(Iterator<T> iterator, Consumer<T> consumer) { IteratorCompat.forEachRemaining(iterator, consumer); } public static <T> void forEachRemaining(Iterator<T> iterator, BiConsumer<T, Integer> consumer) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); consumer.accept(t, index); ++index; } } public static <I extends Iterator<T>, T> void forEachRemaining( I iterator, TriConsumer<T, Integer, I> consumer) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); consumer.accept(t, index, iterator); ++index; } } public static <T, U, J extends Collection<? super U>> J mapRemaining(Iterator<T> iterator, Function<T, U> function, J collector) { while (iterator.hasNext()) { T t = iterator.next(); collector.add(function.apply(t)); } return collector; } @CheckResult public static <T, U, J extends Collection<? super U>> ArrayList<U> mapRemaining( Iterator<T> iterator, Function<T, U> function) { return mapRemaining(iterator, function, new ArrayList<>()); } public static <T, U, J extends Collection<? super U>> J mapRemaining( Iterator<T> iterator, BiFunction<T, Integer, U> function, J collector) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); collector.add(function.apply(t, index)); ++index; } return collector; } @CheckResult public static <T, U, J extends Collection<? super U>> ArrayList<U> mapRemaining( Iterator<T> iterator, BiFunction<T, Integer, U> function) { return mapRemaining(iterator, function, new ArrayList<>()); } public static <I extends Iterator<T>, T, U, J extends Collection<? super U>> J mapRemaining( I iterator, TriFunction<T, Integer, I, U> function, J collector) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); collector.add(function.apply(t, index, iterator)); ++index; } return collector; } @CheckResult public static <I extends Iterator<T>, T, U, J extends Collection<? super U>> ArrayList<U> mapRemaining(I iterator, TriFunction<T, Integer, I, U> function) { return mapRemaining(iterator, function, new ArrayList<>()); } public static <T, U> U reduceRemaining(Iterator<T> iterator, BiFunction<U, T, U> function, U initialValue) { U accumulator = initialValue; while (iterator.hasNext()) { T t = iterator.next(); accumulator = function.apply(accumulator, t); } return accumulator; } public static <T, U> U reduceRemaining(Iterator<T> iterator, TriFunction<U, T, Integer, U> function, U initialValue) { U accumulator = initialValue; int index = 0; while (iterator.hasNext()) { T t = iterator.next(); accumulator = function.apply(accumulator, t, index); ++index; } return accumulator; } public static <I extends Iterator<T>, T, U> U reduceRemaining( I iterator, QuadFunction<U, T, Integer, I, U> function, U initialValue) { U accumulator = initialValue; int index = 0; while (iterator.hasNext()) { T t = iterator.next(); accumulator = function.apply(accumulator, t, index, iterator); ++index; } return accumulator; } public static <T> T reduceRemaining(Iterator<T> iterator, BiFunction<T, T, T> function) { if (!iterator.hasNext()) { throw new IllegalArgumentException("Reduce of empty iterator with no initial value"); } return reduceRemaining(iterator, function, iterator.next()); } public static <T> T reduceRemaining(Iterator<T> iterator, TriFunction<T, T, Integer, T> function) { if (!iterator.hasNext()) { throw new IllegalArgumentException("Reduce of empty iterator with no initial value"); } return reduceRemaining(iterator, (accumulator, t, index) -> function.apply(accumulator, t, index + 1), iterator.next()); } public static <I extends Iterator<T>, T> T reduceRemaining( I iterator, QuadFunction<T, T, Integer, I, T> function) { if (!iterator.hasNext()) { throw new IllegalArgumentException("Reduce of empty iterator with no initial value"); } return reduceRemaining(iterator, (accumulator, t, index, iterator2) -> function.apply(accumulator, t, index + 1, iterator2), iterator.next()); } public static <T> boolean someRemaining(Iterator<T> iterator, Predicate<T> predicate) { while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t)) { return true; } } return false; } public static <T> boolean someRemaining(Iterator<T> iterator, BiPredicate<T, Integer> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index)) { return true; } ++index; } return false; } public static <I extends Iterator<T>, T> boolean someRemaining( I iterator, TriPredicate<T, Integer, I> predicate) { int index = 0; while (iterator.hasNext()) { T t = iterator.next(); if (predicate.test(t, index, iterator)) { return true; } ++index; } return false; } public static class ReverseIterator<T> implements Iterator<T> { private ListIterator<T> mListIterator; public ReverseIterator(List<T> list) { mListIterator = list.listIterator(list.size()); } @Override public boolean hasNext() { return mListIterator.hasPrevious(); } @Override public T next() { return mListIterator.previous(); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/FunctionalIterator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
2,619
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ObjLongConsumer; /** * Represents an operation that accepts an object-valued and a * {@code long}-valued argument, and returns no result. This is the * {@code (reference, long)} specialization of {@link ThrowingBiConsumer}. * Unlike most other functional interfaces, {@code ThrowingObjLongConsumer} is * expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, long)}. * * @param <T> the type of the object argument to the operation * * @see ThrowingBiConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingObjLongConsumer<T> extends ObjLongConsumer<T> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ void acceptThrows(T t, long value) throws Exception; /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ default void accept(T t, long value) { try { acceptThrows(t, value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingObjLongConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
542
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleUnaryOperator; /** * Represents an operation on a single {@code double}-valued operand that produces * a {@code double}-valued result. This is the primitive type specialization of * {@link ThrowingUnaryOperator} for {@code double}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(double)}. * * @see ThrowingUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleUnaryOperator extends DoubleUnaryOperator { /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ double applyAsDoubleThrows(double operand) throws Exception; /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ default double applyAsDouble(double operand) { try { return applyAsDoubleThrows(operand); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed operator that first applies the {@code before} * operator to its input, and then applies this operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param before the operator to apply before this operator is applied * @return a composed operator that first applies the {@code before} * operator and then applies this operator * @throws NullPointerException if before is null * * @see #andThen(ThrowingDoubleUnaryOperator) */ default ThrowingDoubleUnaryOperator compose(ThrowingDoubleUnaryOperator before) { Objects.requireNonNull(before); return (double v) -> applyAsDoubleThrows(before.applyAsDoubleThrows(v)); } /** * Returns a composed operator that first applies this operator to * its input, and then applies the {@code after} operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param after the operator to apply after this operator is applied * @return a composed operator that first applies this operator and then * applies the {@code after} operator * @throws NullPointerException if after is null * * @see #compose(ThrowingDoubleUnaryOperator) */ default ThrowingDoubleUnaryOperator andThen(ThrowingDoubleUnaryOperator after) { Objects.requireNonNull(after); return (double t) -> after.applyAsDoubleThrows(applyAsDoubleThrows(t)); } /** * Returns a unary operator that always returns its input argument. * * @return a unary operator that always returns its input argument */ static ThrowingDoubleUnaryOperator identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
885
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntUnaryOperator; /** * Represents an operation on a single {@code int}-valued operand that produces * an {@code int}-valued result. This is the primitive type specialization of * {@link ThrowingUnaryOperator} for {@code int}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(int)}. * * @see ThrowingUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingIntUnaryOperator extends IntUnaryOperator { /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ int applyAsIntThrows(int operand) throws Exception; /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ default int applyAsInt(int operand) { try { return applyAsIntThrows(operand); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed operator that first applies the {@code before} * operator to its input, and then applies this operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param before the operator to apply before this operator is applied * @return a composed operator that first applies the {@code before} * operator and then applies this operator * @throws NullPointerException if before is null * * @see #andThen(ThrowingIntUnaryOperator) */ default ThrowingIntUnaryOperator compose(ThrowingIntUnaryOperator before) { Objects.requireNonNull(before); return (int v) -> applyAsIntThrows(before.applyAsIntThrows(v)); } /** * Returns a composed operator that first applies this operator to * its input, and then applies the {@code after} operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param after the operator to apply after this operator is applied * @return a composed operator that first applies this operator and then * applies the {@code after} operator * @throws NullPointerException if after is null * * @see #compose(ThrowingIntUnaryOperator) */ default ThrowingIntUnaryOperator andThen(ThrowingIntUnaryOperator after) { Objects.requireNonNull(after); return (int t) -> after.applyAsIntThrows(applyAsIntThrows(t)); } /** * Returns a unary operator that always returns its input argument. * * @return a unary operator that always returns its input argument */ static ThrowingIntUnaryOperator identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
885
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ObjIntConsumer; /** * Represents an operation that accepts an object-valued and a * {@code int}-valued argument, and returns no result. This is the * {@code (reference, int)} specialization of {@link ThrowingBiConsumer}. * Unlike most other functional interfaces, {@code ThrowingObjIntConsumer} is * expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, int)}. * * @param <T> the type of the object argument to the operation * * @see ThrowingBiConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingObjIntConsumer<T> extends ObjIntConsumer<T> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ void acceptThrows(T t, int value) throws Exception; /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ default void accept(T t, int value) { try { acceptThrows(t, value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingObjIntConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
542
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; /** * Represents an operation on a single operand that produces a result of the * same type as its operand. This is a specialization of {@code ThrowingFunction} for * the case where the operand and result are of the same type. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object)}. * * @param <T> the type of the operand and result of the operator * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingUnaryOperator<T> extends ThrowingFunction<T, T> { /** * Returns a unary operator that always returns its input argument. * * @param <T> the type of the input and output of the operator * @return a unary operator that always returns its input argument */ static <T> ThrowingUnaryOperator<T> identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
436
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntConsumer; /** * Represents an operation that accepts a single {@code int}-valued argument and * returns no result. This is the primitive type specialization of * {@link ThrowingConsumer} for {@code int}. Unlike most other functional interfaces, * {@code ThrowingIntConsumer} is expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(int)}. * * @see ThrowingConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingIntConsumer extends IntConsumer { /** * Performs this operation on the given argument. * * @param value the input argument */ void acceptThrows(int value) throws Exception; /** * Performs this operation on the given argument. * * @param value the input argument */ default void accept(int value) { try { acceptThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed {@code ThrowingIntConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code ThrowingIntConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default ThrowingIntConsumer andThen(ThrowingIntConsumer after) { Objects.requireNonNull(after); return (int t) -> { acceptThrows(t); after.acceptThrows(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
666
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntToLongFunction; /** * Represents a function that accepts an int-valued argument and produces a * long-valued result. This is the {@code int}-to-{@code long} primitive * specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(int)}. * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingIntToLongFunction extends IntToLongFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ long applyAsLongThrows(int value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default long applyAsLong(int value) { try { return applyAsLongThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntToLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
488
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleSupplier; /** * Represents a supplier of {@code double}-valued results. This is the * {@code double}-producing primitive specialization of {@link ThrowingSupplier}. * * <p>There is no requirement that a distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsDouble()}. * * @see ThrowingSupplier * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleSupplier extends DoubleSupplier { /** * Gets a result. * * @return a result */ double getAsDoubleThrows() throws Exception; /** * Gets a result. * * @return a result */ default double getAsDouble() { try { return getAsDoubleThrows(); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
459
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleToLongFunction; /** * Represents a function that accepts a double-valued argument and produces a * long-valued result. This is the {@code double}-to-{@code long} primitive * specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(double)}. * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleToLongFunction extends DoubleToLongFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ long applyAsLongThrows(double value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default long applyAsLong(double value) { try { return applyAsLongThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleToLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
488
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.extension.TriPredicate; @FunctionalInterface public interface ThrowingTriPredicate<T, U, V> extends TriPredicate<T, U, V> { boolean testThrows(T t, U u, V v) throws Exception; default boolean test(T t, U u, V v) { try { return testThrows(t, u, v); } catch (Exception e) { throw new FunctionalException(e); } } default ThrowingTriPredicate<T, U, V> and(ThrowingTriPredicate<? super T, ? super U, ? super V> other) { Objects.requireNonNull(other); return (T t, U u, V v) -> testThrows(t, u, v) && other.testThrows(t, u, v); } default ThrowingTriPredicate<T, U, V> negate() { return (T t, U u, V v) -> !testThrows(t, u, v); } default ThrowingTriPredicate<T, U, V> or(ThrowingTriPredicate<? super T, ? super U, ? super V> other) { Objects.requireNonNull(other); return (T t, U u, V v) -> testThrows(t, u, v) || other.testThrows(t, u, v); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingTriPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
325
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.ObjectsCompat; import me.zhanghai.android.douya.functional.compat.Predicate; /** * Represents a predicate (boolean-valued function) of one argument. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(Object)}. * * @param <T> the type of the input to the predicate * * @since 1.8 */ @FunctionalInterface public interface ThrowingPredicate<T> extends Predicate<T> { /** * Evaluates this predicate on the given argument. * * @param t the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean testThrows(T t) throws Exception; /** * Evaluates this predicate on the given argument. * * @param t the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ default boolean test(T t) { try { return testThrows(t); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingPredicate<T> and(ThrowingPredicate<? super T> other) { Objects.requireNonNull(other); return (t) -> testThrows(t) && other.testThrows(t); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default ThrowingPredicate<T> negate() { return (t) -> !testThrows(t); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingPredicate<T> or(ThrowingPredicate<? super T> other) { Objects.requireNonNull(other); return (t) -> testThrows(t) || other.testThrows(t); } /** * Returns a predicate that tests if two arguments are equal according * to {@link Objects#equals(Object, Object)}. * * @param <T> the type of arguments to the predicate * @param targetRef the object reference with which to compare for equality, * which may be {@code null} * @return a predicate that tests if two arguments are equal according * to {@link Objects#equals(Object, Object)} */ static <T> ThrowingPredicate<T> isEqual(Object targetRef) { return (null == targetRef) ? ObjectsCompat::isNull : object -> targetRef.equals(object); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,137
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongConsumer; /** * Represents an operation that accepts a single {@code long}-valued argument and * returns no result. This is the primitive type specialization of * {@link ThrowingConsumer} for {@code long}. Unlike most other functional interfaces, * {@code ThrowingLongConsumer} is expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(long)}. * * @see ThrowingConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingLongConsumer extends LongConsumer { /** * Performs this operation on the given argument. * * @param value the input argument */ void acceptThrows(long value) throws Exception; /** * Performs this operation on the given argument. * * @param value the input argument */ default void accept(long value) { try { acceptThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed {@code ThrowingLongConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code ThrowingLongConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default ThrowingLongConsumer andThen(ThrowingLongConsumer after) { Objects.requireNonNull(after); return (long t) -> { acceptThrows(t); after.acceptThrows(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
666
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ToDoubleBiFunction; /** * Represents a function that accepts two arguments and produces a double-valued * result. This is the {@code double}-producing primitive specialization for * {@link ThrowingBiFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * * @see ThrowingBiFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingToDoubleBiFunction<T, U> extends ToDoubleBiFunction<T, U> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ double applyAsDoubleThrows(T t, U u) throws Exception; /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ default double applyAsDouble(T t, U u) { try { return applyAsDoubleThrows(t, u); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingToDoubleBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
555
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntToDoubleFunction; /** * Represents a function that accepts an int-valued argument and produces a * double-valued result. This is the {@code int}-to-{@code double} primitive * specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(int)}. * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingIntToDoubleFunction extends IntToDoubleFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ double applyAsDoubleThrows(int value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default double applyAsDouble(int value) { try { return applyAsDoubleThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntToDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
488
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.extension.TriFunction; @FunctionalInterface public interface ThrowingTriFunction<T, U, V, R> extends TriFunction<T, U, V, R> { R applyThrows(T t, U u, V v) throws Exception; default R apply(T t, U u, V v) { try { return applyThrows(t, u, v); } catch (Exception e) { throw new FunctionalException(e); } } default <W> ThrowingTriFunction<T, U, V, W> andThen(ThrowingFunction<? super R, ? extends W> after) { Objects.requireNonNull(after); return (T t, U u, V v) -> after.applyThrows(applyThrows(t, u, v)); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingTriFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
214
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntBinaryOperator; /** * Represents an operation upon two {@code int}-valued operands and producing an * {@code int}-valued result. This is the primitive type specialization of * {@link ThrowingBinaryOperator} for {@code int}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(int, int)}. * * @see ThrowingBinaryOperator * @see ThrowingIntUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingIntBinaryOperator extends IntBinaryOperator { /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ int applyAsIntThrows(int left, int right) throws Exception; /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ default int applyAsInt(int left, int right) { try { return applyAsIntThrows(left, right); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
525
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.Supplier; /** * Represents a supplier of results. * * <p>There is no requirement that a new or distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #get()}. * * @param <T> the type of results supplied by this supplier * * @since 1.8 */ @FunctionalInterface public interface ThrowingSupplier<T> extends Supplier<T> { /** * Gets a result. * * @return a result */ T getThrows() throws Exception; /** * Gets a result. * * @return a result */ default T get() { try { return getThrows(); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
438
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ObjDoubleConsumer; /** * Represents an operation that accepts an object-valued and a * {@code double}-valued argument, and returns no result. This is the * {@code (reference, double)} specialization of {@link ThrowingBiConsumer}. * Unlike most other functional interfaces, {@code ThrowingObjDoubleConsumer} is * expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, double)}. * * @param <T> the type of the object argument to the operation * * @see ThrowingBiConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingObjDoubleConsumer<T> extends ObjDoubleConsumer<T> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ void acceptThrows(T t, double value) throws Exception; /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ default void accept(T t, double value) { try { acceptThrows(t, value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingObjDoubleConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
542
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongUnaryOperator; /** * Represents an operation on a single {@code long}-valued operand that produces * a {@code long}-valued result. This is the primitive type specialization of * {@link ThrowingUnaryOperator} for {@code long}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(long)}. * * @see ThrowingUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingLongUnaryOperator extends LongUnaryOperator { /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ long applyAsLongThrows(long operand) throws Exception; /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ default long applyAsLong(long operand) { try { return applyAsLongThrows(operand); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed operator that first applies the {@code before} * operator to its input, and then applies this operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param before the operator to apply before this operator is applied * @return a composed operator that first applies the {@code before} * operator and then applies this operator * @throws NullPointerException if before is null * * @see #andThen(ThrowingLongUnaryOperator) */ default ThrowingLongUnaryOperator compose(ThrowingLongUnaryOperator before) { Objects.requireNonNull(before); return (long v) -> applyAsLongThrows(before.applyAsLongThrows(v)); } /** * Returns a composed operator that first applies this operator to * its input, and then applies the {@code after} operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param after the operator to apply after this operator is applied * @return a composed operator that first applies this operator and then * applies the {@code after} operator * @throws NullPointerException if after is null * * @see #compose(ThrowingLongUnaryOperator) */ default ThrowingLongUnaryOperator andThen(ThrowingLongUnaryOperator after) { Objects.requireNonNull(after); return (long t) -> after.applyAsLongThrows(applyAsLongThrows(t)); } /** * Returns a unary operator that always returns its input argument. * * @return a unary operator that always returns its input argument */ static ThrowingLongUnaryOperator identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
885
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.Function; /** * Represents a function that accepts one argument and produces a result. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object)}. * * @param <T> the type of the input to the function * @param <R> the type of the result of the function * * @since 1.8 */ @FunctionalInterface public interface ThrowingFunction<T, R> extends Function<T, R> { /** * Applies this function to the given argument. * * @param t the function argument * @return the function result */ R applyThrows(T t) throws Exception; /** * Applies this function to the given argument. * * @param t the function argument * @return the function result */ default R apply(T t) { try { return applyThrows(t); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed function that first applies the {@code before} * function to its input, and then applies this function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of input to the {@code before} function, and to the * composed function * @param before the function to apply before this function is applied * @return a composed function that first applies the {@code before} * function and then applies this function * @throws NullPointerException if before is null * * @see #andThen(ThrowingFunction) */ default <V> ThrowingFunction<V, R> compose(ThrowingFunction<? super V, ? extends T> before) { Objects.requireNonNull(before); return (V v) -> applyThrows(before.applyThrows(v)); } /** * Returns a composed function that first applies this function to * its input, and then applies the {@code after} function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of output of the {@code after} function, and of the * composed function * @param after the function to apply after this function is applied * @return a composed function that first applies this function and then * applies the {@code after} function * @throws NullPointerException if after is null * * @see #compose(ThrowingFunction) */ default <V> ThrowingFunction<T, V> andThen(ThrowingFunction<? super R, ? extends V> after) { Objects.requireNonNull(after); return (T t) -> after.applyThrows(applyThrows(t)); } /** * Returns a function that always returns its input argument. * * @param <T> the type of the input and output objects to the function * @return a function that always returns its input argument */ static <T> ThrowingFunction<T, T> identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
957
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongBinaryOperator; /** * Represents an operation upon two {@code long}-valued operands and producing a * {@code long}-valued result. This is the primitive type specialization of * {@link ThrowingBinaryOperator} for {@code long}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(long, long)}. * * @see ThrowingBinaryOperator * @see ThrowingLongUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingLongBinaryOperator extends LongBinaryOperator { /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ long applyAsLongThrows(long left, long right) throws Exception; /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ default long applyAsLong(long left, long right) { try { return applyAsLongThrows(left, right); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
525
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoublePredicate; /** * Represents a predicate (boolean-valued function) of one {@code double}-valued * argument. This is the {@code double}-consuming primitive type specialization * of {@link ThrowingPredicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(double)}. * * @see ThrowingPredicate * @since 1.8 */ @FunctionalInterface public interface ThrowingDoublePredicate extends DoublePredicate { /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean testThrows(double value) throws Exception; /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ default boolean test(double value) { try { return testThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingDoublePredicate and(ThrowingDoublePredicate other) { Objects.requireNonNull(other); return (value) -> testThrows(value) && other.testThrows(value); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default ThrowingDoublePredicate negate() { return (value) -> !testThrows(value); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingDoublePredicate or(ThrowingDoublePredicate other) { Objects.requireNonNull(other); return (value) -> testThrows(value) || other.testThrows(value); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoublePredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
991
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.extension.QuadPredicate; @FunctionalInterface public interface ThrowingQuadPredicate<T, U, V, W> extends QuadPredicate<T, U, V, W> { boolean testThrows(T t, U u, V v, W w) throws Exception; default boolean test(T t, U u, V v, W w) { try { return testThrows(t, u, v, w); } catch (Exception e) { throw new FunctionalException(e); } } default ThrowingQuadPredicate<T, U, V, W> and( ThrowingQuadPredicate<? super T, ? super U, ? super V, ? super W> other) { Objects.requireNonNull(other); return (T t, U u, V v, W w) -> testThrows(t, u, v, w) && other.testThrows(t, u, v, w); } default ThrowingQuadPredicate<T, U, V, W> negate() { return (T t, U u, V v, W w) -> !testThrows(t, u, v, w); } default ThrowingQuadPredicate<T, U, V, W> or( ThrowingQuadPredicate<? super T, ? super U, ? super V, ? super W> other) { Objects.requireNonNull(other); return (T t, U u, V v, W w) -> testThrows(t, u, v, w) || other.testThrows(t, u, v, w); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingQuadPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
371
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.extension.QuadConsumer; @FunctionalInterface public interface ThrowingQuadConsumer<T, U, V, W> extends QuadConsumer<T, U, V, W> { void acceptThrows(T t, U u, V v, W w) throws Exception; default void accept(T t, U u, V v, W w) { try { acceptThrows(t, u, v, w); } catch (Exception e) { throw new FunctionalException(e); } } default ThrowingQuadConsumer<T, U, V, W> andThen( ThrowingQuadConsumer<? super T, ? super U, ? super V, ? super W> after) { Objects.requireNonNull(after); return (t, u, v, w) -> { acceptThrows(t, u, v, w); after.acceptThrows(t, u, v, w); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingQuadConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
240
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Comparator; import java.util.Objects; @FunctionalInterface public interface ThrowingQuaternaryOperator<T> extends ThrowingQuadFunction<T, T, T, T, T> { static <T> ThrowingQuaternaryOperator<T> minBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b, c, d) -> comparator.compare(a, b) <= 0 ? comparator.compare(a, c) <= 0 ? comparator.compare(a, d) <= 0 ? a : d : comparator.compare(c, d) <= 0 ? c : d : comparator.compare(b, c) <= 0 ? comparator.compare(b, d) <= 0 ? b : d : comparator.compare(c, d) <= 0 ? c : d; } static <T> ThrowingQuaternaryOperator<T> maxBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b, c, d) -> comparator.compare(a, b) >= 0 ? comparator.compare(a, c) >= 0 ? comparator.compare(a, d) >= 0 ? a : d : comparator.compare(c, d) >= 0 ? c : d : comparator.compare(b, c) >= 0 ? comparator.compare(b, d) >= 0 ? b : d : comparator.compare(c, d) >= 0 ? c : d; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingQuaternaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
340
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.BiConsumer; /** * Represents an operation that accepts two input arguments and returns no * result. This is the two-arity specialization of {@link ThrowingConsumer}. * Unlike most other functional interfaces, {@code ThrowingBiConsumer} is expected * to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, Object)}. * * @param <T> the type of the first argument to the operation * @param <U> the type of the second argument to the operation * * @see ThrowingConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingBiConsumer<T, U> extends BiConsumer<T, U> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param u the second input argument */ void acceptThrows(T t, U u) throws Exception; /** * Performs this operation on the given arguments. * * @param t the first input argument * @param u the second input argument */ default void accept(T t, U u) { try { acceptThrows(t, u); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed {@code ThrowingBiConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code ThrowingBiConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default ThrowingBiConsumer<T, U> andThen(ThrowingBiConsumer<? super T, ? super U> after) { Objects.requireNonNull(after); return (l, r) -> { acceptThrows(l, r); after.acceptThrows(l, r); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingBiConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
749
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongToDoubleFunction; /** * Represents a function that accepts a long-valued argument and produces a * double-valued result. This is the {@code long}-to-{@code double} primitive * specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(long)}. * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingLongToDoubleFunction extends LongToDoubleFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ double applyAsDoubleThrows(long value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default double applyAsDouble(long value) { try { return applyAsDoubleThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongToDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
488
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntPredicate; /** * Represents a predicate (boolean-valued function) of one {@code int}-valued * argument. This is the {@code int}-consuming primitive type specialization of * {@link ThrowingPredicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(int)}. * * @see ThrowingPredicate * @since 1.8 */ @FunctionalInterface public interface ThrowingIntPredicate extends IntPredicate { /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean testThrows(int value) throws Exception; /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ default boolean test(int value) { try { return testThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingIntPredicate and(ThrowingIntPredicate other) { Objects.requireNonNull(other); return (value) -> testThrows(value) && other.testThrows(value); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default ThrowingIntPredicate negate() { return (value) -> !testThrows(value); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingIntPredicate or(ThrowingIntPredicate other) { Objects.requireNonNull(other); return (value) -> testThrows(value) || other.testThrows(value); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
991
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntSupplier; /** * Represents a supplier of {@code int}-valued results. This is the * {@code int}-producing primitive specialization of {@link ThrowingSupplier}. * * <p>There is no requirement that a distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsInt()}. * * @see ThrowingSupplier * @since 1.8 */ @FunctionalInterface public interface ThrowingIntSupplier extends IntSupplier { /** * Gets a result. * * @return a result */ int getAsIntThrows() throws Exception; /** * Gets a result. * * @return a result */ default int getAsInt() { try { return getAsIntThrows(); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
459
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongSupplier; /** * Represents a supplier of {@code long}-valued results. This is the * {@code long}-producing primitive specialization of {@link ThrowingSupplier}. * * <p>There is no requirement that a distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsLong()}. * * @see ThrowingSupplier * @since 1.8 */ @FunctionalInterface public interface ThrowingLongSupplier extends LongSupplier { /** * Gets a result. * * @return a result */ long getAsLongThrows() throws Exception; /** * Gets a result. * * @return a result */ default long getAsLong() { try { return getAsLongThrows(); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
459
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.extension.QuadFunction; @FunctionalInterface public interface ThrowingQuadFunction<T, U, V, W, R> extends QuadFunction<T, U, V, W, R> { R applyThrows(T t, U u, V v, W w) throws Exception; default R apply(T t, U u, V v, W w) { try { return applyThrows(t, u, v, w); } catch (Exception e) { throw new FunctionalException(e); } } default <X> ThrowingQuadFunction<T, U, V, W, X> andThen(ThrowingFunction<? super R, ? extends X> after) { Objects.requireNonNull(after); return (T t, U u, V v, W w) -> after.applyThrows(applyThrows(t, u, v, w)); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingQuadFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
232
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleConsumer; /** * Represents an operation that accepts a single {@code double}-valued argument and * returns no result. This is the primitive type specialization of * {@link ThrowingConsumer} for {@code double}. Unlike most other functional interfaces, * {@code ThrowingDoubleConsumer} is expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(double)}. * * @see ThrowingConsumer * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleConsumer extends DoubleConsumer { /** * Performs this operation on the given argument. * * @param value the input argument */ void acceptThrows(double value) throws Exception; /** * Performs this operation on the given argument. * * @param value the input argument */ default void accept(double value) { try { acceptThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed {@code ThrowingDoubleConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code ThrowingDoubleConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default ThrowingDoubleConsumer andThen(ThrowingDoubleConsumer after) { Objects.requireNonNull(after); return (double t) -> { acceptThrows(t); after.acceptThrows(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
666
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Comparator; import java.util.Objects; @FunctionalInterface public interface ThrowingTertiaryOperator<T> extends ThrowingTriFunction<T, T, T, T> { static <T> ThrowingTertiaryOperator<T> minBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b, c) -> comparator.compare(a, b) <= 0 ? comparator.compare(a, c) <= 0 ? a : c : comparator.compare(b, c) <= 0 ? b : c; } static <T> ThrowingTertiaryOperator<T> maxBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b, c) -> comparator.compare(a, b) >= 0 ? comparator.compare(a, c) >= 0 ? a : c : comparator.compare(b, c) >= 0 ? b : c; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingTertiaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
223
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleToIntFunction; /** * Represents a function that accepts a double-valued argument and produces an * int-valued result. This is the {@code double}-to-{@code int} primitive * specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(double)}. * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleToIntFunction extends DoubleToIntFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ int applyAsIntThrows(double value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default int applyAsInt(double value) { try { return applyAsIntThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleToIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
485
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ToLongBiFunction; /** * Represents a function that accepts two arguments and produces a long-valued * result. This is the {@code long}-producing primitive specialization for * {@link ThrowingBiFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * * @see ThrowingBiFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingToLongBiFunction<T, U> extends ToLongBiFunction<T, U> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ long applyAsLongThrows(T t, U u) throws Exception; /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ default long applyAsLong(T t, U u) { try { return applyAsLongThrows(t, u); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingToLongBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
556
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import java.util.Comparator; /** * Represents an operation upon two operands of the same type, producing a result * of the same type as the operands. This is a specialization of * {@link ThrowingBiFunction} for the case where the operands and the result are all of * the same type. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object, Object)}. * * @param <T> the type of the operands and result of the operator * * @see ThrowingBiFunction * @see ThrowingUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingBinaryOperator<T> extends ThrowingBiFunction<T,T,T> { /** * Returns a {@link ThrowingBinaryOperator} which returns the lesser of two elements * according to the specified {@code Comparator}. * * @param <T> the type of the input arguments of the comparator * @param comparator a {@code Comparator} for comparing the two values * @return a {@code ThrowingBinaryOperator} which returns the lesser of its operands, * according to the supplied {@code Comparator} * @throws NullPointerException if the argument is null */ static <T> ThrowingBinaryOperator<T> minBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b) -> comparator.compare(a, b) <= 0 ? a : b; } /** * Returns a {@link ThrowingBinaryOperator} which returns the greater of two elements * according to the specified {@code Comparator}. * * @param <T> the type of the input arguments of the comparator * @param comparator a {@code Comparator} for comparing the two values * @return a {@code ThrowingBinaryOperator} which returns the greater of its operands, * according to the supplied {@code Comparator} * @throws NullPointerException if the argument is null */ static <T> ThrowingBinaryOperator<T> maxBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b) -> comparator.compare(a, b) >= 0 ? a : b; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
717
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ToIntFunction; /** * Represents a function that produces an int-valued result. This is the * {@code int}-producing primitive specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(Object)}. * * @param <T> the type of the input to the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingToIntFunction<T> extends ToIntFunction<T> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ int applyAsIntThrows(T value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default int applyAsInt(T value) { try { return applyAsIntThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingToIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
490
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleBinaryOperator; /** * Represents an operation upon two {@code double}-valued operands and producing a * {@code double}-valued result. This is the primitive type specialization of * {@link ThrowingBinaryOperator} for {@code double}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(double, double)}. * * @see ThrowingBinaryOperator * @see ThrowingDoubleUnaryOperator * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleBinaryOperator extends DoubleBinaryOperator { /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ double applyAsDoubleThrows(double left, double right) throws Exception; /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ default double applyAsDouble(double left, double right) { try { return applyAsDoubleThrows(left, right); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
525
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongPredicate; /** * Represents a predicate (boolean-valued function) of one {@code long}-valued * argument. This is the {@code long}-consuming primitive type specialization of * {@link ThrowingPredicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(long)}. * * @see ThrowingPredicate * @since 1.8 */ @FunctionalInterface public interface ThrowingLongPredicate extends LongPredicate { /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean testThrows(long value) throws Exception; /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ default boolean test(long value) { try { return testThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingLongPredicate and(ThrowingLongPredicate other) { Objects.requireNonNull(other); return (value) -> testThrows(value) && other.testThrows(value); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default ThrowingLongPredicate negate() { return (value) -> !testThrows(value); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingLongPredicate or(ThrowingLongPredicate other) { Objects.requireNonNull(other); return (value) -> testThrows(value) || other.testThrows(value); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
991
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.BooleanSupplier; /** * Represents a supplier of {@code boolean}-valued results. This is the * {@code boolean}-producing primitive specialization of {@link ThrowingSupplier}. * * <p>There is no requirement that a new or distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsBoolean()}. * * @see ThrowingSupplier * @since 1.8 */ @FunctionalInterface public interface ThrowingBooleanSupplier extends BooleanSupplier { /** * Gets a result. * * @return a result */ boolean getAsBooleanThrows() throws Exception; /** * Gets a result. * * @return a result */ default boolean getAsBoolean() { try { return getAsBooleanThrows(); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingBooleanSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
461
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.DoubleFunction; /** * Represents a function that accepts a double-valued argument and produces a * result. This is the {@code double}-consuming primitive specialization for * {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(double)}. * * @param <R> the type of the result of the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingDoubleFunction<R> extends DoubleFunction<R> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ R applyThrows(double value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default R apply(double value) { try { return applyThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
487
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongFunction; /** * Represents a function that accepts a long-valued argument and produces a * result. This is the {@code long}-consuming primitive specialization for * {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(long)}. * * @param <R> the type of the result of the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingLongFunction<R> extends LongFunction<R> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ R applyThrows(long value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default R apply(long value) { try { return applyThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
487
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.Consumer; /** * Represents an operation that accepts a single input argument and returns no * result. Unlike most other functional interfaces, {@code ThrowingConsumer} is expected * to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object)}. * * @param <T> the type of the input to the operation * * @since 1.8 */ @FunctionalInterface public interface ThrowingConsumer<T> extends Consumer<T> { /** * Performs this operation on the given argument. * * @param t the input argument */ void acceptThrows(T t) throws Exception; /** * Performs this operation on the given argument. * * @param t the input argument */ default void accept(T t) { try { acceptThrows(t); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed {@code ThrowingConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code ThrowingConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default ThrowingConsumer<T> andThen(ThrowingConsumer<? super T> after) { Objects.requireNonNull(after); return (T t) -> { acceptThrows(t); after.acceptThrows(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
651
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.BiFunction; /** * Represents a function that accepts two arguments and produces a result. * This is the two-arity specialization of {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * @param <R> the type of the result of the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingBiFunction<T, U, R> extends BiFunction<T, U, R> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ R applyThrows(T t, U u) throws Exception; /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ default R apply(T t, U u) { try { return applyThrows(t, u); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed function that first applies this function to * its input, and then applies the {@code after} function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of output of the {@code after} function, and of the * composed function * @param after the function to apply after this function is applied * @return a composed function that first applies this function and then * applies the {@code after} function * @throws NullPointerException if after is null */ default <V> ThrowingBiFunction<T, U, V> andThen(ThrowingFunction<? super R, ? extends V> after) { Objects.requireNonNull(after); return (T t, U u) -> after.applyThrows(applyThrows(t, u)); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
755
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.LongToIntFunction; /** * Represents a function that accepts a long-valued argument and produces an * int-valued result. This is the {@code long}-to-{@code int} primitive * specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(long)}. * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingLongToIntFunction extends LongToIntFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ int applyAsIntThrows(long value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default int applyAsInt(long value) { try { return applyAsIntThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingLongToIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
485
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.IntFunction; /** * Represents a function that accepts an int-valued argument and produces a * result. This is the {@code int}-consuming primitive specialization for * {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(int)}. * * @param <R> the type of the result of the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingIntFunction<R> extends IntFunction<R> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ R applyThrows(int value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default R apply(int value) { try { return applyThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
487
```java /* * All Rights Reserved. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.extension.TriConsumer; @FunctionalInterface public interface ThrowingTriConsumer<T, U, V> extends TriConsumer<T, U, V> { void acceptThrows(T t, U u, V v) throws Exception; default void accept(T t, U u, V v) { try { acceptThrows(t, u, v); } catch (Exception e) { throw new FunctionalException(e); } } default ThrowingTriConsumer<T, U, V> andThen(ThrowingTriConsumer<? super T, ? super U, ? super V> after) { Objects.requireNonNull(after); return (t, u, v) -> { acceptThrows(t, u, v); after.acceptThrows(t, u, v); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingTriConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
216
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.ToLongFunction; /** * Represents a function that produces a long-valued result. This is the * {@code long}-producing primitive specialization for {@link ThrowingFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(Object)}. * * @param <T> the type of the input to the function * * @see ThrowingFunction * @since 1.8 */ @FunctionalInterface public interface ThrowingToLongFunction<T> extends ToLongFunction<T> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ long applyAsLongThrows(T value) throws Exception; /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ default long applyAsLong(T value) { try { return applyAsLongThrows(value); } catch (Exception e) { throw new FunctionalException(e); } } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingToLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
492
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation that accepts an object-valued and a * {@code int}-valued argument, and returns no result. This is the * {@code (reference, int)} specialization of {@link BiConsumer}. * Unlike most other functional interfaces, {@code ObjIntConsumer} is * expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, int)}. * * @param <T> the type of the object argument to the operation * * @see BiConsumer * @since 1.8 */ @FunctionalInterface public interface ObjIntConsumer<T> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ void accept(T t, int value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ObjIntConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
418
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.throwing; import java.util.Objects; import me.zhanghai.android.douya.functional.FunctionalException; import me.zhanghai.android.douya.functional.compat.BiPredicate; /** * Represents a predicate (boolean-valued function) of two arguments. This is * the two-arity specialization of {@link ThrowingPredicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(Object, Object)}. * * @param <T> the type of the first argument to the predicate * @param <U> the type of the second argument the predicate * * @see ThrowingPredicate * @since 1.8 */ @FunctionalInterface public interface ThrowingBiPredicate<T, U> extends BiPredicate<T, U> { /** * Evaluates this predicate on the given arguments. * * @param t the first input argument * @param u the second input argument * @return {@code true} if the input arguments match the predicate, * otherwise {@code false} */ boolean testThrows(T t, U u) throws Exception; /** * Evaluates this predicate on the given arguments. * * @param t the first input argument * @param u the second input argument * @return {@code true} if the input arguments match the predicate, * otherwise {@code false} */ default boolean test(T t, U u) { try { return testThrows(t, u); } catch (Exception e) { throw new FunctionalException(e); } } /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingBiPredicate<T, U> and(ThrowingBiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (T t, U u) -> testThrows(t, u) && other.testThrows(t, u); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default ThrowingBiPredicate<T, U> negate() { return (T t, U u) -> !testThrows(t, u); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default ThrowingBiPredicate<T, U> or(ThrowingBiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (T t, U u) -> testThrows(t, u) || other.testThrows(t, u); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/throwing/ThrowingBiPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
1,102
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation that accepts an object-valued and a * {@code long}-valued argument, and returns no result. This is the * {@code (reference, long)} specialization of {@link BiConsumer}. * Unlike most other functional interfaces, {@code ObjLongConsumer} is * expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, long)}. * * @param <T> the type of the object argument to the operation * * @see BiConsumer * @since 1.8 */ @FunctionalInterface public interface ObjLongConsumer<T> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ void accept(T t, long value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ObjLongConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
418
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a supplier of {@code int}-valued results. This is the * {@code int}-producing primitive specialization of {@link Supplier}. * * <p>There is no requirement that a distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsInt()}. * * @see Supplier * @since 1.8 */ @FunctionalInterface public interface IntSupplier { /** * Gets a result. * * @return a result */ int getAsInt(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
361
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a supplier of {@code double}-valued results. This is the * {@code double}-producing primitive specialization of {@link Supplier}. * * <p>There is no requirement that a distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsDouble()}. * * @see Supplier * @since 1.8 */ @FunctionalInterface public interface DoubleSupplier { /** * Gets a result. * * @return a result */ double getAsDouble(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
361
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents a function that accepts two arguments and produces a result. * This is the two-arity specialization of {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * @param <R> the type of the result of the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface BiFunction<T, U, R> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ R apply(T t, U u); /** * Returns a composed function that first applies this function to * its input, and then applies the {@code after} function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of output of the {@code after} function, and of the * composed function * @param after the function to apply after this function is applied * @return a composed function that first applies this function and then * applies the {@code after} function * @throws NullPointerException if after is null */ default <V> BiFunction<T, U, V> andThen(Function<? super R, ? extends V> after) { Objects.requireNonNull(after); return (T t, U u) -> after.apply(apply(t, u)); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/BiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
614
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation that accepts two input arguments and returns no * result. This is the two-arity specialization of {@link Consumer}. * Unlike most other functional interfaces, {@code BiConsumer} is expected * to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, Object)}. * * @param <T> the type of the first argument to the operation * @param <U> the type of the second argument to the operation * * @see Consumer * @since 1.8 */ @FunctionalInterface public interface BiConsumer<T, U> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param u the second input argument */ void accept(T t, U u); /** * Returns a composed {@code BiConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code BiConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default BiConsumer<T, U> andThen(BiConsumer<? super T, ? super U> after) { Objects.requireNonNull(after); return (l, r) -> { accept(l, r); after.accept(l, r); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/BiConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
614
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that produces a double-valued result. This is the * {@code double}-producing primitive specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(Object)}. * * @param <T> the type of the input to the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface ToDoubleFunction<T> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ double applyAsDouble(T value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ToDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
373
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; import java.util.Comparator; /** * Represents an operation upon two operands of the same type, producing a result * of the same type as the operands. This is a specialization of * {@link BiFunction} for the case where the operands and the result are all of * the same type. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object, Object)}. * * @param <T> the type of the operands and result of the operator * * @see BiFunction * @see UnaryOperator * @since 1.8 */ @FunctionalInterface public interface BinaryOperator<T> extends BiFunction<T,T,T> { /** * Returns a {@link BinaryOperator} which returns the lesser of two elements * according to the specified {@code Comparator}. * * @param <T> the type of the input arguments of the comparator * @param comparator a {@code Comparator} for comparing the two values * @return a {@code BinaryOperator} which returns the lesser of its operands, * according to the supplied {@code Comparator} * @throws NullPointerException if the argument is null */ public static <T> BinaryOperator<T> minBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b) -> comparator.compare(a, b) <= 0 ? a : b; } /** * Returns a {@link BinaryOperator} which returns the greater of two elements * according to the specified {@code Comparator}. * * @param <T> the type of the input arguments of the comparator * @param comparator a {@code Comparator} for comparing the two values * @return a {@code BinaryOperator} which returns the greater of its operands, * according to the supplied {@code Comparator} * @throws NullPointerException if the argument is null */ public static <T> BinaryOperator<T> maxBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator); return (a, b) -> comparator.compare(a, b) >= 0 ? a : b; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/BinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
696
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; import me.zhanghai.android.douya.functional.ObjectsCompat; /** * Represents a predicate (boolean-valued function) of one argument. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(Object)}. * * @param <T> the type of the input to the predicate * * @since 1.8 */ @FunctionalInterface public interface Predicate<T> { /** * Evaluates this predicate on the given argument. * * @param t the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean test(T t); /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default Predicate<T> and(Predicate<? super T> other) { Objects.requireNonNull(other); return (t) -> test(t) && other.test(t); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default Predicate<T> negate() { return (t) -> !test(t); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default Predicate<T> or(Predicate<? super T> other) { Objects.requireNonNull(other); return (t) -> test(t) || other.test(t); } /** * Returns a predicate that tests if two arguments are equal according * to {@link Objects#equals(Object, Object)}. * * @param <T> the type of arguments to the predicate * @param targetRef the object reference with which to compare for equality, * which may be {@code null} * @return a predicate that tests if two arguments are equal according * to {@link Objects#equals(Object, Object)} */ static <T> Predicate<T> isEqual(Object targetRef) { return (null == targetRef) ? ObjectsCompat::isNull : object -> targetRef.equals(object); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/Predicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
997
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation on a single {@code int}-valued operand that produces * an {@code int}-valued result. This is the primitive type specialization of * {@link UnaryOperator} for {@code int}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(int)}. * * @see UnaryOperator * @since 1.8 */ @FunctionalInterface public interface IntUnaryOperator { /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ int applyAsInt(int operand); /** * Returns a composed operator that first applies the {@code before} * operator to its input, and then applies this operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param before the operator to apply before this operator is applied * @return a composed operator that first applies the {@code before} * operator and then applies this operator * @throws NullPointerException if before is null * * @see #andThen(IntUnaryOperator) */ default IntUnaryOperator compose(IntUnaryOperator before) { Objects.requireNonNull(before); return (int v) -> applyAsInt(before.applyAsInt(v)); } /** * Returns a composed operator that first applies this operator to * its input, and then applies the {@code after} operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param after the operator to apply after this operator is applied * @return a composed operator that first applies this operator and then * applies the {@code after} operator * @throws NullPointerException if after is null * * @see #compose(IntUnaryOperator) */ default IntUnaryOperator andThen(IntUnaryOperator after) { Objects.requireNonNull(after); return (int t) -> after.applyAsInt(applyAsInt(t)); } /** * Returns a unary operator that always returns its input argument. * * @return a unary operator that always returns its input argument */ static IntUnaryOperator identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
746
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts a double-valued argument and produces a * result. This is the {@code double}-consuming primitive specialization for * {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(double)}. * * @param <R> the type of the result of the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface DoubleFunction<R> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ R apply(double value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
374
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts a long-valued argument and produces an * int-valued result. This is the {@code long}-to-{@code int} primitive * specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(long)}. * * @see Function * @since 1.8 */ @FunctionalInterface public interface LongToIntFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ int applyAsInt(long value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongToIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
368
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation upon two {@code int}-valued operands and producing an * {@code int}-valued result. This is the primitive type specialization of * {@link BinaryOperator} for {@code int}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(int, int)}. * * @see BinaryOperator * @see IntUnaryOperator * @since 1.8 */ @FunctionalInterface public interface IntBinaryOperator { /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ int applyAsInt(int left, int right); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
392
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation on a single operand that produces a result of the * same type as its operand. This is a specialization of {@code Function} for * the case where the operand and result are of the same type. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object)}. * * @param <T> the type of the operand and result of the operator * * @see Function * @since 1.8 */ @FunctionalInterface public interface UnaryOperator<T> extends Function<T, T> { /** * Returns a unary operator that always returns its input argument. * * @param <T> the type of the input and output of the operator * @return a unary operator that always returns its input argument */ static <T> UnaryOperator<T> identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/UnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
425
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that produces an int-valued result. This is the * {@code int}-producing primitive specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(Object)}. * * @param <T> the type of the input to the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface ToIntFunction<T> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ int applyAsInt(T value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ToIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
373
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation that accepts a single {@code int}-valued argument and * returns no result. This is the primitive type specialization of * {@link Consumer} for {@code int}. Unlike most other functional interfaces, * {@code IntConsumer} is expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(int)}. * * @see Consumer * @since 1.8 */ @FunctionalInterface public interface IntConsumer { /** * Performs this operation on the given argument. * * @param value the input argument */ void accept(int value); /** * Returns a composed {@code IntConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code IntConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default IntConsumer andThen(IntConsumer after) { Objects.requireNonNull(after); return (int t) -> { accept(t); after.accept(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
551
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation that accepts a single {@code long}-valued argument and * returns no result. This is the primitive type specialization of * {@link Consumer} for {@code long}. Unlike most other functional interfaces, * {@code LongConsumer} is expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(long)}. * * @see Consumer * @since 1.8 */ @FunctionalInterface public interface LongConsumer { /** * Performs this operation on the given argument. * * @param value the input argument */ void accept(long value); /** * Returns a composed {@code LongConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code LongConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default LongConsumer andThen(LongConsumer after) { Objects.requireNonNull(after); return (long t) -> { accept(t); after.accept(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
551
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation upon two {@code double}-valued operands and producing a * {@code double}-valued result. This is the primitive type specialization of * {@link BinaryOperator} for {@code double}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(double, double)}. * * @see BinaryOperator * @see DoubleUnaryOperator * @since 1.8 */ @FunctionalInterface public interface DoubleBinaryOperator { /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ double applyAsDouble(double left, double right); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
392
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that produces a long-valued result. This is the * {@code long}-producing primitive specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(Object)}. * * @param <T> the type of the input to the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface ToLongFunction<T> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ long applyAsLong(T value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ToLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
373
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents a function that accepts one argument and produces a result. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object)}. * * @param <T> the type of the input to the function * @param <R> the type of the result of the function * * @since 1.8 */ @FunctionalInterface public interface Function<T, R> { /** * Applies this function to the given argument. * * @param t the function argument * @return the function result */ R apply(T t); /** * Returns a composed function that first applies the {@code before} * function to its input, and then applies this function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of input to the {@code before} function, and to the * composed function * @param before the function to apply before this function is applied * @return a composed function that first applies the {@code before} * function and then applies this function * @throws NullPointerException if before is null * * @see #andThen(Function) */ default <V> Function<V, R> compose(Function<? super V, ? extends T> before) { Objects.requireNonNull(before); return (V v) -> apply(before.apply(v)); } /** * Returns a composed function that first applies this function to * its input, and then applies the {@code after} function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of output of the {@code after} function, and of the * composed function * @param after the function to apply after this function is applied * @return a composed function that first applies this function and then * applies the {@code after} function * @throws NullPointerException if after is null * * @see #compose(Function) */ default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) { Objects.requireNonNull(after); return (T t) -> after.apply(apply(t)); } /** * Returns a function that always returns its input argument. * * @param <T> the type of the input and output objects to the function * @return a function that always returns its input argument */ static <T> Function<T, T> identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/Function.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
826
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation on a single {@code double}-valued operand that produces * a {@code double}-valued result. This is the primitive type specialization of * {@link UnaryOperator} for {@code double}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(double)}. * * @see UnaryOperator * @since 1.8 */ @FunctionalInterface public interface DoubleUnaryOperator { /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ double applyAsDouble(double operand); /** * Returns a composed operator that first applies the {@code before} * operator to its input, and then applies this operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param before the operator to apply before this operator is applied * @return a composed operator that first applies the {@code before} * operator and then applies this operator * @throws NullPointerException if before is null * * @see #andThen(DoubleUnaryOperator) */ default DoubleUnaryOperator compose(DoubleUnaryOperator before) { Objects.requireNonNull(before); return (double v) -> applyAsDouble(before.applyAsDouble(v)); } /** * Returns a composed operator that first applies this operator to * its input, and then applies the {@code after} operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param after the operator to apply after this operator is applied * @return a composed operator that first applies this operator and then * applies the {@code after} operator * @throws NullPointerException if after is null * * @see #compose(DoubleUnaryOperator) */ default DoubleUnaryOperator andThen(DoubleUnaryOperator after) { Objects.requireNonNull(after); return (double t) -> after.applyAsDouble(applyAsDouble(t)); } /** * Returns a unary operator that always returns its input argument. * * @return a unary operator that always returns its input argument */ static DoubleUnaryOperator identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
746
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a supplier of {@code boolean}-valued results. This is the * {@code boolean}-producing primitive specialization of {@link Supplier}. * * <p>There is no requirement that a new or distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsBoolean()}. * * @see Supplier * @since 1.8 */ @FunctionalInterface public interface BooleanSupplier { /** * Gets a result. * * @return a result */ boolean getAsBoolean(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/BooleanSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
363
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents a predicate (boolean-valued function) of two arguments. This is * the two-arity specialization of {@link Predicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(Object, Object)}. * * @param <T> the type of the first argument to the predicate * @param <U> the type of the second argument the predicate * * @see Predicate * @since 1.8 */ @FunctionalInterface public interface BiPredicate<T, U> { /** * Evaluates this predicate on the given arguments. * * @param t the first input argument * @param u the second input argument * @return {@code true} if the input arguments match the predicate, * otherwise {@code false} */ boolean test(T t, U u); /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (T t, U u) -> test(t, u) && other.test(t, u); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default BiPredicate<T, U> negate() { return (T t, U u) -> !test(t, u); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (T t, U u) -> test(t, u) || other.test(t, u); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/BiPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
939
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts a double-valued argument and produces a * long-valued result. This is the {@code double}-to-{@code long} primitive * specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(double)}. * * @see Function * @since 1.8 */ @FunctionalInterface public interface DoubleToLongFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ long applyAsLong(double value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleToLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
369
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents a predicate (boolean-valued function) of one {@code long}-valued * argument. This is the {@code long}-consuming primitive type specialization of * {@link Predicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(long)}. * * @see Predicate * @since 1.8 */ @FunctionalInterface public interface LongPredicate { /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean test(long value); /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default LongPredicate and(LongPredicate other) { Objects.requireNonNull(other); return (value) -> test(value) && other.test(value); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default LongPredicate negate() { return (value) -> !test(value); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default LongPredicate or(LongPredicate other) { Objects.requireNonNull(other); return (value) -> test(value) || other.test(value); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongPredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
847
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts an int-valued argument and produces a * double-valued result. This is the {@code int}-to-{@code double} primitive * specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(int)}. * * @see Function * @since 1.8 */ @FunctionalInterface public interface IntToDoubleFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ double applyAsDouble(int value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntToDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
369
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts a double-valued argument and produces an * int-valued result. This is the {@code double}-to-{@code int} primitive * specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(double)}. * * @see Function * @since 1.8 */ @FunctionalInterface public interface DoubleToIntFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ int applyAsInt(double value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleToIntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
368
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts an int-valued argument and produces a * long-valued result. This is the {@code int}-to-{@code long} primitive * specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(int)}. * * @see Function * @since 1.8 */ @FunctionalInterface public interface IntToLongFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ long applyAsLong(int value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntToLongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
369
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation that accepts a single {@code double}-valued argument and * returns no result. This is the primitive type specialization of * {@link Consumer} for {@code double}. Unlike most other functional interfaces, * {@code DoubleConsumer} is expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(double)}. * * @see Consumer * @since 1.8 */ @FunctionalInterface public interface DoubleConsumer { /** * Performs this operation on the given argument. * * @param value the input argument */ void accept(double value); /** * Returns a composed {@code DoubleConsumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code DoubleConsumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default DoubleConsumer andThen(DoubleConsumer after) { Objects.requireNonNull(after); return (double t) -> { accept(t); after.accept(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoubleConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
551
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation on a single {@code long}-valued operand that produces * a {@code long}-valued result. This is the primitive type specialization of * {@link UnaryOperator} for {@code long}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(long)}. * * @see UnaryOperator * @since 1.8 */ @FunctionalInterface public interface LongUnaryOperator { /** * Applies this operator to the given operand. * * @param operand the operand * @return the operator result */ long applyAsLong(long operand); /** * Returns a composed operator that first applies the {@code before} * operator to its input, and then applies this operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param before the operator to apply before this operator is applied * @return a composed operator that first applies the {@code before} * operator and then applies this operator * @throws NullPointerException if before is null * * @see #andThen(LongUnaryOperator) */ default LongUnaryOperator compose(LongUnaryOperator before) { Objects.requireNonNull(before); return (long v) -> applyAsLong(before.applyAsLong(v)); } /** * Returns a composed operator that first applies this operator to * its input, and then applies the {@code after} operator to the result. * If evaluation of either operator throws an exception, it is relayed to * the caller of the composed operator. * * @param after the operator to apply after this operator is applied * @return a composed operator that first applies this operator and then * applies the {@code after} operator * @throws NullPointerException if after is null * * @see #compose(LongUnaryOperator) */ default LongUnaryOperator andThen(LongUnaryOperator after) { Objects.requireNonNull(after); return (long t) -> after.applyAsLong(applyAsLong(t)); } /** * Returns a unary operator that always returns its input argument. * * @return a unary operator that always returns its input argument */ static LongUnaryOperator identity() { return t -> t; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongUnaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
746
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a supplier of results. * * <p>There is no requirement that a new or distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #get()}. * * @param <T> the type of results supplied by this supplier * * @since 1.8 */ @FunctionalInterface public interface Supplier<T> { /** * Gets a result. * * @return a result */ T get(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/Supplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
347
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts two arguments and produces an int-valued * result. This is the {@code int}-producing primitive specialization for * {@link BiFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsInt(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * * @see BiFunction * @since 1.8 */ @FunctionalInterface public interface ToIntBiFunction<T, U> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ int applyAsInt(T t, U u); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ToIntBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
417
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts an int-valued argument and produces a * result. This is the {@code int}-consuming primitive specialization for * {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(int)}. * * @param <R> the type of the result of the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface IntFunction<R> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ R apply(int value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/IntFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
374
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents an operation that accepts a single input argument and returns no * result. Unlike most other functional interfaces, {@code Consumer} is expected * to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object)}. * * @param <T> the type of the input to the operation * * @since 1.8 */ @FunctionalInterface public interface Consumer<T> { /** * Performs this operation on the given argument. * * @param t the input argument */ void accept(T t); /** * Returns a composed {@code Consumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code Consumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default Consumer<T> andThen(Consumer<? super T> after) { Objects.requireNonNull(after); return (T t) -> { accept(t); after.accept(t); }; } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/Consumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
541
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation upon two {@code long}-valued operands and producing a * {@code long}-valued result. This is the primitive type specialization of * {@link BinaryOperator} for {@code long}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(long, long)}. * * @see BinaryOperator * @see LongUnaryOperator * @since 1.8 */ @FunctionalInterface public interface LongBinaryOperator { /** * Applies this operator to the given operands. * * @param left the first operand * @param right the second operand * @return the operator result */ long applyAsLong(long left, long right); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongBinaryOperator.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
392
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts two arguments and produces a long-valued * result. This is the {@code long}-producing primitive specialization for * {@link BiFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsLong(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * * @see BiFunction * @since 1.8 */ @FunctionalInterface public interface ToLongBiFunction<T, U> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ long applyAsLong(T t, U u); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ToLongBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
417
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a supplier of {@code long}-valued results. This is the * {@code long}-producing primitive specialization of {@link Supplier}. * * <p>There is no requirement that a distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #getAsLong()}. * * @see Supplier * @since 1.8 */ @FunctionalInterface public interface LongSupplier { /** * Gets a result. * * @return a result */ long getAsLong(); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongSupplier.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
361
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts a long-valued argument and produces a * double-valued result. This is the {@code long}-to-{@code double} primitive * specialization for {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(long)}. * * @see Function * @since 1.8 */ @FunctionalInterface public interface LongToDoubleFunction { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ double applyAsDouble(long value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongToDoubleFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
369
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; import java.util.Objects; /** * Represents a predicate (boolean-valued function) of one {@code double}-valued * argument. This is the {@code double}-consuming primitive type specialization * of {@link Predicate}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(double)}. * * @see Predicate * @since 1.8 */ @FunctionalInterface public interface DoublePredicate { /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean test(double value); /** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default DoublePredicate and(DoublePredicate other) { Objects.requireNonNull(other); return (value) -> test(value) && other.test(value); } /** * Returns a predicate that represents the logical negation of this * predicate. * * @return a predicate that represents the logical negation of this * predicate */ default DoublePredicate negate() { return (value) -> !test(value); } /** * Returns a composed predicate that represents a short-circuiting logical * OR of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ORed with this * predicate * @return a composed predicate that represents the short-circuiting logical * OR of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default DoublePredicate or(DoublePredicate other) { Objects.requireNonNull(other); return (value) -> test(value) || other.test(value); } } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/DoublePredicate.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
847
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents an operation that accepts an object-valued and a * {@code double}-valued argument, and returns no result. This is the * {@code (reference, double)} specialization of {@link BiConsumer}. * Unlike most other functional interfaces, {@code ObjDoubleConsumer} is * expected to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object, double)}. * * @param <T> the type of the object argument to the operation * * @see BiConsumer * @since 1.8 */ @FunctionalInterface public interface ObjDoubleConsumer<T> { /** * Performs this operation on the given arguments. * * @param t the first input argument * @param value the second input argument */ void accept(T t, double value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ObjDoubleConsumer.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
418
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts two arguments and produces a double-valued * result. This is the {@code double}-producing primitive specialization for * {@link BiFunction}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #applyAsDouble(Object, Object)}. * * @param <T> the type of the first argument to the function * @param <U> the type of the second argument to the function * * @see BiFunction * @since 1.8 */ @FunctionalInterface public interface ToDoubleBiFunction<T, U> { /** * Applies this function to the given arguments. * * @param t the first function argument * @param u the second function argument * @return the function result */ double applyAsDouble(T t, U u); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/ToDoubleBiFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
417
```java /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package me.zhanghai.android.douya.functional.compat; /** * Represents a function that accepts a long-valued argument and produces a * result. This is the {@code long}-consuming primitive specialization for * {@link Function}. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(long)}. * * @param <R> the type of the result of the function * * @see Function * @since 1.8 */ @FunctionalInterface public interface LongFunction<R> { /** * Applies this function to the given argument. * * @param value the function argument * @return the function result */ R apply(long value); } ```
/content/code_sandbox/app/src/main/java/me/zhanghai/android/douya/functional/compat/LongFunction.java
java
2016-02-01T13:44:19
2024-08-15T05:23:34
Douya
zhanghai/Douya
4,549
374