Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

In this page you can find the example usage for java.util HashSet add.

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:eu.cloudscale.showcase.generate.GenerateMongo.java

@Override
public void populateOrdersAndCC_XACTSTable() {
    GregorianCalendar cal;//from  w  w  w.  j  av a 2  s  .  c  o m
    String[] credit_cards = { "VISA", "MASTERCARD", "DISCOVER", "AMEX", "DINERS" };
    int num_card_types = 5;
    String[] ship_types = { "AIR", "UPS", "FEDEX", "SHIP", "COURIER", "MAIL" };
    int num_ship_types = 6;

    String[] status_types = { "PROCESSING", "SHIPPED", "PENDING", "DENIED" };
    int num_status_types = 4;

    // Order variables
    int O_C_ID;
    java.sql.Timestamp O_DATE;
    double O_SUB_TOTAL;
    double O_TAX;
    double O_TOTAL;
    String O_SHIP_TYPE;
    java.sql.Timestamp O_SHIP_DATE;
    int O_BILL_ADDR_ID, O_SHIP_ADDR_ID;
    String O_STATUS;

    String CX_TYPE;
    int CX_NUM;
    String CX_NAME;
    java.sql.Date CX_EXPIRY;
    String CX_AUTH_ID;
    int CX_CO_ID;

    System.out.println("Populating ORDERS, ORDER_LINES, CC_XACTS with " + NUM_ORDERS + " orders");

    System.out.print("Complete (in 10,000's): ");

    for (int i = 1; i <= NUM_ORDERS; i++) {
        if (i % 10000 == 0)
            System.out.print(i / 10000 + " ");

        int num_items = getRandomInt(1, 5);
        O_C_ID = getRandomInt(1, NUM_CUSTOMERS);
        cal = new GregorianCalendar();
        cal.add(Calendar.DAY_OF_YEAR, -1 * getRandomInt(1, 60));
        O_DATE = new java.sql.Timestamp(cal.getTime().getTime());
        O_SUB_TOTAL = (double) getRandomInt(1000, 999999) / 100;
        O_TAX = O_SUB_TOTAL * 0.0825;
        O_TOTAL = O_SUB_TOTAL + O_TAX + 3.00 + num_items;
        O_SHIP_TYPE = ship_types[getRandomInt(0, num_ship_types - 1)];
        cal.add(Calendar.DAY_OF_YEAR, getRandomInt(0, 7));
        O_SHIP_DATE = new java.sql.Timestamp(cal.getTime().getTime());

        O_BILL_ADDR_ID = getRandomInt(1, 2 * NUM_CUSTOMERS);
        O_SHIP_ADDR_ID = getRandomInt(1, 2 * NUM_CUSTOMERS);
        O_STATUS = status_types[getRandomInt(0, num_status_types - 1)];

        Orders order = new Orders();

        // Set parameter
        order.setOId(i);
        order.setCustomer(customerDao.findById(O_C_ID));
        order.setODate(new Date(O_DATE.getTime()));
        order.setOSubTotal(O_SUB_TOTAL);
        order.setOTax(O_TAX);
        order.setOTotal(O_TOTAL);
        order.setOShipType(O_SHIP_TYPE);
        order.setOShipDate(O_SHIP_DATE);
        order.setAddressByOBillAddrId(addressDao.findById(O_BILL_ADDR_ID));
        order.setAddressByOShipAddrId(addressDao.findById(O_SHIP_ADDR_ID));
        order.setOStatus(O_STATUS);
        order.setCcXactses(new HashSet<ICcXacts>());
        order.setOrderLines(new HashSet<IOrderLine>());

        for (int j = 1; j <= num_items; j++) {
            int OL_ID = j;
            int OL_O_ID = i;
            int OL_I_ID = getRandomInt(1, NUM_ITEMS);
            int OL_QTY = getRandomInt(1, 300);
            double OL_DISCOUNT = (double) getRandomInt(0, 30) / 100;
            String OL_COMMENTS = getRandomAString(20, 100);

            OrderLine orderLine = new OrderLine();
            orderLine.setOlId(OL_ID);
            orderLine.setItem(itemDao.findById(OL_I_ID));
            orderLine.setOlQty(OL_QTY);
            orderLine.setOlDiscount(OL_DISCOUNT);
            orderLine.setOlComment(OL_COMMENTS);
            orderLine.setOrders(order);

            orderLineDao.shrani(orderLine);

            HashSet<IOrderLine> set = new HashSet<IOrderLine>();
            set.add(orderLine);
            set.addAll(order.getOrderLines());

            order.setOrderLines(set);
            ordersDao.shrani(order);
        }

        CX_TYPE = credit_cards[getRandomInt(0, num_card_types - 1)];
        CX_NUM = getRandomNString(16);
        CX_NAME = getRandomAString(14, 30);
        cal = new GregorianCalendar();
        cal.add(Calendar.DAY_OF_YEAR, getRandomInt(10, 730));
        CX_EXPIRY = new java.sql.Date(cal.getTime().getTime());
        CX_AUTH_ID = getRandomAString(15);
        CX_CO_ID = getRandomInt(1, 92);

        CcXacts ccXacts = new CcXacts();
        ccXacts.setId(i);
        ccXacts.setCountry(countryDao.findById(CX_CO_ID));
        ccXacts.setCxType(CX_TYPE);
        ccXacts.setCxNum(CX_NUM);
        ccXacts.setCxName(CX_NAME);
        ccXacts.setCxExpiry(CX_EXPIRY);
        ccXacts.setCxAuthId(CX_AUTH_ID);
        ccXacts.setCxXactAmt(O_TOTAL);
        ccXacts.setCxXactDate(O_SHIP_DATE);

        ccXacts.setOrders(order);
        ccXactsDao.shrani(ccXacts);

        HashSet<ICcXacts> set = new HashSet<ICcXacts>();
        set.add(ccXacts);
        set.addAll(order.getCcXactses());

        order.setCcXactses(set);

        ordersDao.shrani(order);

    }

    System.out.println("");
}

From source file:adams.data.image.ImageMetaDataHelper.java

/**
 * Reads the meta-data from the file (Commons Imaging).
 *
 * @param file   the file to read the meta-data from
 * @return      the meta-data//from   w  ww. j  av  a  2s. c  o  m
 * @throws Exception   if failed to read meta-data
 */
public static SpreadSheet commons(File file) throws Exception {
    SpreadSheet sheet;
    Row row;
    org.apache.commons.imaging.common.ImageMetadata meta;
    String[] parts;
    String key;
    String value;
    org.apache.commons.imaging.ImageInfo info;
    String infoStr;
    String[] lines;
    HashSet<String> keys;

    sheet = new DefaultSpreadSheet();

    // header
    row = sheet.getHeaderRow();
    row.addCell("K").setContent("Key");
    row.addCell("V").setContent("Value");

    keys = new HashSet<String>();

    // meta-data
    meta = Imaging.getMetadata(file.getAbsoluteFile());
    if (meta != null) {
        for (Object item : meta.getItems()) {
            key = null;
            value = null;
            if (item instanceof ImageMetadata.Item) {
                key = ((ImageMetadata.Item) item).getKeyword().trim();
                value = ((ImageMetadata.Item) item).getText().trim();
            } else {
                parts = item.toString().split(": ");
                if (parts.length == 2) {
                    key = parts[0].trim();
                    value = parts[1].trim();
                }
            }
            if (key != null) {
                if (!keys.contains(key)) {
                    keys.add(key);
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(fixDateTime(Utils.unquote(value)));
                }
            }
        }
    }

    // image info
    info = Imaging.getImageInfo(file.getAbsoluteFile());
    if (info != null) {
        infoStr = info.toString();
        lines = infoStr.split(System.lineSeparator());
        for (String line : lines) {
            parts = line.split(": ");
            if (parts.length == 2) {
                key = parts[0].trim();
                value = parts[1].trim();
                if (!keys.contains(key)) {
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(Utils.unquote(value));
                    keys.add(key);
                }
            }
        }
    }

    return sheet;
}

From source file:com.tk.httpClientErp.headmancheck.Headmancheckqianshuzhi.java

/**
 * json/*from   w  w w  .  j  av  a 2 s.  c  om*/
 * 
 * @return
 */
private List<HashMap<String, Object>> classification(List<HashMap<String, Object>> jsontoList) {
    boolean initCompare = true; // true
    HashMap<String, Object> compareContainer = null; // 
    List<HashMap<String, Object>> fenzuList = new ArrayList<HashMap<String, Object>>();
    // 
    if (jsontoList.size() == 0)
        return fenzuList;
    // 
    HashSet<String> gd_no = new HashSet<String>();
    for (HashMap<String, Object> bean : jsontoList) {
        gd_no.add(bean.get("gd_no").toString());
    }
    //
    for (String gdstr : gd_no) {
        compareContainer = new HashMap<String, Object>();
        for (HashMap<String, Object> bean : jsontoList) {
            if (gdstr.equals(bean.get("gd_no").toString()) && initCompare) {
                compareContainer = bean;
                initCompare = false;
            } else if (gdstr.equals(bean.get("gd_no").toString())) {
                compareContainer = bean;
            }
        }
        compareContainer.put("mResult", false);
        fenzuList.add(compareContainer);
        initCompare = true;
    }
    return fenzuList;
}

From source file:adams.data.image.ImageMetaDataHelper.java

/**
 * Reads the meta-data from the file (using Sanselan).
 * /*ww w.j  av  a 2 s. com*/
 * @param file   the file to read the meta-data from
 * @return      the meta-data
 * @throws Exception   if failed to read meta-data
 */
public static SpreadSheet sanselan(File file) throws Exception {
    SpreadSheet sheet;
    Row row;
    org.apache.sanselan.common.IImageMetadata meta;
    String[] parts;
    String key;
    String value;
    org.apache.sanselan.ImageInfo info;
    String infoStr;
    String[] lines;
    HashSet<String> keys;

    sheet = new DefaultSpreadSheet();

    // header
    row = sheet.getHeaderRow();
    row.addCell("K").setContent("Key");
    row.addCell("V").setContent("Value");

    keys = new HashSet<String>();

    // meta-data
    meta = Sanselan.getMetadata(file.getAbsoluteFile());
    if (meta != null) {
        for (Object item : meta.getItems()) {
            key = null;
            value = null;
            if (item instanceof ImageMetadata.Item) {
                key = ((ImageMetadata.Item) item).getKeyword().trim();
                value = ((ImageMetadata.Item) item).getText().trim();
            } else {
                parts = item.toString().split(": ");
                if (parts.length == 2) {
                    key = parts[0].trim();
                    value = parts[1].trim();
                }
            }
            if (key != null) {
                if (!keys.contains(key)) {
                    keys.add(key);
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(fixDateTime(Utils.unquote(value)));
                }
            }
        }
    }

    // image info
    info = Sanselan.getImageInfo(file.getAbsoluteFile());
    if (info != null) {
        infoStr = info.toString();
        lines = infoStr.split(System.lineSeparator());
        for (String line : lines) {
            parts = line.split(": ");
            if (parts.length == 2) {
                key = parts[0].trim();
                value = parts[1].trim();
                if (!keys.contains(key)) {
                    row = sheet.addRow();
                    row.addCell("K").setContent(key);
                    row.addCell("V").setContent(Utils.unquote(value));
                    keys.add(key);
                }
            }
        }
    }

    return sheet;
}

From source file:org.magnum.mobilecloud.video.VideoSvcCtrl.java

