Coverage Report - org.apache.commons.flatfile.util.ApplyOptions
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplyOptions
90%
9/10
100%
2/2
0
 
 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: 757266 $ $Date: 2009-03-22 17:12:27 -0500 (Sun, 22 Mar 2009) $
 34  
  */
 35  0
 public abstract class ApplyOptions {
 36  
 
 37  
     private static final SimpleLanguage MORPH_LANGUAGE;
 38  
 
 39  
     static {
 40  1
         MORPH_LANGUAGE = new SimpleLanguage();
 41  1
         MORPH_LANGUAGE.setReflector(new SimpleDelegatingReflector(
 42  
                 new Reflector[] { new EntityCollectionReflector() }, true));
 43  1
         MORPH_LANGUAGE.setConverter(new SimpleDelegatingTransformer(
 44  
                 new Transformer[] { new TextToByteConverter(),
 45  
                         new FieldOptionConstantConverter() }, true));
 46  1
     }
 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, ? extends Object> options) {
 56  14
         for (Map.Entry<String, ? extends Object> option : options.entrySet()) {
 57  20
             apply(o, option.getKey(), option.getValue());
 58  
         }
 59  14
         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  73
         MORPH_LANGUAGE.set(o, option, value);
 72  73
         return o;
 73  
     }
 74  
 
 75  
 }