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.salesmanager.central.payment.PaymentModuleAction.java

public String save() throws Exception {

    this.prepare();
    Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    if (configurationModuleNames == null) {
        configurationModuleNames = new HashMap();
    }// w w w.  ja  va2  s.c om

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    Date dt = new Date();

    MerchantConfiguration config = null;

    List updateableModules = new ArrayList();

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);
    Map modules = rservice.getPaymentMethodsMap(ctx.getCountryid());
    CoreModuleService module = (CoreModuleService) modules.get(this.getModuleName());

    if (this.getConfigurationModuleNames() != null) {// RT is configured

        // ONE ONLY ALLOWED
        // if one module configured
        if (this.getConfigurationModuleNames().size() == 1) {

            if (this.getConfigurationModuleNames().containsKey(this.getCurrentModuleName())) {// this is the one
                // configured
                // Same module configured
                MerchantConfiguration mconf = (MerchantConfiguration) this.getConfigurationModuleNames()
                        .get(this.getCurrentModuleName());
                if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                    mconf.setConfigurationValue("true");
                } else {
                    mconf.setConfigurationValue("false");
                }
                updateableModules.add(mconf);
            } else {
                // Get module, set flag to false
                Collection coll = this.getConfigurationModuleNames().values();
                Object[] obj = coll.toArray();

                MerchantConfiguration conf = (MerchantConfiguration) obj[0];

                // check if it is a gateway

                if (module != null && module.getCoreModuleServiceSubtype() == 1
                        && this.getModuleEnabled().equals("true")) {

                    if (configurationModuleGatewayNames != null
                            && configurationModuleGatewayNames.containsKey(conf.getConfigurationValue1())) {

                        conf.setConfigurationValue("");

                    }

                }
                updateableModules.add(conf);

                // create a new one
                MerchantConfiguration newconfiguration = new MerchantConfiguration();
                newconfiguration.setConfigurationKey(PaymentConstants.MODULE_PAYMENT_INDICATOR_NAME);
                newconfiguration.setConfigurationModule("");
                newconfiguration.setMerchantId(merchantid);
                if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                    newconfiguration.setConfigurationValue("true");
                } else {
                    newconfiguration.setConfigurationValue("");
                }
                newconfiguration.setConfigurationValue1(this.getModuleName());
                newconfiguration.setDateAdded(new Date(dt.getTime()));
                config = newconfiguration;

                updateableModules.add(newconfiguration);

            }
        } else {// keep the good one and set to false the others

            // if gateway submited
            if (module != null && module.getCoreModuleServiceSubtype() == 1
                    && this.getModuleEnabled().equals("true")

                    && this.getConfigurationModuleGatewayNames() != null) {

                Map coll = this.getConfigurationModuleGatewayNames();

                Iterator i = coll.keySet().iterator();
                while (i.hasNext()) {

                    String key = (String) i.next();
                    if (configurationModuleNames != null) {

                        MerchantConfiguration conf = (MerchantConfiguration) configurationModuleNames.get(key);
                        if (conf != null) {
                            conf.setConfigurationValue("");
                            updateableModules.add(conf);
                        }

                    }

                }

            }
            if (this.getConfigurationModuleNames().containsKey(this.getModuleName())) {
                // contains submited module
                MerchantConfiguration conf = this.getConfigurationModuleNames().get(this.getModuleName());
                if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                    conf.setConfigurationValue("true");
                } else {
                    conf.setConfigurationValue("");
                }
                updateableModules.add(conf);
                config = conf;
            } else {// create a new one

                MerchantConfiguration newconfiguration = new MerchantConfiguration();
                newconfiguration.setConfigurationKey(PaymentConstants.MODULE_PAYMENT_INDICATOR_NAME);
                newconfiguration.setConfigurationModule("");
                newconfiguration.setMerchantId(merchantid);
                if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                    newconfiguration.setConfigurationValue("true");
                } else {
                    newconfiguration.setConfigurationValue("");
                }
                newconfiguration.setConfigurationValue1(this.getModuleName());
                newconfiguration.setDateAdded(new Date(dt.getTime()));
                config = newconfiguration;
                this.getConfigurationModuleNames().put(this.getModuleName(), newconfiguration);
                updateableModules.add(newconfiguration);
            }
        }

    } else {// Nothing configured

        MerchantConfiguration newconfiguration = new MerchantConfiguration();
        newconfiguration.setConfigurationKey(PaymentConstants.MODULE_PAYMENT_INDICATOR_NAME);
        newconfiguration.setConfigurationModule("");
        if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
            newconfiguration.setConfigurationValue("true");
        } else {
            newconfiguration.setConfigurationValue("");
        }
        newconfiguration.setConfigurationValue1(this.getModuleName());
        newconfiguration.setDateAdded(new Date(dt.getTime()));
        newconfiguration.setMerchantId(merchantid);
        config = newconfiguration;
        this.getConfigurationModuleNames().put(this.getModuleName(), newconfiguration);
        updateableModules.add(newconfiguration);
    }

    this.saveModule();
    mservice.saveOrUpdateMerchantConfigurations(updateableModules);
    super.setSuccessMessage();

    return SUCCESS;
}

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

