Address some more PR feedback

Make the javadoc string for the ConfigDocument interface more
explicit about what it does with the value string when setting
a value. Add support for parsing a reader into a ConfigDocument.
This commit is contained in:
Preben Ingvaldsen 2015-03-23 14:02:59 -07:00
parent 28a096f157
commit c3a2e07c6a
3 changed files with 39 additions and 1 deletions

View File

@ -24,7 +24,9 @@ public interface ConfigDocument {
* at the final occurrence of the path. If the path does not exist, it will be added.
*
* @param path the path at which to set the desired value
* @param newValue the value to set at the desired path
* @param newValue the value to set at the desired path, represented as a string. This
* string will be parsed into a ConfigNode, and the text will be inserted
* as-is into the document, with leading and trailing whitespace removed.
* @return a copy of the ConfigDocument with the desired value at the desired path
*/
ConfigDocument setValue(String path, String newValue);

View File

@ -4,6 +4,7 @@ import com.typesafe.config.impl.ConfigImpl;
import com.typesafe.config.impl.Parseable;
import java.io.File;
import java.io.Reader;
/**
* Factory for automatically creating a ConfigDocument from a given input. Currently
@ -11,6 +12,34 @@ import java.io.File;
*/
public final class ConfigDocumentFactory {
/**
* Parses a Reader into a ConfigDocument instance.
*
* @param reader
* the reader to parse
* @param options
* parse options to control how the reader is interpreted
* @return the parsed configuration
* @throws ConfigException on IO or parse errors
*/
public static ConfigDocument parseReader(Reader reader, ConfigParseOptions options) {
return Parseable.newReader(reader, options).parseConfigDocument();
}
/**
* Parses a reader into a Config instance as with
* {@link #parseReader(Reader,ConfigParseOptions)} but always uses the
* default parse options.
*
* @param reader
* the reader to parse
* @return the parsed configuration
* @throws ConfigException on IO or parse errors
*/
public static ConfigDocument parseReader(Reader reader) {
return parseReader(reader, ConfigParseOptions.defaults());
}
/**
* Parses a file into a ConfigDocument instance.
*

View File

@ -198,4 +198,11 @@ class ConfigDocumentTest extends TestUtils {
val fileText = sb.toString()
assertEquals(fileText, configDocument.render())
}
@Test
def configDocumentReaderParse {
val configDocument = ConfigDocumentFactory.parseReader(new FileReader(resourceFile("/test03.conf")))
val configDocumentFile = ConfigDocumentFactory.parseFile(resourceFile("/test03.conf"))
assertEquals(configDocumentFile.render(), configDocument.render())
}
}