Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ResoruceItem class to record type #77

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@ public void deleteResources() {
ResourceItem<?> resourceItem = s.pop();

try {
resourceItem.getThrowableRunner().run();
resourceItem.throwableRunner().run();
} catch (Exception e) {
e.printStackTrace();
}
numberOfResources.decrementAndGet();
deleteCallbacks.forEach(callback -> {
if (resourceItem.getResource() != null) {
callback.accept(resourceItem.getResource());
if (resourceItem.resource() != null) {
callback.accept(resourceItem.resource());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,21 @@

/**
* Represents an item containing a Kubernetes resource and a runnable action.
* @param <T> Type of Kubernetes resource.
*
* @param throwableRunner delete method
* @param resource resource (can be null)
* @param <T> Type of kubernetes resource
*/
public final class ResourceItem<T extends HasMetadata> {

private final ThrowableRunner throwableRunner;
private final T resource;

/**
* Constructs a ResourceItem with the given runnable action and resource.
* @param throwableRunner The runnable action to execute.
* @param resource The Kubernetes resource associated with the action.
*/
public ResourceItem(ThrowableRunner throwableRunner, T resource) {
this.throwableRunner = throwableRunner;
this.resource = resource;
}
public record ResourceItem<T extends HasMetadata>(
ThrowableRunner throwableRunner,
T resource) {

/**
* Constructs a ResourceItem with the given runnable action.
*
* @param throwableRunner The runnable action to execute.
*/
public ResourceItem(ThrowableRunner throwableRunner) {
this.throwableRunner = throwableRunner;
this.resource = null;
}

/**
* Gets the runnable action associated with this resource item.
* @return The runnable action.
*/
public ThrowableRunner getThrowableRunner() {
return throwableRunner;
}

/**
* Gets the Kubernetes resource associated with this resource item.
* @return The Kubernetes resource.
*/
public T getResource() {
return resource;
this(throwableRunner, null);
}
}
Loading