| 1 | /** |
| 2 | * BSD-style license; for more info see http://xradar.sourceforge.net/license.html |
| 3 | */ |
| 4 | package org.sourceforge.xradar; |
| 5 | |
| 6 | /** |
| 7 | * |
| 8 | * FUTURE: Turn this into an Enum... |
| 9 | * |
| 10 | * @author Zahir Nuckchady, zahir.nu@gmail.com |
| 11 | * @author Romain PELISSE, belaran@gmail.com |
| 12 | * |
| 13 | */ |
| 14 | public class CommandLineArgument { |
| 15 | |
| 16 | private String argument; // --pmd |
| 17 | private int nbValue; // 1 |
| 18 | private boolean[] valueIsAFile; // valueIsAFile[0] => true..checks the diff files passed |
| 19 | |
| 20 | public CommandLineArgument(String string, int nbArgumentMax, boolean needArg) { |
| 21 | this.argument = string; |
| 22 | this.nbValue = nbArgumentMax; |
| 23 | if ( nbArgumentMax == 0 ){ |
| 24 | this.valueIsAFile = new boolean[1]; |
| 25 | } |
| 26 | else{ |
| 27 | this.valueIsAFile = new boolean[nbArgumentMax]; |
| 28 | } |
| 29 | for (int i = 0 ; i < nbArgumentMax ; i++){ |
| 30 | this.valueIsAFile[i] = false; |
| 31 | } |
| 32 | this.valueIsAFile[0] = needArg; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * |
| 37 | * @return |
| 38 | */ |
| 39 | public String getArgument() { |
| 40 | return argument; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * |
| 45 | * @param argument |
| 46 | */ |
| 47 | public void setArgument(String argument) { |
| 48 | this.argument = argument; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * |
| 53 | * @return |
| 54 | */ |
| 55 | public int getNbValue() { |
| 56 | return nbValue; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * |
| 61 | * @param nbValue |
| 62 | */ |
| 63 | public void setNbValue(int nbValue) { |
| 64 | this.nbValue = nbValue; |
| 65 | } |
| 66 | |
| 67 | public boolean isValueAFile(int index) { |
| 68 | if (index <= this.valueIsAFile.length){ |
| 69 | return this.valueIsAFile[index]; //index-1 before debug |
| 70 | } |
| 71 | else{ |
| 72 | throw new IllegalArgumentException("This command line has only " + this.valueIsAFile.length + " arguments"); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | public String toString() { |
| 77 | return this.argument; |
| 78 | } |
| 79 | |
| 80 | } |