List of usage examples for java.util Vector clear
public void clear()
From source file:esg.node.connection.ESGConnectionManager.java
private void pingToPeers() { java.util.Vector<ESGPeer> peers_ = new java.util.Vector<ESGPeer>(); peers_.addAll(unavailablePeers.values()); for (ESGPeer peer : peers_) { log.trace("Inspecting [" + peers_.size() + "] marked peers"); if (peer.equals(defaultPeer)) log.trace("(default peer)"); //TODO: put in random selection and or heartbeat/leasing here... //this is where the relationship maintenance code goes //and detecting when folks fall out of the system. //maybe ping should be expanded to put in lease negotiation proper. peer.ping();/*from ww w.jav a2 s .c om*/ } peers_.clear(); peers_ = null; //gc niceness... }
From source file:org.openmrs.module.solr.web.DWRChartSearchService.java
/** * Returns a map of results with the values as count of matches and a partial list of the * matching concepts (depending on values of start and length parameters) while the keys are are * 'count' and 'objectList' respectively, if the length parameter is not specified, then all * matches will be returned from the start index if specified. * /* w w w . j a v a2s . co m*/ * @param phrase concept name or conceptId * @param includeRetired boolean if false, will exclude retired concepts * @param includeClassNames List of ConceptClasses to restrict to * @param excludeClassNames List of ConceptClasses to leave out of results * @param includeDatatypeNames List of ConceptDatatypes to restrict to * @param excludeDatatypeNames List of ConceptDatatypes to leave out of results * @param start the beginning index * @param length the number of matching concepts to return * @param getMatchCount Specifies if the count of matches should be included in the returned map * @return a map of results * @throws APIException * @since 1.8 */ public Map<String, Object> findCountAndConcepts(Integer patientId, String phrase, boolean includeRetired, List<String> includeClassNames, List<String> excludeClassNames, List<String> includeDatatypeNames, List<String> excludeDatatypeNames, Integer start, Integer length, boolean getMatchCount) throws APIException { //Map to return Map<String, Object> resultsMap = new HashMap<String, Object>(); Vector<Object> objectList = new Vector<Object>(); try { if (!StringUtils.isBlank(phrase)) { long matchCount = 0; if (getMatchCount) { //get the count of matches matchCount += getDocumentListCount(patientId, phrase); } //if we have any matches or this isn't the first ajax call when the caller //requests for the count if (matchCount > 0 || !getMatchCount) { objectList.addAll(findBatchOfConcepts(patientId, phrase, includeRetired, includeClassNames, excludeClassNames, includeDatatypeNames, excludeDatatypeNames, start, length)); } resultsMap.put("count", matchCount); resultsMap.put("objectList", objectList); } else { resultsMap.put("count", 0); objectList.add(Context.getMessageSourceService().getMessage("searchWidget.noMatchesFound")); } } catch (Exception e) { log.error("Error while searching for concepts", e); objectList.clear(); objectList.add( Context.getMessageSourceService().getMessage("Concept.search.error") + " - " + e.getMessage()); resultsMap.put("count", 0); resultsMap.put("objectList", objectList); } return resultsMap; }
From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java
@Override public java.util.List<NavBoxIFace> getNavBoxes() { initialize();//from w ww. ja v a 2 s. c o m Vector<NavBoxIFace> extendedNavBoxes = new Vector<NavBoxIFace>(); extendedNavBoxes.clear(); extendedNavBoxes.addAll(navBoxes); RecordSetTask rsTask = (RecordSetTask) ContextMgr.getTaskByClass(RecordSetTask.class); List<NavBoxIFace> nbs = rsTask.getNavBoxes(); if (nbs != null) { extendedNavBoxes.addAll(nbs); } return extendedNavBoxes; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerDlg.java
@Override public Vector<Locale> getLocalesInUse() { Hashtable<String, Boolean> localeHash = new Hashtable<String, Boolean>(); // Add any from the Database Vector<Locale> localeList = getLocalesInUseInDB(schemaType); for (Locale locale : localeList) { localeHash.put(SchemaLocalizerXMLHelper.makeLocaleKey(locale.getLanguage(), locale.getCountry(), locale.getVariant()), true); }/*from w w w. j ava 2 s. c om*/ for (SpLocaleContainer container : tables) { SchemaLocalizerXMLHelper.checkForLocales(container, localeHash); for (LocalizableItemIFace f : container.getContainerItems()) { SchemaLocalizerXMLHelper.checkForLocales(f, localeHash); } } localeList.clear(); for (String key : localeHash.keySet()) { String[] toks = StringUtils.split(key, "_"); localeList.add(new Locale(toks[0], "", "")); } return localeList; }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanupIndexer.java
/** * // ww w.jav a 2 s . com */ public FindItemInfo getNextLocality() { foundNothing = true; // start by saying we haven't found any matches if (parser == null) { initLuceneforReading(); } if (!hasMoreLocalities()) { isQuitting = true; return null; } FindItemInfo fii = null; boolean cont = true; while (cont) { // Do 20 at a time String sql = String.format( "SELECT LocalityName, FullName, LocalityID FROM locality l LEFT JOIN geography g ON l.GeographyID = g.GeographyID " + "WHERE LocalityName IS NOT NULL AND LocalityID >= %d AND DisciplineID = DSPLNID LIMIT 0, 20", currLocId); sql = QueryAdjusterForDomain.getInstance().adjustSQL(sql); System.out.println(sql); Vector<Object[]> rows = BasicSQLUtils.query(sql); if (rows == null || rows.size() == 0) { isQuitting = true; return null; } for (Object[] row : rows) { String localityName = (String) row[0]; String geoName = fixGeo((String) row[1]); currLocId = (Integer) row[2]; fii = new FindItemInfo(currLocId, localityName); Pair<BigDecimal, BigDecimal> mainLatLon = getLatLon(currLocId); boolean isMainLatLon = (mainLatLon.first != null && mainLatLon.first.doubleValue() != 0.0 && mainLatLon.second != null && mainLatLon.second.doubleValue() != 0.0); StringBuilder sb = new StringBuilder(); sb.append("loc:"); sb.append(localityName); sb.append("^4 AND geo:"); // Boost 4 times sb.append(geoName); System.out.println(sb.toString()); String queryString = sb.toString(); Vector<Pair<Document, Float>> docList = new Vector<Pair<Document, Float>>(); try { Query query = parser.parse(queryString); log.debug("Searching for: " + query.toString()); Document doc = null; int hitsPerPage = 10; TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; docList.clear(); for (int i = 0; i < hits.length; ++i) { if (hits[i].score > 1.0) { int docId = hits[i].doc; doc = searcher.doc(docId); int recId = Integer.parseInt(doc.get("id")); if (currLocId != recId) { docList.add(new Pair<Document, Float>(doc, (Float) hits[i].score)); } } } if (docList.size() > 0) { //System.out.println("\n--------------------------------------------------------------"); //System.out.println(String.format("[%s] ->[%s][%s]", lastNm.toString(), p.first, (p.second != null ? p.second : "null"))); int dupAddedCnt = 0; for (Pair<Document, Float> pp : docList) { if (pp.second > 1.0) { String idStr = pp.first.get("id"); int dupId = Integer.parseInt(idStr); if (dupId != currLocId) { Pair<BigDecimal, BigDecimal> dupLatLon = getLatLon(dupId); boolean isDupLatLon = (dupLatLon.first != null && dupLatLon.first.doubleValue() != 0.0 && dupLatLon.second != null && dupLatLon.second.doubleValue() != 0.0); boolean isOKToAdd = true; if (isMainLatLon && isDupLatLon) { LatLon mainLL = LatLon.fromDegrees(mainLatLon.first.doubleValue(), mainLatLon.second.doubleValue()); LatLon dupLL = LatLon.fromDegrees(dupLatLon.first.doubleValue(), dupLatLon.second.doubleValue()); double distInMeters = LatLon.ellipsoidalDistance(mainLL, dupLL, Earth.WGS84_EQUATORIAL_RADIUS, Earth.WGS84_POLAR_RADIUS); System.out.println(String.format("%8.5f, %8.5f", distInMeters, 0.0)); isOKToAdd = distInMeters < 50.0; } if (isOKToAdd) { fii.addDuplicate(dupId); System.out.println(String.format("%d - %5.3f - %s", dupAddedCnt, pp.second, pp.first.get("full"))); dupAddedCnt++; } } } } if (dupAddedCnt > 0) { foundNothing = false; int btn = chooseLocalitiesToMerge(fii); if (btn == CustomDialog.OK_BTN) { return fii; } if (btn == CustomDialog.CANCEL_BTN) { isQuitting = true; return null; } } } } catch (Exception e) { e.printStackTrace(); } } // for loop if (!hasMoreLocalities()) { isQuitting = true; return null; } } // while loop return fii; }
From source file:org.openmrs.web.dwr.DWREncounterService.java
/** * Returns a map of results with the values as count of matches and a partial list of the * matching encounters (depending on values of start and length parameters) while the keys are * are 'count' and 'objectList' respectively, if the length parameter is not specified, then all * matches will be returned from the start index if specified. * /*from w w w . j ava 2 s . c o m*/ * @param phrase patient name or identifier * @param includeVoided Specifies if voided encounters should be included or not * @param start the beginning index * @param length the number of matching encounters to return * @return a map of results * @throws APIException * @since 1.8 */ @SuppressWarnings("unchecked") public Map<String, Object> findCountAndEncounters(String phrase, boolean includeVoided, Integer start, Integer length, boolean getMatchCount) throws APIException { //Map to return Map<String, Object> resultsMap = new HashMap<String, Object>(); Vector<Object> objectList = new Vector<Object>(); try { EncounterService es = Context.getEncounterService(); int encounterCount = 0; if (getMatchCount) { encounterCount += es.getCountOfEncounters(phrase, includeVoided); if (phrase.matches("\\d+")) { // user searched on a number Encounter e = es.getEncounter(Integer.valueOf(phrase)); if (e != null) { if (!e.isVoided() || includeVoided) { encounterCount++; } } } //If we have any matches, load them or if this is not the first ajax call //for displaying the results on the first page, the getMatchCount is expected to be zero if (encounterCount > 0 || !getMatchCount) { objectList = findBatchOfEncounters(phrase, includeVoided, start, length); } resultsMap.put("count", encounterCount); resultsMap.put("objectList", objectList); } } catch (Exception e) { log.error("Error while searching for encounters", e); objectList.clear(); objectList.add(Context.getMessageSourceService().getMessage("Encounter.search.error") + " - " + e.getMessage()); resultsMap.put("count", 0); resultsMap.put("objectList", objectList); } return resultsMap; }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Converts the ContentValue vector to an array and bulk inserts them * then clears out the vector array//from w ww .j a va 2 s . com * * @param cVVector records to insert * @return int count of how many were actually inserted */ private int insertNews(Vector<ContentValues> cVVector) { int insertCount = 0; if (cVVector == null || cVVector.isEmpty()) return insertCount; int numRecordsToInsert = cVVector.size(); if (numRecordsToInsert > 0) { // convert to an array for the bulk insert to work with ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); // inserts into the storage insertCount = mContext.getContentResolver().bulkInsert(NewsEntry.CONTENT_URI, cvArray); // clear out the loaded records so there are not duplicates cVVector.clear(); } return insertCount; }
From source file:edu.ku.brc.af.ui.forms.IconViewObj.java
public synchronized void setDataIntoUI() { ignoreChanges = true;// www.ja v a 2 s. c o m if (mainComp == null) { initMainComp(); } iconTray.removeAllItems(); Vector<Object> dataObjects = new Vector<Object>(); dataObjects.addAll(dataSet); if (this.orderableDataClass) { Vector<Orderable> sortedDataObjects = new Vector<Orderable>(); for (Object obj : dataObjects) { if (obj instanceof Orderable) { sortedDataObjects.add((Orderable) obj); } } Collections.sort(sortedDataObjects, new OrderableComparator()); dataObjects.clear(); dataObjects.addAll(sortedDataObjects); } for (Object o : dataObjects) { if (!(o instanceof FormDataObjIFace)) { log.error("Icon view data set contains non-FormDataObjIFace objects. Item being ignored."); mainComp.removeAll(); JLabel lbl = createLabel(getResourceString("Error")); mainComp.add(lbl); dataTypeError = true; return; } FormDataObjIFace formDataObj = (FormDataObjIFace) o; iconTray.addItem(formDataObj); } ignoreChanges = false; }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.AgentCleanupIndexer.java
/** * /* w w w . ja v a 2 s .c om*/ */ public FindItemInfo getNextAgent() { if (parser == null) { initLuceneforReading("full"); } if (!hasMoreAgents()) { return null; } FindItemInfo fii = null; boolean cont = true; while (cont) { Integer prevAgentId = currAgentID; // Do 20 at a time String sql = String.format("SELECT LastName, FirstName, MiddleInitial, AgentID FROM agent " + "WHERE SpecifyUserID IS NULL AND LastName IS NOT NULL AND AgentID >= %d AND DivisionID = DIVID LIMIT 0, 20", currAgentID); sql = QueryAdjusterForDomain.getInstance().adjustSQL(sql); System.out.println(sql); Vector<Object[]> rows = query(sql); if (rows == null || rows.size() < 2) { isQuitting = true; return null; } for (Object[] row : rows) { String lastNm = (String) row[0]; String firstNm = (String) row[1]; String midNm = (String) row[2]; currAgentID = (Integer) row[3]; //System.out.println("last["+lastNm+"] first["+firstNm+"] mid["+midNm+"] full["+fullName+"]"); String[] nms = FirstLastVerifier.parseName(lastNm.toString()); if (nms != null) { String last = nms[0]; String first = nms.length > 1 ? nms[1] : null; if (first == null && isNotEmpty(firstNm)) { first = firstNm; } //System.out.println("last["+lastNm+"] first["+firstNm+"] mid["+midNm+"]"); fii = new FindItemInfo(currAgentID, scriptlet.buildNameString(firstNm, lastNm, midNm)); StringBuilder sb = new StringBuilder(); if (isNotEmpty(last)) { sb.append("last:"); sb.append(last); sb.append("^4"); // Boost 4 times } if (isNotEmpty(first)) { sb.append(" "); boolean ok = first.length() > 1; if (ok) sb.append("AND (first:"); sb.append(first); sb.append("~0.6"); if (ok) { sb.append(" OR first:"); sb.append(first.charAt(0)); sb.append("~0.4)"); } } System.out.println(sb.toString()); String queryString = sb.toString(); Vector<Pair<Document, Float>> docList = new Vector<Pair<Document, Float>>(); try { Query query = parser.parse(queryString); log.debug("Searching for: " + query.toString()); Document doc = null; int hitsPerPage = 10; TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; System.out.println("Hits: " + (hits != null ? hits.length : 0)); docList.clear(); for (int i = 0; i < hits.length; ++i) { System.out.println("doc: " + i + " scrore: " + hits[i].score + " " + searcher.doc(hits[i].doc).get("full")); //if (hits[i].score > 1.0) { int docId = hits[i].doc; doc = searcher.doc(docId); lastNm = doc.get("last"); int numCommas = countMatches(lastNm, ","); int numSemiColons = countMatches(lastNm, ";"); int recId = Integer.parseInt(doc.get("id")); if (numSemiColons > 0 || numCommas > 0 || recId == currAgentID) { System.out.println(numSemiColons + " " + numCommas + " " + (recId == currAgentID) + " " + recId); continue; } docList.add(new Pair<Document, Float>(doc, (Float) hits[i].score)); } } System.out.println("docList.size(): " + docList.size()); if (docList.size() > 0) { //System.out.println("\n--------------------------------------------------------------"); //System.out.println(String.format("[%s] ->[%s][%s]", lastNm.toString(), p.first, (p.second != null ? p.second : "null"))); int i = 0; for (Pair<Document, Float> pp : docList) { if (pp.second > 1.0) { String idStr = pp.first.get("id"); int dupId = Integer.parseInt(idStr); if (dupId != currAgentID) { fii.addDuplicate(dupId); System.out.println(String.format("%d - %5.3f - %s", i, pp.second, pp.first.get("full"))); i++; } } } if (i > 0) { int btn = chooseAgentsToMergeNew(fii); if (btn == CustomDialog.OK_BTN) { return fii; } if (btn == CustomDialog.CANCEL_BTN) { isQuitting = true; return null; } } } } catch (Exception e) { e.printStackTrace(); } } else { //System.out.println(String.format("Group [%s] ", name.toString())); } } // for loop if (prevAgentId == currAgentID) { int numRemaining = getCountAsInt("SELECT COUNT(*) FROM agent WHERE AgentID > " + currAgentID); if (numRemaining == 0) { return null; } currAgentID = getCountAsInt("SELECT AgentID FROM agent WHERE AgentID > " + currAgentID + " ORDER BY AgentID ASC LIMIT 0,1"); } } // while loop return fii; }
From source file:org.openmrs.web.dwr.DWRPersonService.java
/** * Returns a map of results with the values as count of matches and a partial list of the * matching people (depending on values of start and length parameters) while the keys are are * 'count' and 'objectList' respectively, if the length parameter is not specified, then all * matches will be returned from the start index if specified. * * @param phrase is the string used to search for people * @param includeRetired Specifies if retired people should be included or not * @param roles If not null, restricts search to only users and only users with these roles * @param start the beginning index// ww w . j ava 2 s. c o m * @param length the number of matching encounters to return * @param getMatchCount Specifies if the count of matches should be included in the returned map * @return a map of results * @throws APIException * @since 1.8 */ public Map<String, Object> findCountAndPeople(String phrase, boolean includeRetired, String roles, Integer start, Integer length, boolean getMatchCount) throws APIException { //Map to return Map<String, Object> resultsMap = new HashMap<String, Object>(); Vector<Object> objectList = new Vector<Object>(); try { UserService us = Context.getUserService(); int personCount = 0; if (getMatchCount) { if (StringUtils.isNotBlank(roles)) { roles = roles.trim(); List<Role> roleList = new Vector<Role>(); String[] splitRoles = roles.split(","); for (String role : splitRoles) { roleList.add(new Role(role)); } personCount = us.getCountOfUsers(phrase, roleList, includeRetired); } else { //TODO get the person count after adding the get count method for persons to the API } } //if we have any matches or this isn't the first ajax call when the caller //requests for the count if (personCount > 0 || !getMatchCount) { objectList = findBatchOfPeopleByRoles(phrase, includeRetired, roles, start, length); } resultsMap.put("count", personCount); resultsMap.put("objectList", objectList); } catch (Exception e) { log.error("Error while searching for persons", e); objectList.clear(); objectList.add( Context.getMessageSourceService().getMessage("Person.search.error") + " - " + e.getMessage()); resultsMap.put("count", 0); resultsMap.put("objectList", objectList); } return resultsMap; }