net.diversionmc.error.TryWithResources Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of result Show documentation
Show all versions of result Show documentation
Diversion Network Result type.
package net.diversionmc.error;
import java.util.Collection;
/**
* Write-only wrapper for a backed-up resource collection
* - in a {@link Result#tryGet(Class, TryF)} / {@link Success#tryRun(Class, TryC)} only writing to the list is allowed,
* while the backed up list is accessed in those methods.
*/
@SuppressWarnings("ClassCanBeRecord") // Backup collection should not be public
public class TryWithResources {
private final Collection backup;
public TryWithResources(Collection backup) {
this.backup = backup;
}
public R resource(R resource) {
backup.add(resource);
return resource;
}
}