Skip to content

Commit

Permalink
plusonelabs#356 Fix: If permissions are needed. "io.vavr.control.Try"…
Browse files Browse the repository at this point in the history
… added
  • Loading branch information
yvolk committed Dec 31, 2019
1 parent fcc81ec commit 598a157
Show file tree
Hide file tree
Showing 20 changed files with 2,553 additions and 35 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ dependencies {
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test:rules:$testRulesVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"

testImplementation "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
}

static getCommitCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ private void assertOneEvent(CalendarEvent event, boolean equal) {
WidgetEntry entry = factory.getWidgetEntries().get(1);
assertTrue(entry instanceof CalendarEntry);
CalendarEvent eventOut = ((CalendarEntry) entry).getEvent();
String msgLog = "Comparing events:\n" +
"in: " + event.toString() + "\n" +
"out:" + eventOut.toString() + "\n";
if (equal) {
assertEquals(event.toString(), eventOut.toString());
assertEquals(msgLog, event.toString(), eventOut.toString());
} else {
assertNotSame(event.toString(), eventOut.toString());
assertNotSame(msgLog, event.toString(), eventOut.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private MockCalendarContentProvider(Context context) {
widgetId = instanceToReuse == null ? lastWidgetId.incrementAndGet() : instanceToReuse.getWidgetId();
InstanceSettings settings = new InstanceSettings(context, widgetId,
"ToDo Agenda " + widgetId + " " + InstanceSettings.TEST_REPLAY_SUFFIX);
settings.setActiveEventSources(settings.getActiveEventSources());

settings.setLockedTimeZoneId(ZONE_IDS[(int)(System.currentTimeMillis() % ZONE_IDS.length)]);
setSettings(settings);
}
Expand Down
79 changes: 79 additions & 0 deletions app/src/main/java/io/vavr/control/CheckedFunction.java
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));
}

}
87 changes: 87 additions & 0 deletions app/src/main/java/io/vavr/control/CheckedPredicate.java
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 (&amp;&amp;).
*
* @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);
}

}
34 changes: 34 additions & 0 deletions app/src/main/java/io/vavr/control/CheckedRunnable.java
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;

}
29 changes: 29 additions & 0 deletions app/src/main/java/io/vavr/control/NonFatalException.java
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);
}

}
Loading

0 comments on commit 598a157

Please sign in to comment.