/**
   * Cloning constructor
   *
   * @param clone the performance parameter to copy
   */
  public PerformanceParameters(PerformanceParameters clone) {
    this.setVMParameters(clone.vmParameters.toString());
    this.setCachePath(clone.getCachePath());

    this.setNbThreads(clone.getNbThreads());
    this.setDefaultTileSize(clone.getDefaultTileSize());
    this.setCacheSize(clone.getCacheSize());
  }
  /**
   * Save the actual configuration
   *
   * @param confToSave The configuration to save
   */
  static synchronized void saveConfiguration(PerformanceParameters confToSave)
      throws IOException, BackingStoreException {

    if (!loadConfiguration().getVMParameters().equals(confToSave.getVMParameters())) {
      confToSave.vmParameters.save();
    }

    Config configuration = EngineConfig.instance().load();
    Preferences preferences = configuration.preferences();

    Path cachePath = confToSave.getCachePath();

    if (!Files.exists(cachePath)) {
      Files.createDirectories(cachePath);
    }

    if (Files.exists(cachePath)) {
      preferences.put(
          SystemUtils.SNAP_CACHE_DIR_PROPERTY_NAME, cachePath.toAbsolutePath().toString());
    } else {
      SystemUtils.LOG.severe(
          "Directory for cache path does not exist and could not be created: "
              + cachePath.toAbsolutePath().toString());
    }

    preferences.putInt(PROPERTY_JAI_PARALLELISM, confToSave.getNbThreads());
    preferences.putInt(PROPERTY_DEFAULT_TILE_SIZE, confToSave.getDefaultTileSize());
    preferences.putInt(PROPERTY_JAI_CACHE_SIZE, confToSave.getCacheSize());
    JAI.getDefaultInstance().getTileCache().setMemoryCapacity(confToSave.getCacheSize());
    preferences.flush();
  }
  /**
   * Reads the parameters files and system settings to retreive the actual performance parameters.
   * It updates the "actualParameters" according to the configuration loaded.
   *
   * @return the actual performance parameters, loaded by this method
   */
  static synchronized PerformanceParameters loadConfiguration() {

    Config configuration = Config.instance().load();
    Preferences preferences = configuration.preferences();

    PerformanceParameters actualParameters = new PerformanceParameters();

    VMParameters netBeansVmParameters = VMParameters.load();
    actualParameters.setVMParameters(netBeansVmParameters.toString());
    actualParameters.setCachePath(SystemUtils.getCacheDir().toPath());

    final int defaultNbThreads = JavaSystemInfos.getInstance().getNbCPUs();
    actualParameters.setNbThreads(preferences.getInt(PROPERTY_JAI_PARALLELISM, defaultNbThreads));
    actualParameters.setDefaultTileSize(preferences.getInt(PROPERTY_DEFAULT_TILE_SIZE, 0));
    actualParameters.setCacheSize(preferences.getInt(PROPERTY_JAI_CACHE_SIZE, 0));

    return actualParameters;
  }