Example usage for org.apache.commons.beanutils ConvertUtils convert

List of usage examples for org.apache.commons.beanutils ConvertUtils convert

Introduction

In this page you can find the example usage for org.apache.commons.beanutils ConvertUtils convert.

Prototype

public static Object convert(String values[], Class clazz) 

Source Link

Document

Convert an array of specified values to an array of objects of the specified class (if possible).

For more details see ConvertUtilsBean.

Usage

From source file:edu.scripps.fl.pubchem.app.RelatedCurveProcessor.java

public static void main(String[] args) throws Exception {
    CommandLineHandler clh = new CommandLineHandler();
    args = clh.handle(args);/*from  w  w w . j  a  v a2s.c o m*/

    Integer[] list = (Integer[]) ConvertUtils.convert(args, Integer[].class);
    Integer referenceAid = list[0];
    Integer[] relatedAids = new Integer[list.length - 1];
    System.arraycopy(list, 1, relatedAids, 0, list.length - 1);

    URL url = PipelineUtils.class.getClassLoader()
            .getResource("edu/scripps/fl/pubchem/RelatedCurvesPipeline.xml");
    Pipeline pipeline = new PipelineUtils().createPipeline(url, Arrays.asList(relatedAids));
    List<Stage> stages = pipeline.getStages();
    BeanUtils.setProperty(stages.get(1), "referenceAID", referenceAid);
    pipeline.run();
    new PipelineUtils().logErrors(pipeline);
}

From source file:edu.scripps.fl.pubchem.app.AssayDownloader.java

public static void main(String[] args) throws Exception {
    CommandLineHandler clh = new CommandLineHandler() {
        public void configureOptions(Options options) {
            options.addOption(OptionBuilder.withLongOpt("data_url").withType("").withValueSeparator('=')
                    .hasArg().create());
            options.addOption(/*from ww w  .  j  a v a  2 s  .c o m*/
                    OptionBuilder.withLongOpt("days").withType(0).withValueSeparator('=').hasArg().create());
            options.addOption(OptionBuilder.withLongOpt("mlpcn").withType(false).create());
            options.addOption(OptionBuilder.withLongOpt("notInDb").withType(false).create());
        }
    };
    args = clh.handle(args);
    String data_url = clh.getCommandLine().getOptionValue("data_url");
    if (null == data_url)
        data_url = "ftp://ftp.ncbi.nlm.nih.gov/pubchem/Bioassay/CSV/";
    //         data_url = "file:///C:/Home/temp/PubChemFTP/";

    AssayDownloader main = new AssayDownloader();
    main.dataUrl = new URL(data_url);

    if (clh.getCommandLine().hasOption("days"))
        main.days = Integer.parseInt(clh.getCommandLine().getOptionValue("days"));
    if (clh.getCommandLine().hasOption("mlpcn"))
        main.mlpcn = true;
    if (clh.getCommandLine().hasOption("notInDb"))
        main.notInDb = true;

    if (args.length == 0)
        main.process();
    else {
        Long[] list = (Long[]) ConvertUtils.convert(args, Long[].class);
        List<Long> l = (List<Long>) Arrays.asList(list);
        log.info("AID to process: " + l);
        main.process(new HashSet<Long>(Arrays.asList(list)));
    }
}

From source file:edu.scripps.fl.pubchem.app.ResultDownloader.java

public static void main(String[] args) throws Exception {
    CommandLineHandler clh = new CommandLineHandler() {
        public void configureOptions(Options options) {
            options.addOption(OptionBuilder.withLongOpt("data_url").withType("").withValueSeparator('=')
                    .hasArg().create());
        }//from w w w  . jav  a 2s  .c o m
    };
    args = clh.handle(args);
    String data_url = clh.getCommandLine().getOptionValue("data_url");
    ResultDownloader rd = new ResultDownloader();

    if (data_url != null)
        rd.setDataUrl(new URL(data_url));
    else
        rd.setDataUrl(new URL("ftp://ftp.ncbi.nlm.nih.gov/pubchem/Bioassay/CSV/"));
    if (args.length == 0)
        rd.process();
    else {
        Integer[] list = (Integer[]) ConvertUtils.convert(args, Integer[].class);
        rd.process(((List<Integer>) Arrays.asList(list)).iterator());
    }
}

From source file:net.eusashead.hateoas.header.impl.PropertyUtil.java

public static <V> V getValue(Object target, String name, Class<V> type) {
    return type.cast(ConvertUtils.convert(getValue(target, name), type));
}

From source file:com.github.dactiv.fear.commons.Casts.java

/**
 *  value /*from   w  ww.jav  a  2s .  c o m*/
 *
 * @param value 
 * @param type  class
 *
 * @param <T> 
 *
 * @return ?
 */
public static <T> T cast(Object value, Class<T> type) {
    return (T) (value == null ? null : ConvertUtils.convert(value, type));
}

From source file:com.yahoo.elide.utils.coerce.CoerceUtil.java

