List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:com.salesmanager.core.util.ProductUtil.java
public static BigDecimal determinePrice(Product product, Locale locale, String currency) { int decimalPlace = 2; Map currenciesmap = RefCache.getCurrenciesListWithCodes(); Currency c = (Currency) currenciesmap.get(currency); // prices// w w w .j a v a2 s. c o m BigDecimal bdprodprice = product.getProductPrice(); BigDecimal bddiscountprice = null; // discount price Special special = product.getSpecial(); java.util.Date spdate = null; java.util.Date spenddate = null; if (special != null) { bddiscountprice = special.getSpecialNewProductPrice(); spdate = special.getSpecialDateAvailable(); spenddate = special.getExpiresDate(); } Date dt = new Date(); // 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); if (pprice.isDefaultPrice()) {// overwrites default price bddiscountprice = null; spdate = null; spenddate = null; bdprodprice = pprice.getProductPriceAmount(); ProductPriceSpecial ppspecial = pprice.getSpecial(); if (ppspecial != null) { if (ppspecial.getProductPriceSpecialStartDate() != null && ppspecial.getProductPriceSpecialEndDate() != null && ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime())) && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } } break; } } } double fprodprice = 0; if (bdprodprice != null) { fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue(); } if (bddiscountprice != null) { return bddiscountprice; } else { return bdprodprice; } }
From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java
/** * Given a vendor, src local, & targ locale, return a hashtable of it's * activities where the key is an activity and the value is it's rate. *//*from w ww . j a v a 2 s . c o m*/ public static HashMap getSelectedActivities(Vendor vendor, GlobalSightLocale srcLocale, GlobalSightLocale targLocale) throws EnvoyServletException { HashMap selectedActivities = new HashMap(); boolean isCostingEnabled = false; try { SystemConfiguration sc = SystemConfiguration.getInstance(); isCostingEnabled = sc.getBooleanParameter(SystemConfigParamNames.COSTING_ENABLED); } catch (Exception e) { } if (isCostingEnabled == false) return selectedActivities; Set roles = vendor.getRoles(); for (Iterator r = roles.iterator(); r.hasNext();) { VendorRole role = (VendorRole) r.next(); LocalePair lp = role.getLocalePair(); if (lp.getSource().equals(srcLocale) && lp.getTarget().equals(targLocale)) { long id = -1; if (role.getRate() != null) { id = role.getRate().getId(); } selectedActivities.put(role.getActivity().getName(), new Long(id)); } } return selectedActivities; }
From source file:com.salesmanager.core.util.CheckoutUtil.java
/** * OrderProductAttribute is configured from javascript This code needs to * invoke catalog objects because it requires getProductOptionValueId, will * not change any price Add attributes to product, add attribute offset * price to original product price/*w w w. j a va 2s . c om*/ * * @param attributes * @param lineId * @param currency * @param request * @return * @throws Exception */ public static OrderProduct addAttributesFromRawObjects(List<OrderProductAttribute> attributes, long productId, String lineId, String currency, HttpServletRequest request) throws Exception { Locale loc = request.getLocale(); String lang = loc.getLanguage(); HttpSession session = request.getSession(); Map cartLines = SessionUtil.getOrderProducts(request); if (cartLines == null) { throw new Exception("No OrderProduct exixt yet, cannot assign attributes"); } OrderProduct scp = (OrderProduct) cartLines.get(lineId); if (scp == null) { throw new Exception("No OrderProduct exixt for lineId " + lineId); } CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); BigDecimal sumPrice = null; // make sure OrderProduct and productId match if (scp.getProductId() == productId) { 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(productId, 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 { // double pr = sumPrice.doubleValue() + // attrPrice.doubleValue(); // sumPrice = new // BigDecimal(sumPrice.doubleValue() + // attrPrice.doubleValue()); BigDecimal currentPrice = sumPrice; sumPrice = currentPrice.add(attrPrice); } } // opa.setOrderId(Long.parseLong(orderId)); opa.setOrderProductId(productId); 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())); scp.setAttributeAdditionalCost(sumPrice);// add additional // attribute // price // 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:cn.fql.utility.StringUtility.java
/** * Convert map keys to Uppercase or Lowercase * * @param map map to be converted/*from ww w .j a v a 2 s .c om*/ * @param upperIt uppercase of lowercase * @return new map with converted keys */ public static Map upperMapKey(Map map, boolean upperIt) { if (map == null) { return null; } Set keys = map.keySet(); Map map2 = new HashMap(); for (Iterator iterator = keys.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); Object o = map.get(key); if (upperIt) { key = key.toUpperCase(); } else { key = key.toLowerCase(); } map2.put(key, o); } return map2; }
From source file:com.salesmanager.core.util.ProductUtil.java
public static BigDecimal determinePriceWithAttributes(Product product, Collection attributes, Locale locale, String currency) {/*from w w w . j a va 2 s . c o m*/ int decimalPlace = 2; Map currenciesmap = RefCache.getCurrenciesListWithCodes(); Currency c = (Currency) currenciesmap.get(currency); // prices BigDecimal bdprodprice = product.getProductPrice(); BigDecimal bddiscountprice = null; // discount price Special special = product.getSpecial(); Date dt = new Date(); java.util.Date spdate = null; java.util.Date spenddate = null; if (special != null) { spdate = special.getSpecialDateAvailable(); spenddate = special.getExpiresDate(); if (spdate.before(new Date(dt.getTime())) && spenddate.after(new Date(dt.getTime()))) { bddiscountprice = special.getSpecialNewProductPrice(); } } // 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); if (pprice.isDefaultPrice()) {// overwrites default price bddiscountprice = null; spdate = null; spenddate = null; bdprodprice = pprice.getProductPriceAmount(); ProductPriceSpecial ppspecial = pprice.getSpecial(); if (ppspecial != null) { if (ppspecial.getProductPriceSpecialStartDate() != null && ppspecial.getProductPriceSpecialEndDate() != null && ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime())) && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } } break; } } } double fprodprice = 0; ; if (bdprodprice != null) { fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue(); } // determine any properties prices 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 (bddiscountprice != null) { if (attributesPrice != null) { bddiscountprice = bddiscountprice.add(attributesPrice); } return bddiscountprice; } else { if (attributesPrice != null) { bdprodprice = bdprodprice.add(attributesPrice); } return bdprodprice; } }
From source file:com.aurel.track.util.GeneralUtils.java
/** * Creates a sorted Set of Integers from an array of ints * @param arrIDs/*from www . j a v a2s .c om*/ * @return */ public static int[] createIntArrFromSet(Set<Integer> integersSet) { if (integersSet == null) { return null; } int[] intArrIDs = new int[integersSet.size()]; Iterator<Integer> iterator = integersSet.iterator(); int i = 0; while (iterator.hasNext()) { intArrIDs[i++] = iterator.next().intValue(); } return intArrIDs; }
From source file:com.aurel.track.util.GeneralUtils.java
/** * Creates an array of Integers from an Set of Integers * @param arrIDs/* w ww .j av a 2 s . c om*/ * @return */ public static Integer[] createIntegerArrFromSet(Set<Integer> integerSet) { if (integerSet == null) { return null; } Integer[] intArr = new Integer[integerSet.size()]; Iterator<Integer> iterator = integerSet.iterator(); int i = 0; while (iterator.hasNext()) { intArr[i++] = iterator.next(); } return intArr; }
From source file:de.mpg.escidoc.pubman.util.CommonUtils.java
/** * Converts a Set to an Array of SelectItems. This method is used to convert Enums into SelectItems for dropDownLists. * @param set the Set to be converted/*from w w w. j a va 2 s . c o m*/ * @param includeEmptyOption if TRUE an empty SelectItem is added at the beginning of the list * @return an Array of SelectItems */ public static SelectItem[] convertToOptions(Set set, boolean includeEmptyOption) { List<SelectItem> options = new ArrayList<SelectItem>(); if (includeEmptyOption) { options.add(new SelectItem("", NO_ITEM_SET)); } Iterator iter = set.iterator(); while (iter.hasNext()) { options.add(new SelectItem(iter.next())); } return (SelectItem[]) options.toArray(new SelectItem[options.size()]); }
From source file:it.baywaylabs.jumpersumo.utility.Finder.java
public static int[] toPrimitive(Set<Integer> integerSet) { int[] result = new int[integerSet.size()]; int i = 0;/* w w w . j av a2 s. c o m*/ for (Iterator<Integer> it = integerSet.iterator(); it.hasNext();) { Integer f = it.next(); result[i] = f; i++; } return result; }
From source file:HttpServerDemo.java
public void handle(HttpExchange exchange) throws IOException { String requestMethod = exchange.getRequestMethod(); if (requestMethod.equalsIgnoreCase("GET")) { Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type", "text/plain"); exchange.sendResponseHeaders(200, 0); OutputStream responseBody = exchange.getResponseBody(); Headers requestHeaders = exchange.getRequestHeaders(); Set<String> keySet = requestHeaders.keySet(); Iterator<String> iter = keySet.iterator(); while (iter.hasNext()) { String key = iter.next(); List values = requestHeaders.get(key); String s = key + " = " + values.toString() + "\n"; responseBody.write(s.getBytes()); }//from w w w .j av a 2 s.c o m responseBody.close(); } }