Example usage for org.apache.commons.collections CollectionUtils addAll

List of usage examples for org.apache.commons.collections CollectionUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils addAll.

Prototype

public static void addAll(Collection collection, Object[] elements) 

Source Link

Document

Adds all elements in the array to the given collection.

Usage

From source file:edu.isi.misd.scanner.network.registry.web.controller.StudyController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<Study> getStudies(@RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_STUDY_NAME,
            REQUEST_PARAM_USER_NAME);//from w w w. jav  a 2 s. c o  m

    String studyName = params.get(REQUEST_PARAM_STUDY_NAME);
    String userName = params.get(REQUEST_PARAM_USER_NAME);
    List<Study> studies = new ArrayList<Study>();
    if (studyName != null) {
        Study study = studyRepository.findByStudyName(studyName);
        if (study == null) {
            throw new ResourceNotFoundException(studyName);
        }
        studies.add(study);
    } else if (userName != null) {
        return studyRepository.findStudiesForUserName(userName);
    } else {
        Iterator iter = studyRepository.findAll().iterator();
        CollectionUtils.addAll(studies, iter);
    }
    return studies;
}

From source file:com.google.gdt.eclipse.designer.launch.AbstractGwtLaunchConfigurationDelegate.java

public String[] getClasspathAll(ILaunchConfiguration configuration) throws CoreException {
    List<String> entries = new ArrayList<String>();
    // add source folders
    IProject project;//  ww  w.ja va  2s .  co  m
    {
        String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                "");
        project = Utils.getProject(projectName);
        addSourceFolders(new HashSet<IProject>(), entries, project);
    }
    // add usual project classpath entries
    // we add them after source folders because GWT Shell compiles sources itself
    {
        String[] originalEntries = super.getClasspath(configuration);
        CollectionUtils.addAll(entries, originalEntries);
    }
    // add GWT DEV jar
    entries.add(Utils.getDevLibPath(project).toPortableString());
    //
    return entries.toArray(new String[entries.size()]);
}

From source file:com.esofthead.mycollab.spring.MyBatisConfiguration.java

private Resource[] buildBatchMapperResources(String... resourcesPath) throws IOException {
    ArrayList<Resource> resources = new ArrayList<>();
    for (String resourcePath : resourcesPath) {
        CollectionUtils.addAll(resources, buildMapperResources(resourcePath));
    }/*from w w w .ja va 2s .c om*/
    return resources.toArray(new Resource[0]);
}

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 w ww  .j av  a 2 s  .  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:edu.isi.misd.scanner.network.registry.web.controller.StudyRequestedSiteController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<StudyRequestedSite> getStudyRequestedSites(
        @RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_SITE_ID, REQUEST_PARAM_STUDY_ID);

    String siteId = params.get(REQUEST_PARAM_SITE_ID);
    String studyId = params.get(REQUEST_PARAM_STUDY_ID);
    List<StudyRequestedSite> studyRequestedSites = new ArrayList<StudyRequestedSite>();
    if (siteId != null) {
        return studyRequestedSiteRepository
                .findBySiteSiteId(validateIntegerParameter(REQUEST_PARAM_SITE_ID, siteId));
    } else if (studyId != null) {
        return studyRequestedSiteRepository
                .findByStudyStudyId(validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
    } else {// w ww.jav a  2  s .  c om
        Iterator iter = studyRequestedSiteRepository.findAll().iterator();
        CollectionUtils.addAll(studyRequestedSites, iter);
    }
    return studyRequestedSites;
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.AnalysisInstanceController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<AnalysisInstance> getAnalysisInstances(@RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_STUDY_ID,
            REQUEST_PARAM_USER_NAME);//  www.  j a va  2s  .co  m

    if (!params.isEmpty()) {
        String studyId = params.get(REQUEST_PARAM_STUDY_ID);
        String userName = params.get(REQUEST_PARAM_USER_NAME);
        if ((studyId != null) && (userName != null)) {
            return analysisInstanceRepository.findByStudyIdAndUserNameFilteredByStudyRole(
                    validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId), userName);
        }
        if (studyId != null) {
            return analysisInstanceRepository
                    .findByStudyStudyId(validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
        }
        if (studyId == null) {
            throw new BadRequestException("Required parameter missing: " + REQUEST_PARAM_STUDY_ID);
        }
    }

    List<AnalysisInstance> analysisInstances = new ArrayList<AnalysisInstance>();
    Iterator iter = analysisInstanceRepository.findAll().iterator();
    CollectionUtils.addAll(analysisInstances, iter);
    return analysisInstances;
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.DataSetDefinitionController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<DataSetDefinition> getDataSetDefinitions(@RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_STUDY_ID,
            REQUEST_PARAM_USER_NAME);/*from  w  w w  . ja va2 s . co m*/

    if (!params.isEmpty()) {
        String studyId = params.get(REQUEST_PARAM_STUDY_ID);
        String userName = params.get(REQUEST_PARAM_USER_NAME);
        if ((studyId != null) && (userName != null)) {
            return dataSetDefinitionRepository.findDataSetsForStudyIdAndUserNameFilteredByStudyPolicy(
                    validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId), userName);
        }
        if (studyId != null) {
            return dataSetDefinitionRepository.findDataSetsForStudyIdFilteredByStudyPolicy(
                    validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
        }
        if (studyId == null) {
            throw new BadRequestException("Required parameter missing: " + REQUEST_PARAM_STUDY_ID);
        }
    }

    List<DataSetDefinition> dataSetDefinitions = new ArrayList<DataSetDefinition>();
    Iterator iter = dataSetDefinitionRepository.findAll().iterator();
    CollectionUtils.addAll(dataSetDefinitions, iter);
    return dataSetDefinitions;
}

