List of usage examples for java.util Vector elementAt
public synchronized E elementAt(int index)
From source file:Main.java
public static void cosineSimilarityCW() { Iterator<Integer> ids = CommentWordCount.keySet().iterator(); while (ids.hasNext()) { int com_id = ids.next(); Set<String> words1; words1 = CommentWordCount.get(com_id).keySet(); Iterator<Integer> com_iter = CommentWordCount.keySet().iterator(); while (com_iter.hasNext()) { int id = com_iter.next(); if (com_id < id) { Set<String> words2; words2 = CommentWordCount.get(id).keySet(); Vector<Integer> vecA = new Vector<Integer>(); Vector<Integer> vecB = new Vector<Integer>(); Iterator<String> w1 = words1.iterator(); Iterator<String> w2 = words2.iterator(); HashSet<String> imp = new HashSet<String>(); while (w1.hasNext()) { String s = w1.next(); imp.add(s);/*from w ww .j av a 2s . c o m*/ } while (w2.hasNext()) { String s = w2.next(); imp.add(s); } for (String s : imp) { if (CommentWordCount.get(com_id).containsKey(s)) { vecA.add(CommentWordCount.get(com_id).get(s)); } else vecA.add(0); if (CommentWordCount.get(id).containsKey(s)) { vecB.add(CommentWordCount.get(id).get(s)); } else vecB.add(0); } //System.out.println("Size : A"+vecA.size()+" Size: B"+vecB.size()+"maxLen:"+maxlength); double similarity; int product = 0; double sumA = 0; double sumB = 0; for (int i = 0; i < vecA.size(); i++) { product += vecA.elementAt(i) * vecB.elementAt(i); sumA += vecA.elementAt(i) * vecA.elementAt(i); sumB += vecB.elementAt(i) * vecB.elementAt(i); } sumA = Math.sqrt(sumA); sumB = Math.sqrt(sumB); similarity = product / (sumA * sumB); similarity = Math.acos(similarity) * 180 / Math.PI; //System.out.println("Result "+com_id+" "+id+" :"+similarity); if (similarity < 75) { //System.out.println("Result "+com_id+" "+id); if (Topic.containsKey(com_id)) { int val = Topic.get(com_id); val++; Topic.put(com_id, val); } else Topic.put(com_id, 1); if (Topic.containsKey(id)) { int val = Topic.get(id); val++; Topic.put(id, val); } else Topic.put(id, 1); } } } } }
From source file:presentation.webgui.vitroappservlet.StyleCreator.java
private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors, Model3dStylesEntry givStyleEntry) { String capSimpleName = givStyleEntry.getCorrCapability(); capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, ""); JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, false, // include legend true, false);//from w w w . j ava 2 s.co m chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14)); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // seen CategoryPlot plot = chart.getCategoryPlot(); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new plot.setNoDataMessage("NO DATA!"); Paint[] tmpPaintCategories = { Color.white }; if (givCategColors.size() > 0) { tmpPaintCategories = new Paint[givCategColors.size()]; for (int i = 0; i < givCategColors.size(); i++) { tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i)); } } CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories); renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new plot.setRenderer(renderer); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new plot.setForegroundAlpha(1f); //new plot.setBackgroundAlpha(1f); //new plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0 plot.setRangeGridlinesVisible(false); //new was true plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray); plot.setOutlinePaint(Color.white); //plot.setOrientation(PlotOrientation.HORIZONTAL); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.04); domainAxis.setUpperMargin(0.04); domainAxis.setVisible(true); domainAxis.setLabelAngle(Math.PI / 2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(0.0, 100.0); // new: was 100 rangeAxis.setVisible(false); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:ext.tmt.utils.EPMUtil.java
/** * EPM/*from w ww . j a va 2s .c o m*/ * update the primary content * @param newDoc * @param filename * @return * @throws WTException * @throws PropertyVetoException * @throws FileNotFoundException * @throws IOException */ public static EPMDocument changeDocumentPrimary(EPMDocument newDoc, String filename) throws WTException, PropertyVetoException, FileNotFoundException, IOException { ContentHolder contentholder = (ContentHolder) newDoc; contentholder = ContentHelper.service.getContents(contentholder); Vector contentListForTarget = ContentHelper.getContentListAll(contentholder); for (int i = 0; i < contentListForTarget.size(); i++) { ContentItem contentItem = (ContentItem) contentListForTarget.elementAt(i); if (contentItem.getRole().toString().equals("PRIMARY")) { System.out.println("Delete Current Primary content!"); ContentServerHelper.service.deleteContent(contentholder, contentItem); break; } } ApplicationData applicationdata = ApplicationData.newApplicationData(contentholder); applicationdata.setRole(ContentRoleType.toContentRoleType("PRIMARY")); applicationdata.setCategory(DEFAULT_CATEGORY); applicationdata = ContentServerHelper.service.updateContent(contentholder, applicationdata, filename); newDoc = (EPMDocument) PersistenceHelper.manager.refresh(newDoc); return newDoc; }
From source file:dao.SearchInTagsQuery.java
/** * This method lists all the results for the search text from directories * @param conn the connection/*from ww w .j a v a 2s . c om*/ * @param collabrumId the collabrumid * @return List the set that has the list of moderators for these collabrums. * @throws BaseDaoException - when error occurs **/ public List run(Connection conn, String sString) throws BaseDaoException { if ((RegexStrUtil.isNull(sString) || conn == null)) { return null; } ResultSet rs = null; StringBuffer sb = new StringBuffer("select * from tags where "); ArrayList columns = new ArrayList(); columns.add("tag"); sb.append(sqlSearch.getConstraint(columns, sString)); logger.info("search query string" + sb.toString()); try { PreparedStatement stmt = conn.prepareStatement(sb.toString()); rs = stmt.executeQuery(); Vector columnNames = null; Yourkeywords tag = null; List pendingList = new ArrayList(); if (rs != null) { columnNames = dbutils.getColumnNames(rs); } else { return null; } while (rs.next()) { tag = (Yourkeywords) eop.newObject(DbConstants.YOURKEYWORDS); for (int j = 0; j < columnNames.size(); j++) { tag.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } pendingList.add(tag); } return pendingList; } catch (Exception e) { throw new BaseDaoException("Error occured while executing search in tag run query " + sb.toString(), e); } }
From source file:org.ecoinformatics.seek.ecogrid.ServicesDisplayPanel.java
private Vector getPartilServiceList(boolean selected) { Vector list = new Vector(); Vector selectedList = tableModel.getSelectedServicesList(); if (selectedList != null) { int length = selectedList.size(); for (int i = 0; i < length; i++) { SelectableEcoGridService service = (SelectableEcoGridService) selectedList.elementAt(i); SelectableServiceName name = service.getSelectableServiceName(); if (name != null && name.getIsSelected()) { SelectableDocumentType[] typeList = service.getSelectableDocumentTypeList(); Vector newTypeList = new Vector(); if (typeList != null) { int size = typeList.length; int count = 0; for (int j = 0; j < size; j++) { SelectableDocumentType type = typeList[j]; if (selected) { if (type != null && type.getIsSelected()) { count++; newTypeList.add(type); } // if } else { if (type != null && !type.getIsSelected()) { count++; newTypeList.add(type); }//from w ww .j a v a2 s.co m } } // for if (count > 0 && count < size) { DocumentType[] newTypes = DocumentType.tranformVectorToArray(newTypeList); service.setDocumentTypeList(newTypes); list.add(service); } } // if } // if } // for } // if return list; }
From source file:dao.VisitTrafficDailySearchTagCountQuery.java
/** * This method lists all the results for the search text from directories * @param conn the connection/*from ww w . j a v a 2 s . c o m*/ * @param collabrumId the collabrumid * @return List the set that has the list of moderators for these collabrums. * @throws BaseDaoException - when error occurs **/ public List run(Connection conn, String sString) throws BaseDaoException { if ((RegexStrUtil.isNull(sString) || conn == null)) { return null; } ResultSet rs = null; StringBuffer sb = new StringBuffer("select count(*) from visittraffic where "); ArrayList columns = new ArrayList(); columns.add("url"); sb.append(sqlSearch.getConstraint(columns, sString)); sb.append( " and YEAR(visitdate)=YEAR(CURDATE()) and MONTH(visitdate)=MONTH(CURDATE()) and DAY(visitdate)=DAY(CURDATE())"); logger.info("search query string" + sb.toString()); try { PreparedStatement stmt = conn.prepareStatement(sb.toString()); rs = stmt.executeQuery(); Vector columnNames = null; Yourkeywords tag = null; List pendingList = new ArrayList(); if (rs != null) { columnNames = dbutils.getColumnNames(rs); } else { return null; } while (rs.next()) { tag = (Yourkeywords) eop.newObject(DbConstants.YOURKEYWORDS); for (int j = 0; j < columnNames.size(); j++) { tag.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } pendingList.add(tag); } return pendingList; } catch (Exception e) { throw new BaseDaoException("Error occured while executing search in tag run query " + sb.toString(), e); } }
From source file:dao.DirectoryFileSearchQuery.java
/** * This method lists all the results for the search text from directories * @param conn the connection//from ww w .j a va 2 s . co m * @param collabrumId the collabrumid * @return HashSet the set that has the list of moderators for these collabrums. * @throws BaseDaoException - when error occurs **/ public HashSet run(Connection conn, String sString, String fileName, String dirName) throws BaseDaoException { //if ((RegexStrUtil.isNull(sString) || conn == null)) { if ((conn == null) || RegexStrUtil.isNull(fileName)) { return null; } //StringBuffer sb = new StringBuffer("select distinct d1.dirname, d2.directoryid, d2.entryid, d2.btitle from directory d1, dirblob d2 where"); StringBuffer sb = new StringBuffer( "select distinct d1.dirname, d2.directoryid, d2.entryid, d2.btitle from directory d1, dirblob d2 where"); if (!RegexStrUtil.isNull(sString)) { ArrayList columns = new ArrayList(); columns.add("dirname"); // set the sqlConstraint as " and " String sqlConstraint = " and "; sb.append(sqlSearch.getConstraint(columns, sString, sqlConstraint)); } else { sb.append("dirpath IS NULL"); } // directory name can be null if (!RegexStrUtil.isNull(dirName)) { sb.append(" and dirname like '%"); sb.append(dirName); sb.append("%'"); } sb.append(" and d1.directoryid=d2.directoryid and "); sb.append("d2.btitle like '%"); sb.append(fileName); sb.append("%'"); logger.info("sb.toString() = " + sb.toString()); try { PreparedStatement stmt = conn.prepareStatement(sb.toString()); ResultSet rs = stmt.executeQuery(); Vector columnNames = null; Directory directory = null; HashSet pendingSet = new HashSet(); if (rs != null) { columnNames = dbutils.getColumnNames(rs); } while (rs.next()) { directory = (Directory) eop.newObject(DbConstants.DIRECTORY); for (int j = 0; j < columnNames.size(); j++) { if (((String) (columnNames.elementAt(j))).equalsIgnoreCase(DbConstants.ENTRY_DATE)) { try { directory.setValue(DbConstants.ENTRY_DATE, GlobalConst.dncalendar.getDisplayDate(rs.getTimestamp(DbConstants.ENTRY_DATE))); } catch (ParseException e) { throw new BaseDaoException("could not parse the date for entrydate in directory " + rs.getTimestamp(DbConstants.ENTRY_DATE), e); } } else { directory.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } } pendingSet.add(directory); } return pendingSet; } catch (Exception e) { throw new BaseDaoException("Error occured while executing search directory run query " + sb.toString(), e); } }
From source file:dao.GeoTargetQuery.java
/** * This method lists all the results for the geotarget text from directories * @param conn the connection/* w w w. j a v a 2 s .c o m*/ * @param collabrumId the collabrumid * @return HashSet the set that has the list of moderators for these collabrums. * @throws BaseDaoException - when error occurs **/ public List run(Connection conn, String ipAddress) throws BaseDaoException { if (RegexStrUtil.isNull(ipAddress) || conn == null) { return null; } List ip = GlobalConst.httputil.parseIP4(ipAddress); StringBuffer iptable = new StringBuffer("ip4_"); iptable.append(ip.get(0)); int b = new Integer((String) ip.get(1)).intValue(); int c = new Integer((String) ip.get(2)).intValue(); String sb = "select state from cityByCountry as geo, " + iptable.toString() + " as iptable where b=" + b + " and c=" + c + " and geo.country=iptable.country and geo.city=iptable.city and (geo.state like '%New York%' or geo.state like '%California%') limit 1"; try { PreparedStatement stmt = conn.prepareStatement(sb); if (stmt == null) { return null; } ResultSet rs = stmt.executeQuery(); Vector columnNames = null; Userpage userpage = null; List pendingList = new ArrayList(); if (rs != null) { columnNames = dbutils.getColumnNames(rs); } else { return null; } while (rs.next()) { userpage = (Userpage) eop.newObject(DbConstants.USER_PAGE); for (int j = 0; j < columnNames.size(); j++) { userpage.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } pendingList.add(userpage); } return pendingList; } catch (Exception e) { throw new BaseDaoException("Error occured while executing geotarget run query ", e); } }
From source file:dao.MykeywordsUserQuery.java
public HashSet run(Connection conn, String sString) throws BaseDaoException { if ((RegexStrUtil.isNull(sString) || conn == null)) { return null; }/* www . j a v a 2 s.c o m*/ ResultSet rs = null; StringBuffer sb = new StringBuffer("select distinct keyword from mykeywords where "); ArrayList columns = new ArrayList(); columns.add("loginid"); sb.append(sqlSearch.getConstraint(columns, sString)); logger.info("MykeywordUserQuery = " + sb.toString()); try { PreparedStatement stmt = conn.prepareStatement(sb.toString()); rs = stmt.executeQuery(); Vector columnNames = null; Mykeywords mykeyword = null; HashSet pendingSet = new HashSet(); if (rs != null) { columnNames = dbutils.getColumnNames(rs); } else { return null; } while (rs.next()) { mykeyword = (Mykeywords) eop.newObject(DbConstants.MYKEYWORDS); for (int j = 0; j < columnNames.size(); j++) { mykeyword.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } pendingSet.add(mykeyword); } return pendingSet; } catch (Exception e) { throw new BaseDaoException("Error occured while executing search in MykeywordsUserQuery run query ", e); } }
From source file:dao.PblogSearchBizAwareQuery.java
/** * This method lists all the results for the search text from pblogs * @param conn the connection//from w ww .java2s. co m * @param sString - search text * @param bid - bid * @return HashSet the set that has the list of search result * @throws BaseDaoException - when error occurs **/ public HashSet run(Connection conn, String sString, String bid) throws BaseDaoException { if (RegexStrUtil.isNull(sString) || RegexStrUtil.isNull(bid) || conn == null) { return null; } ResultSet rs = null; StringBuffer sb = new StringBuffer( "select hdlogin.loginid, hdlogin.login, hdlogin.fname, lname, LEFT(message, 160) as info, entrydate, tid, hits, hdlogin.bid, business.bsearch from business, hdlogin left join pblogtopics on hdlogin.loginid=pblogtopics.pblogid left join pblog on hdlogin.loginid=pblog.loginid where business.bid=hdlogin.bid and ("); ArrayList columns = new ArrayList(); columns.add("topic"); columns.add("message"); sb.append(sqlSearch.getConstraint(columns, sString)); sb.append(") group by login order by hits DESC"); logger.info("search query string" + sb.toString()); try { PreparedStatement stmt = conn.prepareStatement(sb.toString()); rs = stmt.executeQuery(); Vector columnNames = null; Blog pblog = null; HashSet pendingSet = new HashSet(); if (rs != null) { columnNames = dbutils.getColumnNames(rs); } else { return null; } while (rs.next()) { pblog = (Blog) eop.newObject(DbConstants.BLOG); for (int j = 0; j < columnNames.size(); j++) { if (((String) (columnNames.elementAt(j))).equalsIgnoreCase("entrydate")) { try { pblog.setValue("entrydate", GlobalConst.dncalendar.getDisplayDate(rs.getTimestamp("entrydate"))); } catch (ParseException e) { throw new BaseDaoException( "could not parse the date for entrydate in PblogSearchBizAwareQuery()" + rs.getTimestamp("entrydate"), e); } } else { pblog.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } } pendingSet.add(pblog); } return pendingSet; } catch (Exception e) { throw new BaseDaoException("Error occured while executing search in pblog run query " + sb.toString(), e); } }