Making MemorySection much more efficient; Addresses BUKKIT-1454

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot
2012-04-30 16:54:00 -05:00
parent 34681566e0
commit 8726d93ca1
6 changed files with 137 additions and 386 deletions

View File

@@ -1,6 +1,8 @@
package org.bukkit.configuration.file;
import com.google.common.io.Files;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.InvalidConfigurationException;
import java.io.BufferedReader;
import java.io.File;
@@ -45,9 +47,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when file is null.
*/
public void save(File file) throws IOException {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file);
@@ -73,9 +73,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when file is null.
*/
public void save(String file) throws IOException {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
Validate.notNull(file, "File cannot be null");
save(new File(file));
}
@@ -102,9 +100,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
Validate.notNull(file, "File cannot be null");
load(new FileInputStream(file));
}
@@ -121,14 +117,13 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when stream is null.
*/
public void load(InputStream stream) throws IOException, InvalidConfigurationException {
if (stream == null) {
throw new IllegalArgumentException("Stream cannot be null");
}
Validate.notNull(stream, "Stream cannot be null");
InputStreamReader reader = new InputStreamReader(stream);
StringBuilder builder = new StringBuilder();
BufferedReader input = new BufferedReader(reader);
try {
String line;
@@ -158,9 +153,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(String file) throws FileNotFoundException, IOException, InvalidConfigurationException {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
Validate.notNull(file, "File cannot be null");
load(new File(file));
}

View File

@@ -7,6 +7,7 @@ import java.io.InputStream;
import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
@@ -44,9 +45,7 @@ public class YamlConfiguration extends FileConfiguration {
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
if (contents == null) {
throw new IllegalArgumentException("Contents cannot be null");
}
Validate.notNull(contents, "Contents cannot be null");
Map<?, ?> input;
try {
@@ -167,9 +166,7 @@ public class YamlConfiguration extends FileConfiguration {
* @throws IllegalArgumentException Thrown is file is null
*/
public static YamlConfiguration loadConfiguration(File file) {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
Validate.notNull(file, "File cannot be null");
YamlConfiguration config = new YamlConfiguration();
@@ -196,9 +193,7 @@ public class YamlConfiguration extends FileConfiguration {
* @throws IllegalArgumentException Thrown is stream is null
*/
public static YamlConfiguration loadConfiguration(InputStream stream) {
if (stream == null) {
throw new IllegalArgumentException("Stream cannot be null");
}
Validate.notNull(stream, "Stream cannot be null");
YamlConfiguration config = new YamlConfiguration();

View File

@@ -1,5 +1,7 @@
package org.bukkit.configuration.file;
import org.apache.commons.lang.Validate;
/**
* Various settings for controlling the input and output of a {@link YamlConfiguration}
*/
@@ -59,9 +61,8 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
* @return This object, for chaining
*/
public YamlConfigurationOptions indent(int value) {
if ((indent < 2) || (value > 9)) {
throw new IllegalArgumentException("Indent must be between 1 and 10 characters");
}
Validate.isTrue(value >= 2, "Indent must be at least 2 characters");
Validate.isTrue(value <= 9, "Indent cannot be greater than 9 characters");
this.indent = value;
return this;