private Object featureDescription_whereBlockIgnoring() {
    int expectedTextBlocksCount = 1;
    Collection<String> generatedTexts = generateBlockTexts(expectedTextBlocksCount);
    Iterator<String> generatedTextsIterator = generatedTexts.iterator();

    List<BlockInfo> blocks = asList(createBlockInfo(EXPECT, singletonList(generatedTextsIterator.next())),
            createBlockInfo(WHERE, singletonList((String) null)), createBlockInfo(WHERE, singletonList("")));

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

    return new Object[] { "ignoring empty 'where' blocks", createFeatureInfo(blocks), expectedDescription };
}

From source file:fr.free.hd.servers.gui.FaceView.java

private JList CreateList() {
    Collection<Face> faces = facesDAO.getFaces();
    final JList list = new JList(faces.toArray());
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override/*from   ww w  .ja  v  a 2 s .  c o m*/
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                face = (Face) list.getSelectedValue();
            }
        }

    });
    return list;
}

From source file:org.semispace.semimeter.dao.jdbc.SemiMeterDaoJdbc.java

public void performInsertion(Collection<Item> items) {
    //log.debug("Performing batch insertion of "+items.size()+" items.");
    SqlParameterSource[] insertArgs = SqlParameterSourceUtils.createBatch(items.toArray());
    List<Object[]> updateArgs = new ArrayList<Object[]>();

    for (Item item : items) {
        // Original just called insert
        updateArgs.add(new Object[] { item.getAccessNumber(), item.getPath(), item.getWhen() });
    }/*w ww  . j  ava  2 s  .c om*/
    rwl.writeLock().lock();
    try {
        try {
            //log.debug("INSERT INTO meter(updated, count, path) SELECT DISTINCT ?, 0, ? FROM meter WHERE NOT EXISTS ( SELECT * FROM meter WHERE updated=? AND path=?)");
            jdbcTemplate.batchUpdate(
                    "INSERT INTO meter(updated, counted, path) SELECT :when, 0, :path FROM meter WHERE NOT EXISTS ( SELECT * FROM meter WHERE updated=:when AND path=:path) LIMIT 1",
                    insertArgs);

        } catch (Exception e) {
            log.warn(
                    "Unlikely event occurred - failure whilst inserting priming elements. This is not overly critical. Masked exception: "
                            + e);
        }
        jdbcTemplate.batchUpdate("update meter SET counted=counted+? WHERE path like ? and updated=?",
                updateArgs);
    } catch (Exception e) {
        log.error("Could not update elements", e);
    } finally {
        rwl.writeLock().unlock();
    }
}

From source file:io.github.bonigarcia.wdm.BrowserManager.java

public String forceCache(String repository) {
    String driverInCache = null;//from ww w. ja  v a2  s.c  o  m
    for (String driverName : getDriverName()) {
        log.trace("Checking if {} exists in cache {}", driverName, repository);

        Collection<File> listFiles = FileUtils.listFiles(new File(repository), null, true);
        Object[] array = listFiles.toArray();
        Arrays.sort(array, Collections.reverseOrder());

        for (Object f : array) {
            driverInCache = f.toString();
            log.trace("Checking {}", driverInCache);
            if (driverInCache.contains(driverName)) {
                log.info("Found {} in cache: {} ", driverName, driverInCache);
                break;
            } else {
                driverInCache = null;
            }
        }

        if (driverInCache == null) {
            log.trace("{} do not exist in cache {}", driverName, repository);
        } else {
            break;
        }
    }
    return driverInCache;
}

From source file:com.surevine.alfresco.repo.action.EnhancedSecurityModelGroupRemovalBehaviour.java

/**
 * Only allow the update if no previous groups, except those listed in the authorisedDeletion property, have been removed.  We only care about removal
 * from the model - it's OK to change the type of a group.
 * //  w  w w.ja va  2 s  .  co  m
 * Additionally, please note that groups that are commented out are _NOT_ counted as having been removed.  This shouldn't be a problem ibn production,
 * but could cause confusion during test
 */
