# (DD10) Business Logic — NumericFilter.isValid() [17 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.github.blaxk3.ui.NumericFilter` |
| Layer | Utility |
| Module | `ui` (Package: `com.github.blaxk3.ui`) |

## 1. Role

### NumericFilter.isValid()

This method performs a lightweight validation of text input to determine whether the value can be accepted as a numeric field in the UI. It is designed for user-entered strings that may be either empty, integer-like, or decimal-like, and it enforces a narrow character set suitable for numeric entry controls. The method first treats an empty string as valid, which supports optional fields and intermediate typing states in a screen component. For non-empty text, it iterates through each character and allows exactly one decimal point while requiring all other characters to be digits.

In business terms, this is a shared input gatekeeper for numeric display or entry fields rather than a general-purpose number parser. It implements a simple validation-and-rejection pattern: accept blank input, accept digits with at most one decimal separator, and reject any other character such as letters, symbols, or multiple decimal points. The method has no external dependencies, no persistence access, and no service routing; its role is purely local validation inside the UI layer. Because it is used by `NumericFilter` instances, it likely supports consistent client-side enforcement across text fields that represent quantities, prices, or other numeric values.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isValid(text)"])
    CHECK_EMPTY{"text.isEmpty()"}
    RETURN_TRUE_EMPTY(["Return true"])
    INIT_DECIMAL(["decimalCount = 0"])
    INIT_LOOP(["for i from 0 to text.length() - 1"])
    GET_CHAR(["char ch = text.charAt(i)"])
    CHECK_DOT{"ch == '.' and decimalCount != 1"}
    INC_DECIMAL(["decimalCount++"])
    CHECK_DIGIT{"Character.isDigit(ch)"}
    RETURN_FALSE(["Return false"])
    RETURN_TRUE(["Return true"])
    START --> CHECK_EMPTY
    CHECK_EMPTY -->|Yes| RETURN_TRUE_EMPTY
    CHECK_EMPTY -->|No| INIT_DECIMAL
    INIT_DECIMAL --> INIT_LOOP
    INIT_LOOP --> GET_CHAR
    GET_CHAR --> CHECK_DOT
    CHECK_DOT -->|Yes| INC_DECIMAL
    CHECK_DOT -->|No| CHECK_DIGIT
    INC_DECIMAL --> INIT_LOOP
    CHECK_DIGIT -->|No| RETURN_FALSE
    CHECK_DIGIT -->|Yes| INIT_LOOP
    INIT_LOOP --> RETURN_TRUE
```

**Control-flow interpretation:**
- Empty input is accepted immediately.
- Non-empty input is scanned character by character.
- A period character is accepted only while the decimal counter is not already at its limit.
- Any non-digit character other than the accepted period path causes an immediate rejection.
- If the loop completes without rejection, the value is accepted.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `text` | `String` | The candidate UI value entered by the user for a numeric field. It may be blank during editing, contain digits only, or contain one decimal separator. Invalid characters, extra separators, and alphabetic content cause the value to be rejected. |

**Instance fields / external state read by the method:** none. The method depends only on the `text` argument and local variables.

## 4. CRUD Operations / Called Services

There are no CRUD operations and no service/database calls in this method. It performs only local validation logic.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | - | - | - | No external service call; validation is entirely in-memory |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: -

This method is invoked only from sibling validation paths inside the same `UI.java` class, where text entered into the UI is checked before being accepted into a numeric field. The method itself does not dispatch to downstream business services, so the dependency chain terminates at local boolean validation.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Utility: `UI` inner validation logic | `UI.<inner validation logic> -> NumericFilter.isValid` | `isValid [R] in-memory text validation` |
| 2 | Utility: `UI` inner validation logic | `UI.<inner validation logic> -> NumericFilter.isValid` | `isValid [R] in-memory text validation` |

## 6. Per-Branch Detail Blocks

**Block 1** — **IF** `(text.isEmpty())` (L195)

> Accepts blank input as valid so the UI can tolerate optional fields and in-progress user editing.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` |

**Block 2** — **SEQUENTIAL SETUP** `(non-empty text path)` (L199)

> Initializes the decimal-point counter before scanning the input one character at a time.

| # | Type | Code |
|---|------|------|
| 1 | SET | `byte decimalCount = 0;` |
| 2 | FOR | `for (int i = 0; i < text.length(); i++) {` |

**Block 2.1** — **FOR** `(scan each character)` (L200)

> Processes each character in order to ensure the text remains numeric.

| # | Type | Code |
|---|------|------|
| 1 | SET | `char ch = text.charAt(i);` |
| 2 | IF | `if (ch == '.' && decimalCount != 1) {` |

**Block 2.1.1** — **IF** `(ch == '.' && decimalCount != 1)` (L202)

> Allows the first decimal separator and counts it so later separators can be rejected.

| # | Type | Code |
|---|------|------|
| 1 | SET | `decimalCount++;` |

**Block 2.1.2** — **ELSE IF** `(!Character.isDigit(ch))` (L204)

> Rejects any character that is neither an accepted decimal point nor a digit.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return false;` |

**Block 3** — **RETURN** `(loop completed without rejection)` (L208)

> Accepts the text after successful character-by-character validation.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `NumericFilter` | Class | UI-level validation helper that restricts user input to numeric-compatible text. |
| `isValid` | Method | Validation method that approves blank text, digits, and at most one decimal point. |
| `text` | Field/Parameter | Candidate value entered into a numeric input field. |
| `decimalCount` | Local variable | Counter used to track how many decimal separators have been seen in the input. |
| `Character.isDigit` | Java API | Standard library check that confirms whether a character is a digit (`0`–`9`). |
| `UI` | Class | User interface container class that hosts Swing-related helper logic. |
| `Utility` | Layer | Shared helper logic used locally within the UI layer rather than a service, controller, or DAO. |
| Decimal separator (`.`) | Business term | Symbol used to permit decimal numeric values in the input. |
| Numeric field | Business term | Screen field intended to store quantities, prices, or other number-based values. |