Skip to content

Commit dd7f865

Browse files
committed
docs: expand DumAemTargetAttrValueMap API reference
Replace the previous brief 'addWithValue — Polymorphic Dispatch' note with a full API reference for DumAemTargetAttrValueMap in docs-dumont/extending-aem.md. The new content documents the override parameter behavior, typed addWithSingleValue overloads, collection adders, polymorphic addWithValue dispatch, merge semantics, static singleItem factories, usage examples, and a quick-reference table to make the map's behavior and APIs clear to consumers.
1 parent dc4d0e7 commit dd7f865

1 file changed

Lines changed: 131 additions & 4 deletions

File tree

docs-dumont/extending-aem.md

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,143 @@ public class MyPortalModelJson extends DumAemExtModelJsonBase<MyPortalModel> {
399399
}
400400
```
401401

402-
### addWithValuePolymorphic Dispatch
402+
### DumAemTargetAttrValueMapAPI Reference
403403

404-
`DumAemTargetAttrValueMap` includes `addWithValue(String name, Object value, boolean override)` which automatically dispatches to the correct typed method. This is used internally by the fluent API and can also be used directly:
404+
`DumAemTargetAttrValueMap` is the core data structure for collecting extracted attributes. It extends `HashMap<String, TurMultiValue>` and provides typed methods for adding values safely (null values are silently ignored).
405+
406+
#### The `override` parameter
407+
408+
Every method accepts a `boolean override` parameter that controls what happens when the attribute already exists in the map:
409+
410+
| `override` | Attribute exists? | Behavior |
411+
|---|---|---|
412+
| `true` | Yes | **Replaces** the existing value |
413+
| `true` | No | Adds the value |
414+
| `false` | Yes | **Appends** to the existing multi-value (merge) |
415+
| `false` | No | Adds the value |
416+
417+
#### Instance Methods — Adding Single Values
418+
419+
Use `addWithSingleValue` to add a single typed value to the map:
420+
421+
```java
422+
// String
423+
attrValues.addWithSingleValue("title", "My Page Title", true);
424+
425+
// Date
426+
attrValues.addWithSingleValue("publishDate", new Date(), true);
427+
428+
// Boolean
429+
attrValues.addWithSingleValue("isPublished", true, false);
430+
431+
// Integer
432+
attrValues.addWithSingleValue("pageViews", 42, false);
433+
434+
// Long
435+
attrValues.addWithSingleValue("fileSize", 1024L, true);
436+
437+
// Double
438+
attrValues.addWithSingleValue("price", 29.99, false);
439+
440+
// Float
441+
attrValues.addWithSingleValue("rating", 4.5f, true);
442+
443+
// TurMultiValue (pre-built multi-value)
444+
attrValues.addWithSingleValue("tags", turMultiValue, false);
445+
```
446+
447+
All overloads share the same signature pattern:
448+
449+
```java
450+
void addWithSingleValue(String attributeName, <Type> value, boolean override)
451+
```
452+
453+
| Type | Description |
454+
|---|---|
455+
| `String` | Text value |
456+
| `Date` | Date/time value |
457+
| `Boolean` | Boolean flag |
458+
| `Integer` | Integer number |
459+
| `Long` | Long number |
460+
| `Double` | Double-precision decimal |
461+
| `Float` | Single-precision decimal |
462+
| `TurMultiValue` | Pre-built multi-value object |
463+
464+
#### Instance Methods — Adding Collections
465+
466+
Use these to add multiple values at once for a single attribute:
467+
468+
```java
469+
// List of strings
470+
attrValues.addWithStringCollectionValue("tags",
471+
List.of("news", "tech", "java"), true);
472+
473+
// List of dates
474+
attrValues.addWithDateCollectionValue("eventDates",
475+
List.of(startDate, endDate), false);
476+
```
477+
478+
| Method | Value Type | Description |
479+
|---|---|---|
480+
| `addWithStringCollectionValue(name, list, override)` | `List<String>` | Adds multiple string values |
481+
| `addWithDateCollectionValue(name, list, override)` | `List<Date>` | Adds multiple date values |
482+
483+
#### Instance Methods — Polymorphic Dispatch
484+
485+
`addWithValue` accepts any `Object` and automatically dispatches to the correct typed method based on runtime type. This is used internally by the fluent API and can also be used directly:
405486

406487
```java
407-
// Automatically calls the right overload based on runtime type
488+
// Automatically calls the right addWithSingleValue overload
408489
attrValues.addWithValue("myField", someObject, true);
409-
// Supports: String, Date, Boolean, Integer, Long, Double, Float, TurMultiValue
410490
```
411491

492+
Supports: `String`, `Date`, `Boolean`, `Integer`, `Long`, `Double`, `Float`, and `TurMultiValue`. Any other type is converted to `String` via `toString()`.
493+
494+
#### Instance Methods — Merging Maps
495+
496+
```java
497+
// Merge another map into this one (respects override flags)
498+
attrValues.merge(otherAttrValues);
499+
```
500+
501+
The `merge` method combines two attribute maps. For each key in the source map:
502+
- If `override` is `true` on the source value → replaces the existing value
503+
- If `override` is `false` → appends to the existing multi-value
504+
505+
#### Static Factory Methods
506+
507+
Create a pre-populated map with a single attribute in one call:
508+
509+
```java
510+
// From a typed value
511+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("title", "Hello", true);
512+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("date", new Date(), true);
513+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("active", true, false);
514+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("count", 42, false);
515+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("price", 19.99, true);
516+
517+
// From a string collection
518+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("tags",
519+
List.of("a", "b"), true);
520+
521+
// From a TurMultiValue
522+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem("field", turMultiValue);
523+
524+
// From a DumAemTargetAttr (uses the attr's name and textValue)
525+
DumAemTargetAttrValueMap map = DumAemTargetAttrValueMap.singleItem(targetAttr, true);
526+
```
527+
528+
#### Quick Reference Table
529+
530+
| Method | Signature | Use Case |
531+
|---|---|---|
532+
| `addWithSingleValue` | `(String, String/Date/Boolean/Integer/Long/Double/Float/TurMultiValue, boolean)` | Add one typed value |
533+
| `addWithStringCollectionValue` | `(String, List<String>, boolean)` | Add multiple strings |
534+
| `addWithDateCollectionValue` | `(String, List<Date>, boolean)` | Add multiple dates |
535+
| `addWithValue` | `(String, Object, boolean)` | Add any value (auto-dispatches by type) |
536+
| `merge` | `(DumAemTargetAttrValueMap)` | Combine two attribute maps |
537+
| `singleItem` *(static)* | Various overloads | Create a map with one attribute |
538+
412539
---
413540

414541
<div className="page-break" />

0 commit comments

Comments
 (0)