Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

In this page you can find the example usage for java.util Collection toArray.

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this collection.

Usage

From source file:com.sfs.whichdoctor.beans.WhichDoctorCoreIdentityBean.java

/**
 * Sets the email.//w ww .  j  av a2  s  . c o m
 *
 * @param emailAddressesVal the new email
 */
public final void setEmail(final Collection<EmailBean> emailAddressesVal) {
    if (emailAddressesVal != null && emailAddressesVal.size() > 0) {
        Object[] emailArray = emailAddressesVal.toArray();
        this.primaryEmail = (EmailBean) emailArray[0];
    }
    this.emailAddresses = emailAddressesVal;
}

From source file:com.epam.reportportal.spock.NodeInfoUtilsTest.java

private Object featureDescription_multipleTextsInBlock() {
    int expectedTextBlocksCount = 2;
    Collection<String> generatedTexts = generateBlockTexts(expectedTextBlocksCount);
    Iterator<String> generatedTextsIterator = generatedTexts.iterator();
    List<BlockInfo> blocks = singletonList(
            createBlockInfo(THEN, asList(generatedTextsIterator.next(), generatedTextsIterator.next())));

    String expectedDescription = String.format("Then: %s%nAnd: %s", generatedTexts.toArray());

    return new Object[] { "several texts in the single block", createFeatureInfo(blocks), expectedDescription };
}

From source file:com.bac.accountserviceapp.data.mysql.MysqlUserDetailsServiceTest.java

public void testLoadUserByUsername_OneAccount() {

    logger.info("testLoadUserByUsername_OneAccount");
    String expUserName = UUID.randomUUID().toString();
    String expUserPassword = UUID.randomUUID().toString();
    String expApplicationName = UUID.randomUUID().toString();
    int expAccessLevelId = 66;
    //      //from www.ja v a 2 s. c  o m
    //
    //  Set access to return the User object
    //
    AccountAccess access = getAccountAccess();
    //
    Set<Account> userAccounts = new HashSet<>();
    Account account = this.getAccount();
    userAccounts.add(account);
    // User

    User user = getUser(userAccounts);
    when(user.getUserEmail()).thenReturn(expUserName);
    when(user.getUserPassword()).thenReturn(expUserPassword.getBytes());
    when(access.getUserBySecondaryKey((User) anyObject())).thenReturn(user);
    //  Application
    Application application = getApplication();
    when(application.getName()).thenReturn(expApplicationName);
    when(application.isEnabled()).thenReturn(true);
    when(access.getApplication((Integer) anyObject())).thenReturn(application);
    // AccountUser
    AccountUser accountUser = getAccountUser();
    when(accountUser.getAccessLevelId()).thenReturn(expAccessLevelId);
    when(accountUser.isEnabled()).thenReturn(true);
    when(access.getAccountUser((AccountUser) anyObject())).thenReturn(accountUser);
    instance.setAccess(access);
    //
    UserDetails result = instance.loadUserByUsername(expUserName);
    assertNotNull(result);
    String resultUserName = result.getUsername();
    String resultPassword = result.getPassword();

    assertEquals(expUserName, resultUserName);
    assertEquals(expUserPassword, resultPassword);
    //
    Collection<? extends GrantedAuthority> resultAuthorities = result.getAuthorities();
    int expAuthoritiesSize = 1;
    int resultAuthoritiesSize = resultAuthorities.size();
    assertEquals(expAuthoritiesSize, resultAuthoritiesSize);
    List<?> authoritiesList = Arrays.asList(resultAuthorities.toArray());
    GrantedAuthority grantedAuthority = (GrantedAuthority) authoritiesList.get(0);
    String expAuthority = expApplicationName + authoritySeparator + expAccessLevelId;
    String resultAuthority = grantedAuthority.getAuthority();
    assertEquals(expAuthority, resultAuthority);
}

From source file:es.pode.buscador.presentacion.avanzado.buscarAvanzado.MostrarResultadosImagenesPaginarImagenes.java

