Coverage Report - org.dozer.loader.api.FieldsMappingOptions
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldsMappingOptions
100%
22/22
100%
2/2
1.034
FieldsMappingOptions$1
100%
3/3
N/A
1.034
FieldsMappingOptions$10
100%
3/3
N/A
1.034
FieldsMappingOptions$11
100%
3/3
N/A
1.034
FieldsMappingOptions$12
100%
4/4
N/A
1.034
FieldsMappingOptions$2
100%
4/4
N/A
1.034
FieldsMappingOptions$3
100%
3/3
N/A
1.034
FieldsMappingOptions$4
100%
3/3
N/A
1.034
FieldsMappingOptions$5
100%
3/3
N/A
1.034
FieldsMappingOptions$6
100%
4/4
N/A
1.034
FieldsMappingOptions$7
100%
4/4
N/A
1.034
FieldsMappingOptions$8
100%
4/4
N/A
1.034
FieldsMappingOptions$9
100%
4/4
N/A
1.034
 
 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.loader.api;
 17  
 
 18  
 import org.apache.commons.lang3.StringUtils;
 19  
 import org.dozer.CustomConverter;
 20  
 import org.dozer.classmap.MappingDirection;
 21  
 import org.dozer.classmap.RelationshipType;
 22  
 import org.dozer.loader.DozerBuilder;
 23  
 
 24  
 /**
 25  
  * Mapping options applied on Field level.
 26  
  *
 27  
  * @author Dmitry Buzdin
 28  
  */
 29  6
 public final class FieldsMappingOptions {
 30  
 
 31  
   public static FieldsMappingOption copyByReference() {
 32  1
     return new FieldsMappingOption() {
 33  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 34  1
         fieldMappingBuilder.copyByReference(true);
 35  1
       }
 36  
     };
 37  
   }
 38  
 
 39  
   public static FieldsMappingOption customConverter(final Class<? extends CustomConverter> type) {
 40  1
     return customConverter(type, null);
 41  
   }
 42  
 
 43  
   public static FieldsMappingOption customConverter(final Class<? extends CustomConverter> type, final String parameter) {
 44  2
     return customConverter(type.getName(), parameter);
 45  
   }
 46  
 
 47  
   public static FieldsMappingOption customConverter(final String type) {
 48  1
     return customConverter(type, null);
 49  
   }
 50  
 
 51  
   public static FieldsMappingOption customConverter(final String type, final String parameter) {
 52  3
     return new FieldsMappingOption() {
 53  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 54  3
         fieldMappingBuilder.customConverter(type);
 55  3
         fieldMappingBuilder.customConverterParam(parameter);
 56  3
       }
 57  
     };
 58  
   }
 59  
 
 60  
   public static FieldsMappingOption customConverterId(final String id) {
 61  1
     return new FieldsMappingOption() {
 62  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 63  1
         fieldMappingBuilder.customConverterId(id);
 64  1
       }
 65  
     };
 66  
   }
 67  
 
 68  
   public static FieldsMappingOption useMapId(final String mapId) {
 69  3
     return new FieldsMappingOption() {
 70  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 71  3
         fieldMappingBuilder.mapId(mapId);
 72  3
       }
 73  
     };
 74  
   }
 75  
 
 76  
   public static FieldsMappingOption oneWay() {
 77  1
     return new FieldsMappingOption() {
 78  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 79  1
         fieldMappingBuilder.type(MappingDirection.ONE_WAY);
 80  1
       }
 81  
     };
 82  
   }
 83  
 
 84  
   public static FieldsMappingOption hintA(final Class<?>... type) {
 85  2
     return new FieldsMappingOption() {
 86  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 87  2
         String declaration = mergeTypeNames(type);
 88  2
         fieldMappingBuilder.srcHintContainer(declaration);
 89  2
       }
 90  
     };
 91  
   }
 92  
 
 93  
   public static FieldsMappingOption hintB(final Class<?>... type) {
 94  2
     return new FieldsMappingOption() {
 95  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 96  2
         String declaration = mergeTypeNames(type);
 97  2
         fieldMappingBuilder.destHintContainer(declaration);
 98  2
       }
 99  
     };
 100  
   }
 101  
 
 102  
   public static FieldsMappingOption deepHintA(final Class<?>... type) {
 103  1
     return new FieldsMappingOption() {
 104  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 105  1
         String declaration = mergeTypeNames(type);
 106  1
         fieldMappingBuilder.srcDeepIndexHintContainer(declaration);
 107  1
       }
 108  
     };
 109  
   }
 110  
 
 111  
   public static FieldsMappingOption deepHintB(final Class<?>... type) {
 112  1
     return new FieldsMappingOption() {
 113  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 114  1
         String declaration = mergeTypeNames(type);
 115  1
         fieldMappingBuilder.destDeepIndexHintContainer(declaration);
 116  1
       }
 117  
     };
 118  
   }
 119  
 
 120  
   private static String mergeTypeNames(Class<?>[] type) {
 121  6
     String[] typeNames = new String[type.length];
 122  13
     for (int i = 0; i < type.length; i++) {
 123  7
       Class<?> t = type[i];
 124  7
       typeNames[i] = t.getName();
 125  
     }
 126  6
     return StringUtils.join(typeNames, ",");
 127  
   }
 128  
 
 129  
   public static FieldsMappingOption removeOrphans() {
 130  1
     return removeOrphans(true);
 131  
   }
 132  
 
 133  
   public static FieldsMappingOption removeOrphans(final boolean removeOrphans) {
 134  1
     return new FieldsMappingOption() {
 135  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 136  1
         fieldMappingBuilder.removeOrphans(removeOrphans);
 137  1
       }
 138  
     };
 139  
   }
 140  
 
 141  
   public static FieldsMappingOption relationshipType(final RelationshipType relationshipType) {
 142  1
     return new FieldsMappingOption() {
 143  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 144  1
         fieldMappingBuilder.relationshipType(relationshipType);
 145  1
       }
 146  
     };
 147  
   }
 148  
 
 149  
   public static FieldsMappingOption collectionStrategy(final boolean removeOrphans, final RelationshipType relationshipType) {
 150  6
     return new FieldsMappingOption() {
 151  
       public void apply(DozerBuilder.FieldMappingBuilder fieldMappingBuilder) {
 152  6
         fieldMappingBuilder.removeOrphans(removeOrphans);
 153  6
         fieldMappingBuilder.relationshipType(relationshipType);
 154  6
       }
 155  
     };
 156  
   }
 157  
 
 158  
 
 159  
 }