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:10] colinr |
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 ====== |
+ | |||
+ | |||
+ | ===== 🧩 Convert Mixed-Type Nested Arrays: | ||
Recursively converts a nested '' | Recursively converts a nested '' | ||
You may use this method when your structure may contain integers, floats, doubles, longs, or strings. Each array level becomes a '' | You may use this method when your structure may contain integers, floats, doubles, longs, or strings. Each array level becomes a '' | ||
- | ==== Example usage ==== | ||
- | <code java> | + | ==== Example method ==== |
- | Object[][] example | + | |
- | {" | + | |
- | {" | + | |
- | }; | + | |
- | + | ||
- | SecsFormat00 result | + | |
- | </ | + | |
- | + | ||
- | **Expected output:** | + | |
- | + | ||
- | < | + | |
- | [[<A ' | + | |
- | </ | + | |
<code java> | <code java> | ||
Line 57: | 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 83: | 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 98: | ||
} | } | ||
</ | </ | ||
- | |||
- | ===== sf00FromStructuredTriple(Object data) ===== | ||
- | |||
- | Converts a nested '' | ||
- | |||
- | Each row becomes a '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
==== Example usage ==== | ==== Example usage ==== | ||
<code java> | <code java> | ||
- | Object[][] triples | + | String[][][] nestedStrings |
- | {"abc", | + | |
- | {"def", | + | |
+ | {" | ||
+ | | ||
+ | | ||
+ | | ||
+ | {" | ||
+ | | ||
}; | }; | ||
- | SecsFormat00 result = sf00FromStructuredTriple(triples); | + | SecsFormat00 result = sf00FromNestedStrings(nestedStrings); |
</ | </ | ||
Line 137: | Line 119: | ||
< | < | ||
- | [[<A 'abc'>, <F4 1.50000>, <I4 42>], [<A 'def'>, <F4 2.50000>, <I4 99>]] | + | [[[<A 'A'>, <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> | <code java> | ||
/** | /** | ||
- | | + | |
- | * has exactly 3 elements in the order: String, Float, Integer. | + | |
* <p> | * <p> | ||
- | | + | |
- | * < | + | |
- | | + | |
- | | + | |
- | | + | |
- | * </ul> | + | |
* | * | ||
- | * @param data the nested Object array (e.g. Object[][]) | + | * @param data the nested Object array |
* @return a {@link SecsFormat00} representing the structured SECS data | * @return a {@link SecsFormat00} representing the structured SECS data | ||
- | * @throws IllegalArgumentException if the structure | + | * @throws IllegalArgumentException if the leaf triple is invalid |
*/ | */ | ||
- | public static SecsFormat00 | + | public static SecsFormat00 |
- | SecsFormat00 outerList = new SecsFormat00(); | + | |
if (!(data instanceof Object[])) { | if (!(data instanceof Object[])) { | ||
- | throw new IllegalArgumentException(" | + | throw new IllegalArgumentException(" |
} | } | ||
- | | + | Object[] |
- | if (!(rowObj instanceof | + | |
- | throw new IllegalArgumentException(" | + | |
- | } | + | |
- | Object[] row = (Object[]) rowObj; | + | // Check if this is a valid leaf triple |
- | if (row.length | + | if (array.length |
- | | + | |
- | } | + | |
+ | array[2] instanceof Integer) { | ||
- | | + | |
- | | + | triple.add(new SecsFormat20((String) array[0])); |
- | | + | |
+ | | ||
+ | return triple; | ||
+ | } | ||
- | if (!(strObj instanceof String)) { | + | // Otherwise, treat as nested structure |
- | | + | |
- | } | + | |
- | if (!(floatObj instanceof Float)) { | + | if (!(element |
- | throw new IllegalArgumentException(" | + | throw new IllegalArgumentException(" |
- | } | + | |
- | if (!(intObj | + | |
- | throw new IllegalArgumentException(" | + | |
} | } | ||
+ | list.add(sf00FromNestedStructuredTriple(element)); | ||
+ | } | ||
- | SecsFormat00 rowList = new SecsFormat00(); | + | return list; |
- | | + | } |
- | | + | </ |
- | rowList.add(new SecsFormat34((Integer) intObj)); | + | |
- | outerList.add(rowList); | + | ==== Example usage ==== |
+ | |||
+ | <code java> | ||
+ | Object[] nested = { | ||
+ | new Object[] { | ||
+ | new Object[] { " | ||
+ | new Object[] { " | ||
+ | }, | ||
+ | new Object[] { | ||
+ | new Object[] { " | ||
} | } | ||
+ | }; | ||
- | return outerList; | + | SecsFormat00 result = sf00FromNestedStructuredTriple(nested); |
- | } | + | </ |
+ | |||
+ | **Expected output:** | ||
+ | |||
+ | < | ||
+ | [[[<A ' | ||
</ | </ | ||