Package de.lmu.ifi.dbs.elki.utilities.optionhandling

Examples of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException


    }
    if(filesType.equals(FilesType.INPUT_FILES)) {
      for(File file : obj) {
        try {
          if(!file.exists()) {
            throw new WrongParameterValueException("Given file " + file.getPath() + " for parameter \"" + getName() + "\" does not exist!\n");
          }
        }

        catch(SecurityException e) {
          throw new WrongParameterValueException("Given file \"" + file.getPath() + "\" cannot be read, access denied!", e);
        }
      }
    }
    return true;
  }
View Full Code Here


    try {
      List<?> l = List.class.cast(obj);
      // do extra validation:
      for (Object o : l) {
        if (!(o instanceof Integer)) {
          throw new WrongParameterValueException("Wrong parameter format for parameter \"" + getName() + "\". Given list contains objects of different type!");
        }
      }
      // TODO: can we use reflection to get extra checks?
      // TODO: Should we copy the list?
      return (List<Integer>)l;
    } catch (ClassCastException e) {
      // continue with others
    }
    if(obj instanceof String) {
      String[] values = SPLIT.split((String) obj);
      ArrayList<Integer> intValue = new ArrayList<Integer>(values.length);
      for(String val : values) {
        intValue.add(Integer.parseInt(val));
      }
      return intValue;
    }
    throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of Integer values!");
  }
View Full Code Here

    try {
      List<?> l = List.class.cast(obj);
      // do extra validation:
      for(Object o : l) {
        if(!(o instanceof Class)) {
          throw new WrongParameterValueException("Wrong parameter format for parameter \"" + getName() + "\". Given list contains objects of different type!");
        }
      }
      // TODO: can we use reflection to get extra checks?
      // TODO: Should we copy the list?
      return (List<Class<? extends C>>) l;
    }
    catch(ClassCastException e) {
      // continue with others
    }
    // Did we get a single class?
    try {
      if(restrictionClass.isAssignableFrom((Class<?>) obj)) {
        List<Class<? extends C>> clss = new ArrayList<Class<? extends C>>(1);
        clss.add((Class<? extends C>) obj);
        return clss;
      }
    }
    catch(ClassCastException e) {
      // continue with others
    }
    if(obj instanceof String) {
      String[] classes = SPLIT.split((String) obj);
      // TODO: allow empty lists (and list constraints) to enforce length?
      if(classes.length == 0) {
        throw new UnspecifiedParameterException("Wrong parameter format! Given list of classes for parameter \"" + getName() + "\" is either empty or has the wrong format!");
      }

      List<Class<? extends C>> cls = new ArrayList<Class<? extends C>>(classes.length);
      for(String cl : classes) {
        try {
          Class<?> c;
          try {
            c = loader.loadClass(cl);
          }
          catch(ClassNotFoundException e) {
            // try in package of restriction class
            c = loader.loadClass(restrictionClass.getPackage().getName() + "." + cl);
          }
          // Redundant check, also in validate(), but not expensive.
          if(!restrictionClass.isAssignableFrom(c)) {
            throw new WrongParameterValueException(this, cl, "Class \"" + cl + "\" does not extend/implement restriction class " + restrictionClass + ".\n");
          }
          else {
            cls.add((Class<? extends C>) c);
          }
        }
        catch(ClassNotFoundException e) {
          throw new WrongParameterValueException(this, cl, "Class \"" + cl + "\" not found.\n", e);
        }
      }
      return cls;
    }
    // INCOMPLETE
    throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of Class values!");
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  protected boolean validate(List<Class<? extends C>> obj) throws ParameterException {
    for(Class<? extends C> cls : obj) {
      if(!restrictionClass.isAssignableFrom(cls)) {
        throw new WrongParameterValueException(this, cls.getName(), "Class \"" + cls.getName() + "\" does not extend/implement restriction class " + restrictionClass + ".\n");
      }
    }
    return super.validate(obj);
  }
View Full Code Here

      try {
        C instance = ClassGenericsUtil.tryInstantiate(restrictionClass, cls, config);
        instances.add(instance);
      }
      catch(Exception e) {
        config.reportError(new WrongParameterValueException(this, cls.getName(), e));
      }
    }
    return instances;
  }
View Full Code Here

        } else if (o instanceof Class) {
          if (restrictionClass.isAssignableFrom((Class<?>)o)) {
          inst.add(null);
          classes.add((Class<? extends C>) o);
          } else {
            throw new WrongParameterValueException(this, ((Class<?>)o).getName(), "Given class not a subclass / implementation of " + restrictionClass.getName());
          }
        } else {
          throw new WrongParameterValueException(this, o.getClass().getName(), "Given instance not an implementation of " + restrictionClass.getName());
        }
      }
      this.instances = inst;
      return super.parseValue(classes);
    }
View Full Code Here

            }
            C instance = ClassGenericsUtil.tryInstantiate(restrictionClass, cls, cfg);
            instances.set(i, instance);
          }
          catch(Exception e) {
            config.reportError(new WrongParameterValueException(this, cls.getName(), e));
          }
        }
      }
    }
    return new ArrayList<C>(instances);
View Full Code Here

    }
    if (obj instanceof String) {
      return (String) obj;
    }
    // TODO: allow anything convertible by toString()?
    throw new WrongParameterValueException("String parameter "+getName()+" is not a string.");
  }
View Full Code Here

      for(ParameterConstraint<S> cons : this.constraints) {
        cons.test(obj);
      }
    }
    catch(ParameterException e) {
      throw new WrongParameterValueException("Specified parameter value for parameter \"" + getName() + "\" breaches parameter constraint.\n" + e.getMessage());
    }
    return true;
  }
View Full Code Here

    try {
      List<?> l = List.class.cast(obj);
      // do extra validation:
      for (Object o : l) {
        if (!(o instanceof Double)) {
          throw new WrongParameterValueException("Wrong parameter format for parameter \"" + getName() + "\". Given list contains objects of different type!");
        }
      }
      // TODO: can we use reflection to get extra checks?
      // TODO: Should we copy the list?
      return (List<Double>)l;
    } catch (ClassCastException e) {
      // continue with others
    }
    if(obj instanceof String) {
      String[] values = SPLIT.split((String) obj);
      ArrayList<Double> doubleValue = new ArrayList<Double>(values.length);
      for(String val : values) {
        doubleValue.add(Double.parseDouble(val));
      }
      return doubleValue;
    }
    throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of Double values!");
  }
View Full Code Here

TOP

Related Classes of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.