All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.cwcode.tkach.config.base.manager.ConfigCreator Maven / Gradle / Ivy

The newest version!
package ru.cwcode.tkach.config.base.manager;

import ru.cwcode.tkach.config.Utils;
import ru.cwcode.tkach.config.base.Config;
import ru.cwcode.tkach.config.base.ConfigPersistOptions;

import java.util.Optional;

import static ru.cwcode.tkach.config.server.ServerPlatform.l10n;

public class ConfigCreator> {
  ConfigManager configManager;
  
  public void setConfigManager(ConfigManager configManager) {
    this.configManager = configManager;
  }
  
  public  Optional create(String name, Class configClass, ConfigPersistOptions persistOptions) {
    
    if (!persistOptions.isSilent()) {
      configManager.platform.info(l10n.get("config.creator.creating", name));
    }
    
    Optional instance = Utils.getNewInstance(configClass);
    
    if (!persistOptions.isSilent()) {
      instance.ifPresentOrElse(__ -> configManager.platform.info(l10n.get("config.creator.created", name)),
                               () -> configManager.platform.info(l10n.get("config.creator.cantCreate", name)));
    }
    
    return instance;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy