Coverage Report - org.apache.johnzon.core.JsonNumberImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonNumberImpl
47%
11/23
30%
3/10
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 JsonNumberImpl implements JsonNumber {
 27  
     private final BigDecimal value;
 28  7291
     private Integer hashCode = null;
 29  
 
 30  7291
     JsonNumberImpl(final BigDecimal decimal) {
 31  7291
         if(decimal == null) {
 32  1
             throw new NullPointerException("decimal must not be null");
 33  
         }
 34  
         
 35  7290
         this.value = decimal;
 36  7290
     }
 37  
 
 38  
     @Override
 39  
     public boolean isIntegral() {
 40  1
         return value.scale() == 0;
 41  
     }
 42  
 
 43  
     @Override
 44  
     public int intValue() {
 45  3
         return value.intValue();
 46  
     }
 47  
 
 48  
     @Override
 49  
     public int intValueExact() {
 50  0
         return value.intValueExact();
 51  
     }
 52  
 
 53  
     @Override
 54  
     public long longValue() {
 55  0
         return value.longValue();
 56  
     }
 57  
 
 58  
     @Override
 59  
     public long longValueExact() {
 60  0
         return value.longValueExact();
 61  
     }
 62  
 
 63  
     @Override
 64  
     public BigInteger bigIntegerValue() {
 65  0
         return value.toBigInteger();
 66  
     }
 67  
 
 68  
     @Override
 69  
     public BigInteger bigIntegerValueExact() {
 70  0
         return value.toBigIntegerExact();
 71  
     }
 72  
 
 73  
     @Override
 74  
     public double doubleValue() {
 75  4
         return value.doubleValue();
 76  
     }
 77  
 
 78  
     @Override
 79  
     public BigDecimal bigDecimalValue() {
 80  0
         return value;
 81  
     }
 82  
 
 83  
     @Override
 84  
     public ValueType getValueType() {
 85  3
         return ValueType.NUMBER;
 86  
     }
 87  
 
 88  
     @Override
 89  
     public String toString() {
 90  1
         return value.toString();
 91  
     }
 92  
 
 93  
     @Override
 94  
     public int hashCode() {
 95  0
         Integer h=hashCode;
 96  0
         if (h == null) {
 97  0
             h = value.hashCode();
 98  0
             hashCode=h;
 99  
         }
 100  0
         return h;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public boolean equals(final Object obj) {
 105  0
         return JsonNumber.class.isInstance(obj) && JsonNumber.class.cast(obj).bigDecimalValue().equals(value);
 106  
     }
 107  
 }