public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
        org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response) throws java.lang.Exception {
    final MostrarResultadosImagenesPaginarImagenesFormImpl specificForm = (MostrarResultadosImagenesPaginarImagenesFormImpl) form;

    final Object previousFormObject = request.getSession().getAttribute("form");

    if (previousFormObject instanceof es.pode.buscador.presentacion.avanzado.buscarAvanzado.BuscarAvanzadoCUFormImpl) {
        es.pode.buscador.presentacion.avanzado.buscarAvanzado.BuscarAvanzadoCUFormImpl oldForm = (es.pode.buscador.presentacion.avanzado.buscarAvanzado.BuscarAvanzadoCUFormImpl) previousFormObject;

        specificForm.setSortingMethod(oldForm.getSortingMethod());
    } else/* w ww.j  a  v  a 2  s.  c  o m*/

    if (previousFormObject instanceof es.pode.buscador.presentacion.avanzado.buscarAvanzado.MostrarResultadosImagenesPaginarImagenesFormImpl) {
        es.pode.buscador.presentacion.avanzado.buscarAvanzado.MostrarResultadosImagenesPaginarImagenesFormImpl oldForm = (es.pode.buscador.presentacion.avanzado.buscarAvanzado.MostrarResultadosImagenesPaginarImagenesFormImpl) previousFormObject;

        specificForm.setSortingMethod(oldForm.getSortingMethod());
    }

    org.apache.struts.action.ActionForward forward = null;

    try {

        //  09/11/2010  Fernando Garcia
        //  This will be for a future combo box to select different sorting
        //  It will be hidden at mostrar-resultados-imagenes.jsp until I'll develop it
        //  TODO: get this struture from a common place (same code at BuscarAvanzadoCU.java and more places)

        Properties props = null;
        try {
            props = new Properties();
            props.load(this.getClass().getResourceAsStream("/spring_buscador.properties"));
        } catch (IOException e) {
            logger.error("ERROR: file not found: spring_buscador.properties", e);
            throw new RuntimeException(e);
        }

        Collection sortingMethodLabelList = new ArrayList();
        Collection sortingMethodValueList = new ArrayList();

        BuscarAvanzadoCU.loadSortingMethodCombo(props, sortingMethodLabelList, sortingMethodValueList);

        specificForm.setSortingMethodLabelList(sortingMethodLabelList.toArray());
        specificForm.setSortingMethodValueList(sortingMethodValueList.toArray());

        forward = _concentradorBusqueda(mapping, form, request, response);

    } catch (java.lang.Exception exception) {
        // we populate the current form with only the request parameters
        Object currentForm = request.getSession().getAttribute("form");
        // if we can't get the 'form' from the session, try from the request
        if (currentForm == null) {
            currentForm = request.getAttribute("form");
        }
        if (currentForm != null) {
            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameter(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(currentForm, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }
    request.getSession().setAttribute("form", form);

    return forward;
}

From source file:com.fiveamsolutions.nci.commons.search.OneCriterionSpecifiedCallback.java

private void processCollectionProperties(String[] fields, Collection<?> col, Class<? extends Object> fieldClass)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    for (String propName : fields) {
        // get the collection of values into a nice collection
        Method m2 = fieldClass.getMethod("get" + StringUtils.capitalize(propName));
        for (Object collectionObj : col.toArray()) {
            Object val = m2.invoke(collectionObj);
            if (val != null) {
                if (isStringAndBlank(val)) {
                    continue;
                }//  w  w  w.j a  va 2 s  . c o  m
                hasOneCriterion = true;
                return;
            }
        }
    }
}

From source file:de.vandermeer.asciitable.AsciiTable.java

/**
 * Adds a content row to the table.//w w w  . j  ava  2s. com
 * For the first content row added, the number of objects given here determines the number of columns in the table.
 * For every subsequent content row, the array must have an entry for each column,
 * i.e. the size of the array must be the same as the result of {@link #getColNumber()}.
 * @param columns content of the columns for the row, must not be null
 * @return the created row for further customization
 * @throws {@link NullPointerException} if columns was null
 * @throws {@link AsciiTableException} if columns does not have the correct size (more or less entries than columns defined for the table)
 */
public final AT_Row addRow(Collection<?> columns) throws NullPointerException, AsciiTableException {
    Validate.notNull(columns);
    return this.addRow(columns.toArray());
}

From source file:io.cloudslang.engine.queue.services.assigner.ExecutionAssignerServiceImpl.java

private String chooseWorker(String groupName, Multimap<String, String> groupWorkersMap,
        Random randIntGenerator) {
    Collection<String> workerNames = groupWorkersMap.get(groupName);

    if (workerNames == null || workerNames.size() == 0) {
        // this returns a worker UUID in case of the group defined on specific worker (private group)
        if (groupName.startsWith("Worker_")) {
            return groupName.substring("Worker_".length());
        } else {/* ww w. j a  v a2 s.  com*/
            return null;
        }
    }

    Object[] workerArr = workerNames.toArray();

    // we assign the worker using random algorithm
    int groupIndex = randIntGenerator.nextInt(workerArr.length);
    groupIndex = groupIndex % workerArr.length;

    return (String) workerArr[groupIndex];
}

From source file:es.pode.buscador.presentacion.avanzado.buscarAvanzado.MostrarQuisoDecirAvanzadoBuscarQuisoDecir.java

public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
        org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request,
        javax.servlet.http.HttpServletResponse response) throws java.lang.Exception {
    final MostrarQuisoDecirAvanzadoBuscarQuisoDecirFormImpl specificForm = (MostrarQuisoDecirAvanzadoBuscarQuisoDecirFormImpl) form;

    org.apache.struts.action.ActionForward forward = null;

    try {/*ww w.  j  av  a2  s.c  o  m*/

        //  09/11/2010  Fernando Garcia
        //  This will be for a future combo box to select different sorting
        //  It will be hidden at mostrar-resultados-imagenes.jsp until I'll develop it
        //  TODO: get this struture from a common place (same code at BuscarAvanzadoCU.java and more places)

        Properties props = null;
        try {
            props = new Properties();
            props.load(this.getClass().getResourceAsStream("/spring_buscador.properties"));
        } catch (IOException e) {
            logger.error("ERROR: file not found: spring_buscador.properties", e);
            throw new RuntimeException(e);
        }

        Collection sortingMethodLabelList = new ArrayList();
        Collection sortingMethodValueList = new ArrayList();

        BuscarAvanzadoCU.loadSortingMethodCombo(props, sortingMethodLabelList, sortingMethodValueList);

        specificForm.setSortingMethodLabelList(sortingMethodLabelList.toArray());
        specificForm.setSortingMethodValueList(sortingMethodValueList.toArray());

        forward = _validarFormulario(mapping, form, request, response);
    } catch (java.lang.Exception exception) {
        // we populate the current form with only the request parameters
        Object currentForm = request.getSession().getAttribute("form");
        // if we can't get the 'form' from the session, try from the request
        if (currentForm == null) {
            currentForm = request.getAttribute("form");
        }
        if (currentForm != null) {
            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameter(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(currentForm, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }
    request.getSession().setAttribute("form", form);

    return forward;
}

From source file:com.nortal.petit.orm.StatementSupport.java

/**
 * Updates beans by primary key mapping
 * /*from  ww w.j  a v  a2  s  . c  o m*/
 * @param beans
 *            Beans to update
 */
public <B> void update(Collection<B> beans) {
    if (CollectionUtils.isEmpty(beans)) {
        return;
    }

    UpdateStatement<B> stm = new UpdateStatement<B>(getJdbcTemplate(), getStatementBuilder(),
            (B[]) beans.toArray());
    if (stm.getMapping().id() != null) {
        stm.exec();
    } else {
        throw new PersistenceException("Model " + beans.iterator().next().getClass().getSimpleName()
                + " does not have primary key mapping");
    }
}

From source file:com.nortal.petit.orm.StatementSupport.java

/**
 * Deletes beans by primary key mapping/*from   ww w  . ja v  a2 s. c o  m*/
 * 
 * @param beans
 *            Beans to deleted
 */
public <B> void delete(Collection<B> beans) {
    if (CollectionUtils.isEmpty(beans)) {
        return;
    }

    DeleteStatement<B> stm = new DeleteStatement<B>(getJdbcTemplate(), getStatementBuilder(),
            (B[]) beans.toArray());
    if (stm.getMapping().id() != null) {
        stm.exec();
    } else {
        throw new PersistenceException("Model " + beans.iterator().next().getClass().getSimpleName()
                + " does not have primary key mapping");
    }
}