-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-drools-6180] accumulate min doesn't evaluate correctly…
… with more than 18 digits BigDecimal
- Loading branch information
Showing
7 changed files
with
562 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...core/src/main/java/org/drools/core/base/accumulators/BigDecimalMaxAccumulateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.drools.core.base.accumulators; | ||
|
||
import java.io.Externalizable; | ||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.math.BigDecimal; | ||
|
||
/** | ||
* An implementation of an accumulator capable of calculating maximum values | ||
*/ | ||
public class BigDecimalMaxAccumulateFunction extends AbstractAccumulateFunction<BigDecimalMaxAccumulateFunction.MaxData> { | ||
|
||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
|
||
} | ||
|
||
public void writeExternal(ObjectOutput out) throws IOException { | ||
|
||
} | ||
|
||
protected static class MaxData implements Externalizable { | ||
public BigDecimal max = null; | ||
|
||
public MaxData() {} | ||
|
||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
max = (BigDecimal) in.readObject(); | ||
} | ||
|
||
public void writeExternal(ObjectOutput out) throws IOException { | ||
out.writeObject(max); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "max"; | ||
} | ||
} | ||
|
||
public MaxData createContext() { | ||
return new MaxData(); | ||
} | ||
|
||
public void init(MaxData data) { | ||
data.max = null; | ||
} | ||
|
||
public void accumulate(MaxData data, | ||
Object value) { | ||
if (value != null) { | ||
BigDecimal bdValue = (BigDecimal) value; | ||
data.max = data.max == null || data.max.compareTo(bdValue) < 0 ? | ||
bdValue : | ||
data.max; | ||
} | ||
} | ||
|
||
public void reverse(MaxData data, | ||
Object value) { | ||
} | ||
|
||
@Override | ||
public boolean tryReverse( MaxData data, Object value ) { | ||
if (value != null) { | ||
return data.max.compareTo((BigDecimal) value) > 0; | ||
} | ||
return true; | ||
} | ||
|
||
public Object getResult(MaxData data) { | ||
return data.max; | ||
} | ||
|
||
public boolean supportsReverse() { | ||
return false; | ||
} | ||
|
||
public Class<?> getResultType() { | ||
return BigDecimal.class; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...core/src/main/java/org/drools/core/base/accumulators/BigDecimalMinAccumulateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.drools.core.base.accumulators; | ||
|
||
import java.io.Externalizable; | ||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.math.BigDecimal; | ||
|
||
/** | ||
* An implementation of an accumulator capable of calculating minimum values | ||
*/ | ||
public class BigDecimalMinAccumulateFunction extends AbstractAccumulateFunction<BigDecimalMinAccumulateFunction.MinData> { | ||
|
||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
} | ||
|
||
public void writeExternal(ObjectOutput out) throws IOException { | ||
} | ||
|
||
protected static class MinData implements Externalizable { | ||
public BigDecimal min = null; | ||
|
||
public MinData() {} | ||
|
||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
min = (BigDecimal) in.readObject(); | ||
} | ||
|
||
public void writeExternal(ObjectOutput out) throws IOException { | ||
out.writeObject(min); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "min"; | ||
} | ||
} | ||
|
||
public MinData createContext() { | ||
return new MinData(); | ||
} | ||
|
||
public void init(MinData data) { | ||
data.min = null; | ||
} | ||
|
||
public void accumulate(MinData data, | ||
Object value) { | ||
if (value != null) { | ||
BigDecimal bdValue = (BigDecimal) value; | ||
data.min = data.min == null || data.min.compareTo(bdValue) > 0 ? | ||
bdValue : | ||
data.min; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean tryReverse( MinData data, Object value ) { | ||
if (value != null) { | ||
return data.min.compareTo((BigDecimal) value) < 0; | ||
} | ||
return true; | ||
} | ||
|
||
public void reverse(MinData data, | ||
Object value) { | ||
} | ||
|
||
public Object getResult(MinData data) { | ||
return data.min; | ||
} | ||
|
||
public boolean supportsReverse() { | ||
return false; | ||
} | ||
|
||
public Class<?> getResultType() { | ||
return BigDecimal.class; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...core/src/main/java/org/drools/core/base/accumulators/BigIntegerMaxAccumulateFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.drools.core.base.accumulators; | ||
|
||
import java.io.Externalizable; | ||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.math.BigInteger; | ||
|
||
/** | ||
* An implementation of an accumulator capable of calculating maximum values | ||
*/ | ||
public class BigIntegerMaxAccumulateFunction extends AbstractAccumulateFunction<BigIntegerMaxAccumulateFunction.MaxData> { | ||
|
||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
|
||
} | ||
|
||
public void writeExternal(ObjectOutput out) throws IOException { | ||
|
||
} | ||
|
||
protected static class MaxData implements Externalizable { | ||
public BigInteger max = null; | ||
|
||
public MaxData() {} | ||
|
||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
max = (BigInteger) in.readObject(); | ||
} | ||
|
||
public void writeExternal(ObjectOutput out) throws IOException { | ||
out.writeObject(max); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "max"; | ||
} | ||
} | ||
|
||
public MaxData createContext() { | ||
return new MaxData(); | ||
} | ||
|
||
public void init(MaxData data) { | ||
data.max = null; | ||
} | ||
|
||
public void accumulate(MaxData data, | ||
Object value) { | ||
if (value != null) { | ||
BigInteger biValue = (BigInteger) value; | ||
data.max = data.max == null || data.max.compareTo(biValue) < 0 ? | ||
biValue : | ||
data.max; | ||
} | ||
} | ||
|
||
public void reverse(MaxData data, | ||
Object value) { | ||
} | ||
|
||
@Override | ||
public boolean tryReverse( MaxData data, Object value ) { | ||
if (value != null) { | ||
return data.max.compareTo((BigInteger) value) > 0; | ||
} | ||
return true; | ||
} | ||
|
||
public Object getResult(MaxData data) { | ||
return data.max; | ||
} | ||
|
||
public boolean supportsReverse() { | ||
return false; | ||
} | ||
|
||
public Class<?> getResultType() { | ||
return BigInteger.class; | ||
} | ||
} |
Oops, something went wrong.