List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:org.apache.solr.analytics.facet.AbstractAnalyticsFacetCloudTest.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public <T extends Comparable<T>> ArrayList calculateStat(ArrayList<ArrayList<T>> lists, String stat) { ArrayList result;// w w w. ja v a 2 s. c o m if (stat.contains("perc_")) { result = new ArrayList<T>(); for (List<T> list : lists) { if (list.size() == 0) continue; int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5)) / 100 * list.size()) - 1; ArrayList<Integer> percs = new ArrayList<>(1); percs.add(ord); OrdinalCalculator.putOrdinalsInPosition(list, percs); result.add(list.get(ord)); } } else if (stat.equals("count")) { result = new ArrayList<Long>(); for (List<T> list : lists) { result.add((long) list.size()); } } else if (stat.equals("missing")) { result = new ArrayList<Long>(); for (ArrayList<T> list : lists) { result.add(calculateMissing(list, latestType)); } } else if (stat.equals("unique")) { result = new ArrayList<Long>(); for (List<T> list : lists) { HashSet<T> set = new HashSet<>(); set.addAll(list); result.add((long) set.size()); } } else if (stat.equals("max")) { result = new ArrayList<T>(); for (List<T> list : lists) { if (list.size() == 0) continue; Collections.sort(list); result.add(list.get(list.size() - 1)); } } else if (stat.equals("min")) { result = new ArrayList<T>(); for (List<T> list : lists) { if (list.size() == 0) continue; Collections.sort((List<T>) list); result.add(list.get(0)); } } else { result = null; } return result; }
From source file:jsentvar.GenerateTestsResults.java
public void substitutionOneTermResult() throws IOException { RDFReader lector = new RDFReader(); String filename;//from w w w.ja va2 s .c o m //filename = "resources/test/miniReasoner.owl"; filename = "resources/IEEE_reasoner20022016.owl"; //String term_value = term_value0.substring(0, 1).toUpperCase() +term_value0.substring(1); model = lector.reader(filename); //Read positions, a json file String possFile = "resources/test/text_doc0.json"; JsonReader jreader = new JsonReader(); HashMap<String, HashMap<Integer, Integer>> poss = jreader.reader(possFile); ArrayList<String> terms1 = new ArrayList<>(); Set originS = poss.keySet(); terms1.addAll(originS); //Get all the terms for substitution Surrogate sur = new Surrogate(model); HashMap<String, ArrayList<String>> alternatives; Utils utils = new Utils(); ArrayList<String> terms = utils.firstUpperForeach(terms1); alternatives = sur.surrogatesForeach(terms); String docFile = "resources/tex_doc0.txt"; String doc = FileUtils.readFileToString(new File(docFile), "utf8"); Substitution gen = new Substitution(); HashSet newDocs = new HashSet(); for (String term : terms) { //System.out.println(term); HashSet newDocs0 = gen.oneTerm(doc, term, alternatives.get(term)); newDocs.addAll(newDocs0); } FileUtils.writeStringToFile(new File("resources/test/substitutionOneTermResult.txt"), newDocs.toString(), "utf8"); }
From source file:org.apache.tika.parser.ner.NamedEntityParserTest.java
@Test public void testParse() throws Exception { //test config is added to resources directory TikaConfig config = new TikaConfig(getClass().getResourceAsStream(CONFIG_FILE)); Tika tika = new Tika(config); JSONParser parser = new JSONParser(); String text = ""; HashMap<Integer, String> hmap = new HashMap<Integer, String>(); HashMap<String, HashMap<Integer, String>> outerhmap = new HashMap<String, HashMap<Integer, String>>(); int index = 0; //Input Directory Path String inputDirPath = "/Users/AravindMac/Desktop/polardata_json_grobid/application_pdf"; int count = 0; try {//from ww w . ja v a2 s.co m File root = new File(inputDirPath); File[] listDir = root.listFiles(); for (File filename : listDir) { if (!filename.getName().equals(".DS_Store") && count < 3573) { count += 1; System.out.println(count); String absoluteFilename = filename.getAbsolutePath().toString(); // System.out.println(absoluteFilename); //Read the json file, parse and retrieve the text present in the content field. Object obj = parser.parse(new FileReader(absoluteFilename)); BufferedWriter bw = new BufferedWriter(new FileWriter(new File(absoluteFilename))); JSONObject jsonObject = (JSONObject) obj; text = (String) jsonObject.get("content"); Metadata md = new Metadata(); tika.parse(new ByteArrayInputStream(text.getBytes()), md); //Parse the content and retrieve the values tagged as the NER entities HashSet<String> set = new HashSet<String>(); set.addAll(Arrays.asList(md.getValues("X-Parsed-By"))); // Store values tagged as NER_PERSON set.clear(); set.addAll(Arrays.asList(md.getValues("NER_PERSON"))); hmap = new HashMap<Integer, String>(); index = 0; for (Iterator<String> i = set.iterator(); i.hasNext();) { String f = i.next(); hmap.put(index, f); index++; } if (!hmap.isEmpty()) { outerhmap.put("PERSON", hmap); } // Store values tagged as NER_LOCATION set.clear(); set.addAll(Arrays.asList(md.getValues("NER_LOCATION"))); hmap = new HashMap<Integer, String>(); index = 0; for (Iterator<String> i = set.iterator(); i.hasNext();) { String f = i.next(); hmap.put(index, f); index++; } if (!hmap.isEmpty()) { outerhmap.put("LOCATION", hmap); } //Store values tagged as NER_ORGANIZATION set.clear(); set.addAll(Arrays.asList(md.getValues("NER_ORGANIZATION"))); hmap = new HashMap<Integer, String>(); index = 0; for (Iterator<String> i = set.iterator(); i.hasNext();) { String f = i.next(); hmap.put(index, f); index++; } if (!hmap.isEmpty()) { outerhmap.put("ORGANIZATION", hmap); } // Store values tagged as NER_DATE set.clear(); set.addAll(Arrays.asList(md.getValues("NER_DATE"))); hmap = new HashMap<Integer, String>(); index = 0; for (Iterator<String> i = set.iterator(); i.hasNext();) { String f = i.next(); hmap.put(index, f); index++; } if (!hmap.isEmpty()) { outerhmap.put("DATE", hmap); } JSONArray array = new JSONArray(); array.put(outerhmap); if (!outerhmap.isEmpty()) { jsonObject.put("OpenNLP", array); //Add the NER entities to the json under NER key as a JSON array. } System.out.println(jsonObject); bw.write(jsonObject.toJSONString()); //Stringify thr JSON and write it back to the file bw.close(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.cloudscale.showcase.generate.GenerateMongo.java
@Override public void populateOrdersAndCC_XACTSTable() { GregorianCalendar cal;/*from w w w . j a va2s .co 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:org.apache.hadoop.hbase.regionserver.TestFlashBackQueryCompaction.java
@Test public void testCornerCaseTTL() throws Exception { HTable table = setupTable(30, 20, 100); byte[] row = new byte[10]; Put put = new Put(row); KeyValue kv1 = new KeyValue(row, families[0], null, 10000, row); KeyValue kv2 = new KeyValue(row, families[0], null, 9999, row); put.add(kv1);// w w w . ja v a2s . c o m put.add(kv2); table.put(put); flushAllRegions(); majorCompact(table.getTableName(), table.getTableDescriptor().getColumnFamilies()); // Get all kvs. setStoreProps(table.getTableName(), table.getTableDescriptor().getColumnFamilies(), false); Scan scan = new Scan(row); scan.setMaxVersions(); HashSet<KeyValue> kvSet = new HashSet<KeyValue>(); for (Result result : table.getScanner(scan)) { kvSet.addAll(result.list()); } assertTrue(kvSet.contains(kv1)); assertFalse(kvSet.contains(kv2)); }
From source file:org.dataconservancy.packaging.tool.model.dprofile.DomainProfile.java
/** * Generates a hashcode for the DomainProfile NodeTypes are excluded from the hashcode to eliminate recursive issues. * Note: Lists are converted to HashSets to make them order independent. * @return The hashcode of this DomainProfile object. *///from w w w . ja va 2 s . c o m @Override public int hashCode() { HashSet<PropertyType> propertyTypeSet = null; if (prop_types != null) { propertyTypeSet = new HashSet<>(); propertyTypeSet.addAll(prop_types); } HashSet<PropertyCategory> propertyCategorySet = null; if (prop_categories != null) { propertyCategorySet = new HashSet<>(); propertyCategorySet.addAll(prop_categories); } HashSet<NodeTransform> nodeTransformSet = null; if (node_transforms != null) { nodeTransformSet = new HashSet<>(); nodeTransformSet.addAll(node_transforms); } final int prime = 31; int result = super.hashCode(); result = prime * result + ((domain_id == null) ? 0 : domain_id.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((nodeTransformSet == null) ? 0 : nodeTransformSet.hashCode()); result = prime * result + ((propertyCategorySet == null) ? 0 : propertyCategorySet.hashCode()); result = prime * result + ((propertyTypeSet == null) ? 0 : propertyTypeSet.hashCode()); return result; }
From source file:org.apache.hadoop.hbase.regionserver.TestFlashBackQueryCompaction.java
@Test public void testCornerCaseMaxVersions() throws Exception { HTable table = setupTable(30, 20, 2); byte[] row = new byte[10]; Put put = new Put(row); KeyValue kv1 = new KeyValue(row, families[0], null, 50000, row); KeyValue kv2 = new KeyValue(row, families[0], null, 40000, row); KeyValue kv3 = new KeyValue(row, families[0], null, 15000, row); KeyValue kv4 = new KeyValue(row, families[0], null, 10000, row); put.add(kv1);/*www . jav a 2s . c o m*/ put.add(kv2); put.add(kv3); put.add(kv4); table.put(put); flushAllRegions(); majorCompact(table.getTableName(), table.getTableDescriptor().getColumnFamilies()); // Get all kvs. setStoreProps(table.getTableName(), table.getTableDescriptor().getColumnFamilies(), false); Scan scan = new Scan(row); scan.setMaxVersions(); HashSet<KeyValue> kvSet = new HashSet<KeyValue>(); for (Result result : table.getScanner(scan)) { kvSet.addAll(result.list()); } assertTrue(kvSet.contains(kv1)); assertTrue(kvSet.contains(kv2)); assertTrue(kvSet.contains(kv3)); assertFalse(kvSet.contains(kv4)); }
From source file:dude.morrildl.weatherport.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // this gets a little hairy, but each class is too trivial to bother // moving to its own file; but together they add up to be a little // irritating. So it goes. // first we need to inflate the View for the Action Bar operations, and // then set click handlers on them. This one is is the add-new-airport // dialog,// w ww .jav a2 s .c o m // which cascades a bit getMenuInflater().inflate(R.menu.main, menu); menu.findItem(R.id.action_add).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // yo dawg, I hurd you like callbacks LayoutInflater inflater = MainActivity.this.getLayoutInflater(); View v = inflater.inflate(R.layout.dialog, null); final EditText et = (EditText) v.findViewById(R.id.dialog_input); // this is the // "enter a new airport code to add to the list" dialog AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog dialog = builder.setTitle(R.string.dialog_title).setIcon(R.drawable.ic_launcher) .setView(v).setPositiveButton(R.string.dialog_pos, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newAirport = et.getText().toString().toUpperCase(); SharedPreferences prefs = MainActivity.this.getSharedPreferences("prefs", Context.MODE_PRIVATE); Set<String> currentList = prefs.getStringSet("airports", new HashSet<String>()); HashSet<String> newSet = new HashSet<String>(); newSet.addAll(currentList); newSet.add(newAirport); prefs.edit().putStringSet("airports", newSet).commit(); ArrayList<String> newList = new ArrayList<String>(); newList.addAll(newSet); Collections.sort(newList); adapter.clear(); adapter.addAll(newList); // I N C E P T I O N } }).setNegativeButton(R.string.dialog_neg, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).create(); et.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean focused) { if (focused) { dialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); dialog.show(); return true; } }); // ...and this one launches our FOSS compliance screen. menu.findItem(R.id.action_settings).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(); intent.setClass(MainActivity.this, AboutActivity.class); MainActivity.this.startActivity(intent); return true; } }); return true; }
From source file:com.celements.web.plugin.cmd.DocFormCommand.java
public Set<XWikiDocument> updateDocFromMap(String fullname, Map<String, String[]> data, XWikiContext context) throws XWikiException { String docSpace = fullname.split("\\.")[0]; String docName = fullname.split("\\.")[1]; DocumentReference docRef = new DocumentReference(context.getDatabase(), docSpace, docName); XWikiDocument doc = context.getWiki().getDocument(docRef, context); String template = context.getRequest().getParameter("template"); if (doc.isNew() && !"".equals(template.trim())) { String templSpace = template.split("\\.")[0]; String templName = template.split("\\.")[1]; DocumentReference templRef = new DocumentReference(context.getDatabase(), templSpace, templName); try {/*from w w w . j av a 2 s . c om*/ doc.readFromTemplate(templRef, context); } catch (XWikiException e) { if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) { context.put("exception", e); } LOGGER.error("Exception reading doc " + docRef + " from template " + templRef, e); } } for (String key : data.keySet()) { if (key != null) { String[] parts = getDocFullname(key, docSpace, docName); DocumentReference saveDocRef = new DocumentReference(context.getDatabase(), parts[0], parts[1]); LOGGER.debug("request key:'" + key + "'=value:" + data.get(key).length); if (key.matches("([a-zA-Z0-9]*\\.[a-zA-Z0-9]*_)?content")) { XWikiDocument tdoc = getTranslatedDoc(saveDocRef, context); tdoc.setContent(collapse(data.get(key))); } else if (key.matches("([a-zA-Z0-9]*\\.[a-zA-Z0-9]*_)?title")) { XWikiDocument tdoc = getTranslatedDoc(saveDocRef, context); tdoc.setTitle(collapse(data.get(key))); } else if (key.matches(getFindObjectFieldInRequestRegex())) { XWikiDocument saveDoc = getUpdateDoc(saveDocRef, context); setObjValue(saveDoc, parts[2], data.get(key), context); } } } HashSet<XWikiDocument> docSet = new HashSet<XWikiDocument>(); docSet.addAll(changedDocs.values()); return docSet; }
From source file:org.apache.myfaces.webapp.filter.MultipartRequestWrapper.java
public Enumeration getParameterNames() { if (parametersMap == null) parseRequest();/* w ww .j a va2 s.c om*/ //return Collections.enumeration( parametersMap.keySet() ); HashSet mergedNames = new HashSet(request.getParameterMap().keySet()); mergedNames.addAll(parametersMap.keySet()); return Collections.enumeration(mergedNames); }