22
22
*
23
23
* @author Aaron Hansen
24
24
*/
25
- public class DSInfo implements ApiObject , GroupListener {
25
+ public class DSInfo < T extends DSIObject > implements ApiObject , GroupListener {
26
26
27
27
///////////////////////////////////////////////////////////////////////////
28
28
// Constants
@@ -44,7 +44,7 @@ public class DSInfo implements ApiObject, GroupListener {
44
44
DSMap metadata ;
45
45
String name ;
46
46
DSInfo next ;
47
- DSIObject object ;
47
+ T object ;
48
48
DSNode parent ;
49
49
DSInfo prev ;
50
50
@@ -55,7 +55,7 @@ public class DSInfo implements ApiObject, GroupListener {
55
55
DSInfo () {
56
56
}
57
57
58
- public DSInfo (String name , DSIObject object ) {
58
+ protected DSInfo (String name , T object ) {
59
59
this .name = name ;
60
60
setObject (object );
61
61
}
@@ -64,22 +64,6 @@ public DSInfo(String name, DSIObject object) {
64
64
// Public Methods
65
65
///////////////////////////////////////////////////////////////////////////
66
66
67
- public DSInfo copy () {
68
- DSInfo ret = new DSInfo ();
69
- ret .copyState (this );
70
- if (isDefaultOnCopy ()) {
71
- DSIObject val = getDefaultObject ();
72
- if (val != null ) {
73
- ret .setObject (val .copy ());
74
- return ret ;
75
- }
76
- }
77
- if (object != null ) {
78
- ret .setObject (object .copy ());
79
- }
80
- return ret ;
81
- }
82
-
83
67
public void decodeState (DSElement state ) {
84
68
flags = state .toInt ();
85
69
}
@@ -159,7 +143,7 @@ public boolean equivalent(Object arg) {
159
143
/**
160
144
* Returns the target object.
161
145
*/
162
- public DSIObject get () {
146
+ public T get () {
163
147
return object ;
164
148
}
165
149
@@ -201,13 +185,6 @@ public Iterator<String> getChildren() {
201
185
return bucket .iterator ();
202
186
}
203
187
204
- /**
205
- * If this is a proxy , this will return the original default instance.
206
- */
207
- public DSIObject getDefaultObject () {
208
- return get ();
209
- }
210
-
211
188
/**
212
189
* A convenience that casts the object. Will call DSIValue.toElement on values.
213
190
*/
@@ -248,15 +225,6 @@ public DSNode getNode() {
248
225
return (DSNode ) get ();
249
226
}
250
227
251
- /**
252
- * User get() instead.
253
- *
254
- * @deprecated 18-11-14
255
- */
256
- public DSIObject getObject () {
257
- return object ;
258
- }
259
-
260
228
public DSNode getParent () {
261
229
return parent ;
262
230
}
@@ -288,7 +256,7 @@ public boolean hasNext() {
288
256
/**
289
257
* True if the value of the info is an instance of the given class.
290
258
*/
291
- public boolean is (Class clazz ) {
259
+ public boolean is (Class <?> clazz ) {
292
260
if (object == null ) {
293
261
return false ;
294
262
}
@@ -328,7 +296,8 @@ public boolean isFrozen() {
328
296
}
329
297
330
298
/**
331
- * True if the info cannot be removed or renamed. Use for non-default nodes.
299
+ * True if the info cannot be removed or renamed.
300
+ * Intended for non-default children, default children are implicitly locked.
332
301
*/
333
302
public boolean isLocked () {
334
303
return getFlag (LOCKED );
@@ -348,7 +317,10 @@ public boolean isNull() {
348
317
if (object == null ) {
349
318
return true ;
350
319
}
351
- return object .isNull ();
320
+ if (isValue ()) {
321
+ return getValue ().isNull ();
322
+ }
323
+ return false ;
352
324
}
353
325
354
326
/**
@@ -388,73 +360,73 @@ public void modified(DSGroup map) {
388
360
}
389
361
390
362
/**
391
- * The next info in the parent node.
363
+ * The next info in the parent node, or null .
392
364
*/
393
365
public DSInfo next () {
394
366
return next ;
395
367
}
396
368
397
369
/**
398
- * The next DSInfo in the parent whose object is of the given type.
370
+ * The next DSInfo in the parent whose object is of the given type, or null .
399
371
*/
400
- public DSInfo next (Class is ) {
372
+ public DSInfo next (Class <?> is ) {
401
373
DSInfo cur = next ;
402
374
while (cur != null ) {
403
375
if (cur .is (is )) {
404
376
return cur ;
405
377
}
406
378
cur = cur .next ();
407
379
}
408
- return cur ;
380
+ return null ;
409
381
}
410
382
411
383
/**
412
384
* The next DSInfo in the parent that is an action, or null.
413
385
*/
414
- public DSInfo nextAction () {
386
+ public DSInfo < DSAction > nextAction () {
415
387
DSInfo cur = next ;
416
388
while (cur != null ) {
417
389
if (cur .isAction ()) {
418
390
return cur ;
419
391
}
420
392
cur = cur .next ();
421
393
}
422
- return cur ;
394
+ return null ;
423
395
}
424
396
425
397
/**
426
398
* The next DSInfo in the parent that is a node, or null.
427
399
*/
428
- public DSInfo nextNode () {
400
+ public DSInfo < DSNode > nextNode () {
429
401
DSInfo cur = next ;
430
402
while (cur != null ) {
431
403
if (cur .isNode ()) {
432
404
return cur ;
433
405
}
434
406
cur = cur .next ();
435
407
}
436
- return cur ;
408
+ return null ;
437
409
}
438
410
439
411
/**
440
412
* The next DSInfo in the parent that is a value, or null.
441
413
*/
442
- public DSInfo nextValue () {
414
+ public DSInfo < DSIValue > nextValue () {
443
415
DSInfo cur = next ;
444
416
while (cur != null ) {
445
417
if (cur .isValue ()) {
446
418
return cur ;
447
419
}
448
420
cur = cur .next ();
449
421
}
450
- return cur ;
422
+ return null ;
451
423
}
452
424
453
425
/**
454
426
* False by default, set to true if you don't want the child to require admin level
455
427
* permissions.
456
428
*/
457
- public DSInfo setAdmin (boolean admin ) {
429
+ public DSInfo < T > setAdmin (boolean admin ) {
458
430
setFlag (ADMIN , admin );
459
431
return this ;
460
432
}
@@ -463,21 +435,21 @@ public DSInfo setAdmin(boolean admin) {
463
435
* False by default, set to true to reset the target to it's default when the encapsulated node
464
436
* is copied.
465
437
*/
466
- public DSInfo setDefaultOnCopy (boolean defaultOnCopy ) {
438
+ public DSInfo < T > setDefaultOnCopy (boolean defaultOnCopy ) {
467
439
setFlag (DEFAULT_ON_COPY , defaultOnCopy );
468
440
return this ;
469
441
}
470
442
471
443
/**
472
444
* False by default, set to true if the info cannot be removed or renamed.
473
- * Use for non-default nodes .
445
+ * Intended for non-default children, default children are implicitly locked .
474
446
*/
475
- public DSInfo setLocked (boolean locked ) {
447
+ public DSInfo < T > setLocked (boolean locked ) {
476
448
setFlag (LOCKED , locked );
477
449
return this ;
478
450
}
479
451
480
- public DSInfo setMetadata (DSMap map ) {
452
+ public DSInfo < T > setMetadata (DSMap map ) {
481
453
map .setParent (this );
482
454
metadata = map ;
483
455
return this ;
@@ -486,23 +458,23 @@ public DSInfo setMetadata(DSMap map) {
486
458
/**
487
459
* False by default, set to true if you don't want the child to be sent to clients.
488
460
*/
489
- public DSInfo setPrivate (boolean hidden ) {
461
+ public DSInfo < T > setPrivate (boolean hidden ) {
490
462
setFlag (PRIVATE , hidden );
491
463
return this ;
492
464
}
493
465
494
466
/**
495
467
* False by default, set to true if you don't want the child to be written by clients.
496
468
*/
497
- public DSInfo setReadOnly (boolean readOnly ) {
469
+ public DSInfo < T > setReadOnly (boolean readOnly ) {
498
470
setFlag (READONLY , readOnly );
499
471
return this ;
500
472
}
501
473
502
474
/**
503
475
* False by default, set to true if you don't want the child persisted.
504
476
*/
505
- public DSInfo setTransient (boolean trans ) {
477
+ public DSInfo < T > setTransient (boolean trans ) {
506
478
setFlag (TRANSIENT , trans );
507
479
return this ;
508
480
}
@@ -518,32 +490,47 @@ public String toString() {
518
490
// Package Methods
519
491
///////////////////////////////////////////////////////////////////////////
520
492
521
- /**
522
- * This is only called by DSNode.copy. Therefore, this will already
523
- * be populated with the default value.
524
- */
525
- void copy (DSInfo info ) {
493
+ DSInfo <T > copy () {
494
+ DSInfo <T > ret = new DSInfo <>();
495
+ ret .copyState (this );
496
+ if (isDefaultOnCopy ()) {
497
+ DSIObject val = getDefaultObject ();
498
+ if (val != null ) {
499
+ ret .setObject ((T ) val .copy ());
500
+ return ret ;
501
+ }
502
+ }
503
+ if (object != null ) {
504
+ ret .setObject ((T ) object .copy ());
505
+ }
506
+ return ret ;
507
+ }
508
+
509
+ void copy (DSInfo <T > info ) {
526
510
copyState (info );
527
511
if (isDefaultOnCopy ()) {
528
512
return ;
529
513
}
530
514
if (info .object != null ) {
531
- setObject (info .object .copy ());
515
+ setObject (( T ) info .object .copy ());
532
516
}
533
517
}
534
518
535
- /**
536
- * This is only called by DSNode.copy. Therefore, this will already
537
- * be populated with the default value.
538
- */
539
- void copyState (DSInfo info ) {
519
+ void copyState (DSInfo <T > info ) {
540
520
flags = info .flags ;
541
521
name = info .name ;
542
522
if (info .metadata != null ) {
543
523
metadata = info .metadata .copy ();
544
524
}
545
525
}
546
526
527
+ /**
528
+ * If this is a proxy , this will return the original default instance.
529
+ */
530
+ T getDefaultObject () {
531
+ return get ();
532
+ }
533
+
547
534
boolean getFlag (int position ) {
548
535
return DSUtil .getBit (flags , position );
549
536
}
@@ -566,28 +553,32 @@ boolean isProxy() {
566
553
return false ;
567
554
}
568
555
569
- DSInfo setFlag (int position , boolean on ) {
556
+ DSInfo <T > newProxy () {
557
+ return new DSInfoProxy <>(this );
558
+ }
559
+
560
+ DSInfo <T > setFlag (int position , boolean on ) {
570
561
//modified?
571
562
flags = DSUtil .setBit (flags , position , on );
572
563
return this ;
573
564
}
574
565
575
- DSInfo setName (String arg ) {
566
+ DSInfo < T > setName (String arg ) {
576
567
this .name = arg ;
577
568
return this ;
578
569
}
579
570
580
- DSInfo setObject (DSIObject arg ) {
571
+ DSInfo < T > setObject (T arg ) {
581
572
this .object = arg ;
582
573
return this ;
583
574
}
584
575
585
- DSInfo setParent (DSNode arg ) {
576
+ DSInfo < T > setParent (DSNode arg ) {
586
577
this .parent = arg ;
587
578
return this ;
588
579
}
589
580
590
- DSInfo setDeclared (boolean arg ) {
581
+ DSInfo < T > setDeclared (boolean arg ) {
591
582
setFlag (DECLARED , arg );
592
583
return this ;
593
584
}
0 commit comments