/**
 * Convert value to target class./*from   w  w w  .ja v  a  2  s .c  o  m*/
 *
 * @param value value to convert
 * @param cls class to convert to
 * @return coerced value
 */
public static Object coerce(Object value, Class<?> cls) {
    if (value == null || cls == null || cls.isAssignableFrom(value.getClass())) {
        return value;
    }

    try {
        return ConvertUtils.convert(value, cls);

    } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) {
        throw new InvalidValueException(value);
    }
}

From source file:edu.scripps.fl.curves.CurveFit.java

public static void fit(Curve curve) {
    log.debug("Fitting Curve: " + curve);
    double y[] = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class);
    double x[] = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class);
    for (int ii = 0; ii < x.length; ii++)
        x[ii] = Math.log10(x[ii]);
    // max, min and range
    double minY = Double.MAX_VALUE;
    double maxY = -Double.MAX_VALUE;
    double maxResp = y[y.length - 1];
    for (int i = 0; i < y.length; i++) {
        minY = Math.min(minY, y[i]);
        maxY = Math.max(maxY, y[i]);
    }//from   ww  w  . j a v a 2s  . co m
    curve.setResponseMin(minY);
    curve.setResponseMax(maxY);
    curve.setResponseRange(maxY - minY);
    curve.setMaxResponse(maxResp);
    // fit
    boolean flags[] = null;
    Map maps[] = null;
    double fitValues[] = null;
    Object fitResults[] = HillFit.doHill(x, y, null, HillConstants.FIT_ITER_NO, HillConstants.P4_FIT);
    if (fitResults != null) {
        flags = (boolean[]) fitResults[0];
        fitValues = (double[]) fitResults[1];
        maps = (Map[]) fitResults[2];
    }
    if (fitValues != null) {
        curve.setYZero(fitValues[6]);
        curve.setLogEC50(fitValues[0]);
        curve.setYInflection(fitValues[1]);
        curve.setHillSlope(fitValues[2]);
        curve.setR2(fitValues[3]);

        double ec50 = 1000000D * Math.exp(Math.log(10D) * curve.getLogEC50());
        double testEC50 = Math.pow(10, curve.getLogEC50());
        Double ic50 = null;
        double logIC50 = BatchHill.iccalc(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(),
                curve.getHillSlope(), 50D);
        if (logIC50 < 0.0D)
            ic50 = 1000000D * Math.exp(Math.log(10D) * logIC50);
        int dn = Math.max(1, x.length - 4);
        double df = dn;
        double p = HillStat.calcPValue(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(),
                curve.getHillSlope(), x, y, flags);
        int mask = 0;
        for (int i = 0; i < x.length; i++)
            if (!flags[i])
                mask++;
        double ss = HillStat.calcHillDeviation(curve.getLogEC50(), curve.getYZero(), curve.getYInflection(),
                curve.getHillSlope(), flags, null, x, y);
        curve.setEC50(ec50);
        curve.setIC50(ic50);
        curve.setPHill(p);
        curve.setSYX(ss / df);
        for (int ii = 0; ii < flags.length; ii++) {
            if (flags[ii] == true) {
                curve.setMasked(true);
                break;
            }
        }
    } else {
        curve.setLogEC50(null);
        curve.setHillSlope(null);
        curve.setR2(null);
        curve.setYInflection(null);
        curve.setYZero(null);
        curve.setEC50(null);
        curve.setIC50(null);
        curve.setPHill(null);
        curve.setSYX(null);
        curve.setMasked(false);
        flags = new boolean[x.length];
    }
    // masks
    List<Boolean> masks = new ArrayList<Boolean>(flags.length);
    CollectionUtils.addAll(masks, (Boolean[]) ConvertUtils.convert(flags, Boolean[].class));
    curve.setMask(masks);
    // classify
    curveClassification(curve, y, x, flags);
    // rank
    double rank = -BatchHill.calcRank(curve.getCurveClass(), curve.getMaxResponse(), curve.getResponseRange());
    curve.setRank(rank);
}

From source file:net.servicefixture.converter.CalendarConverter.java

public Object fromObject(Object source) {
    if (source == null) {
        return null;
    }//from   w w w .j a v a 2  s .c  o  m
    if (source instanceof Calendar) {
        return source;
    }

    Date date = (Date) ConvertUtils.convert(source.toString(), Date.class);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    return calendar;
}

From source file:edu.scripps.fl.pubchem.app.util.ScrollableResultsIterator.java

public E next() {
    Object[] obj = results.get();
    Object obj2 = ConvertUtils.convert(obj[0], clazz);
    return clazz.cast(obj2);
}

From source file:edu.scripps.fl.pubchem.app.cids.FetchSDFStage.java

@Override
public void process(Object obj) throws StageException {
    List<Number> ids = (List<Number>) obj;
    try {//from  w  ww  . ja  va  2  s . c o m
        int[] list = (int[]) ConvertUtils.convert(ids, int[].class);
        URL url = PUGSoapFactory.getInstance().getSDFilefromCIDs(list);
        System.out.println("SDF File URL: " + url);
        emit(url);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new StageException(this, ex);
    }
}