Coverage Report - org.apache.johnzon.core.JsonStringImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JsonStringImpl
65%
13/20
30%
3/10
1,714
 
 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 javax.json.JsonString;
 22  
 
 23  
 final class JsonStringImpl implements JsonString {
 24  
     private final String value;
 25  
     private String escape;
 26  22608
     private Integer hashCode = null;
 27  
 
 28  
 
 29  22608
     JsonStringImpl(final String value) {
 30  22608
         if(value == null) {
 31  1
             throw new NullPointerException("value must not be null");
 32  
         }
 33  
 
 34  22607
         this.value = value;
 35  22607
     }
 36  
 
 37  
     @Override
 38  
     public String getString() {
 39  81
         return value;
 40  
     }
 41  
 
 42  
     @Override
 43  
     public CharSequence getChars() {
 44  0
         return value;
 45  
     }
 46  
 
 47  
     @Override
 48  
     public ValueType getValueType() {
 49  7
         return ValueType.STRING;
 50  
     }
 51  
 
 52  
     @Override
 53  
     public String toString() {
 54  12
         String s = escape;
 55  12
         if (s == null) {
 56  12
             s =  JsonChars.QUOTE_CHAR+Strings.escape(value)+JsonChars.QUOTE_CHAR;
 57  12
             escape=s;
 58  
         }
 59  12
         return s;
 60  
     }
 61  
 
 62  
     @Override
 63  
     public int hashCode() {
 64  0
         Integer h = hashCode;
 65  0
         if (h == null) {
 66  0
             h = value.hashCode();
 67  0
             hashCode=h;
 68  
         }
 69  0
         return h;
 70  
     }
 71  
 
 72  
     @Override
 73  
     public boolean equals(final Object obj) {
 74  0
         return JsonString.class.isInstance(obj) && JsonString.class.cast(obj).getString().equals(value);
 75  
     }
 76  
 }