forked from plusonelabs/calendar-widget
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plusonelabs#356 Fix: If permissions are needed. "io.vavr.control.Try"…
… added
- Loading branch information
Showing
20 changed files
with
2,553 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* ____ ______________ ________________________ __________ | ||
* \ \/ / \ \/ / __/ / \ \/ / \ | ||
* \______/___/\___\______/___/_____/___/\___\______/___/\___\ | ||
* | ||
* Copyright 2018 Vavr, http://vavr.io | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.vavr.control; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A {@linkplain java.util.function.Function} which may throw. | ||
* | ||
* @param <T> the type of this function's domain | ||
* @param <R> the type of this function's codomain, i.e. the return type | ||
*/ | ||
@FunctionalInterface | ||
public interface CheckedFunction<T, R> { | ||
|
||
/** | ||
* Returns the identity {@code CheckedFunction}, i.e. the function that returns its input. | ||
* | ||
* @param <T> argument type (and return type) of the identity function | ||
* @return the identity {@code CheckedFunction} | ||
*/ | ||
static <T> CheckedFunction<T, T> identity() { | ||
return t -> t; | ||
} | ||
|
||
/** | ||
* Applies this function to one argument and returns the result. | ||
* | ||
* @param t argument of type {@code T} | ||
* @return the result of the function application | ||
* @throws Exception if something goes wrong applying this function to the given argument | ||
*/ | ||
R apply(T t) throws Exception; | ||
|
||
/** | ||
* Returns a composed function that first applies this to the given argument and then applies | ||
* {@code after} to the result. | ||
* | ||
* @param <U> return type of after | ||
* @param after the function applied after this | ||
* @return a function composed of this and {@code after} | ||
* @throws NullPointerException if {@code after} is null | ||
*/ | ||
default <U> CheckedFunction<T, U> andThen(CheckedFunction<? super R, ? extends U> after) { | ||
Objects.requireNonNull(after, "after is null"); | ||
return t -> after.apply(apply(t)); | ||
} | ||
|
||
/** | ||
* Returns a composed function that first applies {@code before} to the given argument and then applies this | ||
* to the result. | ||
* | ||
* @param <U> argument type of before | ||
* @param before the function applied before this | ||
* @return a function composed of {@code before} and this | ||
* @throws NullPointerException if {@code before} is null | ||
*/ | ||
default <U> CheckedFunction<U, R> compose(CheckedFunction<? super U, ? extends T> before) { | ||
Objects.requireNonNull(before, "before is null"); | ||
return u -> apply(before.apply(u)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* ____ ______________ ________________________ __________ | ||
* \ \/ / \ \/ / __/ / \ \/ / \ | ||
* \______/___/\___\______/___/_____/___/\___\______/___/\___\ | ||
* | ||
* Copyright 2018 Vavr, http://vavr.io | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.vavr.control; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A {@linkplain java.util.function.Predicate} which may throw. | ||
* | ||
* @param <T> the type of the input to the predicate | ||
*/ | ||
@FunctionalInterface | ||
public interface CheckedPredicate<T> { | ||
|
||
/** | ||
* Negates a given predicate by calling {@code that.negate()}. | ||
* | ||
* @param <T> argument type of {@code that} | ||
* @param that a predicate | ||
* @return the negation of the given predicate {@code that} | ||
* @throws NullPointerException if the given predicate {@code that} is null | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
static <T> CheckedPredicate<T> not(CheckedPredicate<? super T> that) { | ||
Objects.requireNonNull(that, "that is null"); | ||
return (CheckedPredicate<T>) that.negate(); | ||
} | ||
|
||
/** | ||
* 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} | ||
* @throws Exception if an error occurs | ||
*/ | ||
boolean test(T t) throws Exception; | ||
|
||
/** | ||
* Combines this predicate with {@code that} predicate using logical and (&&). | ||
* | ||
* @param that a {@code CheckedPredicate} | ||
* @return a new {@code CheckedPredicate} with {@code p1.and(p2).test(t) == true :<=> p1.test(t) && p2.test(t) == true} | ||
* @throws NullPointerException if the given predicate {@code that} is null | ||
*/ | ||
default CheckedPredicate<T> and(CheckedPredicate<? super T> that) { | ||
Objects.requireNonNull(that, "that is null"); | ||
return t -> test(t) && that.test(t); | ||
} | ||
|
||
/** | ||
* Negates this predicate. | ||
* | ||
* @return A new {@code CheckedPredicate} with {@code p.negate().test(t) == true :<=> p.test(t) == false} | ||
*/ | ||
default CheckedPredicate<T> negate() { | ||
return t -> !test(t); | ||
} | ||
|
||
/** | ||
* Combines this predicate with {@code that} predicate using logical or (||). | ||
* | ||
* @param that a {@code CheckedPredicate} | ||
* @return a new {@code CheckedPredicate} with {@code p1.or(p2).test(t) :<=> p1.test(t) || p2.test(t)} | ||
* @throws NullPointerException if the given predicate {@code that} is null | ||
*/ | ||
default CheckedPredicate<T> or(CheckedPredicate<? super T> that) { | ||
Objects.requireNonNull(that, "that is null"); | ||
return t -> test(t) || that.test(t); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ____ ______________ ________________________ __________ | ||
* \ \/ / \ \/ / __/ / \ \/ / \ | ||
* \______/___/\___\______/___/_____/___/\___\______/___/\___\ | ||
* | ||
* Copyright 2018 Vavr, http://vavr.io | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.vavr.control; | ||
|
||
/** | ||
* A {@linkplain Runnable} which may throw. | ||
*/ | ||
@FunctionalInterface | ||
public interface CheckedRunnable { | ||
|
||
/** | ||
* Performs side-effects. | ||
* | ||
* @throws Exception if an error occurs | ||
*/ | ||
void run() throws Exception; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* ____ ______________ ________________________ __________ | ||
* \ \/ / \ \/ / __/ / \ \/ / \ | ||
* \______/___/\___\______/___/_____/___/\___\______/___/\___\ | ||
* | ||
* Copyright 2018 Vavr, http://vavr.io | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.vavr.control; | ||
|
||
public class NonFatalException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
NonFatalException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
Oops, something went wrong.