@SuppressWarnings("unchecked")
@Override
public void onContentUpdate(NodeRef nodeRef, boolean newContent) {
    if (_nodeService.exists(nodeRef)) { // Q.Only interested in? workspace://SpacesStore/enhanced_security_custom_model
        // A. Sorta.  We're interested in anything with the psg:groups aspect applied, which will (at time of writing) only be one file.
        //    This is taken care of us by the call to policyComponent in the init() method so we don't have to worry about it here, if we bind on init.
        //    If we don't bind on init, then it's up to the caller to call us at the right time!

        //Get the new content and load it into a string
        ContentReader reader = _contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
        String newContentString = reader.getContentString();
        LOGGER.trace("New Model: " + newContentString);
        Collection<String> valuesAfterUpdate = getGroupNamesFromModelContent(newContentString);

        //Get (and log) the list of groups it's OK to remove
        @SuppressWarnings("rawtypes")
        Collection<String> authorisedGroupsToRemove = (Collection) (_nodeService.getProperty(nodeRef,
                _authorisedGroupsToRemoveQName));
        if (LOGGER.isDebugEnabled()) {
            String s = "undefined";
            if (authorisedGroupsToRemove != null) {
                s = StringUtils.join(authorisedGroupsToRemove.toArray(), ",");
                LOGGER.debug(authorisedGroupsToRemove.size() + " authorised groups to remove:  " + s);
            } else {
                LOGGER.debug("No groups are authorised for removal");
            }
        }

        // This is the set of values allowed after the update. Usually retrieved from LDAP.
        final String allowedValues = StringUtils.join(valuesAfterUpdate.toArray(), ',');
        LOGGER.debug("The Model is now allowed the values: " + allowedValues);

        //Get the previous values.  if it's not present, just allow the update
        Object previousValuesPropVal = _nodeService.getProperty(nodeRef, _previousValuesPropertyName);
        if (previousValuesPropVal == null) {
            LOGGER.debug("Existing property: " + _previousValuesPropertyName + " could not be found");
        } else {
            Collection<String> valuesBeforeUpdate = Arrays.asList(previousValuesPropVal.toString().split(","));

            // This is the set of values previously allowed. Retrieved from Alfresco.
            LOGGER.debug("The model was allowed the values: " + previousValuesPropVal.toString());

            //For each group before the update, if it's not in the file after the update, then see if it's in the list of groups to delete.  If it isn't, abort
            Iterator<String> groupNamesBeforeUpdate = valuesBeforeUpdate.iterator();
            while (groupNamesBeforeUpdate.hasNext()) {
                String groupName = groupNamesBeforeUpdate.next();
                LOGGER.debug("Checking for the presence of: " + groupName);
                if (!safeContains(groupName, valuesAfterUpdate)) {
                    if (authorisedGroupsToRemove != null && safeContains(groupName, authorisedGroupsToRemove)) {
                        authorisedGroupsToRemove.remove(groupName);
                        _nodeService.setProperty(nodeRef, _authorisedGroupsToRemoveQName,
                                new ArrayList<String>(authorisedGroupsToRemove));
                    } else {
                        throw new EnhancedSecurityException("The group: " + groupName
                                + " was removed and was not in the authorised removal list");
                    }
                }
            }
        }

        _nodeService.setProperty(nodeRef, _previousValuesPropertyName, allowedValues.toString());

    } else {
        LOGGER.debug("The node does not exist: " + nodeRef);
    }
}

From source file:com.hiperium.dao.common.list.impl.ListOperationDAOImpl.java

/**
 * {@inheritDoc}//w w  w.j a v a 2s. co  m
 */
