GT-2875 - Unswingable - review fixes

This commit is contained in:
dragonmacher 2019-05-21 14:51:32 -04:00
parent 5e8340b7f8
commit 31f3cca1a5
27 changed files with 100 additions and 79 deletions

View file

@ -0,0 +1,53 @@
/* ###
* IP: GHIDRA
*
* 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 utility.function;
/**
* A generic functional interface that is more semantically sound than {@link Runnable}. Use
* anywhere you wish to have a generic callback function.
*/
@FunctionalInterface
public interface Callback {
/**
* Creates a dummy callback function. This is useful to avoid using <tt>null</tt>.
* @return a dummy callback function
*/
public static Callback dummy() {
return () -> {
// no-op
};
}
/**
* Returns the given callback object if it is not <tt>null</tt>. Otherwise, a {@link #dummy()}
* callback is returned. This is useful to avoid using <tt>null</tt>.
*
* @param c the callback function to check for <tt>null</tt>
* @return a non-null callback function
*/
public static Callback dummyIfNull(Callback c) {
if (c == null) {
return dummy();
}
return c;
}
/**
* The method that will be called.
*/
public void call();
}

View file

@ -0,0 +1,33 @@
/* ###
* IP: GHIDRA
*
* 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 utility.function;
/**
* A generic functional interface that is more semantically sound than {@link Runnable}. Use
* anywhere you wish to have a generic callback function and you need to throw an exception.
*
* @param <E> the exception of your choice
*/
@FunctionalInterface
public interface ExceptionalCallback<E extends Exception> {
/**
* The method that will be called
*
* @throws Exception if the call throws an exception
*/
public void call() throws E;
}

View file

@ -0,0 +1,35 @@
/* ###
* IP: GHIDRA
*
* 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 utility.function;
/**
* A generic functional interface that allows you to consume an item and potentially throw
* an exception.
*
* @param <T> the input type
* @param <E> the exception of your choice
*/
@FunctionalInterface
public interface ExceptionalConsumer<T, E extends Exception> {
/**
* The method that will be called
*
* @param t the input
* @throws E if the call throws an exception
*/
public void accept(T t) throws E;
}

View file

@ -0,0 +1,37 @@
/* ###
* IP: GHIDRA
*
* 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 utility.function;
/**
* A generic functional interface that allows you to consume an item, return a result,
* and potentially throw an exception.
*
* @param <I> the input type
* @param <R> the result type
* @param <E> the exception of your choice
*/
@FunctionalInterface
public interface ExceptionalFunction<I, R, E extends Exception> {
/**
* The method that will be called
*
* @param i the input
* @return the result of the call
* @throws E if the call throws an exception
*/
public R apply(I i) throws E;
}