Skip to content

Commit

Permalink
file reading and writing - betta.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedaei79 committed Jun 2, 2020
1 parent 4966bd2 commit a09cc5c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/main/java/database.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
{"allUsers":{"admin1":{"personalInfo":"{\"username\":\"a\",\"firstName\":\"a\",\"lastName\":\"a\",\"emailAddress\":\"[email protected]\",\"phoneNumber\":\"11111\",\"password\":\"a\"}"}},"requestedSellers":{"seller2":{"personalInfo":"{\"username\":\"s\",\"firstName\":\"s\",\"lastName\":\"s\",\"emailAddress\":\"[email protected]\",\"phoneNumber\":\"11111\",\"password\":\"s\"}","listOfOffs":"[]","balance":"0","listOfSellLogs":"[]","availableProducts":"{}","company":"c"}},"allCodedDiscounts":{},"allCategories":{},"mainCategories":{},"allProducts":{},"allLogs":{},"allOffs":{},"allRequests":{"seller register1":{"seller":"seller2","fieldsAndValues":"null","id":"seller register1","requestStatus":"null"}},"allProductSellInfos":{},"allRates":{},"allCompanies":[],"idKeeper":{"usersNewId":2,"codedDiscountsNewId":0,"categoriesNewId":0,"productsNewId":0,"logsNewId":0,"offsNewId":0,"requestsNewId":1,"productSellInfosNewId":0,"ratesNewId":0}}
16 changes: 8 additions & 8 deletions src/main/java/model/MarketCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
import java.util.HashMap;
import java.util.Set;

public class MarketCopier { // copies and rebuilds market
public class MarketCopier {
private static MarketCopier instance = new MarketCopier();
private static Market market = Market.getInstance();
private HashMap<String, HashMap<String, String>> allUsers;// configure type by Id
private HashMap<String, HashMap<String, String>> allUsers;
private HashMap<String, HashMap<String, String>> requestedSellers;
private HashMap<String, HashMap> allCodedDiscounts;
private HashMap<String, HashMap<String, String>> allCategories; // configure type by Id
private HashMap<String, HashMap> mainCategories; // be made from allCategories
private HashMap<String, HashMap<String, String>> allCategories;
private HashMap<String, HashMap> mainCategories;
private HashMap<String, HashMap> allProducts;
private HashMap<String, HashMap> allLogs;
private HashMap<String, HashMap> allOffs;
private HashMap<String, HashMap<String, String>> allRequests; // configure type by Id
private HashMap<String, HashMap> allProductSellInfos; // add news to it
private HashMap<String, HashMap<String, String>> allRequests;
private HashMap<String, HashMap> allProductSellInfos;
private HashMap<String, HashMap> allRates;
private ArrayList<Company> allCompanies;
private IdKeeper idKeeper;
Expand Down Expand Up @@ -194,9 +194,9 @@ private void buildUsersWithHashMaps() {
}

private void buildRequestedSellersWithHashMaps() {
for (String id : allRequests.keySet()) {
for (String id : requestedSellers.keySet()) {
Seller seller = Market.getInstance().getRequestedSellerById(id);
seller.setFieldsFromHashMap(allRequests.get(id));
seller.setFieldsFromHashMap(requestedSellers.get(id));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/model/user/Buyer.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public HashMap<String, String> convertToHashMap() {

result.put("balance", "" + balance);

ArrayList<HashMap> buyLogs = new ArrayList<>();
ArrayList<HashMap<String, String>> buyLogs = new ArrayList<>();
for (BuyLog buyLog : listOfBuyLogs) {
buyLogs.add(buyLog.convertToHashMap());
}
Expand All @@ -172,9 +172,9 @@ public void setFieldsFromHashMap(HashMap<String, String> theMap) {

balance = Integer.parseInt((new Gson()).fromJson(theMap.get("balance"), String.class));

ArrayList<HashMap> buyLogs = (new Gson()).fromJson(theMap.get("listOfBuyLogs"), new TypeToken<ArrayList<String>>(){}.getType());
ArrayList<HashMap<String, String>> buyLogs = (new Gson()).fromJson(theMap.get("listOfBuyLogs"), new TypeToken<ArrayList<HashMap<String, String>>>(){}.getType());
listOfBuyLogs = new ArrayList<>();
for (HashMap hashMap : buyLogs) {
for (HashMap<String, String> hashMap : buyLogs) {
BuyLog buyLog = new BuyLog();
buyLog.setFieldsFromHashMap(hashMap);
listOfBuyLogs.add(buyLog);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/model/user/Seller.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public HashMap<String, String> convertToHashMap() {
result.put("personalInfo", (new Gson()).toJson(personalInfo));
result.put("company", company.getName());

ArrayList<HashMap> sellLogs = new ArrayList<>();
ArrayList<HashMap<String, String>> sellLogs = new ArrayList<>();
for (SellLog sellLog : listOfSellLogs) {
sellLogs.add(sellLog.convertToHashMap());
}
Expand All @@ -130,12 +130,12 @@ public void setFieldsFromHashMap(HashMap<String, String> theMap) {
company = Market.getInstance().getCompanyByName(theMap.get("company"));

listOfSellLogs = new ArrayList<>();
// ArrayList<HashMap> sellLogs = (new Gson()).fromJson(theMap.get("listOfSellLogs"), new TypeToken<ArrayList<String>>(){}.getType());
// for (HashMap hashMap : sellLogs) {
// SellLog sellLog = new SellLog();
// sellLog.setFieldsFromHashMap(hashMap);
// listOfSellLogs.add(sellLog);
// }
ArrayList<HashMap<String, String>> sellLogs = (new Gson()).fromJson(theMap.get("listOfSellLogs"), new TypeToken<ArrayList<HashMap<String, String>>>(){}.getType());
for (HashMap<String, String> hashMap : sellLogs) {
SellLog sellLog = new SellLog();
sellLog.setFieldsFromHashMap(hashMap);
listOfSellLogs.add(sellLog);
}

availableProducts = new HashMap<>();
HashMap<String, String> products = (new Gson()).fromJson(theMap.get("availableProducts"), new TypeToken<HashMap<String, String>>(){}.getType());
Expand Down

0 comments on commit a09cc5c

Please sign in to comment.