List of usage examples for java.util ArrayList equals
public boolean equals(Object o)
From source file:systems.byteswap.publicstream.MainActivity.java
/** * Regular called timer method, fetching the remote lists in 9 concurrent threads *//*from w w w . j ava 2 s.c o m*/ private void TimerMethodRemoteList() { //fetch all offline programs first ArrayList<ORFParser.ORFProgram> temp = store.getOffline(); if (temp != null) { if (!temp.equals(programListOffline)) { programListOffline = temp; try { dataFragment.setProgramListOffline(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } //post all fetch actions (for each day since today-1week) new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListToday)) { programListToday = temp; try { dataFragment.setProgramListToday(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -1); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus1)) { programListTodayMinus1 = temp; try { dataFragment.setProgramListTodayMinus1(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -2); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus2)) { programListTodayMinus2 = temp; try { dataFragment.setProgramListTodayMinus2(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -3); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus3)) { programListTodayMinus3 = temp; try { dataFragment.setProgramListTodayMinus3(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -4); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus4)) { programListTodayMinus4 = temp; try { dataFragment.setProgramListTodayMinus4(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -5); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus5)) { programListTodayMinus5 = temp; try { dataFragment.setProgramListTodayMinus5(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -6); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus6)) { programListTodayMinus6 = temp; try { dataFragment.setProgramListTodayMinus6(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); new Thread(new Runnable() { @Override public void run() { //Create calendar object (today) Calendar today = new GregorianCalendar(); //create parser object ORFParser parser = new ORFParser(); ArrayList<ORFParser.ORFProgram> temp; today.add(Calendar.DAY_OF_MONTH, -7); temp = parser.getProgramsForDay(today.getTime(), store); if (temp != null && !temp.equals(programListTodayMinus7)) { programListTodayMinus7 = temp; try { dataFragment.setProgramListTodayMinus7(temp); } catch (Exception e) { Log.e(MainActivity.TAG_REMOTELIST, "Exception while saving list to fragment"); } runOnUiThread(new Runnable() { @Override public void run() { ViewPager mViewPager = (ViewPager) findViewById(R.id.container); try { mViewPager.getAdapter().notifyDataSetChanged(); } catch (IllegalStateException e) { Log.w(MainActivity.TAG_REMOTELIST, "Exception while updating list: " + e.getMessage()); } } }); } } }).start(); }
From source file:eu.planets_project.tb.gui.backing.exp.NewExpWizardController.java
public String updateBasicPropsAction() { // Flag to indicate validity of submission: boolean validForm = true; // Flag to indicate that the experiment definition is not valid and cannot be constructed boolean validExperiment = true; ExperimentBean expBean = (ExperimentBean) JSFUtil.getManagedObject("ExperimentBean"); log.info("ExpBean: " + expBean.getEname() + " : " + expBean.getEsummary()); // Get the Experiment description objects Experiment exp = expBean.getExperiment(); BasicProperties props = exp.getExperimentSetup().getBasicProperties(); log.info("Setting the experimental properties, " + props.getExperimentName() + " : " + props.getSummary()); // If the experiment already existed, check for valid name changes: try {// www . ja v a2s .c om props.setExperimentName(expBean.getEname()); } catch (InvalidInputException e1) { e1.printStackTrace(); } //set the experiment information props.setSummary(expBean.getEsummary()); props.setConsiderations(expBean.getEconsiderations()); props.setPurpose(expBean.getEpurpose()); props.setFocus(expBean.getEfocus()); props.setScope(expBean.getEscope()); props.setContact(expBean.getEcontactname(), expBean.getEcontactemail(), expBean.getEcontacttel(), expBean.getEcontactaddress()); props.setExperimentFormal(expBean.getFormality()); log.info("Set the experimental properties, " + props.getExperimentName() + " : " + props.getSummary()); String partpnts = expBean.getEparticipants(); String[] partpntlist = partpnts.split(","); for (int i = 0; i < partpntlist.length; i++) { partpntlist[i] = partpntlist[i].trim(); if (partpntlist[i] != "") { props.addInvolvedUser(partpntlist[i]); } } props.setExternalReferenceID(expBean.getExid()); ArrayList<String> litRefDesc = expBean.getLitRefDesc(); ArrayList<String> litRefURI = expBean.getLitRefURI(); ArrayList<String> litRefTitle = expBean.getLitRefTitle(); ArrayList<String> litRefAuthor = expBean.getLitRefAuthor(); if (litRefDesc != null && !litRefDesc.equals("")) { for (int i = 0; i < litRefDesc.size(); i++) { if (!"".equals(litRefDesc.get(i).trim()) && !"".equals(litRefURI.get(i).trim()))//author etc. can be empty props.addLiteratureReference(litRefDesc.get(i).trim(), litRefURI.get(i).trim(), litRefTitle.get(i).trim(), litRefAuthor.get(i).trim()); } } List<Long> refs = new ArrayList<Long>(); if (expBean.getEref() != null && !expBean.getEref().equals("")) { for (int i = 0; i < expBean.getEref().size(); i++) refs.add(Long.parseLong((expBean.getEref().get(i)))); } props.setExperimentReferences(refs); /* props.setDigiTypes(expBean.getDtype()); log.debug("Checking the experiment type."); // Set the experiment type: try { //check if the experiment type has changed. If yes we need to remove the already chosen log.info("Current type: '"+exp.getExperimentSetup().getExperimentTypeID()+"' versus '"+expBean.getEtype()+"'."); //selection from step2, to properly reload all available serivces + operations if(!exp.getExperimentSetup().getExperimentTypeID().equals(expBean.getEtype())){ //exp. type was reselected - remove all chosen template information expBean.removeSelectedServiceTemplate(); //set step2 to substep1 changeAlreadySelectedSerOps(); } // This is what throws the error: exp.getExperimentSetup().setExperimentType(expBean.getEtype()); } catch (InvalidInputException e) { FacesContext ctx = FacesContext.getCurrentInstance(); FacesMessage tfmsg = new FacesMessage(); tfmsg.setSummary("No experiment type specified!"); tfmsg.setDetail("You must select an experiment type."); tfmsg.setSeverity(FacesMessage.SEVERITY_ERROR); ctx.addMessage("etype",tfmsg); validForm = false; log.error("Got error on Etype: "+e); } */ // Exit with failure condition if no valid experiment could be constructed. if (!validForm && !validExperiment) { log.debug("Exiting with failure."); return "failure"; } // Exit with failure condition if the form submission was not valid. exp.getExperimentSetup().setState(Experiment.STATE_IN_PROGRESS); exp.getExperimentSetup().setSubStage(1); //testbedMan.updateExperiment(exp); if (validForm) { exp.getExperimentSetup().setSubStage(2); expBean.setCurrentStage(ExperimentBean.PHASE_EXPERIMENTSETUP_2); log.debug("Exiting in success."); return "success"; } else { log.debug("Exiting in failure - invalid form."); return "failure"; } }
From source file:com.mysql.stresstool.RunnableQueryInsert.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;//w w w .j av a 2s.c o m longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + ","); } else { insert1.append("(UUID()," + pk + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,stroperation) VALUES("; insert2Str = insert2Str + pk + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableClusterQueryInsert.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;/* w w w .j av a 2s .c o m*/ longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); // String uuid = UUID.randomUUID().toString(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; // INSERT INTO tbtest1 ("A","B","C","RECORDTYPE") VALUES(24351216,'d',14447453184,'mba'); if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + ","); } else { insert1.append("(UUID()," + pk + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,stroperation) VALUES("; insert2Str = insert2Str + pk + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableSC2013QueryInsert.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;/*from w ww . java2 s . c o m*/ longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); // String uuid = UUID.randomUUID().toString(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; // INSERT INTO tbtest1 ("A","B","C","RECORDTYPE") VALUES(24351216,'d',14447453184,'mba'); if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + " FROM_DAYS(" + StressTool.getNumberFromRandomMinMax(735325, 735384) + "),"; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + ","); } else { insert1.append("(UUID()," + pk + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,stroperation) VALUES("; insert2Str = insert2Str + pk + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableQueryInsertPartRange.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;/*from w ww . ja va 2 s.co m*/ longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { insert1.append("insert INTO tbtest" + iTable + " (uuid,date,a,b,c,counter,partitionid,strrecordtype) VALUES"); if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { String thisDate = getRangeDate(); // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID(),'" + thisDate + "'," + pk + ","); } else { insert1.append("(UUID(),'" + thisDate + "'," + pk + ","); } insert1.append(insert1Str); } } else { String thisDate = getRangeDate(); insert1Str = ""; insert1Str = insert1Str + "(UUID(),'" + thisDate + "'," + pk + ","; if (lazy) { insert1Str = lazyInsert1; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; String thisDate = getRangeDate(); for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,date,stroperation) VALUES("; insert2Str = insert2Str + pk + ",'" + thisDate + "',"; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { if (this.getOnDuplicateKey() == 0) { lazyInsert2 = "\"" + longtextFld + "\")"; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; } insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:com.mysql.stresstool.RunnableQueryInsertPCH.java
Vector getTablesValues(boolean refresh, int ServerId) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; if (refresh && !lazyInsert1.equals("")) { lazy = true;//from w w w.j a va2 s .com longtextFld = lazyLongText; } else { if (operationShort) longtextFld = StressTool.getStringFromRandom(254).substring(0, 240); else longtextFld = StressTool.getStringFromRandom(40000); } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { if (this.doSimplePk) { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,serverid,b,c,counter,partitionid,strrecordtype) VALUES"); } else { insert1.append("insert INTO tbtest" + iTable + " (uuid,a,serverid,b,c,counter,partitionid,strrecordtype) VALUES"); } if (this.useBatchInsert) { insert1Str = ""; if (lazy) { insert1Str = lazyInsert1;//.substring(0, lazyInsert1.length() - 2 ) + ServerId +")"; } else { insert1Str = "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { // uuid = UUID.randomUUID().toString(); pk = StressTool.getNumberFromRandom(2147483647).intValue(); if (ibatch > 0) { insert1.append(",(UUID()," + pk + "," + ServerId + ","); } else { insert1.append("(UUID()," + pk + "," + ServerId + ","); } insert1.append(insert1Str); } } else { insert1Str = ""; insert1Str = insert1Str + "(UUID()," + pk + "," + ServerId + ","; if (lazy) { insert1Str = lazyInsert1;//.substring(0, lazyInsert1.length() - 2 ) + ServerId +")"; } else { insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 6) : longtextFld.substring(0, 99)) + "\","; insert1Str = insert1Str + "\"" + (this.doSimplePk ? longtextFld.substring(0, 10) : longtextFld.substring(0, 199)) + "\","; insert1Str = insert1Str + StressTool.getNumberFromRandom(2147483647) * StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + StressTool.getNumberFromRandom(20) + ","; insert1Str = insert1Str + "\"" + StressTool.getStringFromRandom(2) + "\""; insert1Str = insert1Str + ")"; lazyInsert1 = insert1Str; } insert1.append(insert1Str); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } if (!this.doSimplePk) { if (dbType.endsWith("MySQL")) { String insert2Str = ""; String insert2bStr = ""; for (int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++) { insert2Str = ""; insert2Str = insert2Str + "insert INTO tbtest_child" + iTable + " (a,serverid,stroperation) VALUES("; insert2Str = insert2Str + pk + "," + ServerId + ","; if (lazy && !lazyInsert2.equals("")) { insert2bStr = lazyInsert2; } else { lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; insert2bStr = lazyInsert2; // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // lazyInsert2 = insert2Str; } if (!insert2Str.equals("")) insertList2.add(insert2Str + insert2bStr); } } } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:imitationNLG.SFX.java
public HashMap<Integer, HashSet<String>> createNaiveAlignments(ArrayList<DatasetInstance> trainingData) { punctPatterns = new HashMap<>(); HashMap<ArrayList<Action>, ArrayList<Action>> calculatedRealizationsCache = new HashMap<>(); HashMap<Integer, HashSet<String>> nGrams = new HashMap<>(); for (DatasetInstance di : trainingData) { HashSet<ArrayList<Action>> initRealizations = new HashSet<>(); for (ArrayList<Action> real : di.getEvalRealizations()) { if (!calculatedRealizationsCache.containsKey(real)) { initRealizations.add(real); }/* ww w . ja v a 2s . co m*/ } if (!calculatedRealizationsCache.containsKey(di.getTrainRealization())) { initRealizations.add(di.getTrainRealization()); } for (ArrayList<Action> realization : initRealizations) { HashMap<String, HashSet<String>> values = new HashMap<>(); for (String attr : di.getMeaningRepresentation().getAttributes().keySet()) { values.put(attr, new HashSet<>(di.getMeaningRepresentation().getAttributes().get(attr))); } ArrayList<Action> randomRealization = new ArrayList<Action>(); for (Action a : realization) { if (a.getAttribute().equals(SFX.TOKEN_PUNCT)) { randomRealization.add(new Action(a.getWord(), a.getAttribute())); } else { randomRealization.add(new Action(a.getWord(), "")); } } if (values.keySet().isEmpty()) { for (int i = 0; i < randomRealization.size(); i++) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!attributes.get(di.getMeaningRepresentation().getPredicate()).contains("empty")) { attributes.get(di.getMeaningRepresentation().getPredicate()).add("empty"); } randomRealization.get(i).setAttribute("empty=empty"); } } } else { HashMap<Double, HashMap<String, ArrayList<Integer>>> indexAlignments = new HashMap<>(); HashSet<String> noValueAttrs = new HashSet<String>(); for (String attr : values.keySet()) { for (String value : values.get(attr)) { if ((!(value.matches("\"[xX][0-9]+\"") || value.matches("[xX][0-9]+") || value.startsWith(SFX.TOKEN_X))) && !value.isEmpty()) { String valueToCheck = value; if (valueToCheck.equals("no") || valueToCheck.equals("yes") || valueToCheck.equals("yes or no") || valueToCheck.equals("none") || valueToCheck.equals("dont_care") || valueToCheck.equals("empty")) { valueToCheck = attr + ":" + value; noValueAttrs.add(attr + "=" + value); } if (valueToCheck.equals(attr)) { noValueAttrs.add(attr + "=" + value); } if (!valueToCheck.equals("empty:empty") && valueAlignments.containsKey(valueToCheck)) { for (ArrayList<String> align : valueAlignments.get(valueToCheck).keySet()) { int n = align.size(); for (int i = 0; i <= randomRealization.size() - n; i++) { ArrayList<String> compare = new ArrayList<String>(); ArrayList<Integer> indexAlignment = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { compare.add(randomRealization.get(i + j).getWord()); indexAlignment.add(i + j); } if (compare.equals(align)) { if (!indexAlignments.containsKey( valueAlignments.get(valueToCheck).get(align))) { indexAlignments.put( valueAlignments.get(valueToCheck).get(align), new HashMap()); } indexAlignments.get(valueAlignments.get(valueToCheck).get(align)) .put(attr + "=" + valueToCheck, indexAlignment); } } } } } } } ArrayList<Double> similarities = new ArrayList<>(indexAlignments.keySet()); Collections.sort(similarities); HashSet<String> assignedAttrValues = new HashSet<String>(); HashSet<Integer> assignedIntegers = new HashSet<Integer>(); for (int i = similarities.size() - 1; i >= 0; i--) { for (String attrValue : indexAlignments.get(similarities.get(i)).keySet()) { if (!assignedAttrValues.contains(attrValue)) { boolean isUnassigned = true; for (Integer index : indexAlignments.get(similarities.get(i)).get(attrValue)) { if (assignedIntegers.contains(index)) { isUnassigned = false; } } if (isUnassigned) { assignedAttrValues.add(attrValue); for (Integer index : indexAlignments.get(similarities.get(i)).get(attrValue)) { assignedIntegers.add(index); randomRealization.get(index).setAttribute(attrValue.toLowerCase().trim()); } } } } } HashMap<String, Integer> attrXIndeces = new HashMap<>(); for (Action a : randomRealization) { if (a.getWord().startsWith(SFX.TOKEN_X)) { String attr = a.getWord().substring(3, a.getWord().lastIndexOf('_')).toLowerCase() .trim(); a.setAttribute(attr + "=" + a.getWord()); } } //System.out.println("-1: " + randomRealization); HashSet<String> unalignedNoValueAttrs = new HashSet<>(); for (String noValueAttr : noValueAttrs) { boolean assigned = false; for (Action a : randomRealization) { if (a.getAttribute().equals(noValueAttr)) { assigned = true; } } if (!assigned) { unalignedNoValueAttrs.add(noValueAttr); } } boolean isAllEmpty = true; boolean hasSpace = false; for (int i = 0; i < randomRealization.size(); i++) { if (!randomRealization.get(i).getAttribute().isEmpty() && !randomRealization.get(i).getAttribute().equals("[]") && !randomRealization.get(i).getAttribute().equals(SFX.TOKEN_PUNCT)) { isAllEmpty = false; } if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { hasSpace = true; } } if (isAllEmpty && hasSpace && !unalignedNoValueAttrs.isEmpty()) { for (String attrValue : unalignedNoValueAttrs) { int index = r.nextInt(randomRealization.size()); boolean change = false; while (!change) { if (!randomRealization.get(index).getAttribute().equals(SFX.TOKEN_PUNCT)) { randomRealization.get(index).setAttribute(attrValue.toLowerCase().trim()); change = true; } else { index = r.nextInt(randomRealization.size()); } } } } //System.out.println(isAllEmpty + " " + hasSpace + " " + unalignedNoValueAttrs); //System.out.println(">> " + noValueAttrs); //System.out.println(">> " + values); //System.out.println("0: " + randomRealization); String previousAttr = ""; for (int i = 0; i < randomRealization.size(); i++) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(SFX.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } else { previousAttr = ""; } } //System.out.println("1: " + randomRealization); previousAttr = ""; for (int i = randomRealization.size() - 1; i >= 0; i--) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(SFX.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } else { previousAttr = ""; } } //System.out.println("2: " + randomRealization); previousAttr = ""; for (int i = 0; i < randomRealization.size(); i++) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(SFX.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } } //System.out.println("3: " + randomRealization); previousAttr = ""; for (int i = randomRealization.size() - 1; i >= 0; i--) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(SFX.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } } //System.out.println("4: " + randomRealization); } //FIX WRONG @PUNCT@ String previousAttr = ""; for (int i = randomRealization.size() - 1; i >= 0; i--) { if (randomRealization.get(i).getAttribute().equals(TOKEN_PUNCT) && !randomRealization.get(i).getWord().matches("[,.?!;:']")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } } ArrayList<Action> cleanRandomRealization = new ArrayList<>(); for (Action a : randomRealization) { if (!a.getAttribute().equals(SFX.TOKEN_PUNCT)) { cleanRandomRealization.add(a); } } //ADD END TOKENS ArrayList<Action> endRandomRealization = new ArrayList<>(); previousAttr = ""; for (int i = 0; i < cleanRandomRealization.size(); i++) { Action a = cleanRandomRealization.get(i); if (!previousAttr.isEmpty()) { if (!a.getAttribute().equals(previousAttr)) { endRandomRealization.add(new Action(SFX.TOKEN_END, previousAttr)); } } endRandomRealization.add(a); previousAttr = a.getAttribute(); } endRandomRealization.add(new Action(SFX.TOKEN_END, previousAttr)); endRandomRealization.add(new Action(SFX.TOKEN_END, SFX.TOKEN_END)); calculatedRealizationsCache.put(realization, endRandomRealization); //System.out.println(di.getMeaningRepresentation().getPredicate() + ": " + endRandomRealization); ArrayList<String> attrValues = new ArrayList<String>(); for (Action a : endRandomRealization) { if (attrValues.isEmpty()) { attrValues.add(a.getAttribute()); } else if (!attrValues.get(attrValues.size() - 1).equals(a.getAttribute())) { attrValues.add(a.getAttribute()); } } if (attrValues.size() > maxAttrRealizationSize) { maxAttrRealizationSize = attrValues.size(); } for (int i = 0; i < randomRealization.size(); i++) { Action a = randomRealization.get(i); if (a.getAttribute().equals(SFX.TOKEN_PUNCT) && !a.getWord().equals(".")) { boolean legal = true; ArrayList<Action> surroundingActions = new ArrayList<>(); if (i - 2 >= 0) { surroundingActions.add(randomRealization.get(i - 2)); } else { surroundingActions.add(null); } if (i - 1 >= 0) { surroundingActions.add(randomRealization.get(i - 1)); } else { legal = false; } if (i + 1 < randomRealization.size()) { surroundingActions.add(randomRealization.get(i + 1)); } else { legal = false; } if (i + 2 < randomRealization.size()) { surroundingActions.add(randomRealization.get(i + 2)); } else { surroundingActions.add(null); } if (legal) { punctPatterns.put(surroundingActions, a); } } } /*for (int i = 2; i <= 6; i++) { for (int j = 0; j < cleanRandomRealization.size() - i; j++) { String ngram = ""; for (int r = 0; r < i; r++) { ngram += cleanRandomRealization.get(j + r).getWord() + "|"; } ngram = ngram.substring(0, ngram.length() - 1); if (!nGrams.containsKey(i)) { nGrams.put(i, new HashSet<String>()); } nGrams.get(i).add(ngram); } }*/ } HashSet<ArrayList<Action>> newRealizations = new HashSet<>(); for (ArrayList<Action> real : di.getEvalRealizations()) { newRealizations.add(calculatedRealizationsCache.get(real)); } di.setEvalRealizations(newRealizations); di.setTrainRealization(calculatedRealizationsCache.get(di.getTrainRealization())); for (ArrayList<Action> rr : di.getEvalRealizations()) { for (Action key : rr) { if (key.getWord().trim().isEmpty()) { System.out.println("RR " + di.getMeaningRepresentation().getMRstr()); System.out.println("RR " + di.getMeaningRepresentation().getAttributes()); System.out.println("RR " + rr); System.out.println("RR " + key); System.exit(0); } if (key.getAttribute().equals("[]") || key.getAttribute().isEmpty()) { System.out.println("RR " + di.getMeaningRepresentation().getMRstr()); System.out.println("RR " + di.getMeaningRepresentation().getAttributes()); System.out.println("RR " + rr); System.out.println("RR " + key); System.exit(0); } } } for (Action key : di.getTrainRealization()) { if (key.getWord().trim().isEmpty()) { System.out.println("RR " + di.getMeaningRepresentation().getMRstr()); System.out.println("RR " + di.getMeaningRepresentation().getAttributes()); System.out.println("RR " + key); System.exit(0); } if (key.getAttribute().equals("[]") || key.getAttribute().isEmpty()) { System.out.println("RR " + di.getMeaningRepresentation().getMRstr()); System.out.println("RR " + di.getMeaningRepresentation().getAttributes()); System.out.println("RR " + di.getTrainRealization()); System.out.println("RR " + key); System.exit(0); } } //di.setRealizations(randomRealizations); } return nGrams; }
From source file:com.mysql.stresstool.RunnableQueryInsertDR.java
Vector getTablesValues(boolean refresh) { String longtextFld = ""; boolean lazy = false; int afld = 0; long counterFld = 0; // if(refresh && !lazyInsert1.equals("")) // {/* w w w. j a va 2 s . c o m*/ // lazy = true; // longtextFld = lazyLongText; // } // else{ // if(operationShort) // longtextFld = StressTool.getStringFromRandom(254).substring(0,240); // else // longtextFld = StressTool.getStringFromRandom(40000); // } Vector v = new Vector(); StringBuffer insert1 = new StringBuffer(); StringBuffer insert2 = new StringBuffer(); // String uuid = UUID.randomUUID().toString(); ArrayList<String> insertList1 = new ArrayList(); ArrayList<String> insertList2 = new ArrayList(); int pk = StressTool.getNumberFromRandom(2147483647).intValue(); String insert1Str = ""; if (dbType.endsWith("MySQL")) { for (int iTable = 1; iTable <= this.getNumberOfprimaryTables(); iTable++) { // +--------+------------+------------+-----------+--------+------------+---------+ // * | emp_no | birth_date | first_name | last_name | gender | hire_date | city_id | // * +--------+------------+------------+-----------+--------+------------+---------+ insert1.append("insert INTO tbtest" + iTable + " (emp_no,birth_date,first_name,last_name,gender,hire_date,city_id,CityName,CountryCode,UUID) VALUES"); if (this.useBatchInsert) { for (int ibatch = 0; ibatch <= this.iBatchInsert; ibatch++) { String nameString = Name .get(StressTool.getNumberFromRandomMinMax(0, Name.size() - 1).intValue()); String lastNString = LastName .get(StressTool.getNumberFromRandomMinMax(0, LastName.size() - 1).intValue()); String cityString = (String) city.keySet().toArray()[StressTool .getNumberFromRandomMinMax(0, city.size() - 1).intValue()]; String[] cityN_ISO = ((String) city.get(cityString)).split("-"); int fromDaysBirth = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); int fromDaysHire = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); String gender = ""; if (fromDaysBirth % 2 == 0) { gender = "M"; } else { gender = "F"; } if (ibatch > 0) { insert1.append(","); } insert1.append("(NULL,FROM_DAYS(" + fromDaysBirth + ")," + "'" + nameString + "'," + "'" + lastNString + "'," + "'" + gender + "'," + "FROM_DAYS(" + fromDaysHire + ")," + cityN_ISO[0] + "," + "'" + cityString + "'," + "'" + cityN_ISO[1] + "'," + "UUID())"); } } else { String nameString = Name .get(StressTool.getNumberFromRandomMinMax(0, Name.size() - 1).intValue()); String lastNString = LastName .get(StressTool.getNumberFromRandomMinMax(0, LastName.size() - 1).intValue()); String cityString = (String) city.keySet().toArray()[StressTool .getNumberFromRandomMinMax(0, city.size() - 1).intValue()]; String[] cityN_ISO = ((String) city.get(cityString)).split("-"); int fromDaysBirth = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); int fromDaysHire = StressTool.getNumberFromRandomMinMax(712223, 735630).intValue(); String gender = ""; if (fromDaysBirth % 2 == 0) { gender = "M"; } else { gender = "F"; } insert1.append("(NULL,FROM_DAYS(" + fromDaysBirth + ")," + "'" + nameString + "'," + "'" + lastNString + "'," + "'" + gender + "'," + "FROM_DAYS(" + fromDaysHire + ")," + cityN_ISO[0] + "," + "'" + cityString + "'," + "'" + cityN_ISO[1] + "'," + "UUID())"); } if (!insertList1.equals("")) insertList1.add(insert1.toString()); insert1.delete(0, insert1.length()); } } // if(!this.doSimplePk) // { // if(dbType.endsWith("MySQL")) // { // String insert2Str = ""; // String insert2bStr = ""; // String thisDate = getRangeDate(); // // for(int iTable = 1; iTable <= this.getNumberOfSecondaryTables(); iTable++){ // insert2Str = ""; // // insert2Str = insert2Str +"insert INTO tbtest_child" + iTable + " (a,date,stroperation) VALUES("; // insert2Str = insert2Str + pk + ",'" + thisDate + "',"; // if(lazy && !lazyInsert2.equals("")){ // insert2bStr = lazyInsert2; // } // else{ // lazyInsert2 = "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // insert2bStr = lazyInsert2; // // insert2Str = insert2Str + "\"" + longtextFld + "\") ON DUPLICATE KEY UPDATE partitionid=0"; // // lazyInsert2 = insert2Str; // } // // if(!insert2Str.equals("")) // insertList2.add(insert2Str + insert2bStr); // // } // // } // } v.add(0, insertList1); v.add(1, insertList2); // v.add(2, new Integer(pk)); return v; }
From source file:structuredPredictionNLG.SFX.java
/** * * @param trainingData// www. j a v a 2s . c o m */ @Override public void createNaiveAlignments(ArrayList<DatasetInstance> trainingData) { HashMap<String, HashMap<ArrayList<Action>, HashMap<Action, Integer>>> punctPatterns = new HashMap<>(); getPredicates().forEach((predicate) -> { punctPatterns.put(predicate, new HashMap<ArrayList<Action>, HashMap<Action, Integer>>()); }); HashMap<DatasetInstance, ArrayList<Action>> punctRealizations = new HashMap<DatasetInstance, ArrayList<Action>>(); trainingData.stream().map((di) -> { HashMap<ArrayList<Action>, ArrayList<Action>> calculatedRealizationsCache = new HashMap<>(); HashSet<ArrayList<Action>> initRealizations = new HashSet<>(); if (!calculatedRealizationsCache.containsKey(di.getDirectReferenceSequence())) { initRealizations.add(di.getDirectReferenceSequence()); } initRealizations.stream().map((realization) -> { HashMap<String, HashSet<String>> values = new HashMap<>(); di.getMeaningRepresentation().getAttributeValues().keySet().forEach((attr) -> { values.put(attr, new HashSet<>(di.getMeaningRepresentation().getAttributeValues().get(attr))); }); ArrayList<Action> randomRealization = new ArrayList<>(); for (int i = 0; i < realization.size(); i++) { Action a = realization.get(i); if (a.getAttribute().equals(Action.TOKEN_PUNCT)) { randomRealization.add(new Action(a.getWord(), a.getAttribute())); } else { randomRealization.add(new Action(a.getWord(), "")); } } if (values.keySet().isEmpty()) { for (int i = 0; i < randomRealization.size(); i++) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!getAttributes().get(di.getMeaningRepresentation().getPredicate()) .contains("empty")) { getAttributes().get(di.getMeaningRepresentation().getPredicate()).add("empty"); } randomRealization.get(i).setAttribute("empty=empty"); } } } else { HashMap<Double, HashMap<String, ArrayList<Integer>>> indexAlignments = new HashMap<>(); HashSet<String> noValueAttrs = new HashSet<String>(); values.keySet().forEach((attr) -> { values.get(attr).stream().filter( (value) -> ((!(value.matches("\"[xX][0-9]+\"") || value.matches("[xX][0-9]+") || value.startsWith(Action.TOKEN_X))) && !value.isEmpty())) .map((value) -> { String valueToCheck = value; if (valueToCheck.equals("no") || valueToCheck.equals("yes") || valueToCheck.equals("yes or no") || valueToCheck.equals("none") //|| attr.equals("dont_care") || valueToCheck.equals("empty")) { valueToCheck = attr + ":" + value; noValueAttrs.add(attr + "=" + value); } if (valueToCheck.equals(attr)) { noValueAttrs.add(attr + "=" + value); } return valueToCheck; }) .filter((valueToCheck) -> (!valueToCheck.equals("empty:empty") && getValueAlignments().containsKey(valueToCheck))) .forEachOrdered((valueToCheck) -> { for (ArrayList<String> align : getValueAlignments().get(valueToCheck) .keySet()) { int n = align.size(); for (int i = 0; i <= randomRealization.size() - n; i++) { ArrayList<String> compare = new ArrayList<String>(); ArrayList<Integer> indexAlignment = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { compare.add(randomRealization.get(i + j).getWord()); indexAlignment.add(i + j); } if (compare.equals(align)) { if (!indexAlignments.containsKey( getValueAlignments().get(valueToCheck).get(align))) { indexAlignments.put( getValueAlignments().get(valueToCheck).get(align), new HashMap()); } indexAlignments .get(getValueAlignments().get(valueToCheck).get(align)) .put(attr + "=" + valueToCheck, indexAlignment); } } } }); }); ArrayList<Double> similarities = new ArrayList<>(indexAlignments.keySet()); Collections.sort(similarities); HashSet<String> assignedAttrValues = new HashSet<String>(); HashSet<Integer> assignedIntegers = new HashSet<Integer>(); for (int i = similarities.size() - 1; i >= 0; i--) { for (String attrValue : indexAlignments.get(similarities.get(i)).keySet()) { if (!assignedAttrValues.contains(attrValue)) { boolean isUnassigned = true; for (Integer index : indexAlignments.get(similarities.get(i)).get(attrValue)) { if (assignedIntegers.contains(index)) { isUnassigned = false; } } if (isUnassigned) { assignedAttrValues.add(attrValue); for (Integer index : indexAlignments.get(similarities.get(i)).get(attrValue)) { assignedIntegers.add(index); randomRealization.get(index).setAttribute(attrValue.toLowerCase().trim()); } } } } } //System.out.println("-1: " + randomRealization); randomRealization.stream().filter((a) -> (a.getWord().startsWith(Action.TOKEN_X))) .forEachOrdered((a) -> { String attr = a.getWord().substring(3, a.getWord().lastIndexOf('_')).toLowerCase() .trim(); a.setAttribute(attr + "=" + a.getWord()); }); HashSet<String> unalignedNoValueAttrs = new HashSet<>(); noValueAttrs.forEach((noValueAttr) -> { boolean assigned = false; for (Action a : randomRealization) { if (a.getAttribute().equals(noValueAttr)) { assigned = true; } } if (!assigned) { unalignedNoValueAttrs.add(noValueAttr); } }); boolean isAllEmpty = true; boolean hasSpace = false; for (int i = 0; i < randomRealization.size(); i++) { if (!randomRealization.get(i).getAttribute().isEmpty() && !randomRealization.get(i).getAttribute().equals("[]") && !randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT)) { isAllEmpty = false; } if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { hasSpace = true; } } if (isAllEmpty && hasSpace && !unalignedNoValueAttrs.isEmpty()) { unalignedNoValueAttrs.forEach((attrValue) -> { int index = getRandomGen().nextInt(randomRealization.size()); boolean change = false; while (!change) { if (!randomRealization.get(index).getAttribute().equals(Action.TOKEN_PUNCT)) { randomRealization.get(index).setAttribute(attrValue.toLowerCase().trim()); change = true; } else { index = getRandomGen().nextInt(randomRealization.size()); } } }); } //System.out.println(isAllEmpty + " " + hasSpace + " " + unalignedNoValueAttrs); //System.out.println(">> " + noValueAttrs); //System.out.println(">> " + values); //System.out.println("0: " + randomRealization); String previousAttr = ""; int start = -1; for (int i = 0; i < randomRealization.size(); i++) { if (!randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT) && !randomRealization.get(i).getAttribute().isEmpty() && !randomRealization.get(i).getAttribute().equals("[]")) { if (start != -1) { int middle = (start + i - 1) / 2 + 1; for (int j = start; j < middle; j++) { if (randomRealization.get(j).getAttribute().isEmpty() || randomRealization.get(j).getAttribute().equals("[]")) { randomRealization.get(j).setAttribute(previousAttr); } } for (int j = middle; j < i; j++) { if (randomRealization.get(j).getAttribute().isEmpty() || randomRealization.get(j).getAttribute().equals("[]")) { randomRealization.get(j) .setAttribute(randomRealization.get(i).getAttribute()); } } } start = i; previousAttr = randomRealization.get(i).getAttribute(); } else { previousAttr = ""; } } //System.out.println("1: " + randomRealization); previousAttr = ""; for (int i = randomRealization.size() - 1; i >= 0; i--) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } else { previousAttr = ""; } } //System.out.println("2: " + randomRealization); previousAttr = ""; for (int i = 0; i < randomRealization.size(); i++) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } } //System.out.println("3: " + randomRealization); previousAttr = ""; for (int i = randomRealization.size() - 1; i >= 0; i--) { if (randomRealization.get(i).getAttribute().isEmpty() || randomRealization.get(i).getAttribute().equals("[]")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } } //System.out.println("4: " + randomRealization); } //FIX WRONG @PUNCT@ String previousAttr = ""; for (int i = randomRealization.size() - 1; i >= 0; i--) { if (randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT) && !randomRealization.get(i).getWord().matches("[,.?!;:']")) { if (!previousAttr.isEmpty()) { randomRealization.get(i).setAttribute(previousAttr); } } else if (!randomRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT)) { previousAttr = randomRealization.get(i).getAttribute(); } } ArrayList<Action> cleanRandomRealization = new ArrayList<>(); randomRealization.stream().filter((a) -> (!a.getAttribute().equals(Action.TOKEN_PUNCT))) .forEachOrdered((a) -> { cleanRandomRealization.add(a); }); //ADD END TOKENS ArrayList<Action> endRandomRealization = new ArrayList<>(); previousAttr = ""; for (int i = 0; i < cleanRandomRealization.size(); i++) { Action a = cleanRandomRealization.get(i); if (!previousAttr.isEmpty() && !a.getAttribute().equals(previousAttr)) { endRandomRealization.add(new Action(Action.TOKEN_END, previousAttr)); } endRandomRealization.add(a); previousAttr = a.getAttribute(); } endRandomRealization.add(new Action(Action.TOKEN_END, previousAttr)); endRandomRealization.add(new Action(Action.TOKEN_END, Action.TOKEN_END)); calculatedRealizationsCache.put(realization, endRandomRealization); //System.out.println(di.getMeaningRepresentation().getPredicate() + ": " + endRandomRealization); ArrayList<String> attrValues = new ArrayList<String>(); endRandomRealization.forEach((a) -> { if (attrValues.isEmpty()) { attrValues.add(a.getAttribute()); } else if (!attrValues.get(attrValues.size() - 1).equals(a.getAttribute())) { attrValues.add(a.getAttribute()); } }); if (attrValues.size() > getMaxContentSequenceLength()) { setMaxContentSequenceLength(attrValues.size()); } ArrayList<Action> punctRealization = new ArrayList<>(); punctRealization.addAll(randomRealization); previousAttr = ""; for (int i = 0; i < punctRealization.size(); i++) { if (!punctRealization.get(i).getAttribute().equals(Action.TOKEN_PUNCT)) { if (!punctRealization.get(i).getAttribute().equals(previousAttr) && !previousAttr.isEmpty()) { punctRealization.add(i, new Action(Action.TOKEN_END, previousAttr)); i++; } previousAttr = punctRealization.get(i).getAttribute(); } } if (!punctRealization.get(punctRealization.size() - 1).getWord().equals(Action.TOKEN_END)) { punctRealization.add(new Action(Action.TOKEN_END, previousAttr)); } return punctRealization; }).map((punctRealization) -> { punctRealizations.put(di, punctRealization); return punctRealization; }).forEachOrdered((punctRealization) -> { for (int i = 0; i < punctRealization.size(); i++) { Action a = punctRealization.get(i); if (a.getAttribute().equals(Action.TOKEN_PUNCT)) { boolean legal = true; ArrayList<Action> surroundingActions = new ArrayList<>(); if (i - 2 >= 0) { surroundingActions.add(punctRealization.get(i - 2)); } else { surroundingActions.add(null); } if (i - 1 >= 0) { surroundingActions.add(punctRealization.get(i - 1)); } else { legal = false; } boolean oneMore = false; if (i + 1 < punctRealization.size()) { surroundingActions.add(punctRealization.get(i + 1)); if (!punctRealization.get(i + 1).getAttribute().equals(Action.TOKEN_END)) { oneMore = true; } } else { legal = false; } if (oneMore && i + 2 < punctRealization.size()) { surroundingActions.add(punctRealization.get(i + 2)); } else { surroundingActions.add(null); } if (legal) { if (!punctPatterns.get(di.getMeaningRepresentation().getPredicate()) .containsKey(surroundingActions)) { punctPatterns.get(di.getMeaningRepresentation().getPredicate()) .put(surroundingActions, new HashMap<Action, Integer>()); } if (!punctPatterns.get(di.getMeaningRepresentation().getPredicate()) .get(surroundingActions).containsKey(a)) { punctPatterns.get(di.getMeaningRepresentation().getPredicate()) .get(surroundingActions).put(a, 1); } else { punctPatterns.get(di.getMeaningRepresentation().getPredicate()) .get(surroundingActions) .put(a, punctPatterns.get(di.getMeaningRepresentation().getPredicate()) .get(surroundingActions).get(a) + 1); } } } } }); di.setDirectReferenceSequence(calculatedRealizationsCache.get(di.getDirectReferenceSequence())); return di; }).forEachOrdered((di) -> { HashSet<String> attrValuesToBeMentioned = new HashSet<>(); di.getMeaningRepresentation().getAttributeValues().keySet().forEach((attribute) -> { int a = 0; for (String value : di.getMeaningRepresentation().getAttributeValues().get(attribute)) { if (value.startsWith("\"x")) { value = "x" + a; a++; } else if (value.startsWith("\"")) { value = value.substring(1, value.length() - 1).replaceAll(" ", "_"); } attrValuesToBeMentioned.add(attribute + "=" + value); } }); di.getDirectReferenceSequence().stream().map((key) -> { attrValuesToBeMentioned.remove(key.getAttribute()); return key; }); }); punctRealizations.keySet().forEach((di) -> { ArrayList<Action> punctRealization = punctRealizations.get(di); punctPatterns.get(di.getMeaningRepresentation().getPredicate()).keySet().forEach((surrounds) -> { int beforeNulls = 0; if (surrounds.get(0) == null) { beforeNulls++; } if (surrounds.get(1) == null) { beforeNulls++; } for (int i = 0 - beforeNulls; i < punctRealization.size(); i++) { boolean matches = true; int m = 0; for (int s = 0; s < surrounds.size(); s++) { if (surrounds.get(s) != null) { if (i + s < punctRealization.size()) { if (!punctRealization.get(i + s).getWord().equals(surrounds.get(s) .getWord()) /*|| !cleanActionList.get(i).getAttribute().equals(surrounds.get(s).getAttribute())*/) { matches = false; s = surrounds.size(); } else { m++; } } else { matches = false; s = surrounds.size(); } } else if (s < 2 && i + s >= 0) { matches = false; s = surrounds.size(); } else if (s >= 2 && i + s < punctRealization.size()) { matches = false; s = surrounds.size(); } } if (matches && m > 0) { Action a = new Action("", ""); if (!punctPatterns.get(di.getMeaningRepresentation().getPredicate()).get(surrounds) .containsKey(a)) { punctPatterns.get(di.getMeaningRepresentation().getPredicate()).get(surrounds).put(a, 1); } else { punctPatterns.get(di.getMeaningRepresentation().getPredicate()).get(surrounds).put(a, punctPatterns.get(di.getMeaningRepresentation().getPredicate()).get(surrounds) .get(a) + 1); } } } }); }); punctPatterns.keySet().forEach((predicate) -> { punctPatterns.get(predicate).keySet().forEach((punct) -> { Action bestAction = null; int bestCount = 0; for (Action a : punctPatterns.get(predicate).get(punct).keySet()) { if (punctPatterns.get(predicate).get(punct).get(a) > bestCount) { bestAction = a; bestCount = punctPatterns.get(predicate).get(punct).get(a); } else if (punctPatterns.get(predicate).get(punct).get(a) == bestCount && bestAction.getWord().isEmpty()) { bestAction = a; } } if (!getPunctuationPatterns().containsKey(predicate)) { getPunctuationPatterns().put(predicate, new HashMap<ArrayList<Action>, Action>()); } if (!bestAction.getWord().isEmpty()) { getPunctuationPatterns().get(predicate).put(punct, bestAction); } }); }); }