Coverage Report - com.lexicalscope.jewel.cli.HelpMessageOptionSummaryBuilderImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMessageOptionSummaryBuilderImpl
100%
42/42
100%
4/4
1.111
 
 1  
 package com.lexicalscope.jewel.cli;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 /*
 6  
  * Copyright 2011 Tim Wood
 7  
  *
 8  
  * Licensed under the Apache License, Version 2.0 (the "License");
 9  
  * you may not use this file except in compliance with the License.
 10  
  * You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing, software
 15  
  * distributed under the License is distributed on an "AS IS" BASIS,
 16  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17  
  * See the License for the specific language governing permissions and
 18  
  * limitations under the License. 
 19  
  */
 20  
 
 21  
 class HelpMessageOptionSummaryBuilderImpl implements OptionHelpMessage {
 22  
     final StringBuilder result;
 23  
 
 24  180
     public HelpMessageOptionSummaryBuilderImpl(final StringBuilder message) {
 25  180
         result = message;
 26  180
     }
 27  
 
 28  
     public HelpMessageOptionSummaryBuilderImpl() {
 29  90
         this(new StringBuilder());
 30  90
     }
 31  
 
 32  
     @Override public void startOptionalOption() {
 33  66
         result.append("[");
 34  66
     }
 35  
 
 36  
     @Override public void startMandatoryOption() {
 37  
 
 38  114
     }
 39  
 
 40  
     @Override public void longName(final List<String> longNames) {
 41  180
         String sepatator = "";
 42  180
         for (final String longName : longNames) {
 43  188
             result.append(sepatator).append("--").append(longName);
 44  188
             sepatator = " ";
 45  188
         }
 46  180
     }
 47  
 
 48  
     @Override public void shortName(final List<String> shortNames) {
 49  180
         for (final String shortName : shortNames) {
 50  58
             result.append(" -").append(shortName);
 51  58
         }
 52  180
     }
 53  
 
 54  
     private void multiValued() {
 55  26
         result.append("...");
 56  26
     }
 57  
 
 58  
     @Override public void multiValuedWithCustomPattern(final String pattern) {
 59  2
         singleValuedWithCustomPattern(pattern);
 60  2
         multiValued();
 61  2
     }
 62  
 
 63  
     @Override public void multiValuedWithCustomPattern() {
 64  24
         singleValued();
 65  24
         multiValued();
 66  24
     }
 67  
 
 68  
     @Override public void singleValuedWithCustomPattern(final String pattern) {
 69  14
         result.append(" /").append(pattern).append("/");
 70  14
     }
 71  
 
 72  
     @Override public void singleValued() {
 73  114
         result.append(" value");
 74  114
     }
 75  
 
 76  
     @Override public void noValued() {
 77  
         // OK
 78  52
     }
 79  
 
 80  
     @Override public void endOptionalOption() {
 81  66
         result.append("]");
 82  66
     }
 83  
 
 84  
     @Override public void endOptionalOption(final String description) {
 85  36
         endOptionalOption();
 86  36
         optionDescription(description);
 87  36
     }
 88  
 
 89  
     @Override public void endMandatoryOption() {
 90  
 
 91  84
     }
 92  
 
 93  
     @Override public void endMandatoryOption(final String description) {
 94  30
         optionDescription(description);
 95  30
     }
 96  
 
 97  
     private void optionDescription(final String description) {
 98  66
         result.append(" : ").append(description);
 99  66
     }
 100  
 
 101  
     @Override public String toString()
 102  
     {
 103  90
         return result.toString();
 104  
     }
 105  
 }