Advertisement
iamgabrieler

Untitled

May 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package it.cicerone.yaml;
  2.  
  3. import java.util.Map;
  4.  
  5. import org.apache.commons.lang3.Validate;
  6.  
  7. import lombok.Getter;
  8.  
  9. /**
  10.  * Questa è un'implementazione di {@link Configuration} che non salva e non
  11.  * carica da nessuna fonte e salva tutti i valori solamente in memoria.
  12.  * È utile per configurazioni temporanee per specificare dei predefiniti.
  13.  */
  14. public class MemoryConfiguration extends MemorySection implements Configuration {
  15.    
  16.     @Getter protected Configuration defaults;
  17.    
  18.     protected MemoryConfigurationOptions options;
  19.  
  20.     /**
  21.      * Crea un {@link MemoryConfiguration} vuoto senza predefiniti.
  22.      */
  23.     public MemoryConfiguration() {}
  24.  
  25.     /**
  26.      * Crea un {@link MemoryConfiguration} vuoto con il {@link Configuration}
  27.      * specificato come fonte di tutti i valori predefiniti.
  28.      *
  29.      * @param defaults Fornitore del valore predefinito
  30.      * @throws IllegalArgumentException lanciata se il predefinito è nullo.
  31.      */
  32.     public MemoryConfiguration(Configuration defaults) {
  33.         this.defaults = defaults;
  34.     }
  35.  
  36.     @Override
  37.     public void addDefault(String path, Object value) {
  38.        
  39.         Validate.notNull(path, "Path may not be null");
  40.  
  41.         if (defaults == null) {
  42.             defaults = new MemoryConfiguration();
  43.         }
  44.  
  45.         defaults.set(path, value);
  46.        
  47.     }
  48.  
  49.     public void addDefaults(Map<String, Object> defaults) {
  50.        
  51.         Validate.notNull(defaults, "Defaults may not be null");
  52.  
  53.         for (Map.Entry<String, Object> entry : defaults.entrySet()) {
  54.             addDefault(entry.getKey(), entry.getValue());
  55.         }
  56.     }
  57.  
  58.     public void addDefaults(Configuration defaults) {
  59.        
  60.         Validate.notNull(defaults, "Defaults may not be null");
  61.         addDefaults(defaults.getValues(true));
  62.        
  63.     }
  64.  
  65.     public void setDefaults(Configuration defaults) {
  66.        
  67.         Validate.notNull(defaults, "Defaults may not be null");
  68.         this.defaults = defaults;
  69.        
  70.     }
  71.  
  72.     @Override
  73.     public ConfigurationSection getParent() {
  74.         return null;
  75.     }
  76.  
  77.     public MemoryConfigurationOptions options() {
  78.        
  79.         if (options == null) {
  80.             options = new MemoryConfigurationOptions(this);
  81.         }
  82.  
  83.         return options;
  84.        
  85.     }
  86.    
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement