Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

In this page you can find the example usage for java.util Set iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:com.salesmanager.core.util.ProductUtil.java

public static String formatHTMLProductPrice(Locale locale, String currency, Product view,
        boolean showDiscountDate, boolean shortDiscountFormat) {

    if (currency == null) {
        log.error("Currency is null ...");
        return "-N/A-";
    }//ww w. ja  v a 2s .c  o m

    int decimalPlace = 2;

    String prefix = "";
    String suffix = "";

    Map currenciesmap = RefCache.getCurrenciesListWithCodes();
    Currency c = (Currency) currenciesmap.get(currency);

    // regular price
    BigDecimal bdprodprice = view.getProductPrice();

    Date dt = new Date();

    // discount price
    java.util.Date spdate = null;
    java.util.Date spenddate = null;
    BigDecimal bddiscountprice = null;
    Special special = view.getSpecial();
    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 = view.getPrices();
    if (prices != null) {
        Iterator pit = prices.iterator();
        while (pit.hasNext()) {
            ProductPrice pprice = (ProductPrice) pit.next();
            if (pprice.isDefaultPrice()) {
                pprice.setLocale(locale);
                suffix = pprice.getPriceSuffix();
                bddiscountprice = null;
                spdate = null;
                spenddate = null;
                bdprodprice = pprice.getProductPriceAmount();
                ProductPriceSpecial ppspecial = pprice.getSpecial();
                if (ppspecial != null) {
                    if (ppspecial.getProductPriceSpecialStartDate() != null
                            && ppspecial.getProductPriceSpecialEndDate() != null) {
                        spdate = ppspecial.getProductPriceSpecialStartDate();
                        spenddate = ppspecial.getProductPriceSpecialEndDate();
                    }
                    bddiscountprice = ppspecial.getProductPriceSpecialAmount();
                }
                break;
            }
        }
    }

    double fprodprice = 0;
    ;
    if (bdprodprice != null) {
        fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    // regular price String
    String regularprice = CurrencyUtil.displayFormatedCssAmountWithCurrency(bdprodprice, currency);

    // discount price String
    String discountprice = null;
    String savediscount = null;

    if (bddiscountprice != null && (spdate != null && spdate.before(new Date(dt.getTime()))
            && spenddate.after(new Date(dt.getTime())))) {

        double fdiscountprice = bddiscountprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue();

        discountprice = CurrencyUtil.displayFormatedAmountWithCurrency(bddiscountprice, currency);

        double arith = fdiscountprice / fprodprice;
        double fsdiscount = 100 - arith * 100;

        Float percentagediscount = new Float(fsdiscount);

        savediscount = String.valueOf(percentagediscount.intValue());

    }

    StringBuffer p = new StringBuffer();
    p.append("<div class='product-price'>");
    if (discountprice == null) {
        p.append("<div class='product-price-price' style='width:50%;float:left;'>");
        p.append(regularprice);
        if (!StringUtils.isBlank(suffix)) {
            p.append(suffix).append(" ");
        }
        p.append("</div>");
        p.append("<div class='product-line'>&nbsp;</div>");
    } else {
        p.append("<div style='width:50%;float:left;'>");
        p.append("<strike>").append(regularprice);
        if (!StringUtils.isBlank(suffix)) {
            p.append(suffix).append(" ");
        }
        p.append("</strike>");
        p.append("</div>");
        p.append("<div style='width:50%;float:right;'>");
        p.append("<font color='red'>").append(discountprice);
        if (!StringUtils.isBlank(suffix)) {
            p.append(suffix).append(" ");
        }
        p.append("</font>");
        if (!shortDiscountFormat) {
            p.append("<br>").append("<font color='red' style='font-size:75%;'>")
                    .append(LabelUtil.getInstance().getText(locale, "label.generic.save")).append(": ")
                    .append(savediscount)
                    .append(LabelUtil.getInstance().getText(locale, "label.generic.percentsign")).append(" ")
                    .append(LabelUtil.getInstance().getText(locale, "label.generic.off")).append("</font>");
        }

        if (showDiscountDate && spenddate != null) {
            p.append("<br>").append(" <font style='font-size:65%;'>")
                    .append(LabelUtil.getInstance().getText(locale, "label.generic.until")).append("&nbsp;")
                    .append(DateUtil.formatDate(spenddate)).append("</font>");
        }

        p.append("</div>").toString();
    }
    p.append("</div>");
    return p.toString();

}

From source file:com.salesmanager.core.util.ProductUtil.java

public static String getProductName(Product product, Locale locale) {

    try {//from w  ww  .  j a v  a2  s  .  co m

        Set descriptionset = product.getDescriptions();
        int lang = LanguageUtil.getLanguageNumberCode(locale.getLanguage());
        if (descriptionset != null) {
            Iterator i = descriptionset.iterator();
            while (i.hasNext()) {
                ProductDescription desc = (ProductDescription) i.next();
                if (desc.getId().getLanguageId() == lang) {
                    return desc.getProductName();
                }
            }
        }

    } catch (Exception e) {
        log.error(e);
    }

    return "";

}

From source file:bc8.movies.dao.ActorDaoImpl.java

public void addActors(Set<Actor> toAdd) {
    Iterator<Actor> it = toAdd.iterator();

    while (it.hasNext()) {
        Actor currActor = it.next();//from   w  w  w.  ja v  a2s  . c  om
        em.persist(currActor);
    }
}

From source file:com.act.lcms.db.analysis.Utils.java

/**
 * Finds all chemical targets for a set of LCMS wells.  Throws an IllegalArgumentException if more than one targets
 * are shared by the wells./* w ww  .jav  a 2s  . co m*/
 * @param db The DB to query for information about the wells/targets.
 * @param wells A set of wells whose targets to scan.
 * @return The single shared target of all the wells, or null.
 * @throws SQLException
 * @throws IllegalArgumentException Thrown when the wells share more than one target chemical.
 */
public static CuratedChemical requireOneTarget(DB db, List<LCMSWell> wells)
        throws SQLException, IllegalArgumentException {
    Set<CuratedChemical> chemicals = extractTargetsForWells(db, wells);
    if (chemicals.size() > 1) {
        // TODO: is there a foreach approach that we can use here that won't break backwards compatibility?
        List<String> chemicalNames = new ArrayList<>(chemicals.size());
        for (CuratedChemical chemical : chemicals) {
            chemicalNames.add(chemical.getName());
        }
        throw new IllegalArgumentException(
                String.format("Found multiple target chemicals where one required: %s",
                        StringUtils.join(chemicalNames, ", ")));
    } else if (chemicals.size() < 1) {
        return null;
    }
    return chemicals.iterator().next();
}

From source file:com.salesmanager.core.util.ProductUtil.java

/**
 * Format like <blue>[if discount striked]SYMBOL BASEAMOUNT</blue> [if
 * discount <red>SYMBOL DISCOUNTAMOUNT</red>] [if discount <red>Save:
 * PERCENTAGE AMOUNT</red>] [if qty discount <red>Buy QTY save [if price qty
 * discount AMOUNT] [if percent qty discount PERCENT]</red>]
 * //w w  w  .  j  a v  a 2 s.c  o  m
 * @param ctx
 * @param view
 * @return
 */
public static String formatHTMLProductPriceWithAttributes(Locale locale, String currency, Product view,
        Collection attributes, boolean showDiscountDate) {

    if (currency == null) {
        log.error("Currency is null ...");
        return "-N/A-";
    }

    int decimalPlace = 2;

    String prefix = "";
    String suffix = "";

    Map currenciesmap = RefCache.getCurrenciesListWithCodes();
    Currency c = (Currency) currenciesmap.get(currency);

    // regular price
    BigDecimal bdprodprice = view.getProductPrice();

    // 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 (attributesPrice != null) {
        bdprodprice = bdprodprice.add(attributesPrice);// new price with
        // properties
    }

    // discount price
    java.util.Date spdate = null;
    java.util.Date spenddate = null;
    BigDecimal bddiscountprice = null;
    Special special = view.getSpecial();
    if (special != null) {
        bddiscountprice = special.getSpecialNewProductPrice();
        if (attributesPrice != null) {
            bddiscountprice = bddiscountprice.add(attributesPrice);// new
            // price
            // with
            // properties
        }
        spdate = special.getSpecialDateAvailable();
        spenddate = special.getExpiresDate();
    }

    // all other prices
    Set prices = view.getPrices();
    if (prices != null) {
        Iterator pit = prices.iterator();
        while (pit.hasNext()) {
            ProductPrice pprice = (ProductPrice) pit.next();
            if (pprice.isDefaultPrice()) {
                pprice.setLocale(locale);
                suffix = pprice.getPriceSuffix();
                bddiscountprice = null;
                spdate = null;
                spenddate = null;
                bdprodprice = pprice.getProductPriceAmount();
                if (attributesPrice != null) {
                    bdprodprice = bdprodprice.add(attributesPrice);// new
                    // price
                    // with
                    // properties
                }
                ProductPriceSpecial ppspecial = pprice.getSpecial();
                if (ppspecial != null) {
                    if (ppspecial.getProductPriceSpecialStartDate() != null
                            && ppspecial.getProductPriceSpecialEndDate() != null) {
                        spdate = ppspecial.getProductPriceSpecialStartDate();
                        spenddate = ppspecial.getProductPriceSpecialEndDate();
                    }
                    bddiscountprice = ppspecial.getProductPriceSpecialAmount();
                    if (bddiscountprice != null && attributesPrice != null) {
                        bddiscountprice = bddiscountprice.add(attributesPrice);// new price with
                        // properties
                    }
                }
                break;
            }
        }
    }

    double fprodprice = 0;
    ;
    if (bdprodprice != null) {
        fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    // regular price String
    String regularprice = CurrencyUtil.displayFormatedCssAmountWithCurrency(bdprodprice, currency);

    Date dt = new Date();

    // discount price String
    String discountprice = null;
    String savediscount = null;
    if (bddiscountprice != null && (spdate != null && spdate.before(new Date(dt.getTime()))
            && spenddate.after(new Date(dt.getTime())))) {

        double fdiscountprice = bddiscountprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue();

        discountprice = CurrencyUtil.displayFormatedAmountWithCurrency(bddiscountprice, currency);

        double arith = fdiscountprice / fprodprice;
        double fsdiscount = 100 - arith * 100;

        Float percentagediscount = new Float(fsdiscount);

        savediscount = String.valueOf(percentagediscount.intValue());

    }

    StringBuffer p = new StringBuffer();
    p.append("<div class='product-price'>");
    if (discountprice == null) {
        p.append("<div class='product-price-price' style='width:50%;float:left;'>");
        p.append(regularprice);
        if (!StringUtils.isBlank(suffix)) {
            p.append(suffix).append(" ");
        }
        p.append("</div>");
        p.append("<div class='product-line'>&nbsp;</div>");
    } else {
        p.append("<div style='width:50%;float:left;'>");
        p.append("<strike>").append(regularprice);
        if (!StringUtils.isBlank(suffix)) {
            p.append(suffix).append(" ");
        }
        p.append("</strike>");
        p.append("</div>");
        p.append("<div style='width:50%;float:right;'>");
        p.append("<font color='red'>").append(discountprice);
        if (!StringUtils.isBlank(suffix)) {
            p.append(suffix).append(" ");
        }
        p.append("</font>").append("<br>").append("<font color='red' style='font-size:75%;'>")
                .append(LabelUtil.getInstance().getText(locale, "label.generic.save")).append(": ")
                .append(savediscount)
                .append(LabelUtil.getInstance().getText(locale, "label.generic.percentsign")).append(" ")
                .append(LabelUtil.getInstance().getText(locale, "label.generic.off")).append("</font>");

        if (showDiscountDate && spenddate != null) {
            p.append("<br>").append(" <font style='font-size:65%;'>")
                    .append(LabelUtil.getInstance().getText(locale, "label.generic.until")).append("&nbsp;")
                    .append(DateUtil.formatDate(spenddate)).append("</font>");
        }

        p.append("</div>").toString();
    }
    p.append("</div>");
    return p.toString();

}

From source file:com.discursive.jccook.collections.predicate.XPathPredicate.java

private void populateVariables(JXPathContext context) {
    Set keys = variables.keySet();
    Iterator keyIter = keys.iterator();
    while (keyIter.hasNext()) {
        String key = (String) keyIter.next();
        context.getVariables().declareVariable(key, variables.get(key));
    }//w  w w . j a va2s.  c o  m
}

From source file:com.discursive.jccook.collections.bag.BagExample.java

private void printAlbums(Bag albumBag) {
    Set albums = albumBag.uniqueSet();
    Iterator albumIterator = albums.iterator();
    while (albumIterator.hasNext()) {
        Album album = (Album) albumIterator.next();
        NumberFormat format = NumberFormat.getInstance();
        format.setMinimumIntegerDigits(3);
        format.setMaximumFractionDigits(0);
        System.out.println("\t" + format.format(albumBag.getCount(album)) + " - " + album.getBand());
    }//from w w  w . j a  v a2s . c  o  m
}

From source file:com.att.archive.restful.query.GroupSolrQueryHandler.java

private Query createGroupOptions(Set<String> group) {
    Query qCriteria = new SimpleQuery();
    Iterator<String> itr = group.iterator();
    while (itr.hasNext()) {
        qCriteria.addGroupByField(new SimpleField(itr.next()));
    }/*from   w ww  . j  a  v a2s . c  o m*/
    return qCriteria;
}

From source file:net.datenwerke.transloader.clone.reflect.internal.MapClonesOperation.java

private void mapClonesFrom(Set originals) throws Exception {
    for (Iterator iterator = originals.iterator(); iterator.hasNext();)
        mapCloneFrom(iterator.next());/*from   w ww  .jav  a 2s  . co m*/
}

From source file:importer.handler.post.importer.JDocWrapper.java

/**
 * Construct the wrapper/*from w w w . j  ava2  s. c  o m*/
 * @param body the raw data 
 * @param params a map of key-value pairs
 */
public JDocWrapper(String body, Map<String, String> params) {
    jdoc = new JSONObject();
    jdoc.put(JSONKeys.BODY, Utils.cleanCR(body, false));
    Set<String> keys = params.keySet();
    Iterator<String> iter = keys.iterator();
    while (iter.hasNext()) {
        String key = iter.next();
        String value = params.get(key);
        if (isValidKey(key)) {
            jdoc.put(key, Utils.cleanCR(value, false));
        }
    }
}