---

# Business Logic — Example.writeHeader() [7 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.string.Example` |
| Layer | Utility |
| Module | `string` (Package: `io.github.biezhi.java11.string`) |

## 1. Role

### Example.writeHeader()

The `writeHeader` method is a private static utility that formats and prints a styled text header to standard output. It serves as a shared presentation helper within the `Example` class, which demonstrates Java 11 `String` API features. The method creates a visual header decoration by computing a separator line of equal-sign characters (`=`) that wraps around the provided header text, and then prints the opening separator, the header text itself, and the closing separator as three consecutive console lines. It implements a simple **formatting pattern**: computing a decorative separator width based on the input text length and printing a consistent visual block. This method plays the role of a **presentation utility** — it is not part of any business transaction or data processing pipeline. Instead, it is a cosmetic helper invoked by multiple demo entry methods (e.g., `demonstrateStringLines`, `demonstrateStrip`, `demonstrateStripLeading`, `demonstrateStripTrailing`, `demonstrateIsBlank`) to visually delimit sections of the demo output. All branches are straightforward sequential execution — there are no conditional branches or loops in the implementation.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["writeHeader headerText"])
    STEP1["Create separator string using String repeat"]
    STEP2["Print newline plus separator"]
    STEP3["Print header text"]
    STEP4["Print closing separator"]
    END_NODE(["Return void"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> END_NODE
```

**Processing Flow Description:**

1. **Compute separator**: The method calculates the total width of the header line by adding 4 to the length of the input text (`headerText.length() + 4`), then calls `"=".repeat(width)` to generate a string of `=` characters of that total length. The extra 4 characters provide visual padding (2 on each side) around the header text when it is conceptually centered within the separator line.

2. **Print top separator**: Outputs a newline character followed by the computed separator string to `System.out`, establishing visual separation from any preceding output.

3. **Print header text**: Outputs the provided `headerText` on its own line — this is the main title or section label.

4. **Print bottom separator**: Outputs the same separator string again, creating a symmetric boxed appearance around the header text.

5. **Return**: The method returns `void`, having completed its side effect of printing to standard output.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `headerText` | `final String` | The title text displayed in the center of the header decoration. This parameter carries the section heading or label for a demo output segment. It can be any non-null `String` value, and its length directly determines the width of the generated separator line (separator width = `headerText.length() + 4`). An empty string would produce a 4-character separator. The parameter is declared `final`, indicating the method does not modify it. |

**External state read:**
- None — this method is stateless and relies solely on its parameter and static `System.out`.

## 4. CRUD Operations / Called Services

This method performs no CRUD operations, database access, or service component calls. It is a pure presentation utility that writes to standard output.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| *(none)* | — | — | — | No data access operations — this method prints to `System.out` for demonstration purposes only. |

**Method calls made by `writeHeader`:**

| # | Call Target | API Level | Description |
|---|-------------|-----------|-------------|
| 1 | `"=".repeat(int)` | `java.lang.String.repeat(int)` (Java 11+) | Generates a separator string by repeating the `=` character the specified number of times |
| 2 | `System.out.println(String)` | `java.io.PrintStream.println(String)` | Writes the decorated header block to standard output in three lines |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 6 methods within the same class.

Trace of all callers and what `writeHeader` ultimately calls:

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `Example.demonstrateStringLines()` | `Example.demonstrateStringLines()` -> `writeHeader` | *(none — utility only)* |
| 2 | `Example.demonstrateStrip()` | `Example.demonstrateStrip()` -> `writeHeader` | *(none — utility only)* |
| 3 | `Example.demonstrateStripLeading()` | `Example.demonstrateStripLeading()` -> `writeHeader` | *(none — utility only)* |
| 4 | `Example.demonstrateStripTrailing()` | `Example.demonstrateStripTrailing()` -> `writeHeader` | *(none — utility only)* |
| 5 | `Example.demonstrateIsBlank()` | `Example.demonstrateIsBlank()` -> `writeHeader` | *(none — utility only)* |
| 6 | `Example.demonstrateLines()` | `Example.demonstrateLines()` -> `writeHeader` | *(none — utility only)* |

**Notes:**
- All callers are private demo methods within the same `Example` class.
- There are no external callers, screens, batches, or controllers that invoke this method.
- The method produces no side effects beyond console output; no data is persisted or read.
- One call site (line 105) is commented out: `// writeHeader("User-Agent\tMozilla/5.0 ...")` — an unused demonstration stub.

## 6. Per-Branch Detail Blocks

This method contains no conditional branches, loops, switch statements, or try-catch blocks. It is a straight-line sequential implementation.

**Block 1** — [SEQUENTIAL EXECUTION] (L24)

> The entire method body executes sequentially without any branching. It computes a separator decoration and prints a three-line header block to the console.

| # | Type | Code |
|---|------|------|
| 1 | DECLARE | `final String headerSeparator` | [L24] |
| 2 | SET | `headerSeparator = "=".repeat(headerText.length() + 4)` | Compute separator width = text length + 4 characters of padding, then repeat `=` to fill the width. [L24] |
| 3 | CALL | `System.out.println("
" + headerSeparator)` | Print a leading newline and the top separator line. [L26] |
| 4 | CALL | `System.out.println(headerText)` | Print the header title text. [L27] |
| 5 | CALL | `System.out.println(headerSeparator)` | Print the bottom separator line to close the header decoration. [L28] |
| 6 | RETURN | `return;` (implicit) | Method returns void. [L24] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `writeHeader` | Method | Console header formatter — prints a styled text header with `=` separators around a title string |
| `headerText` | Parameter | The text content of a header title displayed in demo console output |
| `String.repeat(int)` | API | Java 11+ method that returns a new string composed of the original string concatenated the specified number of times |
| `System.out` | External | Standard output stream — the console destination for demo output |
| `Example` | Class | A demonstration class showcasing Java 11 `String` API features (strip, isBlank, repeat, lines, etc.) |
| `demonstrateStringLines` | Method | Demo entry point that exercises `String.lines()` method |
| `demonstrateStrip` | Method | Demo entry point that exercises `String.strip()` method |
| `demonstrateStripLeading` | Method | Demo entry point that exercises `String.stripLeading()` method |
| `demonstrateStripTrailing` | Method | Demo entry point that exercises `String.stripTrailing()` method |
| `demonstrateIsBlank` | Method | Demo entry point that exercises `String.isBlank()` method |
| `demonstrateLines` | Method | Demo entry point that exercises `String.lines()` method |

---
