ns2/Parser.java
Go to the documentation of this file.00001 package ns2;
00002
00008 public class Parser {
00015 public static Parameter parse(String[] args) throws IllegalArgumentException {
00016 String net = "";
00017 String trace = "";
00018 String activity = "";
00019 String mobility = "";
00020 String config = "";
00021 double begin = 0;
00022 double end = 0;
00023 double penetration = 0;
00024 long seed = 0;
00025
00026 boolean hasNet = false;
00027 boolean hasTrace = false;
00028 boolean hasActivity = false;
00029 boolean hasMobility = false;
00030 boolean hasConfig = false;
00031 boolean hasBegin = false;
00032 boolean hasEnd = false;
00033 boolean hasPenetration = false;
00034
00035 for (int i=0; i<args.length; i++) {
00036 if ("ns2".equals(args[i].toLowerCase())) {
00037 }
00038
00039 if ("-n".equals(args[i])) {
00040
00041 if (++i<args.length) {
00042 if (!args[i].startsWith("-")) {
00043 net = args[i];
00044 hasNet = true;
00045 }
00046 }
00047 }
00048
00049 if ("-t".equals(args[i])) {
00050
00051 if (++i<args.length) {
00052 if (!args[i].startsWith("-")) {
00053 trace = args[i];
00054 hasTrace = true;
00055 }
00056 }
00057 }
00058
00059 if ("-a".equals(args[i])) {
00060
00061 if (++i<args.length) {
00062 if (!args[i].startsWith("-")) {
00063 activity = args[i];
00064 hasActivity = true;
00065 }
00066 }
00067 }
00068
00069 if ("-m".equals(args[i])) {
00070
00071 if (++i<args.length) {
00072 if (!args[i].startsWith("-")) {
00073 mobility = args[i];
00074 hasMobility = true;
00075 }
00076 }
00077 }
00078
00079 if ("-c".equals(args[i])) {
00080
00081 if (++i<args.length) {
00082 if (!args[i].startsWith("-")) {
00083 config = args[i];
00084 hasConfig = true;
00085 }
00086 }
00087 }
00088
00089 if ("-b".equals(args[i])) {
00090
00091 if (++i<args.length) {
00092 begin = Double.parseDouble(args[i]);
00093 if (begin >= 0) {
00094 hasBegin = true;
00095 }
00096 }
00097 }
00098
00099 if ("-e".equals(args[i])) {
00100
00101 if (++i<args.length) {
00102 end = Double.parseDouble(args[i]);
00103 if (begin < end) {
00104 hasEnd = true;
00105 }
00106 }
00107 }
00108
00109 if ("-p".equals(args[i])) {
00110
00111 if (++i<args.length) {
00112 if (!args[i].startsWith("-")) {
00113 penetration = Double.parseDouble(args[i]);
00114 if (penetration>=0 && penetration<=1) {
00115 hasPenetration = true;
00116 } else {
00117 penetration = 0;
00118 }
00119 }
00120 }
00121 }
00122
00123 if ("-s".equals(args[i])) {
00124
00125 if (++i<args.length) {
00126 seed = Long.parseLong(args[i]);
00127
00128 }
00129 }
00130 }
00131
00132
00133 if (!hasNet) {
00134 throw new IllegalArgumentException("no netfile specified!");
00135 }
00136
00137
00138 if (!hasTrace) {
00139 throw new IllegalArgumentException("no tracefile specified!");
00140 }
00141
00142
00143 if (!hasActivity) {
00144 throw new IllegalArgumentException("no activity specified!");
00145 }
00146
00147
00148 if (!hasMobility) {
00149 throw new IllegalArgumentException("no mobility specified!");
00150 }
00151
00152
00153 if (!hasConfig) {
00154 throw new IllegalArgumentException("no config specified!");
00155 }
00156
00157
00158 if (!hasBegin) {
00159 begin = 0;
00160 }
00161
00162
00163 if (!hasEnd) {
00164
00165 end = begin;
00166 }
00167
00168
00169
00170
00171
00172 return new Parameter(net, trace, activity, mobility, config, begin, end, penetration, seed, hasPenetration);
00173 }
00174 }