Coverage Report - com.lexicalscope.jewel.cli.validation.OptionCollectionImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionCollectionImpl
92%
13/14
66%
4/6
2.25
 
 1  
 /*
 2  
  * Copyright 2006 Tim Wood
 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 http://www.apache.org/licenses/LICENSE-2.0
 7  
  *
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 
 15  
 package com.lexicalscope.jewel.cli.validation;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 
 21  
 import com.lexicalscope.jewel.cli.specification.OptionsSpecification;
 22  
 import com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification;
 23  
 
 24  
 
 25  
 class OptionCollectionImpl implements OptionCollection
 26  
 {
 27  
     private final OptionsSpecification<?> specification;
 28  
     private final Map<ParsedOptionSpecification, List<String>> arguments;
 29  
     private final List<String> unparsed;
 30  
 
 31  
     public OptionCollectionImpl(
 32  
             final OptionsSpecification<?> specification,
 33  
             final Map<ParsedOptionSpecification,
 34  
             List<String>> arguments,
 35  
             final List<String> unparsed)
 36  160
     {
 37  160
         this.specification = specification;
 38  160
         this.arguments = arguments;
 39  160
         this.unparsed = unparsed;
 40  160
     }
 41  
 
 42  
     @Override public List<String> getUnparsed()
 43  
     {
 44  56
         return new ArrayList<String>(unparsed);
 45  
     }
 46  
 
 47  
     @Override public Argument getArgument(final ParsedOptionSpecification option) {
 48  274
         if (arguments.containsKey(option)) {
 49  162
             return new ArgumentImpl(option, arguments.get(option));
 50  
         }
 51  112
         return null;
 52  
     }
 53  
 
 54  
     @Override public List<String> getValues(final String... options)
 55  
     {
 56  6
         for (final String option : options)
 57  
         {
 58  6
             final ParsedOptionSpecification optionSpecification = specification.getSpecification(option);
 59  6
             if (arguments.containsKey(optionSpecification))
 60  
             {
 61  6
                 return arguments.get(optionSpecification);
 62  
             }
 63  
         }
 64  0
         return null;
 65  
     }
 66  
 }