Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
26490df
debugprint
reschke Apr 13, 2026
0ffaa11
debugprint
reschke Apr 15, 2026
7498a78
serializeForToDebug consistent
reschke Apr 18, 2026
6d6f091
add formatter for class names
reschke Apr 18, 2026
87e2d0a
ByteSequenceItem
reschke Apr 18, 2026
0257c4e
DateItem
reschke Apr 18, 2026
25cc9a5
DecimalItem
reschke Apr 18, 2026
e0596b3
DecimalItem
reschke Apr 18, 2026
922fb56
DecimalItem
reschke Apr 18, 2026
517ed28
InnerList
reschke Apr 19, 2026
787a18d
BooleanItem
reschke Apr 19, 2026
b6a0c36
ByteSequenceItem
reschke Apr 19, 2026
6971aaf
DateItem
reschke Apr 19, 2026
ff852c7
DecimalItem
reschke Apr 19, 2026
9a6a48c
IntegerItem
reschke Apr 19, 2026
b398794
StringItem
reschke Apr 19, 2026
44b488a
DisplayStringItem
reschke Apr 19, 2026
980f2a7
TokenItem
reschke Apr 19, 2026
0f38578
Javadoc
reschke Apr 19, 2026
767efe6
README
reschke Apr 19, 2026
adb48e5
Parameters
reschke Apr 19, 2026
8f549e8
Parameters
reschke Apr 19, 2026
4e5ac2d
OuterList
reschke Apr 20, 2026
3addaad
refactor conversion to Item into Utils
reschke Apr 21, 2026
594b246
conversion method should handle strings that are not SF strings
reschke Apr 21, 2026
8d09850
Outerlist with war objects
reschke Apr 21, 2026
99500e4
example from 3.1.1
reschke Apr 21, 2026
7ebc5f8
InnerList
reschke Apr 22, 2026
1f07b5f
InnerList
reschke Apr 22, 2026
5c2fba9
InnerList
reschke Apr 22, 2026
3277327
InnerListTest
reschke Apr 22, 2026
4d35087
InnerListTest
reschke Apr 22, 2026
f7974cc
dict
reschke Apr 24, 2026
6529d00
dict
reschke Apr 24, 2026
996424e
dict
reschke Apr 26, 2026
1ef84ca
Decimalitem, Dictionary
reschke Apr 27, 2026
d183f76
dict
reschke Apr 30, 2026
5cc0f45
dict
reschke Apr 30, 2026
5005cf6
test restruct
reschke May 2, 2026
ed2c56a
test restruct
reschke May 2, 2026
e0369b5
parameters/lists
reschke May 2, 2026
81e8ffb
parameters/lists
reschke May 2, 2026
2c99f15
valueOfParameters
reschke May 2, 2026
db1e60a
innerlist can take param. items
reschke May 2, 2026
995c864
outerlist can take list item in addition to items
reschke May 2, 2026
23d68ec
restruct
reschke May 2, 2026
2b6f57e
restruct
reschke May 2, 2026
9ce99b4
restruct
reschke May 2, 2026
01d93ee
gitignore
reschke May 3, 2026
d07fb21
gitignore
reschke May 3, 2026
da5415e
apideprecations
reschke May 3, 2026
8a867d4
apideprecations
reschke May 3, 2026
92c3ff9
apideprecations
reschke May 3, 2026
1ee99dc
apideprecations
reschke May 3, 2026
00151ce
apideprecations
reschke May 3, 2026
b8f8e5b
apideprecations
reschke May 3, 2026
51fa477
apideprecations
reschke May 3, 2026
552eb70
apideprecations
reschke May 3, 2026
f5bb259
generics
reschke May 3, 2026
f120d4a
generics
reschke May 3, 2026
51aa809
generics
reschke May 3, 2026
1cdb2a9
apiparseexample
reschke May 6, 2026
ff7667c
Merge branch 'main' into api
reschke May 8, 2026
9e714e9
remove conflicts
reschke May 8, 2026
1045042
javadoc for utils
reschke May 8, 2026
dac5dd9
javadoc
reschke May 9, 2026
f8552b4
javadoc
reschke May 9, 2026
f162bbb
javadoc
reschke May 9, 2026
0f46c2c
api
reschke May 9, 2026
1e83932
api
reschke May 9, 2026
bc895e9
api
reschke May 9, 2026
91c7a42
type enum
reschke May 12, 2026
ef30ca4
type enum
reschke May 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.idea/
14 changes: 12 additions & 2 deletions src/main/java/org/greenbytes/http/sfv/BooleanItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ private BooleanItem(boolean value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.BOOLEAN;
}

