List of usage examples for java.util List clear
void clear();
From source file:dbconverter.dao.util.ToolKit.java
/** * Indexes every document within a FindIterable object * Useful for uploading MongoDB data//from ww w . j a v a2s . com * @param documents The FindIterable containing all documents to be indexed * @param bl Determines where to index the data * @param uploadInterval Determines how frequently to clear local memory * @return The number of documents indexed * @author hightowe */ public static int bulkIndexDocuments(FindIterable<Document> documents, BulkLoader bl, int uploadInterval) { assert documents != null : PARAMETER_ERROR; assert uploadInterval > 0 : PARAMETER_ERROR; assert bl != null && bl.isConfigured() : PARAMETER_ERROR; int count = 0; Set<String> keyset = null; List<Map> docsList = new ArrayList<>(); for (Document doc : documents) { if (count == 0) { keyset = doc.keySet(); } Map<String, Object> currMap = new HashMap<>(); for (String key : keyset) { // need to swap out _id field with an alternative, or else // bulk load will fail if (key.equals("_id")) { currMap.put(MONGO_ID, doc.get(key)); } else { currMap.put(key, doc.get(key)); } } // append a timestamp of when this document was created currMap.put(TIME_STAMP, getISOTime(TIME_STAMP_FORMAT)); docsList.add(currMap); count++; if (count % uploadInterval == 0) { bl.bulkIndex(docsList); logger.info("Indexed " + count + " documents " + getISOTime(TIME_STAMP_FORMAT)); docsList.clear(); // this line should prevent heap space errors } } if (docsList.size() > 0) { bl.bulkIndex(docsList); logger.info("Indexed " + count + " documents " + getISOTime(TIME_STAMP_FORMAT)); } logger.info("Total documents indexed: " + count + ", " + getISOTime(TIME_STAMP_FORMAT)); return count; }
From source file:gov.nih.nci.cabig.caaers.web.participant.SubjectMedHistoryTab.java
/** * Remoce all items from the collection// w ww . j a va 2s . c o m * */ public ModelAndView removeAllPriorTherapyAgents(HttpServletRequest request, Object cmd, Errors errors) { ParticipantInputCommand command = (ParticipantInputCommand) cmd; StudyParticipantPriorTherapy priorTherapy = command.getAssignment().getPriorTherapies() .get(command.getParentIndex()); List<StudyParticipantPriorTherapyAgent> priorTherapyAgents = priorTherapy.getPriorTherapyAgents(); priorTherapyAgents.clear(); //create the indexes in reverse order int size = priorTherapyAgents.size(); Integer[] indexes = new Integer[size]; for (int i = 0; i < size; i++) { indexes[i] = size - (i + 1); } ModelAndView modelAndView = new ModelAndView("par/ajax/priorTherapyAgentFormSection"); modelAndView.getModel().put("priorTherapyAgents", priorTherapyAgents); modelAndView.getModel().put("indexes", indexes); modelAndView.getModel().put("parentIndex", command.getParentIndex()); return modelAndView; }
From source file:it.reply.orchestrator.service.OneDataServiceTest.java
@Test(expected = DeploymentException.class) public void testFailEmptyPopulateProviderInfo() { SpaceDetails details = getSpaceDetails(); String spaceId = details.getSpaceId(); UserSpaces userSpace = getUserSpaces(); List<String> spaces = new ArrayList<String>(); userSpace.getSpaces().add(spaceId);/*w ww .j ava 2 s. c o m*/ OneData oneData = new OneData(onedataToken, "cname2", null, new ArrayList<>(), defaultOneZoneEndpoint); HttpEntity<UserSpaces> entity = getEntity(onedataToken); ResponseEntity<UserSpaces> responseEntity = new ResponseEntity<UserSpaces>(userSpace, HttpStatus.OK); spaces.clear(); userSpace.setSpaces(spaces); responseEntity = new ResponseEntity<UserSpaces>(userSpace, HttpStatus.OK); Mockito.when(restTemplate.exchange(defaultOneZoneEndpoint + "/" + oneZoneBaseRestPath + "user/spaces", HttpMethod.GET, entity, UserSpaces.class)).thenReturn(responseEntity); oneDataService.populateProviderInfo(oneData); }
From source file:com.qmetry.qaf.automation.ui.webdriver.ComponentListHandler.java
public Object invoke(Object object, Method method, Object[] objects) throws Throwable { if (context == null) { context = new WebDriverTestBase().getDriver(); }//from w w w. j av a 2 s . c om final List<WebElement> elements = new ArrayList<WebElement>(); if (method.getName().equalsIgnoreCase("get")) { final int index = (Integer) objects[0]; new QAFWebDriverWait() .withMessage(String.format("Wait timeout for list of %s with size %d", description, index + 1)) .until(new ExpectedCondition<QAFExtendedWebDriver, Boolean>() { @Override public Boolean apply(QAFExtendedWebDriver driver) { try { elements.clear(); elements.addAll(context.findElements(by)); return elements.size() > index; } catch (WebDriverException e) { return false; } } }); } else { elements.clear(); elements.addAll((context).findElements(by)); } List<Object> components = new ArrayList<Object>(); if ((elements != null) && !elements.isEmpty()) { for (WebElement element : elements) { Object component = ComponentFactory.getObject(componentClass, loc, declaringclassObj, context); QAFExtendedWebElement extendedWebElement = (QAFExtendedWebElement) component; extendedWebElement.setId(((QAFExtendedWebElement) element).getId()); extendedWebElement.cacheable = true; extendedWebElement.getMetaData().put("pageClass", declaringclassObj.getClass()); if ((null != context) && (context instanceof QAFExtendedWebElement)) { extendedWebElement.parentElement = (QAFExtendedWebElement) context; } components.add(component); } } try { return method.invoke(components, objects); } catch (Exception e) { throw e.getCause(); } }
From source file:com.taobao.common.tfs.impl.LocalKey.java
private void gcSegment(List<SegmentInfo> segmentInfoList) { long totalLength = 0; for (SegmentInfo segmentInfo : segmentInfoList) { totalLength += segmentInfo.getLength(); gcFile.addSegment(segmentInfo);/*from w w w . j a v a2 s . com*/ segmentInfoSet.remove(segmentInfo); } segmentHead.decrement(segmentInfoList.size(), totalLength); segmentInfoList.clear(); }
From source file:com.linkedin.pinot.core.segment.store.SingleFileIndexDirectory.java
private void mapBufferEntries() throws IOException { SortedMap<Long, IndexEntry> indexStartMap = new TreeMap<>(); for (Map.Entry<IndexKey, IndexEntry> columnEntry : columnEntries.entrySet()) { long startOffset = columnEntry.getValue().startOffset; indexStartMap.put(startOffset, columnEntry.getValue()); }//from w ww .j a v a 2s . c o m long runningSize = 0; List<Long> offsetAccum = new ArrayList<>(); for (Map.Entry<Long, IndexEntry> offsetEntry : indexStartMap.entrySet()) { IndexEntry entry = offsetEntry.getValue(); runningSize += entry.size; if (runningSize >= MAX_ALLOCATION_SIZE) { mapAndSliceFile(indexStartMap, offsetAccum, offsetEntry.getKey()); runningSize = entry.size; offsetAccum.clear(); } offsetAccum.add(offsetEntry.getKey()); } if (offsetAccum.size() > 0) { mapAndSliceFile(indexStartMap, offsetAccum, offsetAccum.get(0) + runningSize); } }
From source file:com.nts.alphamale.monitor.EventMonitor.java
/** * "adb [-s serial] shell getevent -lt" ? ? ? ?. * @see <a href="https://source.android.com/devices/input/getevent.html">Getevent</a> * @param li/*from w ww . ja va 2s . co m*/ * @throws InterruptedException */ public void eventLogAnalysis(LineIterator li) throws Exception { boolean tracking = false; int multiCount = 0; List<EventLog> evtLogList = new ArrayList<EventLog>(); Map<Integer, List<Point>> multiSlot = new HashMap<Integer, List<Point>>(); while (li.hasNext()) { String readLine = li.nextLine().trim(); Matcher m = p.matcher(readLine); if (m.find()) { EventLog event = new EventLog(m); if (readLine.contains("EV_KEY")) { makeKeyEvent(event); evtLogList.clear(); } if (event.getAbsLabel().equals("ABS_MT_TRACKING_ID") && event.getAbsValue() != Integer.MAX_VALUE) { if (!multiSlot.containsKey(multiCount)) multiSlot.put(multiCount, new ArrayList<Point>()); multiCount++; tracking = true; } if (event.getAbsLabel().equals("ABS_MT_TRACKING_ID") && event.getAbsValue() == Integer.MAX_VALUE) { multiCount--; if (multiCount == 0) { tracking = false; if (!evtLogList.isEmpty()) { makeMultiTrackingEvent(multiSlot, evtLogList); } } } if (tracking == true) { if (event.getAbsLabel().contains("ABS_MT_POSITION") || event.getAbsLabel().contains("ABS_MT_SLOT")) evtLogList.add(event); } } } }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Mp3Db.java
public List<Track> getTracksFromTitle(Title title) { List<String[]> recs = tracks.findEquals(Track.FK_TITLE, title.getPk()); tracks.sortByIndex(recs, Track.PK); List<Track> ret = new ArrayList<Track>(); if (recs.isEmpty() == false) { for (String[] rec : recs) { ret.add(new Track(this, rec)); }//from ww w.j av a 2 s . co m for (Track t : ret) { if (t.getMp3Path().exists() == false) { ret.clear(); break; } } } if (ret.isEmpty() == false) { } if (ret.isEmpty() == true) { File dir = title.getMp3Path(); if (dir == null || dir.exists() == false) { return ret; } int no = 0; for (File f : dir.listFiles()) { if (f.getName().endsWith(".mp3") == false) { continue; } Track nt = new Track(this, f, title, no); ret.add(nt); ++no; } Collections.sort(ret, new Comparator<Track>() { @Override public int compare(Track o1, Track o2) { return o1.getNameOnFs().compareTo(o2.getNameOnFs()); } }); } return ret; }
From source file:com.gatf.executor.report.ReportHandler.java
public static void doTAReporting(String prefix, AcceptanceTestContext acontext, boolean isLoadTestingEnabled, TestExecutionPercentile testPercentiles, TestExecutionPercentile runPercentiles) { Map<String, List<Long>> testPercentileValues = testPercentiles.getPercentileTimes(); Map<String, List<Long>> runPercentileValues = runPercentiles.getPercentileTimes(); GatfExecutorConfig config = acontext.getGatfExecutorConfig(); VelocityContext context = new VelocityContext(); try {/*from w ww. j av a 2s. c o m*/ String reportingJson = new ObjectMapper().writeValueAsString(testPercentileValues); context.put("testcaseTAReports", reportingJson); if (testPercentileValues.size() > 0) context.put("isShowTAWrapper", testPercentileValues.values().iterator().next().size() > 0); else context.put("isShowTAWrapper", false); if (runPercentileValues.size() > 0) { List<Long> times90 = new ArrayList<Long>(); List<Long> times50 = new ArrayList<Long>(); for (List<Long> times : runPercentileValues.values()) { times90.add(times.get(0)); times50.add(times.get(1)); } runPercentileValues.put("All", times90); Collections.sort(times90); int index = Math.round((float) 0.9 * times90.size()); long time = times90.get(index - 1); times90.clear(); times90.add(time); Collections.sort(times50); index = Math.round((float) 0.5 * times50.size()); time = times50.get(index - 1); times90.add(time); } reportingJson = new ObjectMapper().writeValueAsString(runPercentileValues); context.put("runTAReports", reportingJson); } catch (Exception e) { e.printStackTrace(); } try { InputStream resourcesIS = GatfTestCaseExecutorMojo.class.getResourceAsStream("/gatf-resources.zip"); if (resourcesIS != null) { File basePath = null; if (config.getOutFilesBasePath() != null) basePath = new File(config.getOutFilesBasePath()); else { URL url = Thread.currentThread().getContextClassLoader().getResource("."); basePath = new File(url.getPath()); } File resource = new File(basePath, config.getOutFilesDir()); VelocityEngine engine = new VelocityEngine(); engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.init(); context.put("isLoadTestingEnabled", isLoadTestingEnabled); StringWriter writer = new StringWriter(); engine.mergeTemplate("/gatf-templates/index-ta.vm", context, writer); prefix = prefix == null ? "" : prefix; BufferedWriter fwriter = new BufferedWriter(new FileWriter(new File( resource.getAbsolutePath() + SystemUtils.FILE_SEPARATOR + prefix + "index-ta.html"))); fwriter.write(writer.toString()); fwriter.close(); /*if(distributedTestStatus!=null && distributedTestStatus.getReportFileContent().size()<5) { distributedTestStatus.getReportFileContent().put("", writer.toString()); }*/ } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java
public void copyNodes(List nodes) { List newNodes = getModel().copy(nodes, NodeModel.NORMAL); nodes.clear(); nodes.addAll(newNodes); }