List of usage examples for java.util Collection toArray
Object[] toArray();
From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java
/** * Returns the appropriate string representation for the specified object. * * @param value// w w w .j av a2 s . co m * object to convert to string representation * * @return string representation of object */ public static String toString(Object value) { if (value instanceof int[]) { return Arrays.toString((int[]) value); } if (value instanceof byte[]) { return getString((byte[]) value); // return Arrays.toString((byte[]) value); } if (value instanceof char[]) { return new String((char[]) value); // return Arrays.toString((char[]) value); } if (value instanceof long[]) { return Arrays.toString((long[]) value); } if (value instanceof float[]) { return Arrays.toString((float[]) value); } if (value instanceof short[]) { return Arrays.toString((short[]) value); } if (value instanceof double[]) { return Arrays.toString((double[]) value); } if (value instanceof boolean[]) { return Arrays.toString((boolean[]) value); } if (value instanceof Object[]) { return toStringDeep((Object[]) value); } if (value instanceof Collection) { Collection<?> c = (Collection<?>) value; return toString(c.toArray()); } if (value instanceof Map) { Map<?, ?> m = (Map<?, ?>) value; return toString(m.entrySet()); } return String.valueOf(value); }
From source file:com.salesmanager.central.catalog.EditProductAttributesAction.java
public String displayProductAttributes() throws Exception { try {/*from w w w . java2s . c o m*/ Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context); Integer merchantid = ctx.getMerchantid(); prepare(); if (this.getProduct() == null || this.getProduct().getProductId() == 0) { log.error("Should have received a productId"); MessageUtil.addErrorMessage(super.getServletRequest(), LabelUtil.getInstance().getText(super.getLocale(), "errors.technical")); return SUCCESS; } CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); Collection options = cservice.getProductOptions(ctx.getMerchantid()); if (options != null) { ProductOption option = (ProductOption) options.toArray()[0]; ProductOption optionWithValues = cservice.getProductOptionWithValues(option.getProductOptionId()); Iterator i = options.iterator(); while (i.hasNext()) { ProductOption o = (ProductOption) i.next(); ProductOptionDisplay pod = new ProductOptionDisplay(); pod.setProductOptionId(o.getProductOptionId()); pod.setProductOptionName(String.valueOf(o.getProductOptionId())); Set descs = o.getDescriptions(); if (descs != null) { Iterator descsiter = descs.iterator(); while (descsiter.hasNext()) { ProductOptionDescription podesc = (ProductOptionDescription) descsiter.next(); ProductOptionDescriptionId id = podesc.getId(); if (id.getLanguageId() == LanguageUtil.getLanguageNumberCode(ctx.getLang())) { pod.setProductOptionName(podesc.getProductOptionName()); break; } } } optionList.add(pod); } if (optionWithValues != null) { Set values = optionWithValues.getValues(); if (values != null) { Iterator viter = values.iterator(); while (viter.hasNext()) { ProductOptionValue pov = (ProductOptionValue) viter.next(); ProductOptionValueDisplay povd = new ProductOptionValueDisplay(); povd.setProductOptionValueId(pov.getProductOptionValueId()); povd.setProductOptionValueName(String.valueOf(pov.getProductOptionValueId())); Set descs = pov.getDescriptions(); if (descs != null) { Iterator descsiter = descs.iterator(); while (descsiter.hasNext()) { ProductOptionValueDescription povdesc = (ProductOptionValueDescription) descsiter .next(); ProductOptionValueDescriptionId id = povdesc.getId(); if (id.getLanguageId() == LanguageUtil.getLanguageNumberCode(ctx.getLang())) { povd.setProductOptionValueName(povdesc.getProductOptionValueName()); break; } } } optionValueList.add(povd); } } } } Collection attributes = cservice.getProductAttributes(this.getProduct().getProductId(), super.getLocale().getLanguage()); super.getServletRequest().setAttribute("attributes", attributes); } catch (Exception e) { log.error(e); super.setTechnicalMessage(); } return SUCCESS; }
From source file:com.bac.accountserviceapp.data.AccountServiceUserDetailsTest.java
@Test public void testGetAuthorities_OneValidAuthority() { logger.info("testGetAuthorities_OneValidAuthority"); ////from ww w . ja v a 2 s .c o m // // String expApplicationName = UUID.randomUUID().toString(); Integer expAccessLevelId = new Double(Math.random()).intValue(); String expAuthority = expApplicationName + authoritySeparator + accessLevelRole.name(); Application application = getApplication(expApplicationName, true); // AccountUser accountUser = getAccountUser(expAccessLevelId, true); AccessLevel accessLevel = getAccessLevel(expAccessLevelId); userDetailsAuthorities.add(new UserDetailsAuthority(application, accessLevel)); instance = new AccountServiceUserDetails(null, userDetailsAuthorities); Collection<? extends GrantedAuthority> result = instance.getAuthorities(); assertNotNull(result); assertTrue(result instanceof Set<?>); int expSize = 1; int resultSize = result.size(); assertEquals(expSize, resultSize); // // // GrantedAuthority grantedAuthority0 = (GrantedAuthority) result.toArray()[0]; String resultAuthority = grantedAuthority0.getAuthority(); assertEquals(expAuthority, resultAuthority); }
From source file:com.sfs.whichdoctor.dao.TagDAOImpl.java
/** * Used to get a Collection of TagBeans for a specified GUID. * * @param guid the guid/*from www. ja v a 2s .c o m*/ * @param username the username * @param fullResults the full results * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<TagBean> load(final int guid, final String username, final boolean fullResults) throws WhichDoctorDaoException { dataLogger.info("Tags for GUID: " + guid + " requested"); Collection<TagBean> tags = new ArrayList<TagBean>(); String loadTags = this.getSQL().getValue("tag/loadAnonymous"); Collection<Object> parameters = new ArrayList<Object>(); parameters.add(guid); parameters.add("Private"); if (StringUtils.isNotEmpty(username)) { loadTags = this.getSQL().getValue("tag/loadAuthenticated"); parameters.add("Private"); parameters.add(username); } try { tags = this.getJdbcTemplateReader().query(loadTags, parameters.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadTag(rs, fullResults); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results for this search: " + ie.getMessage()); } return tags; }
From source file:com.globalsight.everest.webapp.pagehandler.administration.config.fileextension.FileExtensionMainHandler.java
/** * Get data for main table.//from w w w. j a va 2s . c om */ private void dataForTable(HttpServletRequest p_request, HttpSession p_session) throws RemoteException, NamingException, GeneralException { Collection fileextensions = ServerProxy.getFileProfilePersistenceManager().getAllFileExtensions(); Locale uiLocale = (Locale) p_session.getAttribute(WebAppConstants.UILOCALE); SessionManager sessionManager = (SessionManager) p_session.getAttribute(WebAppConstants.SESSION_MANAGER); String FileExtensionName = (String) sessionManager.getAttribute("FileExtensionName"); String FileExtensionCName = (String) sessionManager.getAttribute("FileExtensionCName"); Object[] extensions = fileextensions.toArray(); ArrayList fes = new ArrayList(); if (FileExtensionName != "" || FileExtensionCName != "") { if (FileExtensionName != null && FileExtensionName != "") { for (int i = 0; i < extensions.length; i++) { if (extensions[i].toString().indexOf(FileExtensionName) >= 0) { fes.add(extensions[i]); } } } else if (FileExtensionCName != null && FileExtensionCName != "") { for (int i = 0; i < extensions.length; i++) { String compName = CompanyWrapper .getCompanyNameById(((FileExtensionImpl) extensions[i]).getCompanyId()).toLowerCase(); if (compName.indexOf(FileExtensionCName) >= 0) { fes.add(extensions[i]); } } } else { for (int i = 0; i < extensions.length; i++) { fes.add(extensions[i]); } } } else { for (int i = 0; i < extensions.length; i++) { fes.add(extensions[i]); } } int numberPerPage = getNumPerPage(p_request, p_session); setTableNavigation(p_request, p_session, (ArrayList) fes, new FileExtensionComparator(uiLocale), numberPerPage, EXTENSION_LIST, EXTENSION_KEY); }
From source file:com.bac.accountserviceapp.data.AccountServiceUserDetailsTest.java
@Test public void testGetAuthorities_OneValidOneInvalidAuthority() { logger.info("testGetAuthorities_OneValidOneInvalidAuthority"); ////from www.j a v a 2s .c o m // Valid authority // String expApplicationName = UUID.randomUUID().toString(); Integer expAccessLevelId = new Double(Math.random()).intValue(); String expAuthority = expApplicationName + authoritySeparator + accessLevelRole.name(); Application application = getApplication(expApplicationName, true); // AccountUser accountUser = getAccountUser(expAccessLevelId, true); AccessLevel accessLevel = getAccessLevel(expAccessLevelId); userDetailsAuthorities.add(new UserDetailsAuthority(application, accessLevel)); // // Invalid authority // application = getApplication(UUID.randomUUID().toString(), false); // accountUser = getAccountUser(new Double(Math.random()).intValue(), false); accessLevel = getAccessLevel(expAccessLevelId); userDetailsAuthorities.add(new UserDetailsAuthority(application, accessLevel)); instance = new AccountServiceUserDetails(null, userDetailsAuthorities); Collection<? extends GrantedAuthority> result = instance.getAuthorities(); assertNotNull(result); assertTrue(result instanceof Set<?>); int expSize = 1; int resultSize = result.size(); assertEquals(expSize, resultSize); // // // GrantedAuthority grantedAuthority0 = (GrantedAuthority) result.toArray()[0]; String resultAuthority = grantedAuthority0.getAuthority(); assertEquals(expAuthority, resultAuthority); }
From source file:lineage2.commons.collections.LazyArrayList.java
/** * Method addAll./*from ww w . j a v a 2s . c om*/ * @param c Collection<? extends E> * @return boolean * @see java.util.List#addAll(Collection<? extends E>) */ @Override public boolean addAll(Collection<? extends E> c) { if ((c == null) || c.isEmpty()) { return false; } Object[] a = c.toArray(); int numNew = a.length; ensureCapacity(size + numNew); System.arraycopy(a, 0, elementData, size, numNew); size += numNew; return true; }