This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
forked from lightbend/config
/
ConfigRenderOptions.java
134 lines (124 loc) · 4.37 KB
/
ConfigRenderOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
*/
package com.typesafe.config;
/**
* <p>
* A set of options related to rendering a {@link ConfigValue}. Passed to
* {@link ConfigValue#render(ConfigRenderOptions)}.
*
* <p>
* Here is an example of creating a {@code ConfigRenderOptions}:
*
* <pre>
* ConfigRenderOptions options =
* ConfigRenderOptions.defaults().setComments(false)
* </pre>
*/
public final class ConfigRenderOptions {
private final boolean originComments;
private final boolean comments;
private final boolean formatted;
private ConfigRenderOptions(boolean originComments, boolean comments, boolean formatted) {
this.originComments = originComments;
this.comments = comments;
this.formatted = formatted;
}
/**
* Returns the default render options which are verbose (commented and
* formatted). See {@link ConfigRenderOptions#concise} for stripped-down
* options. This rendering will not be valid JSON since it has comments.
*
* @return the default render options
*/
public static ConfigRenderOptions defaults() {
return new ConfigRenderOptions(true, true, true);
}
/**
* Returns concise render options (no whitespace or comments). For a
* resolved {@link Config}, the concise rendering will be valid JSON.
*
* @return the concise render options
*/
public static ConfigRenderOptions concise() {
return new ConfigRenderOptions(false, false, false);
}
/**
* Returns options with comments toggled. This controls human-written
* comments but not the autogenerated "origin of this setting" comments,
* which are controlled by {@link ConfigRenderOptions#setOriginComments}.
*
* @param value
* true to include comments in the render
* @return options with requested setting for comments
*/
public ConfigRenderOptions setComments(boolean value) {
if (value == comments)
return this;
else
return new ConfigRenderOptions(originComments, value, formatted);
}
/**
* Returns whether the options enable comments. This method is mostly used
* by the config lib internally, not by applications.
*
* @return true if comments should be rendered
*/
public boolean getComments() {
return comments;
}
/**
* Returns options with origin comments toggled. If this is enabled, the
* library generates comments for each setting based on the
* {@link ConfigValue#origin} of that setting's value. For example these
* comments might tell you which file a setting comes from.
*
* <p>
* {@code setOriginComments()} controls only these autogenerated
* "origin of this setting" comments, to toggle regular comments use
* {@link ConfigRenderOptions#setComments}.
*
* @param value
* true to include autogenerated setting-origin comments in the
* render
* @return options with origin comments toggled
*/
public ConfigRenderOptions setOriginComments(boolean value) {
if (value == originComments)
return this;
else
return new ConfigRenderOptions(value, comments, formatted);
}
/**
* Returns whether the options enable automated origin comments. This method
* is mostly used by the config lib internally, not by applications.
*
* @return true if origin comments should be rendered
*/
public boolean getOriginComments() {
return originComments;
}
/**
* Returns options with formatting toggled. Formatting means indentation and
* whitespace, enabling formatting makes things prettier but larger.
*
* @param value
* true to include comments in the render
* @return options with requested setting for formatting
*/
public ConfigRenderOptions setFormatted(boolean value) {
if (value == formatted)
return this;
else
return new ConfigRenderOptions(originComments, comments, value);
}
/**
* Returns whether the options enable formatting. This method is mostly used
* by the config lib internally, not by applications.
*
* @return true if comments should be rendered
*/
public boolean getFormatted() {
return formatted;
}
}