List of usage examples for java.util List listIterator
ListIterator<E> listIterator();
From source file:edu.harvard.i2b2.pm.util.PMUtil.java
public void convertToUppercaseStrings(List<String> list) { ListIterator<String> iterator = list.listIterator(); while (iterator.hasNext()) { String color = iterator.next(); // get item iterator.set(color.toUpperCase()); // convert to upper case } // end while }
From source file:airbrake.Backtrace.java
private final List<String> filter(final List<String> backtrace) { final ListIterator<String> iterator = backtrace.listIterator(); while (iterator.hasNext()) { String string = iterator.next(); if (mustBeIgnored(string)) { continue; }//from ww w . j a v a2s .c om if (notValidBacktrace(string)) { string = removeDobuleDot(string); } filteredBacktrace.add(string); } return filteredBacktrace; }
From source file:ch.cern.dss.teamcity.agent.MockAgentBuildRunner.java
/** * Create the BuildProcess extension that will be actually run as this build stage. * * @param build the currently running build. * @param context this build runner's context parameters. * * @return an instance of our custom BuildProcess extension. * @throws RunBuildException//from w ww. j a v a2 s .com */ @NotNull @Override public BuildProcess createBuildProcess(@NotNull AgentRunningBuild build, @NotNull BuildRunnerContext context) throws RunBuildException { Map<String, String> runnerParameters = context.getRunnerParameters(); BuildProgressLogger logger = build.getBuildLogger(); // Append config extension if necessary List<String> chrootNamesPattern = FileUtil .splitStringOnWhitespace(runnerParameters.get(MockConstants.CHROOTS)); for (ListIterator<String> i = chrootNamesPattern.listIterator(); i.hasNext();) { String chrootName = i.next(); if (!chrootName.endsWith(".cfg")) { i.set(chrootName + ".cfg"); } } // Find mock config files List<String> mockConfigFiles = FileUtil.findFiles(runnerParameters.get(MockConstants.CONFIG_DIR), StringUtil.join(chrootNamesPattern, " ")); List<String> chrootNames = new ArrayList<String>(); for (String configFile : mockConfigFiles) { chrootNames.add(FilenameUtils.removeExtension(new File(configFile).getName())); } logger.message("Building in the following chroots: " + Arrays.toString(chrootNames.toArray())); // Find srpms List<String> srpms = FileUtil.findFiles(runnerParameters.get(MockConstants.SOURCE_RPM_DIR), runnerParameters.get(MockConstants.SOURCE_RPMS)); logger.message("Building packages: " + Arrays.toString(srpms.toArray())); // Return custom build process return new MockBuildProcess(chrootNames, srpms, runnerParameters, build.getArtifactsPaths(), context.getBuildParameters().getEnvironmentVariables(), logger); }
From source file:com.twitter.hraven.etl.FileLister.java
/** * prunes the given list/array of files based on their sizes * * @param maxFileSize -max #bytes to be stored in an hbase cell * @param origList - input list of files to be processed * @param hdfs - filesystem to be looked at * @param inputPath - root dir of the path containing history files * @return - pruned array of FileStatus of files to be processed *//*from w w w .j av a2 s . co m*/ static FileStatus[] pruneFileListBySize(long maxFileSize, FileStatus[] origList, FileSystem hdfs, Path inputPath) { LOG.info("Pruning orig list of size " + origList.length + " for source" + inputPath.toUri()); long fileSize = 0L; List<FileStatus> prunedFileList = new ArrayList<FileStatus>(); Set<String> toBeRemovedJobId = new HashSet<String>(); for (int i = 0; i < origList.length; i++) { fileSize = origList[i].getLen(); // check if hbase can store this file if yes, consider it for processing if (fileSize <= maxFileSize) { prunedFileList.add(origList[i]); } else { Path hugeFile = origList[i].getPath(); LOG.info("In getListFilesToProcess filesize " + fileSize + " has exceeded maxFileSize " + maxFileSize + " for " + hugeFile.toUri()); // note the job id so that we can remove the other file (job conf or job history) toBeRemovedJobId.add(getJobIdFromPath(hugeFile)); } } if (prunedFileList.size() == 0) { LOG.info("Found no files worth processing. Returning 0 sized array"); return new FileStatus[0]; } String jobId = null; ListIterator<FileStatus> it = prunedFileList.listIterator(); while (it.hasNext()) { if (toBeRemovedJobId.size() == 0) { // no files to remove break; } Path curFile = it.next().getPath(); jobId = getJobIdFromPath(curFile); if (toBeRemovedJobId.contains(jobId)) { LOG.info("Removing from prunedList " + curFile.toUri()); it.remove(); /* * removing the job id from the hash set since there would be only * one file with this job id in the prunedList, the other file with * this job id was huge and was already moved out */ toBeRemovedJobId.remove(jobId); } } return prunedFileList.toArray(new FileStatus[prunedFileList.size()]); }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderStoreRead.java
public static ExtDirectStoreResult<Row> createExtDirectStoreResult(ExtDirectStoreReadRequest request, final String appendix) { List<Row> rows = createRows(appendix); int totalSize = rows.size(); if (request != null) { if ("name".equals(request.getQuery())) { for (Iterator<Row> iterator = rows.listIterator(); iterator.hasNext();) { Row row = iterator.next(); if (!row.getName().startsWith("name")) { iterator.remove();//from w w w.ja v a 2 s . c o m } } } else if ("firstname".equals(request.getQuery())) { for (Iterator<Row> iterator = rows.listIterator(); iterator.hasNext();) { Row row = iterator.next(); if (!row.getName().startsWith("firstname")) { iterator.remove(); } } } totalSize = rows.size(); Collection<SortInfo> sorters = request.getSorters(); if (!sorters.isEmpty()) { SortInfo sortInfo = sorters.iterator().next(); assertThat(sortInfo.getProperty()).isEqualTo("id"); if (sortInfo.getDirection() == SortDirection.ASCENDING) { Collections.sort(rows); } else { Collections.sort(rows, new Comparator<Row>() { // @Override @Override public int compare(Row o1, Row o2) { return o2.getId() - o1.getId(); } }); } } else if (StringUtils.hasText(request.getSort())) { assertThat(request.getSort()).isEqualTo("id"); if (request.isAscendingSort()) { Collections.sort(rows); } else if (request.isDescendingSort()) { Collections.sort(rows, new Comparator<Row>() { // @Override @Override public int compare(Row o1, Row o2) { return o2.getId() - o1.getId(); } }); } } Collection<GroupInfo> groups = request.getGroups(); if (!groups.isEmpty()) { GroupInfo groupInfo = groups.iterator().next(); assertThat(groupInfo.getProperty()).isEqualTo("id"); if (groupInfo.getDirection() == SortDirection.ASCENDING) { Collections.sort(rows); } else { Collections.sort(rows, new Comparator<Row>() { // @Override @Override public int compare(Row o1, Row o2) { return o2.getId() - o1.getId(); } }); } } else if (StringUtils.hasText(request.getGroupBy())) { assertThat(request.getGroupBy()).isEqualTo("id"); if (request.isAscendingGroupSort()) { Collections.sort(rows); } else if (request.isDescendingGroupSort()) { Collections.sort(rows, new Comparator<Row>() { // @Override @Override public int compare(Row o1, Row o2) { return o2.getId() - o1.getId(); } }); } } if (request.getStart() != null && request.getLimit() != null) { rows = rows.subList(request.getStart(), Math.min(totalSize, request.getStart() + request.getLimit())); } else { rows = rows.subList(0, 50); } } return new ExtDirectStoreResult<Row>().setTotal(Long.valueOf(totalSize)).setRecords(rows) .setSuccess(Boolean.TRUE); }
From source file:org.apache.pig.backend.hadoop.hbase.HBaseTableInputFormat.java
@Override public List<InputSplit> getSplits(org.apache.hadoop.mapreduce.JobContext context) throws IOException { List<InputSplit> splits = super.getSplits(context); ListIterator<InputSplit> splitIter = splits.listIterator(); while (splitIter.hasNext()) { TableSplit split = (TableSplit) splitIter.next(); byte[] startKey = split.getStartRow(); byte[] endKey = split.getEndRow(); // Skip if the region doesn't satisfy configured options. if ((skipRegion(CompareOp.LESS, startKey, lt_)) || (skipRegion(CompareOp.GREATER, endKey, gt_)) || (skipRegion(CompareOp.GREATER, endKey, gte_)) || (skipRegion(CompareOp.LESS_OR_EQUAL, startKey, lte_))) { splitIter.remove();//from w ww . j a v a 2 s.co m } } return splits; }
From source file:com.digitalgeneralists.assurance.model.entities.ApplicationConfiguration.java
private List<String> transformStringPropertyToListProperty(String property, boolean removeExtensionPatterns) { StrTokenizer tokenizer = new StrTokenizer(property, ','); List<String> tokenizedList = tokenizer.getTokenList(); // NOTE: May want to reconsider the toLowercase conversion. ListIterator<String> iterator = tokenizedList.listIterator(); while (iterator.hasNext()) { String extension = iterator.next(); // NOTE: This is probably a bit overly-aggressive and less-sophisticated than it could be, // but it should handle 99% of the input that will be entered. if (removeExtensionPatterns) { extension = StringUtils.replace(extension, "*.", ""); extension = StringUtils.replace(extension, "*", ""); extension = StringUtils.replace(extension, ".", ""); }/*from w w w. j a v a 2s. c o m*/ iterator.set(extension.toLowerCase().trim()); } return tokenizedList; }
From source file:org.jasig.i18n.translate.AutoTranslationService.java
public Map<String, String> getAutoUpdatedTranslationMap(Map<String, String> mainMap, Map<String, String> targetMap, String languageKey) { // assemble a set of keys represented in the main map but not in the // target language map Set<String> missing = mainMap.keySet(); missing.removeAll(targetMap.keySet()); // put the keys in a list so that we have a consistent ordering List<String> keys = new ArrayList<String>(); keys.addAll(missing);/*from www . j a va 2 s.co m*/ // assemble a list of untranslated messages in the same order as our // missing key list List<String> untranslatedMessages = new ArrayList<String>(); for (String key : keys) { untranslatedMessages.add(mainMap.get(key)); } Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("key", this.apiKey); parameters.put("source", this.defaultLanguageKey); parameters.put("target", languageKey); parameters.put("query", untranslatedMessages); GoogleTranslationResponse response = this.restTemplate.getForObject(urlTemplate, GoogleTranslationResponse.class, parameters); List<Translation> translations = response.getTranslations(); // iterate through the auto-translations, adding each to the target // map ListIterator<Translation> iter = translations.listIterator(); while (iter.hasNext()) { Translation translation = iter.next(); String key = keys.get(iter.previousIndex()); targetMap.put(key, translation.getTranslatedText()); } return targetMap; }
From source file:com.garyclayburg.persistence.repository.AccountMatcher.java
public User attachAccount(UserAccount scimAccount) { User matchedUser = matchAccount(scimAccount); User savedUser = null;/*from w w w . j a v a 2 s .com*/ if (matchedUser != null) { List<UserAccount> userAccounts = matchedUser.getUserAccounts(); if (userAccounts != null) { ListIterator<UserAccount> listIterator = userAccounts.listIterator(); boolean updatedAccount = false; while (listIterator.hasNext()) { UserAccount userAccount = listIterator.next(); String username = userAccount.getUsername(); String accountType = userAccount.getAccountType(); if (username != null && accountType != null) { if (username.equals(scimAccount.getUsername()) && accountType.equals(scimAccount.getAccountType())) { listIterator.set(scimAccount); updatedAccount = true; } } } if (!updatedAccount) { //add as new account for this matched user userAccounts.add(scimAccount); } } else { //user does not have any accounts yet. This will be his first. List<UserAccount> newAccounts = new ArrayList<>(); newAccounts.add(scimAccount); matchedUser.setUserAccounts(newAccounts); } savedUser = auditedUserRepo.save(matchedUser); } return savedUser; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ShowDegreesAction.java
private List buildDegreesList(List executionDegreesList) { if (executionDegreesList == null) { return null; }/* ww w . j a v a 2 s.c om*/ List degreesList = new ArrayList(); ListIterator listIterator = executionDegreesList.listIterator(); while (listIterator.hasNext()) { InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) listIterator.next(); if (!degreesList.contains(infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree())) { degreesList.add(infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree()); } } // order list by alphabetic order of the code Collections.sort(degreesList, new BeanComparator("nome")); return degreesList; }