From source file:de.xirp.ui.widgets.dialogs.ProfileLookupDialog.java

/**
 * Opens the dialog.//from   ww w .  java  2s. co m
 * 
 * @return The chosen profile.
 * 
 * @see de.xirp.profile.Profile
 */
public Profile open() {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });

    dialogShell.setSize(WIDTH, HEIGHT);
    dialogShell.setTextForLocaleKey("ProfileLookupDialog.gui.title"); //$NON-NLS-1$
    image = ImageManager.getSystemImage(SystemImage.QUESTION);
    dialogShell.setImage(image);

    SWTUtil.setGridLayout(dialogShell, 2, true);

    list = new XList(dialogShell, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);

    SWTUtil.setGridData(list, true, true, SWT.FILL, SWT.FILL, 2, 1);
    profiles = new ArrayList<Profile>(ProfileManager.getProfiles());
    profiles.addAll(ProfileManager.getIncompleteProfiles());

    for (Profile p : profiles) {
        Vector<String> itm = new Vector<String>();
        CollectionUtils.addAll(itm, list.getItems());
        if (!itm.contains(p)) {
            if (p.isComplete()) {
                list.add(p.getName() + I18n.getString("ProfileLookupDialog.list.postfix.complete")); //$NON-NLS-1$
            } else {
                list.add(p.getName() + I18n.getString("ProfileLookupDialog.list.postfix.incomplete")); //$NON-NLS-1$
            }
        }
    }
    list.addSelectionListener(new SelectionAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (list.getSelectionCount() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }
    });

    ok = new XButton(dialogShell, XButtonType.OK);
    ok.setEnabled(false);
    SWTUtil.setGridData(ok, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    ok.addSelectionListener(new SelectionAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = list.getSelectionIndex();
            profile = profiles.get(idx);
            dialogShell.close();
        }
    });

    cancel = new XButton(dialogShell, XButtonType.CANCEL);
    SWTUtil.setGridData(cancel, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    cancel.addSelectionListener(new SelectionAdapter() {

        /* (non-Javadoc)
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            dialogShell.close();
        }
    });

    dialogShell.setDefaultButton(ok);
    list.setSelectionWithEvent(0);

    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return profile;
}

From source file:edu.cornell.med.icb.R.RUtils.java

/**
 * Can be used to start a rserve instance.
 * @param threadPool The ExecutorService used to start the Rserve process
 * @param rServeCommand Full path to command used to start Rserve process
 * @param host Host where the command should be sent
 * @param port Port number where the command should be sent
 * @param username Username to send to the server if authentication is required
 * @param password Password to send to the server if authentication is required
 * @return The return value from the Rserve instance
 *//*  w w  w .  j  a va  2 s  .  co m*/
static Future<Integer> startup(final ExecutorService threadPool, final String rServeCommand, final String host,
        final int port, final String username, final String password) {
    if (LOG.isInfoEnabled()) {
        LOG.info("Attempting to start Rserve on " + host + ":" + port);
    }

    return threadPool.submit(new Callable<Integer>() {
        public Integer call() throws IOException {
            final List<String> commands = new ArrayList<String>();

            // if the host is not local, use ssh to exec the command
            if (!"localhost".equals(host) && !"127.0.0.1".equals(host)
                    && !InetAddress.getLocalHost().equals(InetAddress.getByName(host))) {
                commands.add("ssh");
                commands.add(host);
            }

            // TODO - this will fail when spaces are in the the path to the executable
            CollectionUtils.addAll(commands, rServeCommand.split(" "));
            commands.add("--RS-port");
            commands.add(Integer.toString(port));

            final String[] command = commands.toArray(new String[commands.size()]);
            LOG.debug(ArrayUtils.toString(commands));

            final ProcessBuilder builder = new ProcessBuilder(command);
            builder.redirectErrorStream(true);
            final Process process = builder.start();
            BufferedReader br = null;
            try {
                final InputStream is = process.getInputStream();
                final InputStreamReader isr = new InputStreamReader(is);
                br = new BufferedReader(isr);
                String line;
                while ((line = br.readLine()) != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(host + ":" + port + "> " + line);
                    }
                }

                process.waitFor();
                if (LOG.isInfoEnabled()) {
                    LOG.info("Rserve on " + host + ":" + port + " terminated");
                }
            } catch (InterruptedException e) {
                LOG.error("Interrupted!", e);
                process.destroy();
                Thread.currentThread().interrupt();
            } finally {
                IOUtils.closeQuietly(br);
            }

            final int exitValue = process.exitValue();
            if (LOG.isInfoEnabled()) {
                LOG.info("Rserve on " + host + ":" + port + " returned " + exitValue);
            }
            return exitValue;
        }
    });
}

From source file:com.cyclopsgroup.waterview.navigator.impl.DefaultNavigatorNode.java

/**
 * Overwrite or implement method getParentNodes()
 *
 * @see com.cyclopsgroup.waterview.navigator.NavigatorNode#getParentNodes()
 *//*from w  ww . j  a v  a 2 s.  c  om*/
public synchronized NavigatorNode[] getParentNodes() {
    if (parentNodes == null) {
        List parents = new ArrayList();
        NavigatorNode parent = (NavigatorNode) getParentNode();
        if (parent != null) {
            CollectionUtils.addAll(parents, parent.getParentNodes());
            parents.add(parent);
        }
        parentNodes = (NavigatorNode[]) parents.toArray(NavigatorNode.EMPTY_ARRAY);
    }
    return parentNodes;
}