List of usage examples for java.util List clear
void clear();
From source file:data.DefaultExchanger.java
private void importDataFromArray(JsonParser parser, JdbcTemplate jdbcTemplate, int batchSize) throws IOException { int importedNodesCount = 0; final List<JsonNode> nodes = new ArrayList<>(); while (parser.nextToken() != JsonToken.END_ARRAY) { final JsonNode node = parser.readValueAsTree(); nodes.add(node);/*from w w w .j a va2 s .c o m*/ if (nodes.size() == batchSize) { importedNodesCount += batchUpdate(jdbcTemplate, nodes).length; nodes.clear(); } } if (nodes.size() > 0) { importedNodesCount += batchUpdate(jdbcTemplate, nodes).length; } play.Logger.info("imported {{}} {}", importedNodesCount, getTable()); }
From source file:com.gargoylesoftware.htmlunit.attachment.AttachmentTest.java
/** * Tests {@link Attachment#getSuggestedFilename()}. * @throws Exception if an error occurs/* w ww . j a v a 2 s .com*/ */ @Test public void filename() throws Exception { final String content = "<html>But is it really?</html>"; final WebClient client = new WebClient(); final MockWebConnection conn = new MockWebConnection(); client.setWebConnection(conn); final List<Attachment> attachments = new ArrayList<Attachment>(); client.setAttachmentHandler(new CollectingAttachmentHandler(attachments)); final List<NameValuePair> headers1 = new ArrayList<NameValuePair>(); headers1.add(new NameValuePair("Content-Disposition", "attachment;filename=\"hello.html\"")); conn.setResponse(URL_FIRST, content, 200, "OK", "text/html", headers1); client.getPage(URL_FIRST); final Attachment result = attachments.get(0); assertEquals(result.getSuggestedFilename(), "hello.html"); attachments.clear(); final List<NameValuePair> headers2 = new ArrayList<NameValuePair>(); headers2.add(new NameValuePair("Content-Disposition", "attachment; filename=hello2.html; something=else")); conn.setResponse(URL_SECOND, content, 200, "OK", "text/plain", headers2); client.getPage(URL_SECOND); final Attachment result2 = attachments.get(0); assertEquals(result2.getSuggestedFilename(), "hello2.html"); assertEquals(content, ((TextPage) result2.getPage()).getContent()); attachments.clear(); final List<NameValuePair> headers3 = new ArrayList<NameValuePair>(); headers3.add(new NameValuePair("Content-Disposition", "attachment")); final byte[] contentb = new byte[] { (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE }; conn.setResponse(URL_THIRD, contentb, 200, "OK", "application/x-rubbish", headers3); client.getPage(URL_THIRD); final Attachment result3 = attachments.get(0); final InputStream result3Stream = result3.getPage().getWebResponse().getContentAsStream(); assertNull(result3.getSuggestedFilename()); assertEquals(result3.getPage().getWebResponse().getContentType(), "application/x-rubbish"); HttpWebConnectionTest.assertEquals(new ByteArrayInputStream(contentb), result3Stream); attachments.clear(); }
From source file:framework.retrieval.engine.index.all.file.impl.DefaultRFileIndexAll.java
/** * ?//from w w w.j a v a2s .co m * @param list */ private void createFileIndex(List<FileIndexDocument> list) { int length = list.size(); indexCount += length; boolean debugLogFlag = false; if (log.isDebugEnabled()) { debugLogFlag = true; } List<String> deleteFileDocumentIdList = new ArrayList<String>(); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < length; i++) { FileIndexDocument fileIndexDocument = list.get(i); fileIndexDocument.setIndexInfoType(fileIndexAllItem.getIndexInfoType()); fileIndexDocument.setIndexPathType(fileIndexAllItem.getIndexPathType()); //? IIndexAllFileInterceptor indexAllFileInterceptor = fileIndexAllItem.getIndexAllFileInterceptor(); if (indexAllFileInterceptor != null) { Map<String, Object> addonFileDocuments = indexAllFileInterceptor.interceptor(fileIndexDocument); Map<String, Object> addonFileDocumentsType = indexAllFileInterceptor.getFieldsType(); if (addonFileDocuments != null && addonFileDocuments.size() > 0) { Object[][] objects = UtilTool.getMapKeyValue(addonFileDocuments); int objectlength = objects.length; for (int j = 0; j < objectlength; j++) { String fieldName = String.valueOf(objects[j][0]); String fieldValue = String.valueOf(objects[j][1]); String type = ""; if (addonFileDocumentsType != null) { type = String.valueOf(addonFileDocumentsType.get(fieldName)); } RDocItem docItem = new RDocItem(); docItem.setName(fieldName); docItem.setContent(fieldValue); if (!type.equals("")) { if (type.equalsIgnoreCase(String.valueOf(RetrievalType.RDocItemType.KEYWORD))) { fileIndexDocument.addKeyWord(docItem); } else if (type.equalsIgnoreCase(String.valueOf(RetrievalType.RDocItemType.DATE))) { fileIndexDocument.addDateProperty(docItem); } else if (type.equalsIgnoreCase(String.valueOf(RetrievalType.RDocItemType.NUMBER))) { fileIndexDocument.addNumberProperty(docItem); } else if (type.equalsIgnoreCase(String.valueOf(RetrievalType.RDocItemType.PROPERTY))) { fileIndexDocument.addContent(docItem); } else { fileIndexDocument.addContent(docItem); } } else { fileIndexDocument.addContent(docItem); } } } } //??? if (fileIndexAllItem.getIndexOperatorType() == RetrievalType.RIndexOperatorType.UPDATE) { if (debugLogFlag) { stringBuilder.append("?[" + fileIndexDocument.getIndexPathType() + "]:" + fileIndexDocument.getFile().getAbsolutePath() + "\n"); } String existsFileDocumentId = StringClass.getString(queryFacade.queryFileDocumentIndexIdByFileId( fileIndexAllItem.getIndexPathType(), fileIndexDocument.getFileId())); if (existsFileDocumentId.equals("")) { list.add(fileIndexDocument); } else { fileIndexDocument.setId(existsFileDocumentId); list.add(fileIndexDocument); deleteFileDocumentIdList.add(existsFileDocumentId); } } else { if (debugLogFlag) { stringBuilder.append("?[" + fileIndexDocument.getIndexPathType() + "]:" + fileIndexDocument.getFile().getAbsolutePath() + "\n"); } } } log.debug(stringBuilder); if (deleteFileDocumentIdList != null && deleteFileDocumentIdList.size() > 0) { docOperatorFacade.delete(fileIndexAllItem.getIndexPathType(), deleteFileDocumentIdList); } Iterator<FileIndexDocument> it = list.iterator(); List<FileIndexDocument> theList = new ArrayList<FileIndexDocument>(); while (it.hasNext()) { theList.add(it.next()); it.remove(); if (theList.size() >= fileIndexAllItem.getPageSize()) { docOperatorFacade.createFileIndexs(theList, fileIndexAllItem.getMaxIndexFileSize()); theList.clear(); } } if (theList.size() > 0) { docOperatorFacade.createFileIndexs(theList, fileIndexAllItem.getMaxIndexFileSize()); theList.clear(); } theList = null; list.clear(); }
From source file:it.attocchi.jpa2.JPAEntityFilter.java
/** * /* w ww. j a v a 2 s . c o m*/ * @param criteriaBuilder * @param paths * @return */ protected Predicate buildMultiWordLikePredicate(CriteriaBuilder criteriaBuilder, Path<String>... paths) { String[] words = semeRicerca.split(" "); List<Predicate> likeAllFields = new ArrayList<Predicate>(); for (Path<String> path : paths) { List<Predicate> likeOnWord = new ArrayList<Predicate>(); for (String word : words) { likeOnWord.add(criteriaBuilder.like(path, getForLike(word))); } Predicate p1 = criteriaBuilder.and(likeOnWord.toArray(new Predicate[likeOnWord.size()])); likeAllFields.add(p1); likeOnWord.clear(); } Predicate res = criteriaBuilder.or(likeAllFields.toArray(new Predicate[likeAllFields.size()])); return res; }
From source file:com.liato.bankdroid.banking.banks.Statoil.java
@Override protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException { urlopen = new Urllib(true); List<NameValuePair> postData = new ArrayList<NameValuePair>(); response = urlopen.open("https://applications.sebkort.com/nis/external/stse/login.do"); List<NameValuePair> parameters = new ArrayList<NameValuePair>(3); parameters.add(new BasicNameValuePair("USERNAME", "0122" + username.toUpperCase())); parameters.add(new BasicNameValuePair("referer", "login.jsp")); response = urlopen.open("https://applications.sebkort.com/nis/external/hidden.jsp", postData); postData.clear(); postData.add(new BasicNameValuePair("choice", "PWD")); postData.add(new BasicNameValuePair("uname", username.toUpperCase())); postData.add(new BasicNameValuePair("PASSWORD", password)); postData.add(new BasicNameValuePair("target", "/nis/stse/main.do")); postData.add(new BasicNameValuePair("prodgroup", "0122")); postData.add(new BasicNameValuePair("USERNAME", "0122" + username.toUpperCase())); postData.add(new BasicNameValuePair("METHOD", "LOGIN")); postData.add(new BasicNameValuePair("CURRENT_METHOD", "PWD")); return new LoginPackage(urlopen, postData, response, "https://applications.sebkort.com/siteminderagent/forms/generic.fcc"); }
From source file:com.espertech.esper.core.start.EPStatementStartMethodHelperSubselect.java
private static Pair<EventTableFactory, SubordTableLookupStrategyFactory> determineSubqueryIndexInternalFactory( ExprNode filterExpr, EventType viewableEventType, EventType[] outerEventTypes, StreamTypeService subselectTypeService, boolean fullTableScan, Set<String> optionalUniqueProps) throws ExprValidationException { // No filter expression means full table scan if ((filterExpr == null) || fullTableScan) { UnindexedEventTableFactory table = new UnindexedEventTableFactory(0); SubordFullTableScanLookupStrategyFactory strategy = new SubordFullTableScanLookupStrategyFactory(); return new Pair<EventTableFactory, SubordTableLookupStrategyFactory>(table, strategy); }// w w w. ja va 2 s . c o m // Build a list of streams and indexes SubordPropPlan joinPropDesc = QueryPlanIndexBuilder.getJoinProps(filterExpr, outerEventTypes.length, subselectTypeService.getEventTypes()); Map<String, SubordPropHashKey> hashKeys = joinPropDesc.getHashProps(); Map<String, SubordPropRangeKey> rangeKeys = joinPropDesc.getRangeProps(); List<SubordPropHashKey> hashKeyList = new ArrayList<SubordPropHashKey>(hashKeys.values()); List<SubordPropRangeKey> rangeKeyList = new ArrayList<SubordPropRangeKey>(rangeKeys.values()); boolean unique = false; // If this is a unique-view and there are unique criteria, use these if (optionalUniqueProps != null && !optionalUniqueProps.isEmpty()) { boolean found = true; for (String uniqueProp : optionalUniqueProps) { if (!hashKeys.containsKey(uniqueProp)) { found = false; break; } } if (found) { String[] hashKeysArray = hashKeys.keySet().toArray(new String[hashKeys.keySet().size()]); for (String hashKey : hashKeysArray) { if (!optionalUniqueProps.contains(hashKey)) { hashKeys.remove(hashKey); } } hashKeyList = new ArrayList<SubordPropHashKey>(hashKeys.values()); unique = true; rangeKeyList.clear(); rangeKeys.clear(); } } // build table (local table) EventTableFactory eventTable; CoercionDesc hashCoercionDesc; CoercionDesc rangeCoercionDesc; if (hashKeys.size() != 0 && rangeKeys.isEmpty()) { String indexedProps[] = hashKeys.keySet().toArray(new String[hashKeys.keySet().size()]); hashCoercionDesc = CoercionUtil.getCoercionTypesHash(viewableEventType, indexedProps, hashKeyList); rangeCoercionDesc = new CoercionDesc(false, null); if (hashKeys.size() == 1) { if (!hashCoercionDesc.isCoerce()) { eventTable = new PropertyIndexedEventTableSingleFactory(0, viewableEventType, indexedProps[0], unique, null); } else { eventTable = new PropertyIndexedEventTableSingleCoerceAddFactory(0, viewableEventType, indexedProps[0], hashCoercionDesc.getCoercionTypes()[0]); } } else { if (!hashCoercionDesc.isCoerce()) { eventTable = new PropertyIndexedEventTableFactory(0, viewableEventType, indexedProps, unique, null); } else { eventTable = new PropertyIndexedEventTableCoerceAddFactory(0, viewableEventType, indexedProps, hashCoercionDesc.getCoercionTypes()); } } } else if (hashKeys.isEmpty() && rangeKeys.isEmpty()) { eventTable = new UnindexedEventTableFactory(0); hashCoercionDesc = new CoercionDesc(false, null); rangeCoercionDesc = new CoercionDesc(false, null); } else if (hashKeys.isEmpty() && rangeKeys.size() == 1) { String indexedProp = rangeKeys.keySet().iterator().next(); CoercionDesc coercionRangeTypes = CoercionUtil.getCoercionTypesRange(viewableEventType, rangeKeys, outerEventTypes); if (!coercionRangeTypes.isCoerce()) { eventTable = new PropertySortedEventTableFactory(0, viewableEventType, indexedProp); } else { eventTable = new PropertySortedEventTableCoercedFactory(0, viewableEventType, indexedProp, coercionRangeTypes.getCoercionTypes()[0]); } hashCoercionDesc = new CoercionDesc(false, null); rangeCoercionDesc = coercionRangeTypes; } else { String[] indexedKeyProps = hashKeys.keySet().toArray(new String[hashKeys.keySet().size()]); Class[] coercionKeyTypes = SubordPropUtil.getCoercionTypes(hashKeys.values()); String[] indexedRangeProps = rangeKeys.keySet().toArray(new String[rangeKeys.keySet().size()]); CoercionDesc coercionRangeTypes = CoercionUtil.getCoercionTypesRange(viewableEventType, rangeKeys, outerEventTypes); eventTable = new PropertyCompositeEventTableFactory(0, viewableEventType, indexedKeyProps, coercionKeyTypes, indexedRangeProps, coercionRangeTypes.getCoercionTypes()); hashCoercionDesc = CoercionUtil.getCoercionTypesHash(viewableEventType, indexedKeyProps, hashKeyList); rangeCoercionDesc = coercionRangeTypes; } SubordTableLookupStrategyFactory subqTableLookupStrategyFactory = SubordinateTableLookupStrategyUtil .getLookupStrategy(outerEventTypes, hashKeyList, hashCoercionDesc, rangeKeyList, rangeCoercionDesc, false); return new Pair<EventTableFactory, SubordTableLookupStrategyFactory>(eventTable, subqTableLookupStrategyFactory); }
From source file:cc.kave.commons.pointsto.evaluation.cv.StratifiedProjectsCVFoldBuilder.java
@Override public List<List<Usage>> createFolds(Map<ProjectIdentifier, List<Usage>> projectUsages) { EnumeratedDistribution<ProjectIdentifier> projectDistribution; List<Pair<ProjectIdentifier, Double>> projectProbabilities = new ArrayList<>(projectUsages.size()); // initialize distributions long totalUsages = 0; for (Map.Entry<ProjectIdentifier, List<Usage>> project : projectUsages.entrySet()) { projectProbabilities//ww w. j a v a 2 s . c o m .add(new Pair<ProjectIdentifier, Double>(project.getKey(), (double) project.getValue().size())); totalUsages += project.getValue().size(); } // normalization of the probability mass is done by the constructor projectDistribution = new EnumeratedDistribution<>(rndGenerator, projectProbabilities); shuffleUsages(projectUsages.values()); List<List<Usage>> folds = new ArrayList<>(numFolds); int avgFoldSize = (int) (totalUsages / numFolds); for (int f = 0; f < numFolds - 1; ++f) { List<Usage> fold = new ArrayList<>(avgFoldSize); folds.add(fold); for (int i = 0; i < avgFoldSize; ++i) { ProjectIdentifier project; List<Usage> usages; do { project = projectDistribution.sample(); usages = projectUsages.get(project); } while (usages.isEmpty()); int lastIndex = usages.size() - 1; Usage usage = usages.remove(lastIndex); fold.add(usage); } } // add remaining usages to the last fold List<Usage> lastFold = new ArrayList<>(avgFoldSize); folds.add(lastFold); for (List<Usage> usages : projectUsages.values()) { lastFold.addAll(usages); usages.clear(); } Collections.shuffle(lastFold, new Random(rndGenerator.nextLong())); return folds; }
From source file:com.iksgmbh.sql.pojomemodb.sqlparser.SelectParser.java
private void replaceAliasInOrderConditions(final List<OrderCondition> orderConditions, final List<TableId> tableIdList) throws SQLException { final List<OrderCondition> toReturn = new ArrayList<OrderCondition>(); for (OrderCondition orderCondition : orderConditions) { toReturn.add(new OrderCondition(replaceAliases(orderCondition.getColumnName(), tableIdList), orderCondition.getDirection())); }/*from w ww . ja va 2s . co m*/ orderConditions.clear(); orderConditions.addAll(toReturn); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void candidatesGrow(List<Mutable<ILogicalOperator>> opList, List<Mutable<ILogicalOperator>> candidates) { List<Mutable<ILogicalOperator>> previousCandidates = new ArrayList<Mutable<ILogicalOperator>>(); previousCandidates.addAll(candidates); candidates.clear(); boolean validCandidate = false; for (Mutable<ILogicalOperator> op : opList) { List<Mutable<ILogicalOperator>> inputs = op.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); validCandidate = false;//from w w w. j a v a 2 s . c o m for (Mutable<ILogicalOperator> candidate : previousCandidates) { // if current input is in candidates if (inputRef.getValue().equals(candidate.getValue())) { if (inputs.size() == 1) { validCandidate = true; } else { BitSet candidateInputBitMap = opToCandidateInputs.get(op); if (candidateInputBitMap == null) { candidateInputBitMap = new BitSet(inputs.size()); opToCandidateInputs.put(op, candidateInputBitMap); } candidateInputBitMap.set(i); if (candidateInputBitMap.cardinality() == inputs.size()) { validCandidate = true; } } break; } } } if (!validCandidate) continue; if (!candidates.contains(op)) candidates.add(op); } }
From source file:com.evolveum.midpoint.web.page.admin.reports.PageCreatedReports.java
private void deleteSelectedPerformed(AjaxRequestTarget target, ReportDeleteDialogDto.Operation op, ReportOutputType single) {//from ww w . ja v a2s . c om List<ReportOutputType> selected = getSelectedData(); if (single != null) { selected.clear(); selected.add(single); } if (selected.isEmpty()) { return; } ReportDeleteDialogDto dto = new ReportDeleteDialogDto(op, selected); deleteModel.setObject(dto); ModalWindow dialog = (ModalWindow) get(ID_CONFIRM_DELETE); dialog.show(target); }