Skip to content

Commit

Permalink
YamlMapping.add(..., ...) with convenient types
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed May 8, 2024
1 parent 5b74802 commit ac3a3a0
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 8 deletions.
121 changes: 121 additions & 0 deletions src/main/java/com/amihaiemil/eoyaml/YamlMappingBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonStructure;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collection;

/**
Expand Down Expand Up @@ -61,6 +63,125 @@ default YamlMappingBuilder add(final String key, final String value) {
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Char[]
* @return Builder
*/
default YamlMappingBuilder add(final String key, final char[] value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Char
* @return Builder
*/
default YamlMappingBuilder add(final String key, final char value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Int
* @return Builder
*/
default YamlMappingBuilder add(final String key, final int value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Double
* @return Builder
*/
default YamlMappingBuilder add(final String key, final double value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Float
* @return Builder
*/
default YamlMappingBuilder add(final String key, final float value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Long
* @return Builder
*/
default YamlMappingBuilder add(final String key, final long value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value LocalDate
* @return Builder
*/
default YamlMappingBuilder add(final String key, final LocalDate value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value LocalDateTime
* @return Builder
*/
default YamlMappingBuilder add(
final String key, final LocalDateTime value
) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
* @param value Boolean
* @return Builder
*/
default YamlMappingBuilder add(final String key, final boolean value) {
return this.add(
new PlainStringScalar(key),
new PlainStringScalar(String.valueOf(value))
);
}

/**
* Add a pair to the mapping.
* @param key String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ public void returnsBoolean() {
*/
private YamlMapping mapping() {
YamlMapping mapping = Yaml.createYamlMappingBuilder()
.add("integer", "123")
.add("float", "3.54")
.add("double", "2.05")
.add("long", "32165498")
.add("localDate", "2007-12-03")
.add("localDateTime", "2007-12-03T10:15:30")
.add("trueValue", "true")
.add("falseValue", "false")
.add("integer", 123)
.add("float", 3.54)
.add("double", 2.05)
.add("long", 32165498L)
.add("localDate", LocalDate.of(2007, 12, 3))
.add("localDateTime", LocalDateTime.of(2007, 12, 3, 10, 15, 30))
.add("trueValue", true)
.add("falseValue", false)
.build();
return mapping;
}
Expand Down

0 comments on commit ac3a3a0

Please sign in to comment.