Coverage Report - org.apache.commons.flatfile.util.ApplyOptions
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplyOptions
92%
13/14
100%
2/2
1.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.flatfile.util;
 18  
 
 19  
 import java.util.Map;
 20  
 
 21  
 import net.sf.morph.lang.languages.SimpleLanguage;
 22  
 import net.sf.morph.reflect.Reflector;
 23  
 import net.sf.morph.reflect.reflectors.SimpleDelegatingReflector;
 24  
 import net.sf.morph.transform.Transformer;
 25  
 import net.sf.morph.transform.transformers.SimpleDelegatingTransformer;
 26  
 
 27  
 import org.apache.commons.flatfile.morph.EntityCollectionReflector;
 28  
 import org.apache.commons.flatfile.morph.FieldOptionConstantConverter;
 29  
 import org.apache.commons.flatfile.morph.TextToByteConverter;
 30  
 
 31  
 /**
 32  
  * Utilities for applying options.
 33  
  * @version $Revision: 1301244 $ $Date: 2012-03-15 17:16:23 -0500 (Thu, 15 Mar 2012) $
 34  
  */
 35  0
 public abstract class ApplyOptions {
 36  
 
 37  
     private static final SimpleLanguage MORPH_LANGUAGE;
 38  
 
 39  
     static {
 40  6
         MORPH_LANGUAGE = new SimpleLanguage();
 41  8
         MORPH_LANGUAGE.setReflector(new SimpleDelegatingReflector(
 42  2
                 new Reflector[] { new EntityCollectionReflector() }, true));
 43  8
         MORPH_LANGUAGE.setConverter(new SimpleDelegatingTransformer(
 44  4
                 new Transformer[] { new TextToByteConverter(),
 45  2
                         new FieldOptionConstantConverter() }, true));
 46  6
     }
 47  
 
 48  
     /**
 49  
      * Apply the specified option map to <code>o</code>.
 50  
      * @param <T> type of fluent arg/result.
 51  
      * @param o Object target
 52  
      * @param options option map
 53  
      * @return <code>o</code>.
 54  
      */
 55  
     public static <T> T apply(T o, Map<String, ?> options) {
 56  152
         for (Map.Entry<String, ?> option : options.entrySet()) {
 57  120
             apply(o, option.getKey(), option.getValue());
 58  80
         }
 59  84
         return o;
 60  
     }
 61  
 
 62  
     /**
 63  
      * Apply the specified option to <code>o</code>.
 64  
      * @param <T> type of fluent arg/result.
 65  
      * @param o Object target
 66  
      * @param option String option name.
 67  
      * @param value option value.
 68  
      * @return <code>o</code>.
 69  
      */
 70  
     public static <T> T apply(T o, String option, Object value) {
 71  438
         MORPH_LANGUAGE.set(o, option, value);
 72  438
         return o;
 73  
     }
 74  
 
 75  
 }