00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "DotString.h"
00026
00027 namespace cmlabs {
00028
00029
00030
00031
00032
00033 DotString::DotString(const JString& text) {
00034
00035 if (text.length() == 0)
00036 return;
00037
00038 int pos = text.lastIndexOf(':');
00039 if (pos >= 0) {
00040 comment = text.substring(pos+1);
00041
00042 entries = text.substring(0, pos).split(".");
00043 }
00044 else
00045 entries = text.split(".");
00046 }
00047
00048 DotString::DotString(const Collection& oc) {
00049 entries.copyAll(oc);
00050 }
00051
00052
00053
00054
00055
00056
00057 DotString::~DotString() {
00058 }
00059
00060
00061 unsigned long DotString::getPayloadSize() const {
00062 return entries.getPayloadSize() + comment.getPayloadSize();
00063 }
00064
00065 Object* DotString::clone() const {
00066 DotString* ds = new DotString(entries);
00067 ds->comment = comment;
00068 return (Object*) ds;
00069 }
00070
00071 DotString::operator char*() {
00072 return print();
00073 }
00074
00075 DotString::operator JString() {
00076 return print();
00077 }
00078
00079
00080 JString DotString::toXML() {
00081 return print().xmlStringEncode();
00082 }
00083
00084 JString DotString::toText() {
00085 return print();
00086 }
00087
00088 JString DotString::print() {
00089 if (comment.length() > 0)
00090 return JString::format("%s:%s", (char*) entries.printListLine("."), (char*) comment);
00091 else
00092 return entries.printListLine(".");
00093 }
00094
00095
00096
00097
00098
00099
00100
00101 bool DotString::operator ==(const DotString &ds) const {
00102 return (this->equals(ds));
00103 }
00104
00105 bool DotString::operator !=(const DotString &ds) const {
00106 return (!this->equals(ds));
00107 }
00108
00109 bool DotString::isPartOf(const DotString& ds) const {
00110
00111 int c = entries.getCount();
00112 if (c > ds.entries.getCount())
00113 return false;
00114 for (int n=0; n<c; n++) {
00115 if (!entries.get(n).equalsIgnoreCase(ds.entries.get(n)))
00116 return false;
00117 }
00118 return true;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 }
00136
00137 bool DotString::isSupersededBy(const DotString& ds) const {
00138 return (!ds.isPartOf(*this));
00139 }
00140
00141 unsigned long DotString::getHash() const {
00142 if (comment.length() > 0)
00143 return JString::format("%s:%s", (char*) entries.printListLine("."), (char*) comment).getHash();
00144 else
00145 return entries.printListLine(".").getHash();
00146 }
00147
00148 JString DotString::operator [](int n) {
00149 return entries.get(n);
00150 }
00151
00152 int DotString::getCount() const {
00153 return entries.getCount();
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 DotString DotString::getFirst(int n) {
00187
00188 int c = n;
00189 int l = getCount();
00190 if (c > l)
00191 c = l;
00192 Collection oc;
00193 for (int i=0; i<c; i++) {
00194 oc.addLast(entries.get(i));
00195 }
00196 return DotString(oc);
00197 }
00198
00199 DotString DotString::getLast(int n) {
00200 int c = n;
00201 int l = getCount();
00202 if (c > l) c = l;
00203 c = l - c;
00204 Collection oc;
00205 for (int i=c; i<l; i++) {
00206 oc.addLast(entries.get(i));
00207 }
00208 return DotString(oc);
00209 }
00210
00211
00212 bool DotString::equals(const Object* o2) const {
00213 if (o2 == NULL) return false;
00214 if (!this->isSameClass(o2)) {
00215 return false;
00216 }
00217 return this->equals(*(DotString*)o2);
00218 }
00219
00220 bool DotString::equals(const JString& s) const {
00221 JString str = s;
00222 int pos = str.lastIndexOf(':');
00223 bool res = false;
00224
00225 if (pos >= 0) {
00226 JString com = str.substring(pos+1);
00227 if ( (comment.length() != 0) && (com.length() != 0) &&
00228 (!comment.equals("*")) && (!com.equals("*")) ) {
00229 if (!comment.matchesIgnoreCase(com)) {
00230 return false;
00231 }
00232 }
00233 res = entries.printListLine(".").matchesIgnoreCase(str.substring(0, pos));
00234 }
00235 else {
00236 res = entries.printListLine(".").matchesIgnoreCase(str);
00237 }
00238 return res;
00239 }
00240
00241 bool DotString::equals(const DotString& ds) const {
00242
00243
00244
00245
00246
00247
00248 if ( (comment.length() != 0) && (ds.comment.length() != 0) &&
00249 (!comment.equals("*")) && (!ds.comment.equals("*")) ) {
00250
00251 if (!comment.matchesIgnoreCase(ds.comment)) {
00252 if (DEBUGLEVEL(KITCHENSINK)) {
00253 printf("DotString: equals FAILED 1\n");
00254 }
00255 return false;
00256 }
00257 }
00258
00259 JString str10 = entries.printListLine(".");
00260 JString str20 = ds.entries.printListLine(".");
00261 return str10.matchesIgnoreCase(str20);
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 }
00414
00415
00416 bool DotString::unitTest() {
00417
00418 DotString dstr = DotString("first.second.third.fourth:comment");
00419 DotString test;
00420
00421
00422 JString str = "first.second.third.fourth";
00423 if (!dstr.equals((test = str.toDotString())))
00424 return false;
00425
00426 str = "*";
00427 if (!dstr.equals((test = str.toDotString())))
00428 return false;
00429
00430 str = "*.*";
00431 if (!dstr.equals((test = str.toDotString())))
00432 return false;
00433
00434 str = "*.*.*";
00435 if (!dstr.equals((test = str.toDotString())))
00436 return false;
00437
00438 str = "*.*.*.*";
00439 if (!dstr.equals((test = str.toDotString())))
00440 return false;
00441
00442 str = "*.*:*";
00443 if (!dstr.equals((test = str.toDotString())))
00444 return false;
00445
00446 str = "*.*.*.*:*";
00447 if (!dstr.equals((test = str.toDotString())))
00448 return false;
00449
00450 str = "*.*.*.*:comment";
00451 if (!dstr.equals((test = str.toDotString())))
00452 return false;
00453
00454 str = "first.*";
00455 if (!dstr.equals((test = str.toDotString())))
00456 return false;
00457
00458 str = "first.*.*";
00459 if (!dstr.equals((test = str.toDotString())))
00460 return false;
00461
00462 str = "first.*.*.*";
00463 if (!dstr.equals((test = str.toDotString())))
00464 return false;
00465
00466 str = "first.*.*.fourth";
00467 if (!dstr.equals((test = str.toDotString())))
00468 return false;
00469
00470 str = "first.*.third.*";
00471 if (!dstr.equals((test = str.toDotString())))
00472 return false;
00473
00474 str = "*.fourth";
00475 if (!dstr.equals((test = str.toDotString())))
00476 return false;
00477
00478 str = "*.fourth:comment";
00479 if (!dstr.equals((test = str.toDotString())))
00480 return false;
00481
00482
00483
00484 str = "first.*.third";
00485 if (dstr.equals((test = str.toDotString())))
00486 return false;
00487
00488 str = "first.*.";
00489 if (dstr.equals((test = str.toDotString())))
00490 return false;
00491
00492 str = "first.*:com";
00493 if (dstr.equals((test = str.toDotString())))
00494 return false;
00495
00496 str = "first.*.fourth";
00497 if (!dstr.equals((test = str.toDotString())))
00498 return false;
00499
00500 str = "first.*.fourth:comment";
00501 if (!dstr.equals((test = str.toDotString())))
00502 return false;
00503
00504 dstr = DotString("SoB");
00505 str = "*Motor*";
00506 if (dstr.equals((test = str.toDotString())))
00507 return false;
00508
00509 dstr = DotString("SoB");
00510 str = "Motor*";
00511 if (dstr.equals((test = str.toDotString())))
00512 return false;
00513
00514 dstr = DotString("SoB");
00515 str = "*Motor";
00516 if (dstr.equals((test = str.toDotString())))
00517 return false;
00518
00519 dstr = DotString("SoB");
00520 str = "*mote*";
00521 if (dstr.equals((test = str.toDotString())))
00522 return false;
00523
00524 dstr = DotString("SoB");
00525 str = "*mote";
00526 if (dstr.equals((test = str.toDotString())))
00527 return false;
00528
00529
00530 int n = 0;
00531 bool ret1, ret2, ret3, ret4;
00532 bool ret5, ret6, ret7, ret8;
00533
00534 JString str1 = "Output.Plan.Motor.Signal.startBlinking";
00535 JString str2 = "Output.Plan.Motor.Request.Blink";
00536 JString match1 = "*.Plan.*.Request.*";
00537 JString match2 = "*.Motor.*";
00538
00539 if (! (ret1 = match1.matchesIgnoreCase(str1) ) == false)
00540 return false;
00541 if (! (ret2 = match1.matchesIgnoreCase(str2) ) == true)
00542 return false;
00543 if (! (ret3 = match2.matchesIgnoreCase(str1) ) == true)
00544 return false;
00545 if (! (ret4 = match2.matchesIgnoreCase(str2) ) == true)
00546 return false;
00547
00548 if (! (ret5 = str1.matchesIgnoreCase(match1) ) == ret1)
00549 return false;
00550 if (! (ret6 = str2.matchesIgnoreCase(match1) ) == ret2)
00551 return false;
00552 if (! (ret7 = str1.matchesIgnoreCase(match2) ) == ret3)
00553 return false;
00554 if (! (ret8 = str2.matchesIgnoreCase(match2) ) == ret4)
00555 return false;
00556
00557 str1 = "Output.Plan.Motor.Signal.startBlinking";
00558 str2 = "Output.Plan.Motor.Request.Blink";
00559 match1 = "Plan.*.Request.*";
00560 match2 = "*.Motor";
00561
00562 if (! (ret1 = match1.matchesIgnoreCase(str1) ) == false)
00563 return false;
00564 if (! (ret2 = match1.matchesIgnoreCase(str2) ) == false)
00565 return false;
00566 if (! (ret3 = match2.matchesIgnoreCase(str1) ) == false)
00567 return false;
00568 if (! (ret4 = match2.matchesIgnoreCase(str2) ) == false)
00569 return false;
00570
00571 if (! (ret5 = str1.matchesIgnoreCase(match1) ) == ret1)
00572 return false;
00573 if (! (ret6 = str2.matchesIgnoreCase(match1) ) == ret2)
00574 return false;
00575 if (! (ret7 = str1.matchesIgnoreCase(match2) ) == ret3)
00576 return false;
00577 if (! (ret8 = str2.matchesIgnoreCase(match2) ) == ret4)
00578 return false;
00579
00580 str1 = "Output.Plan.*.Signal.startBlinking";
00581 str2 = "Output.Plan.*.Request.Blink";
00582 match1 = "*.Plan.*.Request.*";
00583 match2 = "*.Motor.*";
00584
00585 if (! (ret1 = match1.matchesIgnoreCase(str1) ) == false)
00586 return false;
00587 if (! (ret2 = match1.matchesIgnoreCase(str2) ) == true)
00588 return false;
00589 if (! (ret3 = match2.matchesIgnoreCase(str1) ) == true)
00590 return false;
00591 if (! (ret4 = match2.matchesIgnoreCase(str2) ) == true)
00592 return false;
00593
00594 if (! (ret5 = str1.matchesIgnoreCase(match1) ) == ret1)
00595 return false;
00596 if (! (ret6 = str2.matchesIgnoreCase(match1) ) == ret2)
00597 return false;
00598 if (! (ret7 = str1.matchesIgnoreCase(match2) ) == ret3)
00599 return false;
00600 if (! (ret8 = str2.matchesIgnoreCase(match2) ) == ret4)
00601 return false;
00602
00603 return true;
00604 }
00605
00606
00607 }