Skip to content

Commit

Permalink
refactor: deprecate ManagedDependentResourceContext#put
Browse files Browse the repository at this point in the history
The javadoc declares it returns Optional and the implementation returns
Optional, but the method declares it returns T. put is replaced by
putOrRemove with a consistent signature.

Signed-off-by: Robert Young <robeyoun@redhat.com>
  • Loading branch information
robobario committed Nov 19, 2024
1 parent d492ff6 commit 73688b8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ public <T> Optional<T> get(Object key, Class<T> expectedType) {

@Override
@SuppressWarnings("unchecked")
@Deprecated(forRemoval = true)
public <T> T put(Object key, T value) {
if (value == null) {
return (T) Optional.ofNullable(attributes.remove(key));
}
return (T) Optional.ofNullable(attributes.put(key, value));
return (T) putOrRemove(key, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public interface ManagedDependentResourceContext {
* associated with the specified key
* @return an Optional containing the previous value associated with the key or
* {@link Optional#empty()} if none existed
* @deprecated use {@link #putOrRemove(Object, Object)} instead
*/
@SuppressWarnings("unchecked")
@Deprecated(forRemoval = true)
<T> T put(Object key, T value);

/**
Expand All @@ -52,7 +54,6 @@ public interface ManagedDependentResourceContext {
* @return an Optional containing the previous value associated with the key or
* {@link Optional#empty()} if none existed
*/
@SuppressWarnings("unchecked")
<T> Optional<T> putOrRemove(Object key, T value);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public WorkflowReconcileResult reconcile(P primary, Context<P> context) {
new WorkflowReconcileExecutor<>(this, primary, context);
var result = workflowReconcileExecutor.reconcile();
context.managedDependentResourceContext()
.put(DefaultManagedDependentResourceContext.RECONCILE_RESULT_KEY, result);
.putOrRemove(DefaultManagedDependentResourceContext.RECONCILE_RESULT_KEY, result);
if (throwExceptionAutomatically) {
result.throwAggregateExceptionIfErrorsPresent();
}
Expand All @@ -106,7 +106,7 @@ public WorkflowCleanupResult cleanup(P primary, Context<P> context) {
new WorkflowCleanupExecutor<>(this, primary, context);
var result = workflowCleanupExecutor.cleanup();
context.managedDependentResourceContext()
.put(DefaultManagedDependentResourceContext.CLEANUP_RESULT_KEY, result);
.putOrRemove(DefaultManagedDependentResourceContext.CLEANUP_RESULT_KEY, result);
if (throwExceptionAutomatically) {
result.throwAggregateExceptionIfErrorsPresent();
}
Expand Down

0 comments on commit 73688b8

Please sign in to comment.