All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.diversionmc.error.TryWithResources Maven / Gradle / Ivy

There is a newer version: 1.29.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy