Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
MemoryConfiguration.java
1 package org.bukkit.configuration;
2 
3 import java.util.Map;
4 
5 import org.apache.commons.lang.Validate;
6 
7 /**
8  * This is a {@link Configuration} implementation that does not save or load
9  * from any source, and stores all values in memory only.
10  * This is useful for temporary Configurations for providing defaults.
11  */
12 public class MemoryConfiguration extends MemorySection implements Configuration {
13  protected Configuration defaults;
15 
16  /**
17  * Creates an empty {@link MemoryConfiguration} with no default values.
18  */
19  public MemoryConfiguration() {}
20 
21  /**
22  * Creates an empty {@link MemoryConfiguration} using the specified {@link
23  * Configuration} as a source for all default values.
24  *
25  * @param defaults Default value provider
26  * @throws IllegalArgumentException Thrown if defaults is null
27  */
29  this.defaults = defaults;
30  }
31 
32  @Override
33  public void addDefault(String path, Object value) {
34  Validate.notNull(path, "Path may not be null");
35 
36  if (defaults == null) {
37  defaults = new MemoryConfiguration();
38  }
39 
40  defaults.set(path, value);
41  }
42 
43  public void addDefaults(Map<String, Object> defaults) {
44  Validate.notNull(defaults, "Defaults may not be null");
45 
46  for (Map.Entry<String, Object> entry : defaults.entrySet()) {
47  addDefault(entry.getKey(), entry.getValue());
48  }
49  }
50 
51  public void addDefaults(Configuration defaults) {
52  Validate.notNull(defaults, "Defaults may not be null");
53 
54  addDefaults(defaults.getValues(true));
55  }
56 
57  public void setDefaults(Configuration defaults) {
58  Validate.notNull(defaults, "Defaults may not be null");
59 
60  this.defaults = defaults;
61  }
62 
64  return defaults;
65  }
66 
67  @Override
69  return null;
70  }
71 
73  if (options == null) {
74  options = new MemoryConfigurationOptions(this);
75  }
76 
77  return options;
78  }
79 }
void set(String path, Object value)
Map< String, Object > getValues(boolean deep)
void addDefaults(Map< String, Object > defaults)