@SuppressWarnings("unchecked")
public void process(@NotNull List<T> actualList, @NotNull List<T> newList, @NotNull String sessionId) {
    Collection<T> toUpdateOriginal = CollectionUtils.intersection(actualList, newList);
    Collection<T> toUpdateNew = CollectionUtils.intersection(newList, actualList);
    Collection<T> delete = CollectionUtils.subtract(actualList, newList);
    for (T entity : delete) {
        this.entityManager.remove(entity);
    }
    Collection<T> insert = CollectionUtils.subtract(newList, actualList);
    for (T entity : insert) {
        this.entityManager.persist(entity);
    }
    T[] updatedOriginalList = (T[]) toUpdateOriginal.toArray();
    T[] updatedNewList = (T[]) toUpdateNew.toArray();
    for (int i = 0; i < updatedOriginalList.length; i++) {
        boolean update = false;
        try {
            Map<String, String> originalProperties = BeanUtils.describe(updatedOriginalList[i]);
            Map<String, String> newProperties = BeanUtils.describe(updatedNewList[i]);
            Set<String> properties = originalProperties.keySet();
            for (String string : properties) {
                if (!(originalProperties.get(string) == null && newProperties.get(string) == null)
                        && !originalProperties.get(string).equals(newProperties.get(string))) {
                    update = true;
                    break;
                }
            }
        } catch (Exception e) {
            update = true;
        }
        if (update) {
            this.entityManager.merge(updatedNewList[i]);
        }
    }
}

From source file:com.kodebeagle.parser.ASTParserTest.java

@Test
public void testClassesInFile() {
    Collection<String> expectedClassesInFile = new ArrayList<String>();

    expectedClassesInFile.add("x.y.z.ABC");
    expectedClassesInFile.add("x.y.z.DefaultRequestDirector.DEF");
    expectedClassesInFile.add("x.y.z.DefaultRequestDirector.DEF.GHI");
    expectedClassesInFile.add("x.y.z.DefaultRequestDirector");

    Collection<String> actualClassesInFile = resolver.getClassesInFile().values();
    Assert.assertEquals(expectedClassesInFile.toArray(), actualClassesInFile.toArray());
}

From source file:com.salesmanager.central.shipping.ShippingModuleAction.java

public String save() throws Exception {

    this.prepare();
    Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    if (configurationModuleNames == null) {
        configurationModuleNames = new HashMap();
    }/*from  w  ww .ja  v  a2s .co m*/

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    Date dt = new Date();

    MerchantConfiguration config = null;

    List updateableModules = new ArrayList();

    if (this.getConfigurationModuleNames() != null) {// RT is configured
        // check if only one allowed
        if (conf.getProperty("central.modules.shipping.rt.allowmultiplemodules") == null
                || conf.getProperty("central.modules.shipping.rt.allowmultiplemodules").equals("false")) {
            // ONE ONLY ALLOWED
            // if one module configured
            if (this.getConfigurationModuleNames().size() == 1) {

                // if module== this module, set to true and update, else set
                // to false update and create a new one

                if (this.getConfigurationModuleNames().containsKey(this.getCurrentModuleName())) {// this is the one
                    // configured
                    // Same module configured
                    MerchantConfiguration mconf = (MerchantConfiguration) this.getConfigurationModuleNames()
                            .get(this.getCurrentModuleName());
                    if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                        mconf.setConfigurationValue("true");
                    } else {
                        mconf.setConfigurationValue("false");
                    }
                    updateableModules.add(mconf);
                } else {
                    // Get module, set flag to false
                    Collection coll = this.getConfigurationModuleNames().values();
                    Object[] obj = coll.toArray();

                    MerchantConfiguration conf = (MerchantConfiguration) obj[0];
                    if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                        // conf.setConfigurationValue("true");
                        conf.setConfigurationValue("");
                    }
                    updateableModules.add(conf);

                    // create a new one
                    MerchantConfiguration newconfiguration = new MerchantConfiguration();
                    newconfiguration
                            .setConfigurationKey(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME);
                    newconfiguration.setConfigurationModule("");
                    newconfiguration.setMerchantId(merchantid);
                    if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                        newconfiguration.setConfigurationValue("true");
                    } else {
                        newconfiguration.setConfigurationValue("");
                    }
                    newconfiguration.setConfigurationValue1(this.getModuleName());
                    newconfiguration.setDateAdded(new Date(dt.getTime()));

                    config = newconfiguration;

                    updateableModules.add(newconfiguration);

                }
            } else {// keep the good one and set to false the others

                // delete all modules
                Collection coll = this.getConfigurationModuleNames().values();

                Iterator i = coll.iterator();
                while (i.hasNext()) {
                    MerchantConfiguration conf = (MerchantConfiguration) i.next();
                    if (!conf.getConfigurationValue1().equals(this.getModuleName())) {

                        conf.setConfigurationValue("");
                        updateableModules.add(conf);
                    }
                }

                if (this.getConfigurationModuleNames().containsKey(this.getModuleName())) {
                    // contains submited module
                    MerchantConfiguration conf = this.getConfigurationModuleNames().get(this.getModuleName());
                    if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                        conf.setConfigurationValue("true");
                    } else {
                        conf.setConfigurationValue("");
                    }

                    updateableModules.add(conf);
                    config = conf;
                } else {// create a new one

                    MerchantConfiguration newconfiguration = new MerchantConfiguration();
                    newconfiguration
                            .setConfigurationKey(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME);
                    newconfiguration.setConfigurationModule("");
                    newconfiguration.setMerchantId(merchantid);
                    if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                        newconfiguration.setConfigurationValue("true");
                    } else {
                        newconfiguration.setConfigurationValue("");
                    }
                    newconfiguration.setConfigurationValue1(this.getModuleName());
                    newconfiguration.setDateAdded(new Date(dt.getTime()));

                    config = newconfiguration;
                    this.getConfigurationModuleNames().put(this.getModuleName(), newconfiguration);
                    updateableModules.add(newconfiguration);
                }
            }

        } else {
            // MULTIPLE ARE ALLOWED
            if (this.getConfigurationModuleNames().containsKey(this.getModuleName())) {
                // contains submited module
                MerchantConfiguration conf = this.getConfigurationModuleNames().get(this.getModuleName());
                if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                    conf.setConfigurationValue("true");
                } else {
                    conf.setConfigurationValue("");
                }

                config = conf;
                updateableModules.add(conf);
            } else {// create a new one
                MerchantConfiguration newconfiguration = new MerchantConfiguration();
                newconfiguration.setConfigurationKey(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME);
                newconfiguration.setConfigurationModule("");
                newconfiguration.setMerchantId(merchantid);
                if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
                    newconfiguration.setConfigurationValue("true");
                } else {
                    newconfiguration.setConfigurationValue("");
                }
                newconfiguration.setConfigurationValue1(this.getModuleName());
                newconfiguration.setDateAdded(new Date(dt.getTime()));
                // mservice.saveOrUpdateMerchantConfiguration(newconfiguration);
                config = newconfiguration;
                this.getConfigurationModuleNames().put(this.getModuleName(), newconfiguration);
                updateableModules.add(newconfiguration);
            }

        }

    } else {// Nothing configured

        MerchantConfiguration newconfiguration = new MerchantConfiguration();
        newconfiguration.setConfigurationKey(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME);
        newconfiguration.setConfigurationModule("");
        if (this.getModuleEnabled() != null && this.getModuleEnabled().equals("true")) {
            newconfiguration.setConfigurationValue("true");
        } else {
            newconfiguration.setConfigurationValue("");
        }
        newconfiguration.setConfigurationValue1(this.getModuleName());
        newconfiguration.setDateAdded(new Date(dt.getTime()));
        newconfiguration.setMerchantId(merchantid);

        config = newconfiguration;
        this.getConfigurationModuleNames().put(this.getModuleName(), newconfiguration);
        updateableModules.add(newconfiguration);
    }

    this.saveModule();

    mservice.saveOrUpdateMerchantConfigurations(updateableModules);
    super.setSuccessMessage();

    return SUCCESS;
}

