在 Java 中遇到楼层输入问题

Having trouble with floorentry in Java

我构建了以下 TreeMap :

      TreeMap<Double, BigDecimal> myMap = new TreeMap<>();
      myMap.put(0.00, new BigDecimal(18000));
      myMap.put(62.00, new BigDecimal(25000));
      myMap.put(100.00, new BigDecimal(30000));
      myMap.put(150.00, new BigDecimal(55000));
      myMap.put(200.00, new BigDecimal(55000));
      myMap.put(200.00, new BigDecimal(55000));
      myMap.put(301.00, new BigDecimal(70000));

当我 运行 :

variable = 100;
rebate = myMap.get(variable);

我得到了正确的结果 (30000)。但是当我 运行 :

variable = 75;
rebate = myMap.get(variable);

我的整个程序都中断了。当我尝试 运行ning 时:

rebate = myMap.floorEntry(variable);

我的 IntelliJ 抛出这个错误:

Required type:
BigDecimal


Provided:
Entry
<java.lang.Double,
java.math.BigDecimal>

stacktrace:
    <pre>java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step org.kie.kogito.quarkus.common.deployment.KogitoAssetsProcessor#generateModel threw an exception: java.lang.IllegalStateException: src/main/java/com/zappyride/software/business/P94/LambdaConsequence9423558E6DAA4D0C76452B4B4DFC5AA3.java (115:5948) : Type mismatch: cannot convert from Map.Entry&lt;Double,BigDecimal&gt; to BigDecimal
src/main/java/com/zappyride/software/business/P94/LambdaConsequence9423558E6DAA4D0C76452B4B4DFC5AA3.java (115:5948) : Type mismatch: cannot convert from Map.Entry&lt;Double,BigDecimal&gt; to BigDecimal
    at org.kie.kogito.quarkus.common.deployment.InMemoryCompiler.compile(InMemoryCompiler.java:100)
    at org.kie.kogito.quarkus.common.deployment.KogitoQuarkusResourceUtils.compileGeneratedSources(KogitoQuarkusResourceUtils.java:140)
    at org.kie.kogito.quarkus.common.deployment.KogitoAssetsProcessor.compileAndIndexJavaSources(KogitoAssetsProcessor.java:126)
    at org.kie.kogito.quarkus.common.deployment.KogitoAssetsProcessor.generateModel(KogitoAssetsProcessor.java:95)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at io.quarkus.deployment.ExtensionLoader.execute(ExtensionLoader.java:920)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
    at java.base/java.lang.Thread.run(Thread.java:829)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)

我该如何解决这个问题?本质上我需要能够传递 Java 一个键,如果不是完美匹配,则拉取下一个最低键的相应值。

在此先感谢您!

JavadocTreeMap.floorEntryreturns一Map.Entry<K, V>所示。您应该将设置更改为:

Map.Entry<Double, BigDecimal> entry = myMap.floorEntry(variable);