From b1bf963e57050d6c423a80db76f9d36197a0b475 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Mon, 05 Apr 2021 11:58:38 +0000
Subject: [PATCH] Neuer Ablageort mit generischem Typ

---
 src/de/uhilger/mediaz/store/FileStorage.java |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/de/uhilger/mediaz/store/FileStorage.java b/src/de/uhilger/mediaz/store/FileStorage.java
index 1d6373a..0282ed7 100644
--- a/src/de/uhilger/mediaz/store/FileStorage.java
+++ b/src/de/uhilger/mediaz/store/FileStorage.java
@@ -6,6 +6,7 @@
 package de.uhilger.mediaz.store;
 
 import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import de.uhilger.mediaz.App;
 import de.uhilger.mediaz.Server;
 import de.uhilger.mediaz.entity.Ablageort;
@@ -18,7 +19,9 @@
 import java.util.logging.Logger;
 import de.uhilger.mediaz.entity.Entity;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 
 /**
@@ -41,8 +44,15 @@
   
   private String fileBase;
   
+  private Map<String, TypeToken> types;
+  
   public FileStorage(String base) {
     this.fileBase = base;
+    
+    //TypeToken<List<String>> list = new TypeToken<List<String>>() {};
+    TypeToken<Ablageort> ttAblageort = new TypeToken<Ablageort>() {};
+    types = new HashMap();
+    types.put(Ablageort.class.getSimpleName(), ttAblageort);
   }
   
   /**
@@ -76,7 +86,7 @@
   }
   
   public Entity readFromFile(File file) throws ClassNotFoundException, FileNotFoundException, IOException {
-    String type = typeFromName(file);
+    String type = typeNameFromPath(file);
     StringBuilder sb = new StringBuilder();
     FileReader in = new FileReader(file);
     BufferedReader r = new BufferedReader(in);
@@ -99,14 +109,8 @@
     }
   }
   
-  private String typeFromName(File file) {
-    //String path = file.getPath();
-    //logger.info(path);
+  private String typeNameFromPath(File file) {
     String[] parts = file.getPath().split(App.getRs(Server.RB_SLASH));
-    //for(String part : parts) {
-      //logger.info(part);
-    //}
-    //logger.info("" + parts.length);
     logger.info(parts[parts.length-2]);
     return parts[parts.length-2];
   }
@@ -146,6 +150,11 @@
     return list;
   }
 
+  @Override
+  public TypeToken typeFromName(String name) {
+    return types.get(name);
+  }
+
   
   
 }

--
Gitblit v1.9.3