Simplify Options and Attributes creation
Make compatible changes to guide users for future changes
MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/Attributes.java
asciidoctorj-api/src/main/java/org/asciidoctor/Attributes.java
@@ -62,24 +62,47 @@ public class Attributes {
public static final String HIDE_URI_SCHEME = "hide-uri-scheme";
public static final String COMPAT_MODE = "compat-mode";
- private Map<String, Object> attributes = new LinkedHashMap<String, Object>();
+ private Map<String, Object> attributes = new LinkedHashMap<>();
+ /**
+ * @deprecated Use {@link #builder} instead.
+ */
+ @Deprecated
public Attributes() {
super();
}
+ /**
+ * @deprecated Use {@link #builder} instead.
+ */
+ @Deprecated
public Attributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
+ /**
+ * @deprecated Use {@link #builder} instead.
+ */
+ @Deprecated
public Attributes(String[] attributes) {
this.setAttributes(attributes);
}
+ /**
+ * @deprecated Use {@link #builder} instead.
+ */
+ @Deprecated
public Attributes(String attributes) {
this.setAttributes(attributes);
}
+ /**
+ * @return Empty AttributesBuilder instance.
+ */
+ public static AttributesBuilder builder() {
+ return new AttributesBuilder();
+ }
+
/**
* Allow Asciidoctor to read content from an URI.
* Additionally the option {@link SafeMode} must be less than {@link SafeMode#SECURE} to enable inclusion of content from an URI.
@@ -623,10 +646,6 @@ public class Attributes {
this.attributes.putAll(attributes);
}
- public Map<String, Object> map() {
- return this.attributes;
- }
-
public static String toAsciidoctorFlag(boolean flag) {
return flag ? "" : null;
}
@@ -639,4 +658,11 @@ public class Attributes {
return TIME_FORMAT.format(time);
}
+ /**
+ * @deprecated For internal use only.
+ */
+ @Deprecated
+ public Map<String, Object> map() {
+ return this.attributes;
+ }
}

MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/AttributesBuilder.java
asciidoctorj-api/src/main/java/org/asciidoctor/AttributesBuilder.java
@@ -6,26 +6,30 @@ import java.util.Map;
public class AttributesBuilder {
- private Attributes attributes = new Attributes();
+ private final Attributes attributes = new Attributes();
- private AttributesBuilder() {
+ AttributesBuilder() {
super();
}
/**
* Creates attributes builder.
+ * @deprecated Use {@link Attributes#builder()} instead.
*
- * @return atributes builder.
+ * @return attributes builder.
*/
+ @Deprecated
public static AttributesBuilder attributes() {
return new AttributesBuilder();
}
/**
* Creates attributes builder.
+ * @deprecated Use {@link Attributes#builder()} with {@link #arguments(String...)} instead.
*
- * @return atributes builder.
+ * @return attributes builder.
*/
+ @Deprecated
public static AttributesBuilder attributes(String[] arguments) {
AttributesBuilder attributesBuilder = new AttributesBuilder();
attributesBuilder.arguments(arguments);
@@ -34,9 +38,11 @@ public class AttributesBuilder {
/**
* Creates attributes builder.
+ * @deprecated Use {@link Attributes#builder()} with {@link #arguments(String)} instead.
*
* @return attributes builder.
*/
+ @Deprecated
public static AttributesBuilder attributes(String arguments) {
AttributesBuilder attributesBuilder = new AttributesBuilder();
attributesBuilder.arguments(arguments);
@@ -599,15 +605,29 @@ public class AttributesBuilder {
/**
* Gets a map with configured options.
+ * @deprecated Use {@link #build()} instead.
*
* @return map with all options. By default an empty map is returned.
*/
+ @Deprecated
public Map<String, Object> asMap() {
return this.attributes.map();
}
+ /**
+ * @deprecated Use {@link #build()} instead.
+ */
+ @Deprecated
public Attributes get() {
return this.attributes;
}
+ /**
+ * Returns a valid Attributes instance.
+ *
+ * @return attributes instance.
+ */
+ public Attributes build() {
+ return this.attributes;
+ }
}

MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/Options.java
asciidoctorj-api/src/main/java/org/asciidoctor/Options.java
@@ -33,16 +33,31 @@ public class Options {
public static final String PARSE = "parse";
public static final String PARSE_HEADER_ONLY = "parse_header_only";
- private Map<String, Object> options = new HashMap<String, Object>();
+ private Map<String, Object> options = new HashMap<>();
+ /**
+ * @deprecated Use {@link Options#builder()} instead.
+ */
+ @Deprecated
public Options() {
super();
}
+ /**
+ * @deprecated Use {@link Options#builder()} instead.
+ */
+ @Deprecated
public Options(Map<String, Object> options) {
this.options = options;
}
+ /**
+ * @return Empty OptionsBuilder instance.
+ */
+ public static OptionsBuilder builder() {
+ return new OptionsBuilder();
+ }
+
public void setInPlace(boolean inPlace) {
this.options.put(IN_PLACE, inPlace);
}
@@ -198,6 +213,10 @@ public class Options {
this.options.put(optionName, optionValue);
}
+ /**
+ * @deprecated For internal use only.
+ */
+ @Deprecated
public Map<String, Object> map() {
return this.options;
}

MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java
asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java
@@ -6,17 +6,19 @@ import java.util.Map;
public class OptionsBuilder {
- private Options options = new Options();
+ private final Options options = new Options();
- private OptionsBuilder() {
+ OptionsBuilder() {
super();
}
/**
* Creates options builder instance.
+ * @deprecated Use {@link Options#builder()} instead.
*
* @return options builder instance.
*/
+ @Deprecated
public static OptionsBuilder options() {
return new OptionsBuilder();
}
@@ -123,11 +125,13 @@ public class OptionsBuilder {
/**
* Sets attributes used for rendering input.
+ * @deprecated Use {@link #attributes(Attributes)} instead.
*
* @param attributes
* map.
* @return this instance.
*/
+ @Deprecated
public OptionsBuilder attributes(Map<String, Object> attributes) {
this.options.setAttributes(attributes);
return this;
@@ -141,17 +145,19 @@ public class OptionsBuilder {
* @return this instance.
*/
public OptionsBuilder attributes(Attributes attributes) {
- this.options.setAttributes(attributes.map());
+ this.options.setAttributes(attributes);
return this;
}
/**
* Sets attributes used for rendering input.
+ * @deprecated Use {@link #attributes(Attributes)} instead.
*
* @param attributes
* builder.
* @return this instance.
*/
+ @Deprecated
public OptionsBuilder attributes(AttributesBuilder attributes) {
this.options.setAttributes(attributes.asMap());
return this;
@@ -337,8 +343,6 @@ public class OptionsBuilder {
return this;
}
-
-
/**
* Sets base dir for working directory.
*
@@ -353,15 +357,30 @@ public class OptionsBuilder {
/**
* Gets a map with configured options.
+ * @deprecated Use {@link #build()} instead.
*
* @return map with all options. By default an empty map is returned.
*/
+ @Deprecated
public Map<String, Object> asMap() {
return this.options.map();
}
+ /**
+ * @deprecated Use {@link #build()} instead.
+ */
+ @Deprecated
public Options get() {
return this.options;
}
+ /**
+ * Returns a valid Options instance.
+ *
+ * @return options instance.
+ */
+ public Options build() {
+ return this.options;
+ }
+
}

Simplify Options and Attributes creation

Make compatible changes to guide users for future changes