0

3 つのオブジェクトを持つプログラムがあります。そのうちの 1 つは、ResulSet の列を表す 6 つの変数オブジェクトです。他の 2 つには 3 つの変数があり、他の 6 つの変数オブジェクトの最初と最後の 3 つと一致します。ResultSet レコード自体を表す List<6 Var object> があります。6 つの変数オブジェクトのリストを解析して結果セットを圧縮し、小さな 3 つの変数オブジェクトのキーごとに 1 つのレコードしか持たないようにしようとしています。これを実現するために、2 つの 3 var オブジェクトのハッシュ マップを使用しています。以下は、リストを受け取り、同じものを凝縮して返す私のメソッド自体です。ItemQuantities は私の 6 つの変数オブジェクトです。CustomerProductClass は私の 3 つの値のキーであり、Item は、返されたリストで一意にしたい 3 つの値のキーです。現在の HashMap を比較しようとしていることがわかります。現在のオブジェクトのキーが含まれており、既存のレコードを削除してそれ自体を挿入する必要があるかどうかのロジックをステップ実行します。私の最初の if ステートメントが常にパスし、else ステートメントに到達しない理由がわかれば教えてください。

public static List<ItemQuantities> getCondensedItemQuantities (List<ItemQuantities> fullItems) {
    Map<CustomerProductClass,Item> groupedProductQuantities = new  HashMap<CustomerProductClass,Item>();//making the map to put shit in

    for(int i = 0;i<fullItems.size();i++){
        ItemQuantities itemQuantities;
        itemQuantities = fullItems.get(i);
        Item item  = new Item(itemQuantities.itmType, itemQuantities.quant, itemQuantities.unitPrice);
        CustomerProductClass myCustomerProductClass = new CustomerProductClass(itemQuantities.customer,itemQuantities.location, itemQuantities.prodClass);


        if(!groupedProductQuantities.containsKey(myCustomerProductClass)){
            groupedProductQuantities.put(myCustomerProductClass,item);
        }
        else{
            if(item.Quantity > groupedProductQuantities.get(myCustomerProductClass).Quantity){
                groupedProductQuantities.remove(myCustomerProductClass);
                groupedProductQuantities.put(myCustomerProductClass, item);
            }
            if(item.Quantity == groupedProductQuantities.get(myCustomerProductClass).Quantity){
                if(item.UnitPrice > groupedProductQuantities.get(myCustomerProductClass).UnitPrice){
                    groupedProductQuantities.remove(myCustomerProductClass);
                    groupedProductQuantities.put(myCustomerProductClass, item);
                }
            }
        }
    }
    List<ItemQuantities> finalList= new ArrayList<ItemQuantities>();
    for(CustomerProductClass customerProductClass : groupedProductQuantities.keySet()){
        ItemQuantities itemQuantities = new ItemQuantities(customerProductClass.Customer,customerProductClass.Location,customerProductClass.ProductClass,groupedProductQuantities.get(customerProductClass).Name,groupedProductQuantities.get(customerProductClass).Quantity,groupedProductQuantities.get(customerProductClass).UnitPrice);
        finalList.add(itemQuantities);
    }
    return finalList; //return the hash map combined into a list of ItemQuantities.
}
4

0 に答える 0