From source file:org.semispace.semimeter.dao.SemiMeterDao.java

protected void performInsertion(Collection<Item> items) {
    //log.debug("Performing batch insertion of "+items.size()+" items.");
    SqlParameterSource[] insertArgs = SqlParameterSourceUtils.createBatch(items.toArray());
    List<Object[]> updateArgs = new ArrayList<Object[]>();

    for (Item item : items) {
        // Original just called insert
        updateArgs.add(new Object[] { item.getAccessNumber(), item.getPath(), item.getWhen() });
    }//  w  w w .j  a v  a 2 s  . c om
    rwl.writeLock().lock();
    try {
        try {
            //log.debug("INSERT INTO meter(updated, count, path) SELECT DISTINCT ?, 0, ? FROM meter WHERE NOT EXISTS ( SELECT * FROM meter WHERE updated=? AND path=?)");
            jdbcTemplate.batchUpdate(
                    "INSERT INTO meter(updated, counted, path) SELECT DISTINCT :when, 0, :path FROM meter WHERE NOT EXISTS ( SELECT * FROM meter WHERE updated=:when AND path=:path)",
                    insertArgs);
        } catch (Exception e) {
            log.warn(
                    "Unlikely event occurred - failure whilst inserting priming elements. This is not overly critical. Masked exception: "
                            + e);
        }
        jdbcTemplate.batchUpdate("update meter SET counted=counted+? WHERE path like ? and updated=?",
                updateArgs);
    } catch (Exception e) {
        log.error("Could not update elements", e);
    } finally {
        rwl.writeLock().unlock();
    }
}