| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CommandLine |
|
| 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; | |
| 25 | ||
| 26 | import java.util.List; | |
| 27 | import java.util.Arrays; | |
| 28 | import java.util.ListIterator; | |
| 29 | ||
| 30 | /** | |
| 31 | * Command line. | |
| 32 | * | |
| 33 | * @author Michael Heuer | |
| 34 | */ | |
| 35 | 0 | public final class CommandLine |
| 36 | implements ListIterator<String> | |
| 37 | { | |
| 38 | /** Wrapped iterator. */ | |
| 39 | private final ListIterator<String> iterator; | |
| 40 | ||
| 41 | ||
| 42 | /** | |
| 43 | * Create a new command line with the specified arguments. | |
| 44 | * | |
| 45 | * @param args command line arguments | |
| 46 | */ | |
| 47 | public CommandLine(final String[] args) | |
| 48 | 478 | { |
| 49 | 478 | if (args == null) |
| 50 | { | |
| 51 | 1 | throw new IllegalArgumentException("args must not be null"); |
| 52 | } | |
| 53 | ||
| 54 | 477 | List<String> argumentList = Arrays.asList(args); |
| 55 | 477 | iterator = argumentList.listIterator(); |
| 56 | 477 | } |
| 57 | ||
| 58 | ||
| 59 | /** {@inheritDoc} */ | |
| 60 | public void add(final String s) | |
| 61 | { | |
| 62 | 2 | throw new UnsupportedOperationException("add operation not supported by CommandLine"); |
| 63 | } | |
| 64 | ||
| 65 | /** {@inheritDoc} */ | |
| 66 | public boolean hasNext() | |
| 67 | { | |
| 68 | 1301 | return iterator.hasNext(); |
| 69 | } | |
| 70 | ||
| 71 | /** {@inheritDoc} */ | |
| 72 | public boolean hasPrevious() | |
| 73 | { | |
| 74 | 1004 | return iterator.hasPrevious(); |
| 75 | } | |
| 76 | ||
| 77 | /** {@inheritDoc} */ | |
| 78 | public String next() | |
| 79 | { | |
| 80 | 1704 | return iterator.next(); |
| 81 | } | |
| 82 | ||
| 83 | /** {@inheritDoc} */ | |
| 84 | public int nextIndex() | |
| 85 | { | |
| 86 | 1 | return iterator.nextIndex(); |
| 87 | } | |
| 88 | ||
| 89 | /** {@inheritDoc} */ | |
| 90 | public String previous() | |
| 91 | { | |
| 92 | 949 | return iterator.previous(); |
| 93 | } | |
| 94 | ||
| 95 | /** {@inheritDoc} */ | |
| 96 | public int previousIndex() | |
| 97 | { | |
| 98 | 1 | return iterator.previousIndex(); |
| 99 | } | |
| 100 | ||
| 101 | /** {@inheritDoc} */ | |
| 102 | public void remove() | |
| 103 | { | |
| 104 | 2 | throw new UnsupportedOperationException("remove operation not supported by CommandLine"); |
| 105 | } | |
| 106 | ||
| 107 | /** {@inheritDoc} */ | |
| 108 | public void set(final String s) | |
| 109 | { | |
| 110 | 2 | throw new UnsupportedOperationException("set operation not supported by CommandLine"); |
| 111 | } | |
| 112 | } |