0

I have set up a maven project. I am running it in Eclipse IDE but it throws an error:

I have already tried mvn clean and mvn eclipse: eclipse from scratch.

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.amazon.mws.finances._2015_05_01.model.ShipmentEvent;
import com.amazon.mws.finances._2015_05_01.model.ShipmentItem;
import com.sun.tools.javac.util.Pair;
public Map<String, BigDecimal> getRefundEventFinancialSummary(ShipmentEvent shipmentEvent) {
Map<String, BigDecimal> chargeMap = new HashMap<>();
            List<ShipmentItem> refundItemsList = shipmentEvent.getShipmentItemAdjustmentList();
            List<Pair<String, BigDecimal>> accountedCostsList = refundItemsList.stream().map(this::getAccountedCosts)
                    .flatMap(List::stream).collect(Collectors.toList());
            for (Pair<String, BigDecimal> pair : accountedCostsList) {
                String keyString = pair.getKey();
                if (chargeMap.containsKey(keyString)) {
                    chargeMap.replace(keyString, chargeMap.get(keyString).add(pair.getValue()));
                } else {
                    chargeMap.put(keyString, pair.getValue());
                }
            }
            return chargeMap;
          }

I don't see any issue with the logic but it throws this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method getKey() is undefined for the type Pair<String,BigDecimal>
The method getValue() is undefined for the type Pair<String,BigDecimal>
The method getValue() is undefined for the type Pair<String,BigDecimal>

Please help me what could be the possible issue? Is it an eclipse problem?

Edit: Added the import statements.

Katya047
  • 43
  • 1
  • 8

2 Answers2

2

It seems that the Pair class which you are using doesn't have these methods. Try opening the Pair class in your eclipse(using java decompiler plugin). If you are using com.sun.tools.javac.util.Pair class, you need to use pair.fst and pair.snd. Changed code:

for (Pair<String, BigDecimal> pair : accountedCostsList) {
            String keyString = pair.fst;
            if (chargeMap.containsKey(keyString)) {
                chargeMap.replace(keyString, chargeMap.get(keyString).add(pair.snd));
            } else {
                chargeMap.put(keyString, pair.snd);
            }
        }
Gaurav Gupta
  • 142
  • 7
  • Hi Gaurav, You guessed it right. I'm using com.sun.tools.javac.util.Pair but adding import pair.fst; and import pair.snd; didn't solve the problem either. – Katya047 Oct 31 '19 at 08:16
  • Use `pair.fst` instead of using `pair.getKey()`. You don't need to add anything in your import statements. Check updated answer. Hope this helps. – Gaurav Gupta Oct 31 '19 at 09:39
  • @Katya047 Can you accept the answer, if this solves your issue? – Gaurav Gupta Oct 31 '19 at 12:11
0

I tried import javafx.util.Pair and the problem got solved. Thanks, everyone!!

Katya047
  • 43
  • 1
  • 8