Coverage Report - org.dishevelled.commandline.argument.ByteListArgument
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteListArgument
100%
11/11
100%
2/2
1.5
 
 1  
 /*
 2  
 
 3  
     dsh-commandline  Command line parser based on typed arguments.
 4  
     Copyright (c) 2004-2012 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.commandline.argument;
 25  
 
 26  
 import java.util.List;
 27  
 import java.util.ArrayList;
 28  
 import java.util.StringTokenizer;
 29  
 
 30  
 import org.apache.commons.lang.StringUtils;
 31  
 
 32  
 /**
 33  
  * A byte list argument.
 34  
  *
 35  
  * @author  Michael Heuer
 36  
  * @version $Revision: 1059 $ $Date: 2012-01-03 14:03:02 -0600 (Tue, 03 Jan 2012) $
 37  
  */
 38  16
 public final class ByteListArgument
 39  
     extends AbstractArgument<List<Byte>>
 40  
 {
 41  
 
 42  
     /**
 43  
      * Create a new byte list argument.
 44  
      *
 45  
      * @param shortName short argument name
 46  
      * @param longName long argument name
 47  
      * @param description argument description
 48  
      * @param required <code>true</code> if this argument is required
 49  
      */
 50  
     public ByteListArgument(final String shortName,
 51  
                             final String longName,
 52  
                             final String description,
 53  
                             final boolean required)
 54  
     {
 55  7
         super(shortName, longName, description, required);
 56  7
     }
 57  
 
 58  
 
 59  
     /** {@inheritDoc} */
 60  
     protected List<Byte> convert(final String s)
 61  
         throws Exception
 62  
     {
 63  16
         List<Byte> list = new ArrayList<Byte>();
 64  16
         StringTokenizer st = new StringTokenizer(s, ",");
 65  38
         while (st.hasMoreTokens())
 66  
         {
 67  28
             String token = StringUtils.stripToEmpty(st.nextToken());
 68  28
             Byte b = Byte.valueOf(token);
 69  22
             list.add(b);
 70  22
         }
 71  10
         return list;
 72  
     }
 73  
 }