Skip to content

Commit

Permalink
Hide the ErrorSwallowing interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akang31 committed Feb 13, 2025
1 parent 99efa7e commit 706e85e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ interface Subscription {
@Override
T get();

/**
* Return the most recent value of the property, swallowing any exceptions that occur.
*
* @return Most recent value for the property
*/
default T getSwallowErrors() {
return get();
}

/**
* Add a listener that will be called whenever the property value changes.
* @implNote Implementors of this interface MUST override this method or {@link #subscribe(Consumer)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,15 @@ public T invoke(Object[] args) {
return value != null ? value : defaultValueSupplier.apply(null);
}

@SuppressWarnings({"unchecked"})
@Override
public T invokeSwallowErrors(Object[] args) {
T value = prop.getSwallowErrors();
T value;
if (prop instanceof DefaultPropertyFactory.ErrorSwallowingProperty) {
value = ((DefaultPropertyFactory.ErrorSwallowingProperty<T>) prop).getSwallowErrors();
} else {
value = prop.get();
}
return value != null ? value : defaultValueSupplier.apply(null);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ private <T> Property<T> getFromSupplier(KeyAndType<T> keyAndType, Supplier<T> su
return (Property<T>) properties.computeIfAbsent(keyAndType, (ignore) -> new PropertyImpl<>(keyAndType, supplier));
}

interface ErrorSwallowingProperty<T> {
T getSwallowErrors();
}

/**
* Implementation of the Property interface. This class looks at the factory's masterVersion on each read to
* determine if the cached parsed values is stale.
*/
private final class PropertyImpl<T> implements Property<T> {
private final class PropertyImpl<T> implements Property<T>, ErrorSwallowingProperty<T> {

private final KeyAndType<T> keyAndType;
private final Supplier<T> supplier;
Expand Down

0 comments on commit 706e85e

Please sign in to comment.