# Business Logic — Items.exist() [8 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.Items` |
| Layer | Common Component (Shared utility class in the `com.fujitsu.futurity.bp.custom.common` package) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### Items.exist()

`Items.exist()` is a generic utility method that determines whether any element within a collection satisfies a given condition. It implements the **Collection Predicate** pattern (commonly known as the "any match" pattern) — iterating over each element of an `ArrayList<I>` and delegating the condition check to a `Predicater<I>` functional interface. This method is the collection-aware equivalent of a simple `anyMatch` operation. Its role in the larger system is that of a shared, reusable predicate-checking utility used across many CBS (Component-Based Service) classes, screens, and batch operations to determine membership or conditional presence within lists of business objects — such as checking whether any target service exists in a collection, whether a service meets certain criteria, or whether any pending item matches a specific condition. It is called directly by higher-level methods like `JKKWribSvcKeiOperateCC.isCollectTrgtSvcsAll()` and `JKKWribSvcKeiOperateCC.isCollectTrgtSvcsAny()` to decide whether a set of service objects should be collected or processed.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["exist(ArrayList<I> in, Predicater<I> predicater)"])
    START --> INIT["Initialize iteration over in"]
    INIT --> LOOP{"Has next item?"}
    LOOP -->|Yes| EVAL["item = next item from in"]
    EVAL --> CHECK{"predicater.evaluate(item)"}
    CHECK -->|true| RETURN_TRUE["return true"]
    CHECK -->|false| LOOP
    LOOP -->|No| RETURN_FALSE["return false"]
    RETURN_TRUE --> END(["End"])
    RETURN_FALSE --> END
    END --> NEXT(["Return to Caller"])
```

**Processing description:**

The method receives an `ArrayList<I>` of generic type `I` and a `Predicater<I>` functional interface. It iterates sequentially through each element of the list. For every element, it delegates a condition check to `predicater.evaluate(item)`. If any single evaluation returns `true`, the method immediately returns `true` (short-circuit on first match). If the iteration exhausts all elements without any match, it returns `false`. This is a classic short-circuit "anyMatch" pattern — O(n) in the worst case, O(1) on average if a match is found early. The method is null-safe in the sense that an empty list results in a `false` return (no iteration occurs).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `in` | `ArrayList<I>` | A collection of business objects of generic type `I`. This list represents a set of items to be inspected — such as a list of target services, order items, contract lines, or any domain entity grouped together for conditional evaluation. The list may contain zero or more elements. |
| 2 | `predicater` | `Predicater<I>` | A functional interface that defines a single-argument `evaluate(I item)` method returning `boolean`. It encapsulates a business rule or condition to be tested against each element. For example, "is this a collectable service?" or "does this item match the required criteria?" The predicate is the core business logic carrier — this method is generic and delegates all condition-specific behavior to it. |

**External state / instance fields:** None. This method is fully stateless and side-effect-free.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Predicater.evaluate` | Predicater | - | Delegates condition evaluation to the `Predicater` functional interface |

**Analysis:** This method performs **no direct CRUD operations** on entities or databases. It is a pure in-memory collection predicate check. The only method it invokes is `Predicater.evaluate(item)`, which is a functional interface call whose concrete implementation is provided by the caller. Any database or entity access is performed by the concrete `Predicater` implementation, not by this method itself.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 3 methods.
Terminal operations from this method: `evaluate` [-], `evaluate` [-], `evaluate` [-], `evaluate` [-], `evaluate` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JKKWribSvcKeiOperateCC.isCollectTrgtSvcsAll()` | `isCollectTrgtSvcsAll()` -> `Items.exist()` | `evaluate` (Predicate check on service collection) |
| 2 | CBS: `JKKWribSvcKeiOperateCC.isCollectTrgtSvcsAny()` | `isCollectTrgtSvcsAny()` -> `Items.exist()` | `evaluate` (Predicate check on service collection) |
| 3 | Functional: `Predicater.evaluate()` | `Predicater` interface method | Invoked by `Items.exist()` during iteration |

**Analysis:** This method is a leaf-level utility with no further dependency chain. All terminal operations point to `Predicater.evaluate()`, which is the conditional evaluation delegate. The two CBS callers (`isCollectTrgtSvcsAll` and `isCollectTrgtSvcsAny`) use this method to determine whether all or any services in a collection satisfy a target-collection predicate.

## 6. Per-Branch Detail Blocks

**Block 1** — `FOR` (iterate over `in`) `(L16644)`

> Iterate over each element in the input ArrayList and evaluate the predicate against it.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `for (I item : in)` // Enhanced for-each iteration over input collection |
| 2 | CALL | `predicater.evaluate(item)` // Delegates condition check to the Predicater functional interface |

**Block 1.1** — `IF` (predicate returns `true`) `(L16645)`

> If the predicate evaluates to true for the current item, short-circuit and return true immediately — the collection "exists" per the condition.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` // Short-circuit: at least one matching element found |

**Block 2** — `RETURN` (post-iteration fallback) `(L16649)`

> After exhausting all elements without any predicate returning true, the method concludes no element exists in the collection matching the condition.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return false;` // No element satisfied the predicate; collection is empty or all elements do not match |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `Predicater<I>` | Interface | A functional interface that evaluates a single argument of type `I` and returns a boolean. Used to encapsulate arbitrary business conditions. |
| `ArrayList<I>` | Type | A resizable-array implementation of the Java List interface, used to pass a collection of generic business objects to the method. |
| `I` | Type Parameter | Generic type parameter representing the element type of the collection — could be a service object, order item, contract record, or any domain entity. |
| `exist` | Method | Checks whether any element in a collection matches a given predicate condition. Equivalent to Java 8's `Collection.stream().anyMatch()`. |
| `Predicater.evaluate` | Method | The predicate evaluation method that contains the actual business rule. Called for each element until a `true` result is found or the list is exhausted. |
| CBS | Acronym | Component-Based Service — a service layer component in the Fujitsu Futurity platform that encapsulates business logic. |
| JKKWribSvcKeiOperateCC | Class | A CBS class that handles operation on wrib (likely "writing" or "recording") service items. Its methods `isCollectTrgtSvcsAll` and `isCollectTrgtSvcsAny` use `Items.exist()` to check target service collections. |
