1

Java RMI で単純な信頼できないシステムを開発しましたが、今度はそれを Web サービスに変更する必要があります。データ構造に問題があります:

Hashtable<String, ArrayList<Records>> recordsTable;

オブジェクトを正しくシリアル化/更新しません。

このような問題を克服するためにデータ構造を変更する方法がわかりませんか?

【編集済】

簡単にするために、次のデータ構造があるとします。

Hashtable<String, Integer> store = new Hashtable<String, Integer>();

公開されている buy() および display() サービスがあります。最初は店に 100 個のリンゴがあるので、10 個のリンゴを buy() すると、90 個のリンゴの結果が出力されます。しかし、後で表示を呼び出すと、100 個のリンゴが出力されます。

そのため、シリアル化の問題があり、それを修正する方法がわかりません。

public class StoreServer{

Hashtable<String, Integer> store= new Hashtable<String, Integer>();

public StoreServer()
{
    store.put("Coffee", 20);
    store.put("Apple", 100);
    store.put("Banana", 50);
    display();
}

public String buy(String item, int quantity)
{
    if(store.containsKey(item))
    {
        int oldQuantity = store.get(item);
        int newQuantity;
        if(oldQuantity-quantity>=0)
        {
            newQuantity= oldQuantity -quantity;
            store.put(item, newQuantity);
            return quantity+" "+item+" were successfully purchased!\n" +

                    ("1. Coffee: "+store.get("Coffee")+"\n")+
                    ("2. Apples: "+store.get("Apple")+"\n")+
                    ("3. Bananas: "+store.get("Banana")+"\n")+
                    ("---------------------------\n");
        }
        else
        {
            return "error with your purchase";
        }
    }
    else
    {
        return "error with your purchase";
    }
}


public void display()
{
    System.out.println("------Store Inventory-----");
    System.out.println("1. Coffee: "+store.get("Coffee"));
    System.out.println("2. Apples: "+store.get("Apple"));
    System.out.println("3. Bananas: "+store.get("Banana"));
    System.out.println("---------------------------");
}}
4

1 に答える 1