/**
* Creates a {@link BooleanItem} instance representing the specified
* {@code boolean} value.
*
*
* @param value
* a {@code boolean} value.
* @return a {@link BooleanItem} representing {@code value}.
*/
public static BooleanItem valueOf(boolean value) {
public static BooleanItem of(boolean value) {
return value ? TRUE : FALSE;
}

Expand All @@ -44,6 +49,11 @@ public BooleanItem withParams(Parameters params) {
return new BooleanItem(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public BooleanItem withParamValuesOf(Object... obs) {
return new BooleanItem(this.value, Parameters.valueOf(obs));
}

@Override
public StringBuilder serializeTo(StringBuilder sb) {
sb.append(value ? "?1" : "?0");
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/greenbytes/http/sfv/ByteSequenceItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ private ByteSequenceItem(byte[] value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.BYTESEQUENCE;
}

/**
* Creates a {@link ByteSequenceItem} instance representing the specified
* {@code byte[]} value.
Expand All @@ -41,6 +46,11 @@ public ByteSequenceItem withParams(Parameters params) {
return new ByteSequenceItem(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public ByteSequenceItem withParamValuesOf(Object... obs) {
return new ByteSequenceItem(this.value, Parameters.valueOf(obs));
}

@Override
public Parameters getParams() {
return params;
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/greenbytes/http/sfv/DateItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ private DateItem(long value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.DATE;
}

/**
* Creates an {@link DateItem} instance representing the specified
* {@code long} value.
Expand All @@ -42,12 +47,17 @@ public DateItem withParams(Parameters params) {
return new DateItem(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public DateItem withParamValuesOf(Object... obs) {
return new DateItem(this.value, Parameters.valueOf(obs));
}

@Override
public Parameters getParams() {
return params;
}

public StringBuilder serializeToNoParams(StringBuilder sb) {
private StringBuilder serializeToNoParams(StringBuilder sb) {
return sb.append('@').append(value);
}

Expand All @@ -61,6 +71,7 @@ public String serialize() {
return serializeTo(new StringBuilder()).toString();
}

@Override
public StringBuilder serializeToForDebug(StringBuilder sb, int indentLevel, Function<Class, String> formatter) {
String indent = indentLevel != 0 ? String.format("%" + indentLevel + "s", "") : "";
String classn = formatter.apply(this.getClass());
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/org/greenbytes/http/sfv/DecimalItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ private DecimalItem(long value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.DECIMAL;
}

/**
* Creates a {@link DecimalItem} instance representing the specified
* {@code long} value, where the implied divisor is {@code 1000}.
Expand All @@ -61,17 +66,34 @@ public static DecimalItem valueOf(BigDecimal value) {
return valueOf(permille.longValue());
}

/**
* Creates a {@link DecimalItem} instance representing the specified
* {@code Double} value, with potential rounding.
*
* @param value
* a {@code Double} value.
* @return a {@link DecimalItem} representing {@code value}.
*/
public static DecimalItem valueOf(double value) {
return valueOf(BigDecimal.valueOf(value));
}

@Override
public DecimalItem withParams(Parameters params) {
return new DecimalItem(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public DecimalItem withParamValuesOf(Object... obs) {
return new DecimalItem(this.value, Parameters.valueOf(obs));
}

@Override
public Parameters getParams() {
return params;
}

public StringBuilder serializeToNoParams(StringBuilder sb) {
private StringBuilder serializeToNoParams(StringBuilder sb) {

String sign = value < 0 ? "-" : "";

Expand Down Expand Up @@ -105,6 +127,7 @@ public String serialize() {
return serializeTo(new StringBuilder(20)).toString();
}

@Override
public StringBuilder serializeToForDebug(StringBuilder sb, int indentLevel, Function<Class, String> formatter) {
String indent = indentLevel != 0 ? String.format("%" + indentLevel + "s", "") : "";
String classn = formatter.apply(this.getClass());
Expand Down
53 changes: 52 additions & 1 deletion src/main/java/org/greenbytes/http/sfv/Dictionary.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.greenbytes.http.sfv;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

/**
Expand All @@ -19,6 +21,11 @@ private Dictionary(Map<String, ListElement<?>> value) {
this.value = Collections.unmodifiableMap(Utils.checkKeys(value));
}

@Override
public SfDataType getType() {
return SfDataType.DICTIONARY;
}

/**
* Creates a {@link Dictionary} instance representing the specified
* {@code Map<String, Item>} value.
Expand All @@ -31,10 +38,39 @@ private Dictionary(Map<String, ListElement<?>> value) {
* a {@code Map<String, Item>} value
* @return a {@link Dictionary} representing {@code value}.
*/
public static Dictionary valueOf(Map<String, ListElement<?>> value) {
public static Dictionary of(Map<String, ListElement<?>> value) {
return new Dictionary(value);
}

/**
* Creates a {@link Dictionary} instance representing the values
* (key/value pairs)
*
* @param obs
* a sequence of key/value pairs
* @return a {@link Dictionary} representing the {@code values}.
*/
public static Dictionary valueOf(Object... obs) {
if (obs.length % 2 != 0) {
throw new IllegalArgumentException("requires even number of arguments, got: " + obs.length);
} else {
Map<String, ListElement<?>> map = new LinkedHashMap<>();
for (int i = 0; i < obs.length; i += 2) {
String key = obs[i].toString();
Object value = obs[i + 1];
if (map.containsKey(key)) {
throw new IllegalArgumentException("key " + key + " already exists");
}
if (value instanceof ListElement) {
map.put(key, (ListElement<?>) value);
} else {
map.put(key, Utils.asItem(obs[i + 1]));
}
}
return of(map);
}
}

@Override
public Map<String, ListElement<?>> get() {
return value;
Expand Down Expand Up @@ -79,4 +115,19 @@ public StringBuilder serializeToForDebug(StringBuilder sb, int indentLevel, Func
}
return sb;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Dictionary)) {
return false;
} else {
Dictionary that = (Dictionary) o;
return Objects.equals(value, that.value);
}
}

@Override
public int hashCode() {
return Objects.hashCode(value);
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/greenbytes/http/sfv/DisplayStringItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ private DisplayStringItem(String value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.DISPLAYSTRING;
}

/**
* Creates a {@link DisplayStringItem} instance representing the specified
* {@code String} value.
Expand All @@ -37,6 +42,11 @@ public DisplayStringItem withParams(Parameters params) {
return new DisplayStringItem(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public DisplayStringItem withParamValuesOf(Object... obs) {
return new DisplayStringItem(this.value, Parameters.valueOf(obs));
}

@Override
public Parameters getParams() {
return params;
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/org/greenbytes/http/sfv/InnerList.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.greenbytes.http.sfv;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Represents an Inner List.
Expand All @@ -21,23 +23,56 @@ private InnerList(List<Item<?>> value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.INNERLIST;
}

/**
* Creates an {@link InnerList} instance representing the specified
* {@code List<Item>} value.
*
*
* @param value
* a {@code List<Item>} value.
* @return a {@link InnerList} representing {@code value}.
*/
public static InnerList valueOf(List<Item<?>> value) {
public static InnerList of(List<Item<?>> value) {
return new InnerList(value, Parameters.EMPTY);
}

/**
* Creates an {@link InnerList} instance representing the specified
* {@code Item} values.
*
* @param values
* {@code Item} values.
* @return a {@link InnerList} representing {@code values}.
*/
public static InnerList of(Item<?>... values) {
return of(Arrays.stream(values).collect(Collectors.toList()));
}

/**
* Creates an {@link InnerList} instance representing the specified
* {@linkplain Object} values after best-effort conversion to {@linkplain Item}s.
*
* @param values {@link Object}s to populate the list with
* @return a {@link InnerList} representing {@code values}.
*/
public static InnerList valueOf(Object... values) {
return of(Arrays.stream(values).map(Utils::asItem).collect(Collectors.toList()));
}

@Override
public InnerList withParams(Parameters params) {
return new InnerList(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public InnerList withParamValuesOf(Object... obs) {
return new InnerList(this.value, Parameters.valueOf(obs));
}

private StringBuilder serializeToNoParams(StringBuilder sb) {
String separator = "";

Expand All @@ -59,6 +94,7 @@ public StringBuilder serializeTo(StringBuilder sb) {
return params.serializeTo(serializeToNoParams(sb));
}

@Override
public StringBuilder serializeToForDebug(StringBuilder sb, int indentLevel, Function<Class, String> formatter) {
String indent = indentLevel != 0 ? String.format("%" + indentLevel + "s", "") : "";
String classn = formatter.apply(this.getClass());
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/greenbytes/http/sfv/IntegerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ private IntegerItem(long value, Parameters params) {
this.params = Objects.requireNonNull(params, "params must not be null");
}

@Override
public SfDataType getType() {
return SfDataType.INTEGER;
}

/**
* Creates an {@link IntegerItem} instance representing the specified
* {@code long} value.
*
*
* @param value
* a {@code long} value.
* @return a {@link IntegerItem} representing {@code value}.
*/
public static IntegerItem valueOf(long value) {
public static IntegerItem of(long value) {
return new IntegerItem(value, Parameters.EMPTY);
}

Expand All @@ -42,6 +47,11 @@ public IntegerItem withParams(Parameters params) {
return new IntegerItem(this.value, Objects.requireNonNull(params, "params must not be null"));
}

@Override
public IntegerItem withParamValuesOf(Object... obs) {
return new IntegerItem(this.value, Parameters.valueOf(obs));
}

@Override
public Parameters getParams() {
return params;
Expand Down
Loading