Skip to content

Commit

Permalink
Implement #512: refactory YAML read/write features (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Nov 30, 2024
1 parent 50782ec commit ddfb208
Show file tree
Hide file tree
Showing 23 changed files with 317 additions and 313 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ implementations)
(suggested by @SebastianSolidwork)
#510: JSTEP-8: rename `CsvParser.Feature` as `CsvReadFeature`,
`CsvGenerator.Feature` as `CsvWriteFeature`
#512: JSTEP-8: rename `YAMLParser.Feature` as `YAMLReadFeature`,
`YAMLGenerator.Feature` as `YAMLWriteFeature`
- Add `XxxMapper.shared()` methods for getting globally shared default instances

CSV:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Enumeration that defines all togglable features for TOML parsers.
*/
public enum TomlReadFeature
implements FormatFeature {
implements FormatFeature
{
/**
* TOML has special syntax for time types corresponding to {@link java.time.LocalDate}, {@link java.time.LocalTime},
* {@link java.time.LocalDateTime} and {@link java.time.OffsetDateTime}. By default, the TOML parser just returns
Expand All @@ -17,8 +18,8 @@ public enum TomlReadFeature
*/
PARSE_JAVA_TIME(false);

final boolean _defaultState;
final int _mask;
private final boolean _defaultState;
private final int _mask;

// Method that calculates bit set (flags) of all features that
// are enabled by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
/**
* Enumeration that defines all togglable features for TOML generators.
*/
public enum TomlWriteFeature implements FormatFeature {
public enum TomlWriteFeature implements FormatFeature
{
/**
* The TOML spec does not allow null values. We instead write an empty string when
* {@link JsonGenerator#writeNull()} by default.
Expand All @@ -20,8 +21,8 @@ public enum TomlWriteFeature implements FormatFeature {
*/
static final int INTERNAL_PROHIBIT_INTERNAL_BUFFER_ALLOCATE = 0x80000000;

final boolean _defaultState;
final int _mask;
private final boolean _defaultState;
private final int _mask;

// Method that calculates bit set (flags) of all features that
// are enabled by default.
Expand Down
20 changes: 10 additions & 10 deletions yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class YAMLFactory
* Bitfield (set of flags) of all generator features that are enabled
* by default.
*/
protected final static int DEFAULT_YAML_PARSER_FEATURE_FLAGS = YAMLParser.Feature.collectDefaults();
protected final static int DEFAULT_YAML_PARSER_FEATURE_FLAGS = YAMLReadFeature.collectDefaults();

/**
* Bitfield (set of flags) of all generator features that are enabled
* by default.
*/
protected final static int DEFAULT_YAML_GENERATOR_FEATURE_FLAGS = YAMLGenerator.Feature.collectDefaults();
protected final static int DEFAULT_YAML_GENERATOR_FEATURE_FLAGS = YAMLWriteFeature.collectDefaults();

/*
/**********************************************************************
Expand Down Expand Up @@ -64,9 +64,9 @@ public class YAMLFactory
/**
* Configuration for underlying generator to follow, if specified;
* left as {@code null} for backwards compatibility (which means
* the dumper options are derived based on {@link YAMLGenerator.Feature}s).
* the dumper options are derived based on {@link YAMLWriteFeature}s).
* <p>
* These {@link YAMLGenerator.Feature}s are ignored if you provide your own DumperOptions:
* These {@link YAMLWriteFeature}s are ignored if you provide your own DumperOptions:
* <ul>
* <li>{@code YAMLGenerator.Feature.ALLOW_LONG_KEYS}</li>
* <li>{@code YAMLGenerator.Feature.CANONICAL_OUTPUT}</li>
Expand Down Expand Up @@ -204,13 +204,13 @@ public boolean canUseSchema(FormatSchema schema) {
}

@Override
public Class<YAMLParser.Feature> getFormatReadFeatureType() {
return YAMLParser.Feature.class;
public Class<YAMLReadFeature> getFormatReadFeatureType() {
return YAMLReadFeature.class;
}

@Override
public Class<YAMLGenerator.Feature> getFormatWriteFeatureType() {
return YAMLGenerator.Feature.class;
public Class<YAMLWriteFeature> getFormatWriteFeatureType() {
return YAMLWriteFeature.class;
}

@Override
Expand All @@ -219,11 +219,11 @@ public Class<YAMLGenerator.Feature> getFormatWriteFeatureType() {
@Override
public int getFormatWriteFeatures() { return _formatWriteFeatures; }

public boolean isEnabled(YAMLParser.Feature f) {
public boolean isEnabled(YAMLReadFeature f) {
return (_formatReadFeatures & f.getMask()) != 0;
}

public boolean isEnabled(YAMLGenerator.Feature f) {
public boolean isEnabled(YAMLWriteFeature f) {
return (_formatWriteFeatures & f.getMask()) != 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class YAMLFactoryBuilder
/**
* Configuration for underlying generator to follow, if specified;
* left as {@code null} for backwards compatibility (which means
* the dumper options are derived based on {@link YAMLGenerator.Feature}s).
* the dumper options are derived based on {@link YAMLWriteFeature}s).
* <p>
* These {@link YAMLGenerator.Feature}s are ignored if you provide your own DumperOptions:
* These {@link YAMLWriteFeature}s are ignored if you provide your own DumperOptions:
* <ul>
* <li>{@code YAMLGenerator.Feature.ALLOW_LONG_KEYS}</li>
* <li>{@code YAMLGenerator.Feature.CANONICAL_OUTPUT}</li>
Expand Down Expand Up @@ -97,33 +97,33 @@ public YAMLFactoryBuilder(YAMLFactory base) {
/**********************************************************
*/

public YAMLFactoryBuilder enable(YAMLGenerator.Feature f) {
public YAMLFactoryBuilder enable(YAMLWriteFeature f) {
_formatWriteFeatures |= f.getMask();
return this;
}

public YAMLFactoryBuilder enable(YAMLGenerator.Feature first, YAMLGenerator.Feature... other) {
public YAMLFactoryBuilder enable(YAMLWriteFeature first, YAMLWriteFeature... other) {
_formatWriteFeatures |= first.getMask();
for (YAMLGenerator.Feature f : other) {
for (YAMLWriteFeature f : other) {
_formatWriteFeatures |= f.getMask();
}
return this;
}

public YAMLFactoryBuilder disable(YAMLGenerator.Feature f) {
public YAMLFactoryBuilder disable(YAMLWriteFeature f) {
_formatWriteFeatures &= ~f.getMask();
return this;
}

public YAMLFactoryBuilder disable(YAMLGenerator.Feature first, YAMLGenerator.Feature... other) {
public YAMLFactoryBuilder disable(YAMLWriteFeature first, YAMLWriteFeature... other) {
_formatWriteFeatures &= ~first.getMask();
for (YAMLGenerator.Feature f : other) {
for (YAMLWriteFeature f : other) {
_formatWriteFeatures &= ~f.getMask();
}
return this;
}

public YAMLFactoryBuilder configure(YAMLGenerator.Feature f, boolean state) {
public YAMLFactoryBuilder configure(YAMLWriteFeature f, boolean state) {
return state ? enable(f) : disable(f);
}

Expand All @@ -133,33 +133,33 @@ public YAMLFactoryBuilder configure(YAMLGenerator.Feature f, boolean state) {
/**********************************************************
*/

public YAMLFactoryBuilder enable(YAMLParser.Feature f) {
public YAMLFactoryBuilder enable(YAMLReadFeature f) {
_formatReadFeatures |= f.getMask();
return this;
}

public YAMLFactoryBuilder enable(YAMLParser.Feature first, YAMLParser.Feature... other) {
public YAMLFactoryBuilder enable(YAMLReadFeature first, YAMLReadFeature... other) {
_formatReadFeatures |= first.getMask();
for (YAMLParser.Feature f : other) {
for (YAMLReadFeature f : other) {
_formatReadFeatures |= f.getMask();
}
return this;
}

public YAMLFactoryBuilder disable(YAMLParser.Feature f) {
public YAMLFactoryBuilder disable(YAMLReadFeature f) {
_formatReadFeatures &= ~f.getMask();
return this;
}

public YAMLFactoryBuilder disable(YAMLParser.Feature first, YAMLParser.Feature... other) {
public YAMLFactoryBuilder disable(YAMLReadFeature first, YAMLReadFeature... other) {
_formatReadFeatures &= ~first.getMask();
for (YAMLParser.Feature f : other) {
for (YAMLReadFeature f : other) {
_formatReadFeatures &= ~f.getMask();
}
return this;
}

public YAMLFactoryBuilder configure(YAMLParser.Feature f, boolean state) {
public YAMLFactoryBuilder configure(YAMLReadFeature f, boolean state) {
return state ? enable(f) : disable(f);
}

Expand Down Expand Up @@ -226,9 +226,9 @@ public YAMLFactoryBuilder loadSettings(LoadSettings settings) {
/**
* Configuration for underlying generator to follow, if specified;
* left as {@code null} for backwards compatibility (which means
* the dumper options are derived based on {@link YAMLGenerator.Feature}s).
* the dumper options are derived based on {@link YAMLWriteFeature}s).
* <p>
* These {@link YAMLGenerator.Feature}s are ignored if you provide your own DumperOptions:
* These {@link YAMLWriteFeature}s are ignored if you provide your own DumperOptions:
* <ul>
* <li>{@code YAMLGenerator.Feature.ALLOW_LONG_KEYS}</li>
* <li>{@code YAMLGenerator.Feature.CANONICAL_OUTPUT}</li>
Expand Down Expand Up @@ -283,9 +283,9 @@ public LoadSettings loadSettings() {
/**
* Configuration for underlying generator to follow, if specified;
* left as {@code null} for backwards compatibility (which means
* the dumper options are derived based on {@link YAMLGenerator.Feature}s).
* the dumper options are derived based on {@link YAMLWriteFeature}s).
* <p>
* These {@link YAMLGenerator.Feature}s are ignored if you provide your own DumperOptions:
* These {@link YAMLWriteFeature}s are ignored if you provide your own DumperOptions:
* <ul>
* <li>{@code YAMLGenerator.Feature.ALLOW_LONG_KEYS}</li>
* <li>{@code YAMLGenerator.Feature.CANONICAL_OUTPUT}</li>
Expand Down
Loading

0 comments on commit ddfb208

Please sign in to comment.