Skip to content

Commit

Permalink
Implement #526: rename Ion read/write features (JSTEP-8) (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Nov 30, 2024
1 parent 5119905 commit 57155b9
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 143 deletions.
16 changes: 8 additions & 8 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public class IonFactory
* Bitfield (set of flags) of all parser features that are enabled
* by default.
*/
protected final static int DEFAULT_ION_PARSER_FEATURE_FLAGS = IonParser.Feature.collectDefaults();
protected final static int DEFAULT_ION_PARSER_FEATURE_FLAGS = IonReadFeature.collectDefaults();

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

/*
/**********************************************************************
Expand Down Expand Up @@ -206,14 +206,14 @@ public boolean canHandleBinaryNatively() {
/**
* Checked whether specified parser feature is enabled.
*/
public final boolean isEnabled(IonParser.Feature f) {
public final boolean isEnabled(IonReadFeature f) {
return (_formatReadFeatures & f.getMask()) != 0;
}

/**
* Check whether specified generator feature is enabled.
*/
public final boolean isEnabled(IonGenerator.Feature f) {
public final boolean isEnabled(IonWriteFeature f) {
return (_formatWriteFeatures & f.getMask()) != 0;
}

Expand All @@ -234,13 +234,13 @@ public boolean canUseSchema(FormatSchema schema) {
}

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

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

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,65 +85,65 @@ public IonFactoryBuilder ionSystem(IonSystem system) {

// // // Parser features

public IonFactoryBuilder enable(IonParser.Feature f) {
public IonFactoryBuilder enable(IonReadFeature f) {
_formatReadFeatures |= f.getMask();
return _this();
}

public IonFactoryBuilder enable(IonParser.Feature first, IonParser.Feature... other) {
public IonFactoryBuilder enable(IonReadFeature first, IonReadFeature... other) {
_formatReadFeatures |= first.getMask();
for (IonParser.Feature f : other) {
for (IonReadFeature f : other) {
_formatReadFeatures |= f.getMask();
}
return _this();
}

public IonFactoryBuilder disable(IonParser.Feature f) {
public IonFactoryBuilder disable(IonReadFeature f) {
_formatReadFeatures &= ~f.getMask();
return _this();
}

public IonFactoryBuilder disable(IonParser.Feature first, IonParser.Feature... other) {
public IonFactoryBuilder disable(IonReadFeature first, IonReadFeature... other) {
_formatReadFeatures &= ~first.getMask();
for (IonParser.Feature f : other) {
for (IonReadFeature f : other) {
_formatReadFeatures &= ~f.getMask();
}
return _this();
}

public IonFactoryBuilder configure(IonParser.Feature f, boolean state) {
public IonFactoryBuilder configure(IonReadFeature f, boolean state) {
return state ? enable(f) : disable(f);
}

// // // Generator features

public IonFactoryBuilder enable(IonGenerator.Feature f) {
public IonFactoryBuilder enable(IonWriteFeature f) {
_formatWriteFeatures |= f.getMask();
return _this();
}

public IonFactoryBuilder enable(IonGenerator.Feature first, IonGenerator.Feature... other) {
public IonFactoryBuilder enable(IonWriteFeature first, IonWriteFeature... other) {
_formatWriteFeatures |= first.getMask();
for (IonGenerator.Feature f : other) {
for (IonWriteFeature f : other) {
_formatWriteFeatures |= f.getMask();
}
return _this();
}

public IonFactoryBuilder disable(IonGenerator.Feature f) {
public IonFactoryBuilder disable(IonWriteFeature f) {
_formatWriteFeatures &= ~f.getMask();
return _this();
}

public IonFactoryBuilder disable(IonGenerator.Feature first, IonGenerator.Feature... other) {
public IonFactoryBuilder disable(IonWriteFeature first, IonWriteFeature... other) {
_formatWriteFeatures &= ~first.getMask();
for (IonGenerator.Feature f : other) {
for (IonWriteFeature f : other) {
_formatWriteFeatures &= ~f.getMask();
}
return _this();
}

public IonFactoryBuilder configure(IonGenerator.Feature f, boolean state) {
public IonFactoryBuilder configure(IonWriteFeature f, boolean state) {
return state ? enable(f) : disable(f);
}

Expand Down
56 changes: 2 additions & 54 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,6 @@
public class IonGenerator
extends GeneratorBase
{
/**
* Enumeration that defines all toggleable features for Ion generators
*/
public enum Feature implements FormatFeature
{
/**
* Whether to use Ion native Type Id construct for indicating type (true);
* or "generic" type property (false) when writing. Former works better for
* systems that are Ion-centric; latter may be better choice for interoperability,
* when converting between formats or accepting other formats.
*<p>
* Enabled by default for backwards compatibility as that has been the behavior
* of `jackson-dataformat-ion` since 2.9 (first official public version)
*
* @see <a href="https://amzn.github.io/ion-docs/docs/spec.html#annot">The Ion Specification</a>
*
* @since 2.12
*/
USE_NATIVE_TYPE_ID(true),
;

protected final boolean _defaultState;
protected final int _mask;

/**
* Method that calculates bit set (flags) of all features that
* are enabled by default.
*/
public static int collectDefaults()
{
int flags = 0;
for (Feature f : values()) {
if (f.enabledByDefault()) {
flags |= f.getMask();
}
}
return flags;
}

private Feature(boolean defaultState) {
_defaultState = defaultState;
_mask = (1 << ordinal());
}

@Override
public boolean enabledByDefault() { return _defaultState; }
@Override
public boolean enabledIn(int flags) { return (flags & _mask) != 0; }
@Override
public int getMask() { return _mask; }
}

/*
/**********************************************************************
/* Basic configuration
Expand All @@ -105,7 +53,7 @@ private Feature(boolean defaultState) {

/**
* Bit flag composed of bits that indicate which
* {@link IonGenerator.Feature}s
* {@link IonWriteFeature}s
* are enabled.
*/
protected int _formatFeatures;
Expand Down Expand Up @@ -239,7 +187,7 @@ public void flush()
public boolean canWriteTypeId() {
// yes, Ion does support Native Type Ids!
// 29-Nov-2020, jobarr: Except as per [dataformats-binary#225] might not want to...
return Feature.USE_NATIVE_TYPE_ID.enabledIn(_formatFeatures);
return IonWriteFeature.USE_NATIVE_TYPE_ID.enabledIn(_formatFeatures);
}

@Override
Expand Down
20 changes: 10 additions & 10 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ protected MapperBuilderState _saveState() {
/******************************************************************
*/

public Builder enable(IonParser.Feature... features) {
for (IonParser.Feature f : features) {
public Builder enable(IonReadFeature... features) {
for (IonReadFeature f : features) {
_formatReadFeatures |= f.getMask();
}
return this;
}

public Builder disable(IonParser.Feature... features) {
for (IonParser.Feature f : features) {
public Builder disable(IonReadFeature... features) {
for (IonReadFeature f : features) {
_formatReadFeatures &= ~f.getMask();
}
return this;
}

public Builder configure(IonParser.Feature feature, boolean state)
public Builder configure(IonReadFeature feature, boolean state)
{
if (state) {
_formatReadFeatures |= feature.getMask();
Expand All @@ -115,21 +115,21 @@ public Builder configure(IonParser.Feature feature, boolean state)
return this;
}

public Builder enable(IonGenerator.Feature... features) {
for (IonGenerator.Feature f : features) {
public Builder enable(IonWriteFeature... features) {
for (IonWriteFeature f : features) {
_formatWriteFeatures |= f.getMask();
}
return this;
}

public Builder disable(IonGenerator.Feature... features) {
for (IonGenerator.Feature f : features) {
public Builder disable(IonWriteFeature... features) {
for (IonWriteFeature f : features) {
_formatWriteFeatures &= ~f.getMask();
}
return this;
}

public Builder configure(IonGenerator.Feature feature, boolean state)
public Builder configure(IonWriteFeature feature, boolean state)
{
if (state) {
_formatWriteFeatures |= feature.getMask();
Expand Down
52 changes: 2 additions & 50 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,54 +36,6 @@
public class IonParser
extends ParserMinimalBase
{
/**
* Enumeration that defines all togglable features for Ion parsers.
*/
public enum Feature implements FormatFeature
{
/**
* Whether to expect Ion native Type Id construct for indicating type (true);
* or "generic" type property (false) when deserializing.
*<p>
* Enabled by default for backwards compatibility as that has been the behavior
* of `jackson-dataformat-ion` since 2.9 (first official public version)
*
* @see <a href="https://amzn.github.io/ion-docs/docs/spec.html#annot">The Ion Specification</a>
*/
USE_NATIVE_TYPE_ID(true),
;

final boolean _defaultState;
final int _mask;

/**
* Method that calculates bit set (flags) of all features that
* are enabled by default.
*/
public static int collectDefaults()
{
int flags = 0;
for (Feature f : values()) {
if (f.enabledByDefault()) {
flags |= f.getMask();
}
}
return flags;
}

private Feature(boolean defaultState) {
_defaultState = defaultState;
_mask = (1 << ordinal());
}

@Override
public boolean enabledByDefault() { return _defaultState; }
@Override
public boolean enabledIn(int flags) { return (flags & _mask) != 0; }
@Override
public int getMask() { return _mask; }
}

// @since 2.14
protected final static JacksonFeatureSet<StreamReadCapability> ION_READ_CAPABILITIES
= DEFAULT_READ_CAPABILITIES.with(StreamReadCapability.EXACT_FLOATS);
Expand All @@ -100,7 +52,7 @@ private Feature(boolean defaultState) {

/**
* Bit flag composed of bits that indicate which
* {@link IonParser.Feature}s are enabled.
* {@link IonReadFeature}s are enabled.
*/
protected int _formatFeatures;

Expand Down Expand Up @@ -173,7 +125,7 @@ public IOContext ioContext() {
public boolean canReadTypeId() {
// yes, Ion got 'em
// 31-Mar-2021, manaigrn: but we might want to ignore them as per [dataformats-binary#270]
return Feature.USE_NATIVE_TYPE_ID.enabledIn(_formatFeatures);
return IonReadFeature.USE_NATIVE_TYPE_ID.enabledIn(_formatFeatures);
}

@Override
Expand Down
52 changes: 52 additions & 0 deletions ion/src/main/java/tools/jackson/dataformat/ion/IonReadFeature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tools.jackson.dataformat.ion;

import tools.jackson.core.FormatFeature;

/**
* Enumeration that defines all togglable features for Ion parsers.
*<p>
* NOTE: in Jackson 2.x this was named {@code IonParser.Feature}.
*/
public enum IonReadFeature implements FormatFeature
{
/**
* Whether to expect Ion native Type Id construct for indicating type (true);
* or "generic" type property (false) when deserializing.
*<p>
* Enabled by default.
*
* @see <a href="https://amzn.github.io/ion-docs/docs/spec.html#annot">The Ion Specification</a>
*/
USE_NATIVE_TYPE_ID(true),
;

private final boolean _defaultState;
private final int _mask;

/**
* Method that calculates bit set (flags) of all features that
* are enabled by default.
*/
public static int collectDefaults()
{
int flags = 0;
for (IonReadFeature f : values()) {
if (f.enabledByDefault()) {
flags |= f.getMask();
}
}
return flags;
}

private IonReadFeature(boolean defaultState) {
_defaultState = defaultState;
_mask = (1 << ordinal());
}

@Override
public boolean enabledByDefault() { return _defaultState; }
@Override
public boolean enabledIn(int flags) { return (flags & _mask) != 0; }
@Override
public int getMask() { return _mask; }
}
Loading

0 comments on commit 57155b9

Please sign in to comment.