| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LongSetArgument |
|
| 1.5;1.5 |
| 1 | /* | |
| 2 | ||
| 3 | dsh-commandline Command line parser based on typed arguments. | |
| 4 | Copyright (c) 2004-2014 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.Set; | |
| 27 | import java.util.HashSet; | |
| 28 | import java.util.StringTokenizer; | |
| 29 | ||
| 30 | import org.apache.commons.lang.StringUtils; | |
| 31 | ||
| 32 | /** | |
| 33 | * A long set argument. | |
| 34 | * | |
| 35 | * @author Michael Heuer | |
| 36 | */ | |
| 37 | 12 | public final class LongSetArgument |
| 38 | extends AbstractArgument<Set<Long>> | |
| 39 | { | |
| 40 | ||
| 41 | /** | |
| 42 | * Create a new long set argument. | |
| 43 | * | |
| 44 | * @param shortName short argument name | |
| 45 | * @param longName long argument name | |
| 46 | * @param description argument description | |
| 47 | * @param required <code>true</code> if this argument is required | |
| 48 | */ | |
| 49 | public LongSetArgument(final String shortName, | |
| 50 | final String longName, | |
| 51 | final String description, | |
| 52 | final boolean required) | |
| 53 | { | |
| 54 | 7 | super(shortName, longName, description, required); |
| 55 | 7 | } |
| 56 | ||
| 57 | ||
| 58 | /** {@inheritDoc} */ | |
| 59 | protected Set<Long> convert(final String s) | |
| 60 | throws Exception | |
| 61 | { | |
| 62 | 12 | Set<Long> set = new HashSet<Long>(); |
| 63 | 12 | StringTokenizer st = new StringTokenizer(s, ","); |
| 64 | 28 | while (st.hasMoreTokens()) |
| 65 | { | |
| 66 | 18 | String token = StringUtils.stripToEmpty(st.nextToken()); |
| 67 | 18 | Long l = Long.valueOf(token); |
| 68 | 16 | set.add(l); |
| 69 | 16 | } |
| 70 | 10 | return set; |
| 71 | } | |
| 72 | } |