Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
11e22022
Commit
11e22022
authored
Mar 02, 2017
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1613: fix for bigdecimal value handling to avoid casting to long (#2 - fix…
ATLAS-1613: fix for bigdecimal value handling to avoid casting to long (#2 - fix for unittest failures)
parent
48b05f36
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
AtlasBuiltInTypes.java
...rc/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
+1
-1
TestAtlasBigDecimalType.java
...t/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
+13
-4
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
View file @
11e22022
...
...
@@ -414,7 +414,7 @@ public class AtlasBuiltInTypes {
}
else
if
(
obj
instanceof
BigInteger
)
{
return
new
BigDecimal
((
BigInteger
)
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
BigDecimal
.
valueOf
(((
Number
)
obj
).
doubleValue
());
return
obj
.
equals
(
0
)
?
BigDecimal
.
ZERO
:
BigDecimal
.
valueOf
(((
Number
)
obj
).
doubleValue
());
}
else
{
try
{
return
new
BigDecimal
(
obj
.
toString
());
...
...
intg/src/test/java/org/apache/atlas/type/TestAtlasBigDecimalType.java
View file @
11e22022
...
...
@@ -32,12 +32,12 @@ public class TestAtlasBigDecimalType {
private
final
AtlasBigDecimalType
bigDecimalType
=
new
AtlasBigDecimalType
();
private
final
Object
[]
validValues
=
{
null
,
Byte
.
valueOf
((
byte
)
1
),
Short
.
valueOf
((
short
)
1
),
Integer
.
valueOf
(
1
),
Long
.
valueOf
(
1L
),
Float
.
valueOf
(
1
),
Double
.
valueOf
(
1
),
BigInteger
.
valueOf
(
1
),
BigDecimal
.
valueOf
(
1
),
"1
"
,
Double
.
valueOf
(
1
),
BigInteger
.
valueOf
(
1
),
BigDecimal
.
valueOf
(
1
.0
),
"1.0
"
,
};
private
final
Object
[]
negativeValues
=
{
Byte
.
valueOf
((
byte
)-
1
),
Short
.
valueOf
((
short
)-
1
),
Integer
.
valueOf
(-
1
),
Long
.
valueOf
(-
1L
),
Float
.
valueOf
(-
1
),
Double
.
valueOf
(-
1
),
BigInteger
.
valueOf
(-
1
),
BigDecimal
.
valueOf
(-
1
),
"-1
"
,
Double
.
valueOf
(-
1
),
BigInteger
.
valueOf
(-
1
),
BigDecimal
.
valueOf
(-
1
.0
),
"-1.0
"
,
};
private
final
Object
[]
invalidValues
=
{
""
,
"12ab"
,
"abcd"
,
"-12ab"
};
...
...
@@ -77,14 +77,23 @@ public class TestAtlasBigDecimalType {
BigDecimal
normalizedValue
=
bigDecimalType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(
1
),
"value="
+
value
);
if
(
value
instanceof
BigInteger
)
{
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(
1
),
"value="
+
value
);
}
else
{
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(
1.0
),
"value="
+
value
);
}
}
for
(
Object
value
:
negativeValues
)
{
BigDecimal
normalizedValue
=
bigDecimalType
.
getNormalizedValue
(
value
);
assertNotNull
(
normalizedValue
,
"value="
+
value
);
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(-
1
),
"value="
+
value
);
if
(
value
instanceof
BigInteger
)
{
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(-
1
),
"value="
+
value
);
}
else
{
assertEquals
(
normalizedValue
,
BigDecimal
.
valueOf
(-
1.0
),
"value="
+
value
);
}
}
for
(
Object
value
:
invalidValues
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment