List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:com.salesmanager.core.util.CheckoutUtil.java
/** * Add attributes to an OrderProduct and calculates the OrderProductPrice * accordingly/* w w w . j a va2 s . c o m*/ * * @param attributes * @param product * @param currency * @param locale * @return * @throws Exception */ public static OrderProduct addAttributesToProduct(List<OrderProductAttribute> attributes, OrderProduct product, String currency, Locale locale) throws Exception { Locale loc = locale; String lang = loc.getLanguage(); CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); BigDecimal sumPrice = null; // get attributes for this product Collection productAttributes = cservice.getProductAttributes(product.getProductId(), locale.getLanguage()); Map mapAttributes = new HashMap(); if (productAttributes != null) { Iterator i = productAttributes.iterator(); while (i.hasNext()) { ProductAttribute p = (ProductAttribute) i.next(); mapAttributes.put(p.getOptionValueId(), p); } } StringBuffer attributesLine = null; if (attributes != null) { attributesLine = new StringBuffer(); int count = 0; Iterator i = attributes.iterator(); while (i.hasNext()) { OrderProductAttribute opa = (OrderProductAttribute) i.next(); String attrPriceText = opa.getPrice(); BigDecimal attrPrice = null; if (attrPriceText != null) { attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency); } else { attrPrice = opa.getOptionValuePrice(); } // get all information from the attribute ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId()); if (pa != null) { if (attrPrice == null) { attrPrice = pa.getOptionValuePrice(); } } if (attrPrice != null) { opa.setOptionValuePrice(attrPrice); opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency)); if (sumPrice == null) { // try { // sumPrice= new // BigDecimal(attrPrice.doubleValue()).setScale(BigDecimal.ROUND_UNNECESSARY); sumPrice = attrPrice; // } catch (Exception e) { // } } else { BigDecimal currentPrice = sumPrice; sumPrice = currentPrice.add(attrPrice); } } opa.setOrderProductId(product.getProductId()); opa.setProductAttributeIsFree(pa.isProductAttributeIsFree()); opa.setProductOption(""); if (StringUtils.isBlank(opa.getProductOptionValue())) { opa.setProductOptionValue(""); } ProductOption po = pa.getProductOption(); Set poDescriptions = po.getDescriptions(); if (poDescriptions != null) { Iterator pi = poDescriptions.iterator(); while (pi.hasNext()) { ProductOptionDescription pod = (ProductOptionDescription) pi.next(); if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) { opa.setProductOption(pod.getProductOptionName()); break; } } } if (StringUtils.isBlank(opa.getProductOptionValue())) { ProductOptionValue pov = pa.getProductOptionValue(); if (pov != null) { Set povDescriptions = pov.getDescriptions(); if (povDescriptions != null) { Iterator povi = povDescriptions.iterator(); while (povi.hasNext()) { ProductOptionValueDescription povd = (ProductOptionValueDescription) povi.next(); if (povd.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) { opa.setProductOptionValue(povd.getProductOptionValueName()); break; } } } } } opa.setProductAttributeWeight(pa.getProductAttributeWeight()); if (count == 0) { attributesLine.append("[ "); } attributesLine.append(opa.getProductOption()).append(" -> ").append(opa.getProductOptionValue()); if (count + 1 == attributes.size()) { attributesLine.append("]"); } else { attributesLine.append(", "); } count++; } } // add attribute price to productprice if (sumPrice != null) { // get product price BigDecimal productPrice = product.getProductPrice(); productPrice = productPrice.add(sumPrice); // added product.setProductPrice(productPrice); BigDecimal finalPrice = productPrice.multiply(new BigDecimal(product.getProductQuantity())); product.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency)); product.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency)); } if (attributesLine != null) { product.setAttributesLine(attributesLine.toString()); } Set attributesSet = new HashSet(attributes); product.setOrderattributes(attributesSet); return product; }
From source file:com.icesoft.faces.webapp.parser.JspPageToDocument.java
static String[] scanJars(ExternalContext context, String namespaceURL) { try {//from w w w. ja v a2 s .c o m String[] location = null; Set resourcePaths = context.getResourcePaths("/WEB-INF/lib/"); if (resourcePaths == null) { if (log.isDebugEnabled()) { log.debug("there are no libraries in /WEB-INF/lib/ "); } return null; } Iterator paths = resourcePaths.iterator(); while (paths.hasNext()) { String path = (String) paths.next(); if (!path.endsWith(".jar")) { continue; } path = context.getResource(path).toString(); JarURLConnection connection = (JarURLConnection) new URL("jar:" + path + "!/").openConnection(); location = scanJar(connection, namespaceURL); if (null != location) { return location; } } } catch (Exception e) { if (log.isWarnEnabled()) { log.warn("Jar scanning under /WEB_INF/lib failed " + e.getMessage(), e); } } return null; }
From source file:com.selventa.whistle.cli.Rcr.java
/** * Compute the {@link KamNode hypothesis node} to * {@link Downstream downstreams} that are in the population measured. * * @param hyps the hypothesis {@link List list} * @param population the {@link Set set} of measurements in the * population//from w ww . j ava 2 s. c o m * @return a {@link Map map} of {@link KamNode hypothesis node} to * {@link Downstream downstreams} in the measured population */ private static Map<KamNode, Set<Downstream>> computeHypMap(List<Hypothesis> hyps, Map<Integer, KamNode> population) { Map<KamNode, Set<Downstream>> hypDownstreams = new HashMap<Kam.KamNode, Set<Downstream>>(); for (final Hypothesis hyp : hyps) { // new set of downstreams Set<Downstream> newset = new HashSet<Downstream>(); // remove all downstreams not in population Set<Downstream> oldset = hyp.getDownstreams(); Iterator<Downstream> it = oldset.iterator(); while (it.hasNext()) { Downstream down = it.next(); KamNode dn = down.getKamNode(); KamNode pn = population.get(dn.getId()); if (pn != null) { newset.add(new Downstream(pn, down.getDirectionType())); } } // store mechanism to downstreams in population hypDownstreams.put(hyp.getKamNode(), newset); } return hypDownstreams; }
From source file:com.salesmanager.core.util.CheckoutUtil.java
public static String getAttributesLine(OrderProduct product) { Set attributes = product.getOrderattributes(); if (attributes != null) { StringBuffer attributesLine = null; attributesLine = new StringBuffer(); int count = 0; Iterator i = attributes.iterator(); while (i.hasNext()) { OrderProductAttribute opa = (OrderProductAttribute) i.next(); if (count == 0) { attributesLine.append("[ "); }/*from w ww . j a va2 s . c o m*/ attributesLine.append(opa.getProductOption()).append(" -> ").append(opa.getProductOptionValue()); if (count + 1 == attributes.size()) { attributesLine.append("]"); } else { attributesLine.append(", "); } count++; } return attributesLine.toString(); } else { return null; } }
From source file:com.salesmanager.core.util.ProductUtil.java
public static BigDecimal determinePriceNoDiscountWithAttributes(Product product, Collection<Long> attributes, Locale locale, String currency) { BigDecimal price = product.getProductPrice(); // all other prices Set prices = product.getPrices(); if (prices != null) { Iterator pit = prices.iterator(); while (pit.hasNext()) { ProductPrice pprice = (ProductPrice) pit.next(); pprice.setLocale(locale);/*from www . j av a2 s .co m*/ if (pprice.isDefaultPrice()) {// overwrites default price price = pprice.getProductPriceAmount(); } } } BigDecimal attributesPrice = null; if (attributes != null) { Iterator i = attributes.iterator(); while (i.hasNext()) { ProductAttribute attr = (ProductAttribute) i.next(); if (!attr.isAttributeDisplayOnly() && attr.getOptionValuePrice().longValue() > 0) { if (attributesPrice == null) { attributesPrice = new BigDecimal(0); } attributesPrice = attributesPrice.add(attr.getOptionValuePrice()); } } } if (attributesPrice != null) { price = price.add(attributesPrice); } return price; }
From source file:com.salesmanager.core.util.CheckoutUtil.java
/** * OrderProductAttribute is configured from javascript This code needs to * invoke catalog objects require getProductOptionValueId * /* www.j av a2s. c om*/ * @param attributes * @param lineId * @param currency * @param request * @return * @throws Exception */ public static OrderProduct addAttributesFromRawObjects(List<OrderProductAttribute> attributes, OrderProduct scp, String currency, HttpServletRequest request) throws Exception { Locale loc = request.getLocale(); String lang = loc.getLanguage(); CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); BigDecimal sumPrice = null; Locale locale = (Locale) request.getSession().getAttribute("WW_TRANS_I18N_LOCALE"); if (locale == null) locale = request.getLocale(); // get attributes for this product Collection productAttributes = cservice.getProductAttributes(scp.getProductId(), locale.getLanguage()); Map mapAttributes = new HashMap(); if (productAttributes != null) { Iterator i = productAttributes.iterator(); while (i.hasNext()) { ProductAttribute p = (ProductAttribute) i.next(); mapAttributes.put(p.getOptionValueId(), p); } } if (scp != null) { StringBuffer attributesLine = null; if (attributes != null) { attributesLine = new StringBuffer(); int count = 0; Iterator i = attributes.iterator(); while (i.hasNext()) { OrderProductAttribute opa = (OrderProductAttribute) i.next(); String attrPriceText = opa.getPrice(); BigDecimal attrPrice = null; if (attrPriceText != null) { attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency); } else { attrPrice = opa.getOptionValuePrice(); } // get all information from the attribute ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId()); if (pa != null) { if (attrPrice == null) { attrPrice = pa.getOptionValuePrice(); } } if (attrPrice != null) { opa.setOptionValuePrice(attrPrice); opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency)); if (sumPrice == null) { sumPrice = new BigDecimal(attrPrice.doubleValue()).setScale(2); } else { BigDecimal currentPrice = sumPrice; sumPrice = currentPrice.add(attrPrice); } } // opa.setOrderId(Long.parseLong(orderId)); opa.setOrderProductId(scp.getProductId()); opa.setProductAttributeIsFree(pa.isProductAttributeIsFree()); opa.setProductOption(""); if (StringUtils.isBlank(opa.getProductOptionValue())) { opa.setProductOptionValue(""); } ProductOption po = pa.getProductOption(); Set poDescriptions = po.getDescriptions(); if (poDescriptions != null) { Iterator pi = poDescriptions.iterator(); while (pi.hasNext()) { ProductOptionDescription pod = (ProductOptionDescription) pi.next(); if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) { opa.setProductOption(pod.getProductOptionName()); break; } } } if (StringUtils.isBlank(opa.getProductOptionValue())) { ProductOptionValue pov = pa.getProductOptionValue(); if (pov != null) { Set povDescriptions = pov.getDescriptions(); if (povDescriptions != null) { Iterator povi = povDescriptions.iterator(); while (povi.hasNext()) { ProductOptionValueDescription povd = (ProductOptionValueDescription) povi .next(); if (povd.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) { opa.setProductOptionValue(povd.getProductOptionValueName()); break; } } } } } opa.setProductAttributeWeight(pa.getProductAttributeWeight()); if (count == 0) { attributesLine.append("[ "); } attributesLine.append(opa.getProductOption()).append(" -> ") .append(opa.getProductOptionValue()); if (count + 1 == attributes.size()) { attributesLine.append("]"); } else { attributesLine.append(", "); } count++; } } // add attribute price to productprice if (sumPrice != null) { // sumPrice = sumPrice.multiply(new // BigDecimal(scp.getProductQuantity())); // get product price BigDecimal productPrice = scp.getProductPrice(); productPrice = productPrice.add(sumPrice); // added scp.setProductPrice(productPrice); // BigDecimal finalPrice = scp.getFinalPrice(); BigDecimal finalPrice = productPrice.multiply(new BigDecimal(scp.getProductQuantity())); // finalPrice = finalPrice.add(sumPrice); // BigDecimal cost = scp.get scp.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency)); scp.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency)); } if (attributesLine != null) { scp.setAttributesLine(attributesLine.toString()); } Set attributesSet = new HashSet(attributes); scp.setOrderattributes(attributesSet); } return scp; }
From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java
private static VendorRole activityInRole(String activityName, LocalePair lp, Vendor vendor) { Set roles = vendor.getRoles(); for (Iterator r = roles.iterator(); r.hasNext();) { VendorRole role = (VendorRole) r.next(); LocalePair existingLP = role.getLocalePair(); if (existingLP.getId() == lp.getId() && activityName.equals(role.getActivity().getActivityName())) { return role; }/*from w w w .j ava 2 s . c om*/ } return null; }
From source file:Main.java
static <E> Set<E> ungrowableSet(final Set<E> s) { return new Set<E>() { @Override/*from www . ja v a 2s . c o m*/ public int size() { return s.size(); } @Override public boolean isEmpty() { return s.isEmpty(); } @Override public boolean contains(Object o) { return s.contains(o); } @Override public Object[] toArray() { return s.toArray(); } @Override public <T> T[] toArray(T[] a) { return s.toArray(a); } @Override public String toString() { return s.toString(); } @Override public Iterator<E> iterator() { return s.iterator(); } @Override public boolean equals(Object o) { return s.equals(o); } @Override public int hashCode() { return s.hashCode(); } @Override public void clear() { s.clear(); } @Override public boolean remove(Object o) { return s.remove(o); } @Override public boolean containsAll(Collection<?> coll) { return s.containsAll(coll); } @Override public boolean removeAll(Collection<?> coll) { return s.removeAll(coll); } @Override public boolean retainAll(Collection<?> coll) { return s.retainAll(coll); } @Override public boolean add(E o) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> coll) { throw new UnsupportedOperationException(); } }; }
From source file:net.jawr.web.resource.bundle.factory.util.PathNormalizer.java
/** * Normalizes all the paths in a Set./*from w w w .ja v a2 s . c o m*/ * * @param paths * @return */ public static final Set<String> normalizePaths(Set<String> paths) { Set<String> ret = new HashSet<String>(); for (Iterator<String> it = paths.iterator(); it.hasNext();) { String path = normalizePath((String) it.next()); ret.add(path); } return ret; }
From source file:com.salesmanager.core.util.ProductUtil.java
/** * Set product information to Order product * @param orderProduct// ww w. j av a 2s . com * @param currency * @return */ public static OrderProduct initOrderProduct(OrderProduct orderProduct, String currency) { try { OrderService oservice = (OrderService) ServiceFactory.getService(ServiceFactory.OrderService); CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); Product product = cservice.getProduct(orderProduct.getProductId()); int maxOrderQuantity = CatalogConstants.DEFAULT_MAX_ORDER_BY_PRODUCT; if (product != null) { maxOrderQuantity = product.getProductQuantityOrderMax(); } orderProduct.setProductQuantityOrderMax(maxOrderQuantity); orderProduct.setPriceFormated( CurrencyUtil.displayFormatedAmountWithCurrency(orderProduct.getProductPrice(), currency)); double finalPrice = orderProduct.getProductPrice().doubleValue() * orderProduct.getProductQuantity(); //revise precision BigDecimal bdFinalPrice = new BigDecimal(finalPrice); orderProduct.setCostText(CurrencyUtil.displayFormatedAmountWithCurrency(bdFinalPrice, currency)); orderProduct.setPriceText( CurrencyUtil.displayFormatedAmountNoCurrency(orderProduct.getProductPrice(), currency)); orderProduct.setFinalPrice(bdFinalPrice); orderProduct.setQuantityText(String.valueOf(orderProduct.getProductQuantity())); orderProduct.setPriceText( CurrencyUtil.displayFormatedAmountNoCurrency(orderProduct.getProductPrice(), currency)); if (orderProduct.getOrderattributes() != null && orderProduct.getOrderattributes().size() > 0) { orderProduct.setAttributes(true); orderProduct.setAttributesLine(CheckoutUtil.getAttributesLine(orderProduct)); } // get all discounts associated with prices Set prices = orderProduct.getPrices(); if (prices != null) { Iterator i = prices.iterator(); while (i.hasNext()) { OrderProductPrice opp = (OrderProductPrice) i.next(); // get specials OrderProductPriceSpecial opps = oservice .getOrderProductPriceSpecial(opp.getOrderProductPrice()); if (opps != null) { ProductPriceSpecial pps = new ProductPriceSpecial(); pps.setOriginalPriceAmount(opps.getOriginalPrice()); pps.setProductPriceSpecialAmount(opps.getSpecialNewProductPrice()); pps.setProductPriceSpecialDurationDays(opps.getOrderProductSpecialDurationDays()); pps.setProductPriceSpecialEndDate(opps.getOrderProductSpecialEndDate()); pps.setProductPriceSpecialStartDate(opps.getOrderProductPriceSpecialStartDate()); opp.setSpecial(pps); } } } } catch (Exception e) { log.error(e); } return orderProduct; }