# Transformer

## Purpose

`Transformer` is a generic functional interface nested inside the `Items` utility class, which itself lives within `JKKWribSvcKeiOperateCC`. It defines the contract for converting an input value of type `I` into an output value of type `O`. This interface serves as the core abstraction in a LINQ-style collection-processing pattern built on top of raw Java collections (`ArrayList`), enabling concise, lambda-style transformations without requiring Java 8+ lambda syntax. It is one of the most central abstractions in the codebase, with 13 inbound connections across the domain.

## Design

`Transformer<I, O>` is a single-method functional interface (akin to Java's `Function<I, O>` introduced later in Java 8). It is nested inside the `Items` helper class alongside two companion interfaces:

- **`Closure<I>`** — a void-returning operation (equivalent to `Consumer<I>`).
- **`Predicater<I>`** — a boolean-returning predicate (equivalent to `Predicate<I>`).

These three interfaces together form a mini functional-collection library:

| Pattern | Companion Interface | Static Utility Method |
|---|---|---|
| Transform each element | `Transformer<I, O>` | `Items.map(ArrayList<I>, Transformer<I, O>)` |
| Side-effect on each element | `Closure<I>` | `Items.each(ArrayList<I>, Closure<I>)` |
| Filter by condition | `Predicater<I>` | `Items.select(ArrayList<I>, Predicater<I>)`, `Items.exist(...)`, `Items.find(...)` |

`Items` also defines two constants:

- `DEFAULT_ARRAY_SIZE = 100` — default initial capacity for result `ArrayList` objects.
- `DEFAULT_HASH_SIZE = 50` — default initial capacity for result `HashMap` objects.

This design provides a pre-Java-8 functional abstraction pattern, making collection processing more declarative and reducing boilerplate iteration code.

## Key Methods

### `O transform(I input)`

```java
public abstract O transform(I input);
```

**What it does:** Transforms an input value of type `I` into an output value of type `O`. This is the sole method in the interface and is intended to be implemented by caller-supplied anonymous classes (or, in later Java versions, lambdas).

**Parameters:**
- `input` — The input value to transform. Type is generic (`I`).

**Return value:** The transformed result. Type is generic (`O`).

**Side effects:** None defined by the interface itself. Implementations may have side effects.

**Usage context:** The `transform` method is invoked inside `Items.map()`, which iterates over an input `ArrayList` and applies the transformer to each element, collecting results into a new `ArrayList<O>`:

```java
// Inside Items.map():
each(in, new Closure<I>() {
    @Override
    public void execute(I input) {
        result.add(transformer.transform(input));
    }
});
```

### `Items.map(ArrayList<I>, Transformer<I, O>)`

```java
public static <I, O> ArrayList<O> map(ArrayList<I> in,
        final Transformer<I, O> transformer)
```

**What it does:** Applies a `Transformer` to every element of the input list and returns a new list containing the transformed results. This is the primary consumer of `Transformer`.

**Parameters:**
- `in` — The input `ArrayList` to transform.
- `transformer` — The `Transformer` instance that defines the conversion logic.

**Return value:** A new `ArrayList<O>` containing the transformed elements, pre-sized to `DEFAULT_ARRAY_SIZE` (100).

**Side effects:** Creates a new list; the original list is not modified.

## Relationships

```mermaid
flowchart LR
    A["JKKWribSvcKeiOperateCC"] --> B["Items (nested class)"]
    B --> C["Transformer<I, O> interface"]
    C --> D["Sequencer"]
    C --> E["PartSequencer"]
    C --> F["ValuesPicker"]
    C --> G["CAANMsgValuesPicker"]
    C --> H["CAANMsgMover"]
    C --> I["Items.map()"]
```

### Who implements `Transformer`

The following five classes implement the `Transformer` interface (as indicated by the task spec's "Used by" section). Each applies the `transform` method to convert a `CAANMsg` (a message object used in this system's messaging layer) into a `HashMap<String, String>`:

| Class | Likely Purpose |
|---|---|
| **Sequencer** | Core message sequencing logic, transforming incoming messages into structured key-value maps. |
| **PartSequencer** | Partial sequencing — handles subsets or fragments of messages. |
| **ValuesPicker** | Extracts and selects specific values from messages for downstream processing. |
| **CAANMsgValuesPicker** | Message-specific value picker, likely specialized for CAANMsg types. |
| **CAANMsgMover** | Transforms messages as part of a move/copy operation between message queues or structures. |

### Outbound dependencies

The `Transformer` interface itself declares no outbound dependencies. It is a pure functional interface with no imports, no references to external types beyond its generic type parameters `I` and `O`.

### Who uses it statically

The `Items.map()` static method is the primary programmatic consumer of `Transformer`. Additional uses may exist in anonymous inner-class instantiations across the codebase (contributing to the 13 inbound connections).

## Usage Example

In practice, a `Transformer` is typically instantiated as an anonymous inner class (given the pre-Java 8 era of this codebase):

```java
Transformer<CAANMsg, HashMap<String, String>> transformer =
    new Transformer<CAANMsg, HashMap<String, String>>() {
        @Override
        public HashMap<String, String> transform(CAANMsg in) {
            HashMap<String, String> out = new HashMap<String, String>(DEFAULT_HASH_SIZE);
            // Extract relevant fields from the message
            out.put("id", in.getString(SOME_KEY));
            out.put("status", in.getString(STATUS_KEY));
            // ... more field extraction
            return out;
        }
    };

// Apply to a list of messages
ArrayList<HashMap<String, String>> results =
    Items.map(messageList, transformer);
```

A real-world implementation is seen in the `Sequencer` class (lines 17035–17114 of the source file), where `transform(CAANMsg in)` maps fields from a `CAANMsg` object into a `HashMap<String, String>`. The implementation reads dispatch/offer message fields using domain-specific constant keys (e.g., `EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_NO`) and conditionally sets different `kei_kind` values (`WRIB` or `HNSOKU`) based on the content of the input message. It also handles a special case for network phone TV contracts (`DT0000002`) where start/end dates are intentionally cleared.

## Notes for Developers

- **Pre-Java 8 pattern:** This interface predates Java 8's `java.util.function.Function`. In modern code, `Function<I, O>` would replace `Transformer<I, O>`, and the `Items` utility methods could be replaced with `stream().map()`, `stream().filter()`, etc.
- **Thread safety:** The `Transformer` interface imposes no thread-safety guarantees. Each call to `transform()` creates its own output object (typically a new `HashMap`), which makes individual transformations stateless by convention, but the interface itself does not enforce immutability or thread safety.
- **Generic type flexibility:** Both `I` and `O` are unconstrained generics. This allows the `Transformer` to work with any pair of types, though in practice it is most commonly used to convert message objects (`CAANMsg`) to `HashMap<String, String>` flat maps.
- **Null handling:** The interface and its methods do not explicitly handle null inputs. Callers should guard against null `CAANMsg` objects before passing them to `transform()`.
- **Initialization sizing:** The `DEFAULT_ARRAY_SIZE` (100) and `DEFAULT_HASH_SIZE` (50) constants are used to pre-size result collections, reducing re-allocation overhead during bulk transforms.
- **Nested class scope:** The `Items` class and its nested interfaces are package-private (`class Items`, `interface Transformer`), meaning they are primarily intended for internal use within `JKKWribSvcKeiOperateCC` rather than as a public API.