@PreAuthorize("hasRole(USER)")
@RequestMapping(method = RequestMethod.POST, value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like")
public @ResponseBody void likeVideo(@PathVariable("id") long id, Principal principal,
        HttpServletResponse response) {/* w  w w.j av a 2s .c  o m*/
    Video v = videoRepo.findOne(id);
    if (v != null) {
        HashSet<String> likers = v.getLikers();
        if (likers.contains(principal.getName()))
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        else {
            likers.add(principal.getName());
            videoRepo.save(v);
            response.setStatus(HttpServletResponse.SC_OK);
        }
    } else
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.l2jfree.gameserver.model.skills.effects.templates.EffectTemplate.java

/**
 * Support for improved buffs, in case it gets overwritten in DP
 * /*from   w w  w.j  av  a2  s  .c o  m*/
 * @param skill
 * @param template
 * @return
 */
public boolean merge(L2Skill skill, EffectTemplate template) {
    if (!name.equals(template.name))
        return false;

    if (lambda != 0 || template.lambda != 0)
        return false;

    if (count != template.count || period != template.period)
        return false;

    if (effectPower != template.effectPower || effectType != template.effectType)
        return false;

    if (triggeredSkill != null || template.triggeredSkill != null)
        return false;

    if (chanceCondition != null || template.chanceCondition != null)
        return false;

    abnormalEffect |= template.abnormalEffect;
    specialEffect |= template.specialEffect;

    final HashSet<String> tmp = new HashSet<String>();

    for (String s : stackTypes)
        tmp.add(s);

    for (String s : template.stackTypes)
        tmp.add(s);

    stackTypes = tmp.toArray(new String[tmp.size()]);
    stackOrder = 99;

    showIcon = showIcon || template.showIcon;

    for (FuncTemplate f : template.funcTemplates)
        attach(f);

    _log.info("Effect templates merged for " + skill);
    return true;
}

From source file:com.stephengream.simplecms.authentication.SimpleCmsUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    CmsUser u = userDao.loadByUsername(username);
    if (u == null) {
        throw new UsernameNotFoundException(username + " not found");
    }/* w  w  w  .  j  a v a2 s  .c  om*/
    HashSet<GrantedAuthority> roles = new HashSet<>();
    try {
        final Set<Role> userRoles = u.getRoles();
        if (userRoles != null && userRoles.size() > 0) {
            for (Role role : userRoles) {
                roles.add(new SimpleGrantedAuthority(role.getRoleName()));
            }
        }
    } catch (Exception e) {
        Logger.getLogger(UserDetails.class.getName()).log(Logger.Level.INFO, e.getStackTrace());
    }

    return new User(u.getUsername(), u.getPassHash(), roles);
}

From source file:gov.nih.nci.ncicb.cadsr.common.security.LogoutServlet.java

private Set copyAllsessionKeys(HttpSession session) {
    log.error("LogoutServlet.copyAllsessionKeys end:" + TimeUtils.getEasternTime());
    HashSet set = new HashSet();
    Enumeration keys = session.getAttributeNames();
    for (; keys.hasMoreElements();) {
        String key = (String) keys.nextElement();
        set.add(key);
    }/*from  w w  w . j  a v  a2s  . com*/
    log.error("LogoutServlet.copyAllsessionKeys start:" + TimeUtils.getEasternTime());
    return set;
}

From source file:com.agileapes.couteau.maven.mojo.AbstractSpringPluginExecutor.java

/**
 * @return task definitions found in the application context. Note that only singleton beans are
 * loaded, and that these beans will be eagerly initialized for the purpose of this plugin.
 *//*from  w  w w .  j ava2  s.c o m*/
@Override
protected Collection<PluginTask<?>> getTasks() {
    final Map<String, PluginTask> beansOfType = applicationContext.getBeansOfType(PluginTask.class, false,
            true);
    final HashSet<PluginTask<?>> tasks = new HashSet<PluginTask<?>>();
    for (Map.Entry<String, PluginTask> entry : beansOfType.entrySet()) {
        final PluginTask task = entry.getValue();
        task.setName(entry.getKey());
        tasks.add(task);
    }
    return tasks;
}

From source file:RdfDataGenerationApplication.java

/**
 * This helper method is used for both web sites and database sources.
 * OpenCalais, Freebase, and DBpedia are used to add useful links.
 *
 * @param uri/*from   w w w  .  ja v a2  s.com*/
 * @param text
 * @param for_shared_properties
 * @throws Exception
 */
private void process_data_source(String uri, String text, Map<String, Set<String>> for_shared_properties)
        throws Exception {
    // OpenCalais:
    Map<String, List<String>> results = new OpenCalaisClient().getPropertyNamesAndValues(text);
    out.println("<" + uri
            + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://knowledgebooks.com/rdf/webpage> .");
    out.println(
            "<" + uri + "> <http://knowledgebooks.com/rdf/contents> \"" + text.replaceAll("\"", "'") + "\" .");
    if (results.get("Person") != null)
        for (String person : results.get("Person")) {
            out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPerson> \""
                    + person.replaceAll("\"", "'") + "\" .");
        }
    for (String key : results.keySet()) {
        System.out.println("  " + key + ": " + results.get(key));
        for (Object val : results.get(key)) {
            if (("" + val).length() > 0) {
                String property = "<http://knowledgebooks.com/rdf/" + key + ">";
                out.println("<" + uri + "> <http://knowledgebooks.com/rdf/" + key + "> \"" + val + "\" .");
                HashSet<String> hs = (HashSet<String>) for_shared_properties.get(property);
                if (hs == null)
                    hs = new HashSet<String>();
                hs.add("\"" + val + "\"");
                for_shared_properties.put("<http://knowledgebooks.com/rdf/" + key + ">", hs);
            }
        }
    }
    // Find search terms in text:
    ExtractSearchTerms extractor = new ExtractSearchTerms(text);
    System.out.println("Best search terms " + extractor.getBest());
    // Get people and place names in this web page's content:
    ScoredList[] ret = new ExtractNames().getProperNames(text);
    List<String> people = ret[0].getStrings();
    List<String> places = ret[1].getStrings();
    System.out.println("Human names: " + people);
    System.out.println("Place names: " + places);

    // Freebase:
    EntityToRdfHelpersFreebase.processPeople(out, uri, text, "person", people, extractor.getBest());
    EntityToRdfHelpersFreebase.processPlaces(out, uri, "place", places);

    // DBpedia:
    EntityToRdfHelpersDbpedia.processEntity(out, uri, "person", people, extractor.getBest(),
            processed_DBpedia_queries);
    EntityToRdfHelpersDbpedia.processEntity(out, uri, "place", places, extractor.getBest(),
            processed_DBpedia_queries);

    // process databases with D2R SPARQL endpoint front ends:
    new EntityToD2RHelpers(uri, database_config_file, people, places, out);

    shared_properties_for_all_sources.put(uri, for_shared_properties);
}