Coverage Report - org.apache.johnzon.core.JsonDoubleImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonDoubleImpl
44 %
8/18
50 %
4/8
1,286
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements. See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License. You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied. See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.johnzon.core;
 20  
 
 21  
 import java.math.BigDecimal;
 22  
 import java.math.BigInteger;
 23  
 
 24  
 import javax.json.JsonNumber;
 25  
 
 26  
 final class JsonDoubleImpl implements JsonNumber {
 27  
     private final double value;
 28  
 
 29  6
     JsonDoubleImpl(final double value) {
 30  
         
 31  6
         if(Double.isInfinite(value) || Double.isNaN(value)) {
 32  3
             throw new NumberFormatException("double value must not be NaN or Infinite");
 33  
         }
 34  
         
 35  3
         this.value = value;
 36  3
     }
 37  
 
 38  
     @Override
 39  
     public boolean isIntegral() {
 40  0
         return false;
 41  
     }
 42  
 
 43  
     @Override
 44  
     public int intValue() {
 45  0
         return (int) value;
 46  
     }
 47  
 
 48  
     @Override
 49  
     public int intValueExact() {
 50  0
         return intValue();
 51  
     }
 52  
 
 53  
     @Override
 54  
     public long longValue() {
 55  0
         return (long) value;
 56  
     }
 57  
 
 58  
     @Override
 59  
     public long longValueExact() {
 60  0
         return (long) value;
 61  
     }
 62  
 
 63  
     @Override
 64  
     public BigInteger bigIntegerValue() {
 65  1
         return new BigDecimal(toString()).toBigInteger();
 66  
     }
 67  
 
 68  
     @Override
 69  
     public BigInteger bigIntegerValueExact() {
 70  1
         return new BigDecimal(toString()).toBigIntegerExact();
 71  
     }
 72  
 
 73  
     @Override
 74  
     public double doubleValue() {
 75  0
         return value;
 76  
     }
 77  
 
 78  
     @Override
 79  
     public BigDecimal bigDecimalValue() {
 80  0
         return new BigDecimal(toString());
 81  
     }
 82  
 
 83  
     @Override
 84  
     public ValueType getValueType() {
 85  0
         return ValueType.NUMBER;
 86  
     }
 87  
 
 88  
     @Override
 89  
     public String toString() {
 90  3
         return Double.toString(value);
 91  
     }
 92  
 
 93  
     @Override
 94  
     public int hashCode() {
 95  0
         return Double.valueOf(value).hashCode();
 96  
     }
 97  
 
 98  
     @Override
 99  
     public boolean equals(final Object obj) {
 100  0
         return JsonNumber.class.isInstance(obj) && JsonNumber.class.cast(obj).doubleValue() == value;
 101  
     }
 102  
 }