List of usage examples for java.util HashSet iterator
public Iterator<E> iterator()
From source file:dao.SearchDaoDb.java
/** * LuceneSearchBlobs - lucene search blobs * @param dirPath - directory path/*from w ww .j ava 2 s. com*/ * @param searchText - search text * @return List - list of matches based on the text */ public List luceneSearchBlobs(String dirPath, String searchText) { logger.info("searchText indexDir() = " + dirPath); dirPath = dirPath + "/"; logger.info("searchText searchText() = " + searchText); // index the directory try { luceneManager.indexDir(new File(dirPath)); } catch (Exception e) { throw new BaseDaoException( "Exception in LuceneManager.indexDir(), dirPath = " + dirPath + " " + e.getMessage(), e); } // get the hits ArrayList arrayHits = null; if (!RegexStrUtil.isNull(searchText)) { // String modexpr = searchText.replaceAll("[[\\W]&&[\\S]]", ""); String modexpr = RegexStrUtil.goodStr(searchText); StringTokenizer st = new StringTokenizer(modexpr, " "); while (st.hasMoreTokens()) { String token = st.nextToken(); Hits hits = null; try { logger.info("token search docs:" + token); hits = luceneManager.searchDocs(token); } catch (Exception e) { throw new BaseDaoException( "Exception in LuceneManager searchDocs(token), token=" + token + e.getMessage(), e); } if (hits == null) { logger.info("LuceneManager, hits is null"); return null; } else { logger.info("hits.length() = " + hits.length()); arrayHits = new ArrayList(); for (int j = 0; j < hits.length(); j++) { logger.info("hits.length() = " + j); Document doc = null; try { doc = hits.doc(j); } catch (Exception e) { throw new BaseDaoException( "Exception in LuceneManager, hits.doc(j),j=" + j + " errMsg=" + e.getMessage(), e); } if (doc == null) { logger.info("doc is null for j = " + j); continue; } else { logger.info("doc = " + doc.toString()); if (!RegexStrUtil.isNull(doc.get("path"))) { String fileName = null; String docDir = null; String dirName = null; String str = doc.get("path"); // find the sanpath in the str and strip it off int ind = -1; if (str.startsWith(dirPath)) { ind = dirPath.length(); } if (ind != -1) { docDir = str.substring(ind, str.length()); logger.info("docDir = " + docDir.toString()); if (!RegexStrUtil.isNull(docDir)) { // get filename, docDir (directories) separated with spaces int endInd = docDir.lastIndexOf(File.separator); if (endInd != -1) { if ((endInd + 1) <= docDir.length()) { fileName = docDir.substring(endInd + 1, docDir.length()).trim(); logger.info("fileName = " + fileName.toString()); docDir = docDir.substring(0, endInd).trim(); endInd = docDir.lastIndexOf(File.separator); if (endInd != -1) { if (endInd + 1 <= docDir.length()) { dirName = docDir.substring(endInd + 1, docDir.length()) .trim(); docDir = docDir.substring(0, endInd).trim(); } } logger.info("fileName = " + fileName); logger.info("dirName = " + dirName); logger.info("docDir = " + docDir); } if (!RegexStrUtil.isNull(docDir)) { // write the query docDir = docDir.replaceAll(File.separator, " "); logger.info("docDir with spaces = " + docDir.toString()); } // docDir can be null i.e dirPath can be null HashSet hs = getDirectoryFile(docDir, fileName, dirName); // there should be only one match of a file for each sanpath if (hs != null && hs.size() == 1) { Iterator it1 = hs.iterator(); while (it1.hasNext()) { Directory dir = (Directory) it1.next(); if (dir == null) continue; logger.info(" found filematch = " + dir.toString()); arrayHits.add(dir); } // while } // if hs } // endInd != -1 } // docDir } // ind != -1 } // if } // else } // for } // else } // while } // if return arrayHits; }
From source file:org.eclipse.wb.tests.gef.GraphicalRobot.java
/** * Asserts that feedback layer contains exactly same {@link Figure}'s as described. *///from www . j a va 2s .c om public void assertFeedbackFigures(FigureDescription... descriptions) { HashSet<Figure> feedbackFigures = new HashSet<Figure>(getFeedbackFigures()); // for (int i = 0; i < descriptions.length; i++) { FigureDescription description = descriptions[i]; // try to find figure for current description boolean figureFound = false; for (Iterator<Figure> I = feedbackFigures.iterator(); I.hasNext();) { Figure figure = I.next(); if (description.match(figure)) { I.remove(); figureFound = true; break; } } // figure should be found assertThat(figureFound).describedAs("No figure found for " + description).isTrue(); } // all figure should be matched if (!feedbackFigures.isEmpty()) { String message = "Following figures are not matched:"; for (Figure figure : feedbackFigures) { message += "\n\t" + figure.getClass().getName() + " " + figure.getBounds() + " " + figure.toString(); } assertThat(true).describedAs(message).isFalse(); } }
From source file:dao.PendingfriendDaoDb.java
/** * This method adds a pending friend as a friend. * @param guestLogin - the guest login that is added as a pending friend * @param memberId - the memberId to whom the pending friend is added. * @param memberLoginInfo - the members login information bean * @throws BaseDaoException//from www .j a va2 s . co m **/ public void addPendingFriend(String guestLogin, String memberId, Hdlogin memberLoginInfo) throws BaseDaoException { /** * (loginId = memberId) (sending person) * (destloginId=guestLogin) (Receiving person, receives the request as a friend) */ if (RegexStrUtil.isNull(guestLogin) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null"); } /** * Get the guest's login information from guestLogin * the person sending the request, the order is important, do not remove this */ Hdlogin hdlogin = getLoginid(guestLogin); if (hdlogin == null) { throw new BaseDaoException("hdlogin is null for guestLogin " + guestLogin); } String guestId = hdlogin.getValue(DbConstants.LOGIN_ID); if (RegexStrUtil.isNull(guestId)) { throw new BaseDaoException("guestId is null for guestLogin " + guestLogin); } String gfname = hdlogin.getValue("fname"); String glname = hdlogin.getValue("lname"); String to = hdlogin.getValue("email"); /** * if already a friend, ignore it */ List prefResult = null; Object[] myParams = { (Object) guestId, (Object) memberId }; /** * Get scalability datasource for pendingfriends - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addPendingfriend() " + sourceName); } String from = webconstants.getMailfrom(); /** * check if this entry exists for this user, do read_uncommitted also */ HashSet pendingSet = null; Connection conn = null; try { conn = ds.getConnection(); if (conn != null) { conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); pendingSet = listQuery.run(conn, memberId, guestId); conn.close(); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("connection close exception ", e1); } throw new BaseDaoException("error occured in db query", e); } /** * this entry already exists in the pendinglist, return */ if (!pendingSet.isEmpty()) { Iterator it1 = pendingSet.iterator(); Integer count = new Integer(((Pendingfriend) it1.next()).getValue("count(*)")); if (count > 0) { return; } } /** * add this friend */ try { addQuery.run(guestId, memberId); } catch (Exception e) { throw new BaseDaoException("error occured while adding a PendingfriendAddQuery()" + addQuery.getSql() + ", guestId = " + guestId + ", memberId = " + memberId, e); } /** * If the Email "to" field is missing, don't send email, just return */ if (!RegexStrUtil.isNull(to)) { /** * Get scalability datasource for hdprofile - partitioned on loginId */ sourceName = scalabilityManager.getReadScalability(guestId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addPendingfriend() " + sourceName); } /** * check if the guest needs to be notified */ Object[] params = { (Object) guestId }; //params[0] = guestId; prefResult = null; try { prefResult = myprofileQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error occured while executing HdprofileQuery()" + myprofileQuery.getSql() + " guestId = " + params[0], e); } if (prefResult.size() == 1) { Hdprofile hdprofile = (Hdprofile) prefResult.get(0); if (hdprofile.getValue("informfd").equalsIgnoreCase("1")) { //memberId = memberLoginInfo.getValue(DbConstants.LOGIN_ID); String fname = memberLoginInfo.getValue(DbConstants.FIRST_NAME); String lname = memberLoginInfo.getValue(DbConstants.LAST_NAME); String subject = "Invitation for friendship with " + fname + " " + lname; String msg = "Hi, " + gfname + "\n" + fname + " " + lname + " has sent you " + "\n\n" + "Members webpage: " + webconstants.getHddomain() + "/userpage?member=" + memberLoginInfo.getValue(DbConstants.LOGIN) + webconstants.getMailfooter(); hdmail.sendEmail(to, subject, msg, from); } } } Fqn fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, guestLogin)) { treeCache.remove(fqn, guestLogin); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, memberLoginInfo.getValue(DbConstants.LOGIN))) { treeCache.remove(fqn, memberLoginInfo.getValue(DbConstants.LOGIN)); } }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.RWikiObjectServiceImpl.java
/** * Add page references to the rwiki object. Limit length of the * string to save to a fixed value that will cover the common cases * without using resources for degenerate cases. * @param rwo - The rwiki object/*from w w w . j av a2s .co m*/ * @param referenced - the hash of the references to save. */ public StringBuffer extractReferences(RWikiCurrentObject rwo, final HashSet referenced) { StringBuffer sb = new StringBuffer(); Iterator i = referenced.iterator(); String next = null; while (i.hasNext()) { next = (String) i.next(); int referencedLength = sb.length() + 4 + next.length(); if (referencedLength >= maxReferencesStringSize) { // SAK-12115 break; } else { sb.append("::").append(next); //$NON-NLS-1$ } } sb.append("::"); //$NON-NLS-1$ return sb; }
From source file:kz.nurlan.kaspandr.KaspandrWindow.java
@Override public void initialize(Map<String, Object> namespace, URL location, Resources resources) { mapper = new ObjectMapper(); jsonMergeButton.getButtonPressListeners().add(new ButtonPressListener() { @Override//from w ww . j a v a 2s . c o m public void buttonPressed(Button button) { ApplicationContext.scheduleCallback(new Runnable() { @Override public void run() { activityIndicatorBoxPane.setVisible(true); } }, 0); ApplicationContext.scheduleCallback(new Runnable() { @Override public void run() { activityIndicatorBoxPane.setVisible(false); } }, 2000); try { String finalJson = ""; int firstID = 0; HashSet<String> groupNameSet = new HashSet<String>(); HashMap<String, ArrayNode> grouppedLessonsByGroupMap1 = groupByLessonsByGroup( firstJson.getText().replaceAll("'", "\"")); HashMap<String, ArrayNode> grouppedLessonsByGroupMap2 = groupByLessonsByGroup( secondJson.getText().replaceAll("'", "\"")); HashMap<String, Integer> lessonCountByGroupMap1 = getCountedLessonsByGroup( firstJson.getText().replaceAll("'", "\"")); HashMap<String, Integer> lessonCountByGroupMap2 = getCountedLessonsByGroup( secondJson.getText().replaceAll("'", "\"")); for (String groupName : grouppedLessonsByGroupMap1.keySet()) { groupNameSet.add(groupName); } for (String groupName : grouppedLessonsByGroupMap2.keySet()) { groupNameSet.add(groupName); } Iterator<String> it = groupNameSet.iterator(); HashMap<String, ArrayNode> linkForGrouppedLessonsByGroupMap = grouppedLessonsByGroupMap1; while (it.hasNext()) { String groupName = it.next(); if (lessonCountByGroupMap1.get(groupName) != null && lessonCountByGroupMap2.get(groupName) == null) linkForGrouppedLessonsByGroupMap = grouppedLessonsByGroupMap1; else if (lessonCountByGroupMap1.get(groupName) == null && lessonCountByGroupMap2.get(groupName) != null) linkForGrouppedLessonsByGroupMap = grouppedLessonsByGroupMap2; else if (lessonCountByGroupMap1.get(groupName) > lessonCountByGroupMap2.get(groupName)) linkForGrouppedLessonsByGroupMap = grouppedLessonsByGroupMap1; else linkForGrouppedLessonsByGroupMap = grouppedLessonsByGroupMap2; ArrayNode lessonArrayNode = linkForGrouppedLessonsByGroupMap.get(groupName); Iterator<JsonNode> lanIt = lessonArrayNode.elements(); while (lanIt.hasNext()) { if (!finalJson.isEmpty()) finalJson += ","; ObjectNode lesson = (ObjectNode) lanIt.next(); lesson.put("id", "" + firstID++); finalJson += mapper.writeValueAsString(lesson).replace('"', '\''); } } finalLessonSequence.setText("" + (firstID)); finalJsonText.setText(finalJson); checkGroupText3.setText(checkLessonCountByGroup(finalJsonText.getText().replaceAll("'", "\""))); } catch (JsonParseException e) { Alert.alert(MessageType.ERROR, "Incorrect JSON format!", "JsonParseException", null, KaspandrWindow.this, null); e.printStackTrace(); } catch (JsonMappingException e) { Alert.alert(MessageType.ERROR, "JsonMappingException. Make bug report to Nurlan Rakhimzhanov(nurlan.rakhimzhanov@bee.kz).", KaspandrWindow.this); e.printStackTrace(); } catch (IOException e) { Alert.alert(MessageType.ERROR, "IOException. Make bug report to Nurlan Rakhimzhanov(nurlan.rakhimzhanov@bee.kz).", KaspandrWindow.this); e.printStackTrace(); } } }); checkGroupButton1.getButtonPressListeners().add(new ButtonPressListener() { @Override public void buttonPressed(Button button) { try { checkGroupText1.setText(checkLessonCountByGroup(firstJson.getText().replaceAll("'", "\""))); } catch (JsonParseException e) { Alert.alert(MessageType.ERROR, "Incorrect JSON format!", "JsonParseException", null, KaspandrWindow.this, null); e.printStackTrace(); } catch (JsonMappingException e) { Alert.alert(MessageType.ERROR, "Make bug report to Nurlan Rakhimzhanov\n(nurlan.rakhimzhanov@bee.kz).", "JsonMappingException", null, KaspandrWindow.this, null); e.printStackTrace(); } catch (IOException e) { Alert.alert(MessageType.ERROR, "Make bug report to Nurlan Rakhimzhanov\n(nurlan.rakhimzhanov@bee.kz).", "IOException", null, KaspandrWindow.this, null); e.printStackTrace(); } } }); checkGroupButton2.getButtonPressListeners().add(new ButtonPressListener() { @Override public void buttonPressed(Button button) { try { checkGroupText2.setText(checkLessonCountByGroup(secondJson.getText().replaceAll("'", "\""))); } catch (JsonParseException e) { Alert.alert(MessageType.ERROR, "Incorrect JSON format!", "JsonParseException", null, KaspandrWindow.this, null); e.printStackTrace(); } catch (JsonMappingException e) { Alert.alert(MessageType.ERROR, "Make bug report to Nurlan Rakhimzhanov\n(nurlan.rakhimzhanov@bee.kz).", "JsonMappingException", null, KaspandrWindow.this, null); e.printStackTrace(); } catch (IOException e) { Alert.alert(MessageType.ERROR, "Make bug report to Nurlan Rakhimzhanov\n(nurlan.rakhimzhanov@bee.kz).", "IOException", null, KaspandrWindow.this, null); e.printStackTrace(); } } }); nextButton.getButtonPressListeners().add(new ButtonPressListener() { @Override public void buttonPressed(Button button) { try { firstJson.setText(finalJsonText.getText()); secondJson.setText(""); finalJsonText.setText(""); checkGroupText1.setText(""); checkGroupText2.setText(""); checkGroupText3.setText(""); } catch (Exception e) { Alert.alert(MessageType.ERROR, "Make bug report to Nurlan Rakhimzhanov\n(nurlan.rakhimzhanov@bee.kz).", "Unknown error", null, KaspandrWindow.this, null); e.printStackTrace(); } } }); }
From source file:org.freebxml.omar.server.common.ServerRequestContext.java
/** * Delete of composed objects such as ClassificationNodes within Schemes * can result in duplicate ObjectRefs being deleted. *//*ww w . ja v a2s . c o m*/ private void removeDuplicateAffectedObjects(AuditableEventType ae) { HashSet ids = new HashSet(); HashSet duplicateObjectRefs = new HashSet(); //Determine duplicate ObjectRefs Iterator iter = ae.getAffectedObjects().getObjectRef().iterator(); while (iter.hasNext()) { ObjectRefType oref = (ObjectRefType) iter.next(); String id = oref.getId(); if (ids.contains(id)) { duplicateObjectRefs.add(oref); } else { ids.add(id); } } //Now remove duplicate ObjectRefs iter = duplicateObjectRefs.iterator(); while (iter.hasNext()) { ae.getAffectedObjects().getObjectRef().remove(iter.next()); } }
From source file:org.apache.hadoop.hive.ql.parse.CommonSubtreeDetect.java
private void validate(HashSet<List<Object>> candidates) { /*/*from www . ja v a 2 s.c om*/ * Check validation: * A sub-tree should be considered as a common sub-tree if and * only if all of its sub-trees are common sub-trees */ boolean changed = true; int totalValidOps = 0, iterId = 0; while (changed) { changed = false; totalValidOps = 0; Iterator<List<Object>> iter = candidates.iterator(); LOG.debug("# of iteration: " + iterId++); while (iter.hasNext()) { List<Object> obj = iter.next(); List<Object> invalidList = new ArrayList<Object>(); boolean last_valid = true; LOG.debug("current sub-string: " + obj.toString()); for (int i = 0; i < obj.size(); i++) { if (obj.get(i) instanceof Operator<?>) { /* If last op is invalid which means the subtree lead by it is not * a common sub-tree, then the current op could never be able to * lead a common sub-tree either. Otherwise, the current op might * be able to lead a common sub-tree if all of its ancestors have * already be considered to be in some common sub-trees. * If the current op is not an instance of logical operator, reset * the last invalid flag. */ if (!last_valid) { invalidList.add(obj.get(i)); sameOpToOp.remove((Operator<?>) (obj.get(i))); } else { /* last_valid is true */ Operator<?> op = (Operator<?>) (obj.get(i)); List<Operator<?>> parents = op.getParentOperators(); if (parents != null) { for (Operator<?> parent : parents) { if (sameOpToOp.get(parent) == null) { last_valid = false; break; } } } if (!last_valid) { invalidList.add(op); sameOpToOp.remove(op); } else if (op instanceof JoinOperator || op instanceof GroupByOperator) { totalValidOps++; } } } else { last_valid = true; } } // remove common sub-strings which contain no valid operator if (invalidList.size() > 0) { changed = true; if (invalidList.size() == obj.size()) { LOG.debug("remove a whole string: " + obj.toString()); iter.remove(); continue; } } // including common sub-strings which contain no operator int validOps = 0; for (int i = 0; i < obj.size(); i++) { if (obj.get(i) instanceof Operator<?> && !invalidList.contains(obj.get(i))) { validOps++; } } if (validOps <= 0) { LOG.debug("remove a whole string: " + obj.toString()); iter.remove(); } else if (invalidList.size() > 0) { LOG.debug("remove a sub string: " + invalidList.toString()); obj.removeAll(invalidList); } } // Too strict /*if (totalValidOps <= 0) { LOG.debug("remove all candidate strings"); candidates.clear(); break; }*/ } LOG.info("After validation: "); for (List<Object> candidate : candidates) { //LOG.info(candidate.toString()); System.out.println(candidate.toString()); } }
From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java
public JSONRPCResult call(Object context[], JSONObject jsonReq) { JSONRPCResult result = null;//from w w w. j a v a2 s . c o m String encodedMethod = null; Object requestId = null; JSONArray arguments = null; try { // Get method name, arguments and request id encodedMethod = jsonReq.getString("method"); arguments = jsonReq.getJSONArray("params"); requestId = jsonReq.opt("id"); } catch (NoSuchElementException e) { log.severe("no method or parameters in request"); return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, null, JSONRPCResult.MSG_ERR_NOMETHOD); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (isDebug()) log.fine("call " + encodedMethod + "(" + arguments + ")" + ", requestId=" + requestId); String className = null; String methodName = null; int objectID = 0; // Parse the class and methodName StringTokenizer t = new StringTokenizer(encodedMethod, "."); if (t.hasMoreElements()) className = t.nextToken(); if (t.hasMoreElements()) methodName = t.nextToken(); // See if we have an object method in the format ".obj#<objectID>" if (encodedMethod.startsWith(".obj#")) { t = new StringTokenizer(className, "#"); t.nextToken(); objectID = Integer.parseInt(t.nextToken()); } ObjectInstance oi = null; ClassData cd = null; HashMap methodMap = null; Method method = null; Object itsThis = null; if (objectID == 0) { // Handle "system.listMethods" if (encodedMethod.equals("system.listMethods")) { HashSet m = new HashSet(); globalBridge.allInstanceMethods(m); if (globalBridge != this) { globalBridge.allStaticMethods(m); globalBridge.allInstanceMethods(m); } allStaticMethods(m); allInstanceMethods(m); JSONArray methods = new JSONArray(); Iterator i = m.iterator(); while (i.hasNext()) methods.put(i.next()); return new JSONRPCResult(JSONRPCResult.CODE_SUCCESS, requestId, methods); } // Look up the class, object instance and method objects if (className == null || methodName == null || ((oi = resolveObject(className)) == null && (cd = resolveClass(className)) == null)) return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, requestId, JSONRPCResult.MSG_ERR_NOMETHOD); if (oi != null) { itsThis = oi.o; methodMap = oi.classData().methodMap; } else { methodMap = cd.staticMethodMap; } } else { if ((oi = resolveObject(new Integer(objectID))) == null) return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, requestId, JSONRPCResult.MSG_ERR_NOMETHOD); itsThis = oi.o; methodMap = oi.classData().methodMap; // Handle "system.listMethods" if (methodName.equals("listMethods")) { HashSet m = new HashSet(); uniqueMethods(m, "", oi.classData().staticMethodMap); uniqueMethods(m, "", oi.classData().methodMap); JSONArray methods = new JSONArray(); Iterator i = m.iterator(); while (i.hasNext()) methods.put(i.next()); return new JSONRPCResult(JSONRPCResult.CODE_SUCCESS, requestId, methods); } } if ((method = resolveMethod(methodMap, methodName, arguments)) == null) return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, requestId, JSONRPCResult.MSG_ERR_NOMETHOD); // Call the method try { if (debug) log.fine("invoking " + method.getReturnType().getName() + " " + method.getName() + "(" + argSignature(method) + ")"); Object javaArgs[] = unmarshallArgs(context, method, arguments); for (int i = 0; i < context.length; i++) preInvokeCallback(context[i], itsThis, method, javaArgs); Object o = method.invoke(itsThis, javaArgs); for (int i = 0; i < context.length; i++) postInvokeCallback(context[i], itsThis, method, o); SerializerState state = new SerializerState(); result = new JSONRPCResult(JSONRPCResult.CODE_SUCCESS, requestId, ser.marshall(state, o)); } catch (UnmarshallException e) { for (int i = 0; i < context.length; i++) errorCallback(context[i], itsThis, method, e); result = new JSONRPCResult(JSONRPCResult.CODE_ERR_UNMARSHALL, requestId, e.getMessage()); } catch (MarshallException e) { for (int i = 0; i < context.length; i++) errorCallback(context[i], itsThis, method, e); result = new JSONRPCResult(JSONRPCResult.CODE_ERR_MARSHALL, requestId, e.getMessage()); } catch (Throwable e) { if (e instanceof InvocationTargetException) e = ((InvocationTargetException) e).getTargetException(); for (int i = 0; i < context.length; i++) errorCallback(context[i], itsThis, method, e); result = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, requestId, e); } // Return the results return result; }
From source file:Evaluator.PerQueryRelDocs.java
public HashMap<String, Double> computeAvgRank(ArrayList runList, int qid, HashSet SampleData) { double rankSum = 0; HashMap<String, Double> docrankMap = new HashMap<>(); for (int i = 0; i < runList.size(); i++) { retRcds.resFile = runFileFolderPath + "/" + runList.get(i); retRcds.allRetMap = new TreeMap<>(); retRcds.load();// ww w .j av a 2s . com Iterator it = SampleData.iterator(); while (it.hasNext()) { String docname = (String) it.next(); Integer h = qid; if (relRcds.perQueryRels.get(h.toString()).relMap.containsKey(docname)) { double rank = retRcds.allRetMap.get(h.toString()).pool.indexOf(docname); if (rank != -1) { if (docrankMap.containsKey(docname)) { docrankMap.put(docname, docrankMap.get(docname) + rank); } else { docrankMap.put(docname, rank); } } else { if (docrankMap.containsKey(docname)) { docrankMap.put(docname, docrankMap.get(docname) + 0); } else { double x = 0; docrankMap.put(docname, x); } } } } } Iterator it = docrankMap.keySet().iterator(); while (it.hasNext()) { String st = (String) it.next(); double r = docrankMap.get(st); docrankMap.put(st, (r / 1000) / runList.size()); } return docrankMap; }
From source file:dao.SearchDaoDb.java
/** * cleanForBizAccess - looks for business access for the accessibility * @param resultSet - resultSet of objects * @param bid - bid to which the login belongs * @param login - login who is searching for info * @param modelType - type of the model (Userpage/Blog/Photo) * @return HashSet - cleanedup for biz access resultSet * @throws BaseDaoException If we have a problem interpreting the data or the data is missing * or incorrect// w w w.j av a2 s . c om */ private HashSet cleanForBizAccess(HashSet resultSet, String bid, String login, int modelType) { if (RegexStrUtil.isNull(bid) || RegexStrUtil.isNull(login) || resultSet == null) { throw new BaseDaoException("params are null"); } logger.info("bid = " + bid + " login=" + login); logger.info("resultSet = " + resultSet.toString()); /** * don't create a new set - in future, fix this */ HashSet bizHashSet = new HashSet(); Iterator it1 = resultSet.iterator(); while (it1.hasNext()) { Object obj = it1.next(); String mbid, bsearch; bsearch = mbid = null; if (modelType == USER_PAGE) { mbid = ((Userpage) obj).getValue(DbConstants.BID); bsearch = ((Userpage) obj).getValue(DbConstants.BSEARCH); } if (modelType == BLOG) { mbid = ((Blog) obj).getValue(DbConstants.BID); bsearch = ((Blog) obj).getValue(DbConstants.BSEARCH); } if (modelType == PHOTO) { mbid = ((Photo) obj).getValue(DbConstants.BID); bsearch = ((Photo) obj).getValue(DbConstants.BSEARCH); } if ((bsearch != null && bsearch.equals(DbConstants.BSEARCH_ALLOW)) || (mbid != null && mbid.equals(bid))) { /** cannot access this members information * remove it from the list */ bizHashSet.add(obj); } } logger.info("bizHashSet = " + bizHashSet.toString()); return bizHashSet; }