Coverage Report - org.dozer.cache.CacheKeyFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
CacheKeyFactory
50%
2/4
N/A
3.125
CacheKeyFactory$1
N/A
N/A
3.125
CacheKeyFactory$CacheKey
92%
25/27
60%
18/30
3.125
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.dozer.cache;
 17  
 
 18  
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 19  
 import org.apache.commons.lang3.builder.ToStringStyle;
 20  
 
 21  
 /**
 22  
  * Internal class that is responsible for producing cache keys. Only intended for internal use.
 23  
  * 
 24  
  * @author tierney.matt
 25  
  * @author dmitry.buzdin
 26  
  */
 27  
 public final class CacheKeyFactory {
 28  
 
 29  0
   private CacheKeyFactory() {
 30  0
   }
 31  
 
 32  
   public static Object createKey(Class<?> destClass, Class<?> srcClass) {
 33  304093
     return new CacheKey(srcClass, destClass);
 34  
   }
 35  
 
 36  
   public static Object createKey(Class<?> destClass, Class<?> srcClass, String mapId) {
 37  2
     return new CacheKey(srcClass, destClass, mapId);
 38  
   }
 39  
 
 40  304095
   private static class CacheKey {
 41  
 
 42  
     private Class<?> srcClass;
 43  
     private Class<?> destClass;
 44  
     private String mapId;
 45  
 
 46  2
     private CacheKey(Class<?> srcClass, Class<?> destClass, String mapId) {
 47  2
       this.srcClass = srcClass;
 48  2
       this.destClass = destClass;
 49  2
       this.mapId = mapId;
 50  2
     }
 51  
 
 52  304093
     private CacheKey(Class<?> srcClass, Class<?> destClass) {
 53  304093
       this.srcClass = srcClass;
 54  304093
       this.destClass = destClass;
 55  304093
     }
 56  
 
 57  
     @Override
 58  
     public boolean equals(final Object o) {
 59  429159
       if(this == o) {
 60  1
         return true;
 61  
       }
 62  429158
       if (o == null || getClass() != o.getClass()) {
 63  1
         return false;
 64  
       }
 65  429157
       final CacheKey cacheKey = (CacheKey) o;
 66  429157
       if (destClass != null ? !destClass.equals(cacheKey.destClass) : cacheKey.destClass != null) {
 67  2
         return false;
 68  
       }
 69  429155
       if (srcClass != null ? !srcClass.equals(cacheKey.srcClass) : cacheKey.srcClass != null) {
 70  0
         return false;
 71  
       }
 72  429155
       if (mapId != null ? !mapId.equals(cacheKey.mapId) : cacheKey.mapId != null) {
 73  2
         return false;
 74  
       }
 75  429153
       return true;
 76  
     }
 77  
 
 78  
 
 79  
     @Override
 80  
     public int hashCode() {
 81  
         int result;
 82  435806
         result = (srcClass != null ? srcClass.hashCode() : 0);
 83  435806
         result = 31 * result + (destClass != null ? destClass.hashCode() : 0);
 84  435806
         result = 31 * result + (mapId != null ? mapId.hashCode() : 0);
 85  435806
         return result;
 86  
     }
 87  
 
 88  
 
 89  
       @Override
 90  
     public String toString() {
 91  0
       return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
 92  
     }
 93  
   }
 94  
 
 95  
 }