Package zeroecho.core.marshal
Class PairSeq
java.lang.Object
zeroecho.core.marshal.PairSeq
Immutable sequence of string key-value pairs with cursor-based iteration and
simple text serialization.
A PairSeq stores pairs in a flat String[] array
representation: [k0, v0, k1, v1, ...]. It is designed for compact
transport of structured metadata where keys and values are UTF-8–safe strings
(binary data should be Base64 encoded before storing).
Usage
PairSeq seq = PairSeq.of("type", "SntruPrimePublicKeySpec",
"x509.b64", "BASE64ENCODED");
for (PairSeq.Cursor c = seq.cursor(); c.next();) {
System.out.println(c.key() + " = " + c.value());
}
Serialization
writeTo(Appendable)outputs each pair ask=v\nlines without escaping.readFrom(java.io.Reader)parses lines in the same format, ignoring blank lines and comments starting with#.
Thread-safety
Instances are immutable and safe to share across threads. ThePairSeq.Cursor is not thread-safe and should be confined to a
single thread.- Since:
- 1.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptioncursor()Returns a forward-only cursor for iterating the pairs.keyAt(int i) Returns the key at the given index.static PairSeqCreates a new sequence from an even-length list of keys and values.static PairSeqReads aPairSeqfrom a line-based text format.intsize()Returns the number of key-value pairs in this sequence.valAt(int i) Returns the value at the given index.voidwriteTo(Appendable out) Appends all pairs to the target askey=valuelines.
-
Method Details
-
of
Creates a new sequence from an even-length list of keys and values.- Parameters:
kv- alternating key and value strings; must have even length- Returns:
- new
PairSeqwith the given contents - Throws:
IllegalArgumentException- ifkvisnullor has odd length
-
size
public int size()Returns the number of key-value pairs in this sequence.- Returns:
- pair count
-
keyAt
Returns the key at the given index.- Parameters:
i- index of the pair (0-based)- Returns:
- key string
- Throws:
ArrayIndexOutOfBoundsException- ifiis out of range
-
valAt
Returns the value at the given index.- Parameters:
i- index of the pair (0-based)- Returns:
- value string
- Throws:
ArrayIndexOutOfBoundsException- ifiis out of range
-
cursor
Returns a forward-only cursor for iterating the pairs.- Returns:
- new cursor over this sequence
-
writeTo
Appends all pairs to the target askey=valuelines.No escaping is performed; callers must ensure keys and values do not contain newlines. Binary data should be stored as Base64.
- Parameters:
out- appendable target- Throws:
UncheckedIOException- if the append fails
-
readFrom
Reads aPairSeqfrom a line-based text format.Each non-empty, non-comment line must have the form
key=value. Lines without an equals sign or with empty keys are skipped. Comments start with#.- Parameters:
reader- character source- Returns:
- parsed
PairSeq - Throws:
IOException- if reading fails
-