Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. /**
  2.  * Define CRUD operations on persistent data-types
  3.  * @param <T>
  4.  */
  5. public interface DataManager<T extends Serializable> {
  6.  
  7.     /**
  8.      * Default method automatically available to all implementations
  9.      * @param path
  10.      * @return
  11.      * @throws IOException
  12.      */
  13.     default File getFile(String path) throws IOException {
  14.         // NIO needs a FileChannel => I have to retrieve a File handle => I can't retrieve a File handle from the classpath
  15.         // => the file is placed outsite the classpath and therefore I use the relative path from the root of the
  16.         // project
  17.         File file = new File(path);
  18.         if (!file.exists()) {
  19.             file.getParentFile().mkdirs();
  20.             Files.createFile(file.toPath());
  21.         }
  22.         return file;
  23.     }
  24.  
  25.     default Optional<T> get(UUID id) {
  26.         return getAll().stream().filter(t -> t.id.equals(id)).findFirst();
  27.     }
  28.  
  29.     List<T> getAll();
  30.     Optional<UUID> create(T entity);
  31.     boolean update(T entity);
  32.     boolean delete(T entity);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement