Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
from_multidimensional_java_arrays [2025/04/18 17:02] colinr [sf00FromNestedStrings(Object data)] |
from_multidimensional_java_arrays [2025/04/18 17:31] (current) colinr |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== sf00FromNested(Object data) ===== | + | ====== Programmatically Creating Complex SecsFormat00 Objects from Java Arrays ====== |
- | Recursively converts a nested '' | ||
- | Use this method when your structure may contain integers, floats, doubles, longs, or strings. Each array level becomes a '' | + | ===== 🧩 Convert Mixed-Type Nested Arrays: sf00FromNested(Object data) ===== |
- | ==== Example usage ==== | + | Recursively converts a nested '' |
- | <code java>Â | + | You may use this method when your structure may contain integers, floats, doubles, longs, or strings. Each array level becomes a '' |
- | Object[][] example = {Â | + | |
- | {" | + | |
- | {" | + | |
- | }; | + | |
- | SecsFormat00 result | + | ==== Example method ==== |
- | </ | + | |
- | Â | + | |
- | **Expected output:**Â | + | |
- | Â | + | |
- | < | + | |
- | [[<A ' | + | |
- | </ | + | |
<code java> | <code java> | ||
Line 58: | Line 46: | ||
} | } | ||
</ | </ | ||
- | |||
- | |||
- | ===== sf00FromNestedStrings(Object data) ===== | ||
- | |||
- | Recursively converts a nested '' | ||
==== Example usage ==== | ==== Example usage ==== | ||
<code java> | <code java> | ||
- | String[][][] nestedStrings | + | Object[][] example |
- | | + | {"abc", |
- | | + | {"xyz", |
- | {" | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
}; | }; | ||
- | SecsFormat00 result = sf00FromNestedStrings(nestedStrings); | + | SecsFormat00 result = sf00FromNested(example); |
</ | </ | ||
Line 84: | Line 61: | ||
< | < | ||
- | [[[<A 'A'>, <A ' | + | [[<A 'abc'>, <I4 123>, <F8 1.23000>], [<A 'xyz'>, [<I8 456>, <F4 7.89000>]]] |
</ | </ | ||
+ | |||
+ | |||
+ | ===== 🔤 Convert All-String Nested Arrays: sf00FromNestedStrings(Object data) ===== | ||
+ | |||
+ | Recursively converts a nested '' | ||
+ | |||
+ | ==== Example method ==== | ||
<code java> | <code java> | ||
Line 113: | Line 97: | ||
return list; | return list; | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ==== Example usage ==== | ||
+ | |||
+ | <code java> | ||
+ | String[][][] nestedStrings = { | ||
+ | { | ||
+ | {" | ||
+ | {" | ||
+ | }, | ||
+ | { | ||
+ | {" | ||
+ | {" | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | SecsFormat00 result = sf00FromNestedStrings(nestedStrings); | ||
+ | </ | ||
+ | |||
+ | **Expected output:** | ||
+ | |||
+ | < | ||
+ | [[[<A ' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== 📦 Convert Structured Triple Arrays: sf00FromNestedStructuredTriple(Object data) ===== | ||
+ | |||
+ | Recursively converts a nested '' | ||
+ | Non-array elements are assumed to be leaf-level triples: **[String, Float, Integer]**. | ||
+ | Arrays are recursively processed into nested '' | ||
+ | |||
+ | ==== Example method ==== | ||
+ | |||
+ | <code java> | ||
+ | /** | ||
+ | * Recursively converts a nested {@code Object} array into a hierarchical SECS structure. | ||
+ | * <p> | ||
+ | * Non-array elements are assumed to be leaf-level triples: [String, Float, Integer]. | ||
+ | * Arrays are recursively processed into nested {@link SecsFormat00} structures. | ||
+ | * | ||
+ | * @param data the nested Object array | ||
+ | * @return a {@link SecsFormat00} representing the structured SECS data | ||
+ | * @throws IllegalArgumentException if the leaf triple is invalid or structure is malformed | ||
+ | */ | ||
+ | public static SecsFormat00 sf00FromNestedStructuredTriple(Object data) { | ||
+ | if (!(data instanceof Object[])) { | ||
+ | throw new IllegalArgumentException(" | ||
+ | } | ||
+ | |||
+ | Object[] array = (Object[]) data; | ||
+ | |||
+ | // Check if this is a valid leaf triple | ||
+ | if (array.length == 3 && | ||
+ | array[0] instanceof String && | ||
+ | array[1] instanceof Float && | ||
+ | array[2] instanceof Integer) { | ||
+ | |||
+ | SecsFormat00 triple = new SecsFormat00(); | ||
+ | triple.add(new SecsFormat20((String) array[0])); | ||
+ | triple.add(new SecsFormat44((Float) array[1])); | ||
+ | triple.add(new SecsFormat34((Integer) array[2])); | ||
+ | return triple; | ||
+ | } | ||
+ | |||
+ | // Otherwise, treat as nested structure | ||
+ | SecsFormat00 list = new SecsFormat00(); | ||
+ | for (Object element : array) { | ||
+ | if (!(element instanceof Object[])) { | ||
+ | throw new IllegalArgumentException(" | ||
+ | } | ||
+ | list.add(sf00FromNestedStructuredTriple(element)); | ||
+ | } | ||
+ | |||
+ | return list; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Example usage ==== | ||
+ | |||
+ | <code java> | ||
+ | Object[] nested = { | ||
+ | new Object[] { | ||
+ | new Object[] { " | ||
+ | new Object[] { " | ||
+ | }, | ||
+ | new Object[] { | ||
+ | new Object[] { " | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | SecsFormat00 result = sf00FromNestedStructuredTriple(nested); | ||
+ | </ | ||
+ | |||
+ | **Expected output:** | ||
+ | |||
+ | < | ||
+ | [[[<A ' | ||
</ | </ | ||