daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.AbstractList;
  2. import java.util.List;
  3. import java.util.Objects;
  4.  
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7.  
  8. public class CloseableList<E extends AutoCloseable> extends AbstractList<E> implements AutoCloseable {
  9.     public static final Logger LOGGER = LoggerFactory.getLogger(CloseableList.class);
  10.     private final List<E> closableList;
  11.  
  12.     /**
  13.      * Create list with closable objects.
  14.      *
  15.      * @param closableList
  16.      *            list of tensor, must not be null
  17.      */
  18.     public CloseableList(List<E> closableList) {
  19.         Objects.requireNonNull(closableList);
  20.         this.closableList = closableList;
  21.     }
  22.  
  23.     @Override
  24.     public E get(int index) {
  25.         return closableList.get(index);
  26.     }
  27.  
  28.     @Override
  29.     public int size() {
  30.         return closableList.size();
  31.     }
  32.  
  33.     @Override
  34.     public void close() {
  35.         for (E item : closableList) {
  36.             try {
  37.                 item.close();
  38.             } catch (Exception e) {
  39.                 LOGGER.warn("Cannot close item in list", e);
  40.             }
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top