/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com */ package dan200.computercraft.test.core; import javax.annotation.Nullable; import java.util.ArrayDeque; import java.util.Deque; import java.util.Objects; /** * An {@link AutoCloseable} implementation which can be used to combine other [AutoCloseable] instances. *
* Values which implement {@link AutoCloseable} can be dynamically registered with [CloseScope.add]. When the scope is * closed, each value is closed in the opposite order. *
* This is largely intended for cases where it's not appropriate to nest try-with-resources blocks, for instance when
* nested would be too deep or when objects are dynamically created.
*/
public class CloseScope implements AutoCloseable {
private final Deque