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

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


    if(c == null) {
      // TODO: better class? AbortException maybe?
      throw new UnsupportedOperationException("Trying to instantiate 'null' class!");
    }
    // Try a V3 parameterization class
    Parameterizer par = getParameterizer(c);
    // TODO: API good?
    if(par != null && par instanceof AbstractParameterizer) {
      final Object instance = ((AbstractParameterizer) par).make(config);
      return r.cast(instance);
    }
View Full Code Here


      // LoggingUtil.warning("Instantiating " + cls.getName());
      FutureTask<?> instantiator = new FutureTask<Object>(new Runnable() {
        @Override
        public void run() {
          // Try a V3 style parameterizer first.
          Parameterizer par = ClassGenericsUtil.getParameterizer(cls);
          if(par != null) {
            par.configure(track);
          }
          else {
            try {
              ClassGenericsUtil.tryInstantiate(Object.class, cls, track);
            }
            catch(java.lang.NoSuchMethodException e) {
              logger.warning("Could not instantiate class " + cls.getName() + " - no appropriate constructor or parameterizer found.");
            }
            catch(java.lang.reflect.InvocationTargetException e) {
              if(e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
              }
              if(e.getCause() instanceof Error) {
                throw (Error) e.getCause();
              }
              throw new RuntimeException(e.getCause());
            }
            catch(RuntimeException e) {
              throw e;
            }
            catch(Exception e) {
              throw new RuntimeException(e);
            }
            catch(java.lang.Error e) {
              throw new RuntimeException(e);
            }
          }
          for(Pair<Object, Parameter<?, ?>> pair : track.getAllParameters()) {
            if(pair.first == null) {
              pair.first = cls;
            }
            options.add(pair);
          }
        }
      }, null);
      es.submit(instantiator);
      try {
        // Wait up to one second.
        instantiator.get(100000L, TimeUnit.MILLISECONDS);
      }
      catch(TimeoutException e) {
        de.lmu.ifi.dbs.elki.logging.LoggingUtil.warning("Timeout on instantiating " + cls.getName());
        es.shutdownNow();
        throw new RuntimeException(e);
      }
      catch(java.util.concurrent.ExecutionException e) {
        de.lmu.ifi.dbs.elki.logging.LoggingUtil.warning("Error instantiating " + cls.getName(), e.getCause());
        /*
         * es.shutdownNow(); if(e.getCause() instanceof RuntimeException) {
         * throw (RuntimeException) e.getCause(); } throw new
         * RuntimeException(e.getCause());
         */
        continue;
      }
      catch(Exception e) {
        /*
         * de.lmu.ifi.dbs.elki.logging.LoggingUtil.warning("Error instantiating "
         * + cls.getName()); es.shutdownNow(); throw new RuntimeException(e);
         */
        continue;
      }
    }

    logger.debug("Documenting " + options.size() + " parameter instances.");
    for(Pair<Object, Parameter<?, ?>> pp : options) {
      if(pp.first == null || pp.second == null) {
        logger.debugFiner("Null: " + pp.first + " " + pp.second);
        continue;
      }
      Class<?> c;
      if(pp.first instanceof Class) {
        c = (Class<?>) pp.first;
      }
      else {
        c = pp.first.getClass();
      }
      Parameter<?, ?> o = pp.second;

      // just collect unique occurrences
      {
        List<Parameter<?, ?>> byc = byclass.get(c);
        boolean inlist = false;
        if(byc != null) {
          for(Parameter<?, ?> par : byc) {
            if(par.getOptionID() == o.getOptionID()) {
              inlist = true;
              break;
            }
          }
        }
View Full Code Here

    if(c == null) {
      // TODO: better class? AbortException maybe?
      throw new UnsupportedOperationException("Trying to instantiate 'null' class!");
    }
    // Try a V3 parameterization class
    Parameterizer par = getParameterizer(c);
    // TODO: API good?
    if(par != null && par instanceof AbstractParameterizer) {
      final Object instance = ((AbstractParameterizer) par).make(config);
      return r.cast(instance);
    }
View Full Code Here

      // LoggingUtil.warning("Instantiating " + cls.getName());
      FutureTask<?> instantiator = new FutureTask<Object>(new Runnable() {
        @Override
        public void run() {
          // Try a V3 style parameterizer first.
          Parameterizer par = ClassGenericsUtil.getParameterizer(cls);
          if(par != null) {
            par.configure(track);
          }
          else {
            try {
              ClassGenericsUtil.tryInstantiate(Object.class, cls, track);
            }
            catch(java.lang.NoSuchMethodException e) {
              logger.warning("Could not instantiate class " + cls.getName() + " - no appropriate constructor or parameterizer found.");
            }
            catch(java.lang.reflect.InvocationTargetException e) {
              if(e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
              }
              if(e.getCause() instanceof Error) {
                throw (Error) e.getCause();
              }
              throw new RuntimeException(e.getCause());
            }
            catch(RuntimeException e) {
              throw e;
            }
            catch(Exception e) {
              throw new RuntimeException(e);
            }
            catch(java.lang.Error e) {
              throw new RuntimeException(e);
            }
          }
          for(Pair<Object, Parameter<?, ?>> pair : track.getAllParameters()) {
            if(pair.first == null) {
              pair.first = cls;
            }
            options.add(pair);
          }
        }
      }, null);
      es.submit(instantiator);
      try {
        // Wait up to one second.
        instantiator.get(100000L, TimeUnit.MILLISECONDS);
      }
      catch(TimeoutException e) {
        de.lmu.ifi.dbs.elki.logging.LoggingUtil.warning("Timeout on instantiating " + cls.getName());
        es.shutdownNow();
        throw new RuntimeException(e);
      }
      catch(java.util.concurrent.ExecutionException e) {
        de.lmu.ifi.dbs.elki.logging.LoggingUtil.warning("Error instantiating " + cls.getName(), e.getCause());
        /*
         * es.shutdownNow(); if(e.getCause() instanceof RuntimeException) {
         * throw (RuntimeException) e.getCause(); } throw new
         * RuntimeException(e.getCause());
         */
        continue;
      }
      catch(Exception e) {
        /*
         * de.lmu.ifi.dbs.elki.logging.LoggingUtil.warning("Error instantiating "
         * + cls.getName()); es.shutdownNow(); throw new RuntimeException(e);
         */
        continue;
      }
    }

    logger.debug("Documenting " + options.size() + " parameter instances.");
    for(Pair<Object, Parameter<?, ?>> pp : options) {
      if(pp.first == null || pp.second == null) {
        logger.debugFiner("Null: " + pp.first + " " + pp.second);
        continue;
      }
      Class<?> c;
      if(pp.first instanceof Class) {
        c = (Class<?>) pp.first;
      }
      else {
        c = pp.first.getClass();
      }
      Parameter<?, ?> o = pp.second;

      // just collect unique occurrences
      {
        List<Parameter<?, ?>> byc = byclass.get(c);
        boolean inlist = false;
        if(byc != null) {
          for(Parameter<?, ?> par : byc) {
            if(par.getOptionID() == o.getOptionID()) {
              inlist = true;
              break;
            }
          }
        }
View Full Code Here

TOP

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

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.