0

I have some phone records in which epoch time is coming in exponential format like 1467.738871E9. I need to validate those records in which number is not in proper format and drop those records.Right now, I am using big decimal,but I have heard that bigdecimal is slow and takes more space. Since I have million of records to be validated,is there any other way to validate time which is more space and time efficient.

Code:

try {
    new BigDecimal(data).toBigInteger();
} catch (NumberFormatException n) {
    return false;
}
return true;
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
mahan07
  • 887
  • 4
  • 14
  • 32
  • 1
    Since your code is working (although inefficiently), you might want to ask this question on [codereview](http://codereview.stackexchange.com/). – Aaron Aug 18 '16 at 15:02
  • I am not reviweing it,I am asking if there is any other efficient way to do it. – mahan07 Aug 18 '16 at 15:15
  • The folks at codereview do not only deal with best practice and coding standards, they could review your piece of code with efficiency in mind. Now I'm not saying you won't obtain an answer here, nor did I vote to close your answer, I'm just saying this is an alternative. – Aaron Aug 18 '16 at 15:19
  • Sure will consider your suggestion next time,Thanks. – mahan07 Aug 18 '16 at 15:26
  • 1
    Your question is not completely clear to me. Are you saying that any number in that column that is given in exponential notation is invalid? If so, why not just look for the letter "E" in the string? By the way, your existing code won't throw an exception because exponential notation is just fine for BigDecimal. – Klitos Kyriacou Aug 18 '16 at 16:17
  • @Klitos valid: 1.467983982E9, 1.468119771E9, 1467858808E9, 1.468119771E11, 1468119771E11 invalid: 1.46A802215E9, null, 4.1B46A802215E9,ABCF456E9 – mahan07 Aug 18 '16 at 17:03
  • If it is only about validity, the "rules" are the same for `double`, so you could just as well use that. It could be faster. No need to convert to integer either. – Rudy Velthuis Aug 20 '16 at 01:29

0 Answers0