简体   繁体   English

在 Java 中使用 floorentry 时遇到问题

[英]Having trouble with floorentry in Java

I built the following TreeMap :我构建了以下 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));

When I run :当我运行时:

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

I get correct results (30000).我得到正确的结果(30000)。 But when I run :但是当我运行时:

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

My entire program breaks.我的整个程序都中断了。 When I try running :当我尝试运行时:

rebate = myMap.floorEntry(variable);

My IntelliJ throws me this error:我的 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$2.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)

How do I fix this?我该如何解决? Essentially I need to be able to pass Java a key, and pull the corresponding value of the next lowest key if it is not a perfect match.本质上,我需要能够向 Java 传递一个键,如果它不是完美匹配,则拉出下一个最低键的相应值。

Thank you in advanced!先谢谢了!

As indicated in the Javadoc , TreeMap.floorEntry returns a Map.Entry<K, V> .Javadoc 中所示TreeMap.floorEntry返回Map.Entry<K, V> You should change your setup to be:您应该将设置更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM