实施此记录的最佳方式(商店日期以及ID和数量)?

时间:2016-01-21 10:57:15

标签: java android

我想知道存储以下信息的最佳方式:

我有一个帐户对象,在每个帐户对象中,我需要跟踪日期,在该日期购买的商品以及商品数量。这是许多其他内容的补充,例如帐户的客户端ID。我将以下列方式实现这一点

class Account{

int clientID;

LinkedHashMap<String(the date), Map<int(itemID), int(quantity)>> = new ...

...


}

我想知道在我继续执行此操作之前是否有人有任何时间?我的意思是我想到的其他东西是内部类,比如

Class Account{

class Item{

String Date

Array<Int> itemID

Array<Int> item quantity

}

但我觉得第一种方式会更好。谢谢你的建议。

P.S我知道代码中存在问题,例如hashmap中的括号,这只是为了帮助您了解我所获得的内容:)

2 个答案:

答案 0 :(得分:1)

我认为这可能是一个很好的设计:

public class Acount {
    private int clientId;
    private List<Purchase> purchases;
}

public class Purchase {
    private Date date;
    private Map<Item, Integer> itemsCount;
}

public class Item {
    private int itemId;
}
  1. Account有一个clientId和一个购买清单。
  2. 每个Purchase都有一个日期和地图,用于标识所购买的Item以及每个 private static String Remove(String s) { var rs = s.Split(new[] { '"' }).ToList(); return String.Join("\"\"", rs.Where(_ => rs.IndexOf(_) % 2 == 0)); } static void Main(string[] args) { var test = Remove("hello\"world\"\"yeah\" test \"fhfh\""); return; } 的数量。

答案 1 :(得分:0)

存储ID和数据的最佳方式

HashMap<String, String> multiMap = new HashMap<String,String>();

// Put elements to the hashMap
hashMap.put("id1", "data1");
hashMap.put("id2", "data2");  hashMap.put("id3", "data3");