public void resetToDefaults() {
    ConfigurationDefaults def = ConfigurationDefaults.getInstance();

    List<String> def_names = new ArrayList<String>((Set<String>) def.getAllowedParameters());

    for (String s : def_names) {

      if (propertiesMap.remove(s) != null) {

        notifyParameterListeners(s);
      }
    }

    List<ResetToDefaultsListener> listeners;

    synchronized (reset_to_def_listeners) {
      listeners = new ArrayList<ResetToDefaultsListener>(reset_to_def_listeners);
    }

    for (ResetToDefaultsListener l : listeners) {

      try {
        l.reset();

      } catch (Throwable e) {

        Debug.out(e);
      }
    }

    save();
  }
 // Sets a parameter back to its default
 public boolean setParameter(String parameter) throws ConfigurationParameterNotFoundException {
   ConfigurationDefaults def = ConfigurationDefaults.getInstance();
   try {
     return setParameter(parameter, def.getIntParameter(parameter));
   } catch (Exception e) {
     return setParameter(parameter, def.getStringParameter(parameter));
   }
 }
 public String getStringParameter(String parameter) {
   ConfigurationDefaults def = ConfigurationDefaults.getInstance();
   String result;
   try {
     result = getStringParameter(parameter, def.getStringParameter(parameter));
   } catch (ConfigurationParameterNotFoundException e) {
     result = getStringParameter(parameter, ConfigurationDefaults.def_String);
   }
   return result;
 }
 public byte[] getByteParameter(String parameter) {
   ConfigurationDefaults def = ConfigurationDefaults.getInstance();
   byte[] result;
   try {
     result = getByteParameter(parameter, def.getByteParameter(parameter));
   } catch (ConfigurationParameterNotFoundException e) {
     result = getByteParameter(parameter, ConfigurationDefaults.def_bytes);
   }
   return result;
 }
 public boolean getBooleanParameter(String parameter) {
   ConfigurationDefaults def = ConfigurationDefaults.getInstance();
   int result;
   try {
     result = getIntParameter(parameter, def.getIntParameter(parameter));
   } catch (ConfigurationParameterNotFoundException e) {
     result = getIntParameter(parameter, ConfigurationDefaults.def_boolean);
   }
   return result == 0 ? false : true;
 }
  public boolean verifyParameter(String parameter, String value) {
    List verifiers = ConfigurationDefaults.getInstance().getVerifiers(parameter);

    if (verifiers != null) {
      try {
        for (int i = 0; i < verifiers.size(); i++) {

          ParameterVerifier verifier = (ParameterVerifier) verifiers.get(i);

          if (verifier != null) {

            try {
              if (!verifier.verify(parameter, value)) {

                return (false);
              }
            } catch (Throwable e) {

              Debug.printStackTrace(e);
            }
          }
        }
      } catch (Throwable e) {

        // we're not synchronized so possible but unlikely error here

        Debug.printStackTrace(e);
      }
    }

    return (true);
  }
  public Object getParameter(String name) {
    Object value = propertiesMap.get(name);

    if (value == null) {

      value = ConfigurationDefaults.getInstance().getParameter(name);
    }

    return (value);
  }
  public float getFloatParameter(String parameter, float def_val) {
    ConfigurationDefaults def = ConfigurationDefaults.getInstance();
    try {
      Object o = propertiesMap.get(parameter);
      if (o instanceof Number) {
        return ((Number) o).floatValue();
      }

      String s = getStringParameter(parameter);

      if (!s.equals(ConfigurationDefaults.def_String)) return Float.parseFloat(s);
    } catch (Exception e) {
      Debug.out("Parameter '" + parameter + "' has incorrect type", e);
    }

    try {
      return def.getFloatParameter(parameter);
    } catch (Exception e2) {
      return def_val;
    }
  }
  /**
   * Returns true if a parameter with the given name exists.
   *
   * @param key The name of the parameter to check.
   * @param explicit If <tt>true</tt>, we only check for a value which is definitely stored
   *     explicitly, <tt>false</tt> means that we'll also check against configuration defaults too.
   */
  public boolean hasParameter(String key, boolean explicit) {

    // We have an explicit value set.
    if (propertiesMap.containsKey(key)) {
      return true;
    }

    // We have a default value set.
    if ((!explicit) && ConfigurationDefaults.getInstance().hasParameter(key)) {
      return true;
    }

    return false;
  }
  public void dumpConfigChanges(IndentWriter writer) {
    ConfigurationDefaults defaults = ConfigurationDefaults.getInstance();

    Set<String> keys =
        new TreeSet<String>(
            new Comparator<String>() {
              public int compare(String o1, String o2) {
                return (o1.compareToIgnoreCase(o2));
              }
            });

    keys.addAll(propertiesMap.keySet());

    Iterator<String> it = keys.iterator();

    while (it.hasNext()) {

      String key = it.next();

      // don't dump crypto stuff

      if (ignoreKeyForDump(key)) {

        continue;
      }

      Object value = propertiesMap.get(key);

      boolean bParamExists = defaults.doesParameterDefaultExist(key.toString());

      if (bParamExists) {

        Object def = defaults.getParameter(key);

        if (def != null && value != null) {

          if (!BEncoder.objectsAreIdentical(def, value)) {

            if (value instanceof Long) {

              writer.println(key + "=" + value);

            } else if (value instanceof List) {

              writer.println(
                  key + "=" + BDecoder.decodeStrings((List) BEncoder.clone(value)) + "[list]");

            } else if (value instanceof Map) {

              writer.println(
                  key + "=" + BDecoder.decodeStrings((Map) BEncoder.clone(value)) + "[map]");

            } else if (value instanceof byte[]) {

              byte[] b = (byte[]) value;

              boolean hex = false;

              for (int i = 0; i < b.length; i++) {

                char c = (char) b[i];

                if (!(Character.isLetterOrDigit(c)
                    || "\\ `¬\"£$%^&*()-_=+[{]};:'@#~,<.>/?'".indexOf(c) != -1)) {

                  hex = true;

                  break;
                }
              }
              writer.println(
                  key + "=" + (hex ? ByteFormatter.nicePrint(b) : bytesToString((byte[]) value)));

            } else {

              writer.println(key + "=" + value + "[unknown]");
            }
          }
        }
      }
    }
  }
  public void generate(IndentWriter writer) {
    writer.println("Configuration Details");

    try {
      writer.indent();

      writer.println(
          "version=" + Constants.AZUREUS_VERSION + ", subver=" + Constants.AZUREUS_SUBVER);

      writer.println("System Properties");

      try {
        writer.indent();

        Properties props = System.getProperties();

        Iterator it = new TreeSet(props.keySet()).iterator();

        while (it.hasNext()) {

          String key = (String) it.next();

          writer.println(key + "=" + props.get(key));
        }
      } finally {

        writer.exdent();
      }

      writer.println("Environment");

      try {
        writer.indent();

        Map<String, String> env = System.getenv();

        if (env == null) {

          writer.println("Not supported");

        } else {

          Iterator it = new TreeSet(env.keySet()).iterator();

          while (it.hasNext()) {

            String key = (String) it.next();

            writer.println(key + "=" + env.get(key));
          }
        }
      } finally {

        writer.exdent();
      }

      writer.println("Azureus Config");

      ConfigurationDefaults defaults = ConfigurationDefaults.getInstance();

      try {
        writer.indent();

        Set<String> keys =
            new TreeSet<String>(
                new Comparator<String>() {
                  public int compare(String o1, String o2) {
                    return (o1.compareToIgnoreCase(o2));
                  }
                });

        keys.addAll(propertiesMap.keySet());

        Iterator<String> it = keys.iterator();

        while (it.hasNext()) {

          String key = it.next();

          // don't dump crypto stuff

          if (ignoreKeyForDump(key)) {

            continue;
          }

          Object value = propertiesMap.get(key);

          boolean bParamExists = defaults.doesParameterDefaultExist(key.toString());

          if (!bParamExists) {

            key = "[NoDef] " + key;
          } else {

            Object def = defaults.getParameter(key);

            if (def != null && value != null) {

              if (!BEncoder.objectsAreIdentical(def, value)) {

                key = "-> " + key;
              }
            }
          }

          if (value instanceof Long) {

            writer.println(key + "=" + value);

          } else if (value instanceof List) {

            writer.println(
                key + "=" + BDecoder.decodeStrings((List) BEncoder.clone(value)) + "[list]");

          } else if (value instanceof Map) {

            writer.println(
                key + "=" + BDecoder.decodeStrings((Map) BEncoder.clone(value)) + "[map]");

          } else if (value instanceof byte[]) {

            byte[] b = (byte[]) value;

            boolean hex = false;

            for (int i = 0; i < b.length; i++) {

              char c = (char) b[i];

              if (!(Character.isLetterOrDigit(c)
                  || "\\ `¬\"£$%^&*()-_=+[{]};:'@#~,<.>/?'".indexOf(c) != -1)) {

                hex = true;

                break;
              }
            }
            writer.println(
                key + "=" + (hex ? ByteFormatter.nicePrint(b) : bytesToString((byte[]) value)));

          } else {

            writer.println(key + "=" + value + "[unknown]");
          }
        }
      } finally {

        writer.exdent();
      }
    } finally {

      writer.exdent();
    }
  }