List of usage examples for org.apache.commons.collections ListUtils union
public static List union(final List list1, final List list2)
From source file:org.onosproject.net.flow.DefaultTrafficTreatment.java
/** * Creates a new traffic treatment from the specified list of instructions. * * @param deferred deferred instructions * @param immediate immediate instructions * @param table table transition instruction * @param clear instruction to clear the deferred actions list *//*from ww w. j ava 2s.c o m*/ private DefaultTrafficTreatment(List<Instruction> deferred, List<Instruction> immediate, Instructions.TableTypeTransition table, boolean clear) { this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); this.deferred = ImmutableList.copyOf(checkNotNull(deferred)); this.all = ListUtils.union(this.immediate, this.deferred); this.table = table; this.hasClear = clear; }
From source file:org.openmrs.module.paperrecord.PaperRecordServiceImpl.java
@Override @Transactional/* ww w . j a v a 2s . c o m*/ public void markPaperRecordsForMerge(PaperRecord preferredPaperRecord, PaperRecord notPreferredPaperRecord) { if (!preferredPaperRecord.getRecordLocation().equals(notPreferredPaperRecord.getRecordLocation())) { throw new IllegalArgumentException("Cannot merge two records from different locations: " + preferredPaperRecord + ", " + notPreferredPaperRecord); } List<PaperRecordRequest> pendingRequests = ListUtils.union( paperRecordRequestDAO.findPaperRecordRequests(PENDING_STATUSES, preferredPaperRecord), paperRecordRequestDAO.findPaperRecordRequests(PENDING_STATUSES, notPreferredPaperRecord)); // for now, we will just cancel any pending paper record requests for the preferred patient and non-preferred patient for (PaperRecordRequest request : pendingRequests) { markPaperRecordRequestAsCancelled(request); } // also copy over all the non-preferred patient SENT requests to the new patient // (this probably isn't exactly right, but it should prevent an error from being thrown one of these charts is returned to the archives room) for (PaperRecordRequest request : paperRecordRequestDAO .findPaperRecordRequests(Collections.singletonList(Status.SENT), notPreferredPaperRecord)) { request.setPaperRecord(preferredPaperRecord); savePaperRecordRequest(request); } // create the request PaperRecordMergeRequest mergeRequest = new PaperRecordMergeRequest(); mergeRequest.setStatus(PaperRecordMergeRequest.Status.OPEN); mergeRequest.setPreferredPaperRecord(preferredPaperRecord); mergeRequest.setNotPreferredPaperRecord(notPreferredPaperRecord); mergeRequest.setCreator(Context.getAuthenticatedUser()); mergeRequest.setDateCreated(new Date()); paperRecordMergeRequestDAO.saveOrUpdate(mergeRequest); // void the non-preferred identifier; we do this now (instead of when the merge is confirmed) // so that all new requests for records for this patient use the right identifier patientService.voidPatientIdentifier(notPreferredPaperRecord.getPatientIdentifier(), "voided during paper record merge"); }
From source file:org.opentestsystem.delivery.testreg.rest.view.CSVView.java
/** * Writes the CSV data to the response stream * //w w w .ja va 2s. c o m * @param model * the model * @param out * the response stream writer */ @SuppressWarnings("unchecked") protected void writeValues(final Map<String, Object> model, final PrintWriter writer) throws IOException { final List<TestRegistrationBase> entityList = (List<TestRegistrationBase>) model.get(DATA_LIST); final String formatType = ((String) model.get(FORMAT_TYPE)).toUpperCase(); String exportType = null; if (formatType.equalsIgnoreCase(FormatType.STUDENT.name())) { exportType = ((String) model.get(EXPORT_TYPE)).toUpperCase(); } final CSVWriter csvWriter = new CSVWriter(writer, ','); // Adding Title to the CSV row String headerColumns[] = new String[100]; if (formatType.equalsIgnoreCase(FormatType.STUDENT.name())) { // Based on export type for FormatType( STUDENT ) assigning headers for export file if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.studentsPlusAccommodations.name())) { List<String> headerStudentList = templateDownloadMap.get(FormatType.STUDENT); String[] headerCodesTemp = headersMap.get(FormatType.DESIGNATEDSUPPORTSANDACCOMMODATIONS.name()); List<String> headerCodes = Arrays.asList(headerCodesTemp); List<String> headerAccommodationList = headerCodes.subList(2, headerCodes.size()); String lastElement = headerStudentList.get(headerStudentList.size() - 1); List<String> combinedHeaders = ListUtils .union(headerStudentList.subList(0, headerStudentList.size() - 1), headerAccommodationList); combinedHeaders.add(lastElement); headerColumns = combinedHeaders.toArray(new String[combinedHeaders.size()]); } else if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.studentsOnly.name())) { List<String> headerStudentList = templateDownloadMap.get(FormatType.STUDENT); headerColumns = headerStudentList.toArray(new String[headerStudentList.size()]); } else if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.accommodationsOnly.name())) { headerColumns = headersMap.get(FormatType.DESIGNATEDSUPPORTSANDACCOMMODATIONS.name()); } else if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.explicitEligibility.name())) { List<String> headerExplicitEligibilityList = templateDownloadMap .get(FormatType.EXPLICITELIGIBILITY); headerColumns = headerExplicitEligibilityList .toArray(new String[headerExplicitEligibilityList.size()]); } } else { headerColumns = this.headersMap.get(formatType); } // Add the Header csvWriter.writeNext(headerColumns); if (!CollectionUtils.isEmpty(entityList)) { for (final TestRegistrationBase entity : entityList) { switch (FormatType.valueOf(formatType)) { case STUDENT: exportStudent(csvWriter, (Student) entity, exportType); break; case STUDENTGROUP: exportStudentGroup(csvWriter, (StudentGroup) entity); break; case USER: // if format is user then we need to customize export to include role associations as separate rows exportUser(csvWriter, (User) entity); break; default: csvWriter.writeNext(this.testRegistrationViewTransformer.transform(entity)); break; } } } csvWriter.flush(); csvWriter.close(); }
From source file:org.opentestsystem.delivery.testreg.rest.view.ExcelView.java
@SuppressWarnings("unchecked") @Override// w w w.j av a 2s. c om protected void buildExcelDocument(final Map<String, Object> model, final HSSFWorkbook workbook, final HttpServletRequest request, final HttpServletResponse response) { // get data model which is passed by the Spring container final List<TestRegistrationBase> entityList = (List<TestRegistrationBase>) model.get(DATA_LIST); final String formatType = ((String) model.get(FORMAT_TYPE)).toUpperCase(); String exportType = null; if (formatType.equalsIgnoreCase(FormatType.STUDENT.name())) { exportType = ((String) model.get(EXPORT_TYPE)).toUpperCase(); HSSFName name = workbook.createName(); // display filename to return to the client name.setNameName(exportType); } final Sheet sheet = workbook.createSheet(formatType); sheet.setDefaultColumnWidth(30); String headerColumns[] = new String[100]; if (formatType.equalsIgnoreCase(FormatType.STUDENT.name())) { // Based on export type for FormatType( STUDENT ) assigning headers for export file if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.studentsPlusAccommodations.name())) { List<String> headerStudentList = templateDownloadMap.get(FormatType.STUDENT); String[] headerCodesTemp = headersMap.get(FormatType.DESIGNATEDSUPPORTSANDACCOMMODATIONS.name()); List<String> headerCodes = Arrays.asList(headerCodesTemp); List<String> headerAccommodationList = headerCodes.subList(2, headerCodes.size()); String lastElement = headerStudentList.get(headerStudentList.size() - 1); List<String> combinedHeaders = ListUtils .union(headerStudentList.subList(0, headerStudentList.size() - 1), headerAccommodationList); combinedHeaders.add(lastElement); headerColumns = combinedHeaders.toArray(new String[combinedHeaders.size()]); } else if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.studentsOnly.name())) { List<String> headerStudentList = templateDownloadMap.get(FormatType.STUDENT); headerColumns = headerStudentList.toArray(new String[headerStudentList.size()]); } else if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.accommodationsOnly.name())) { headerColumns = headersMap.get(FormatType.DESIGNATEDSUPPORTSANDACCOMMODATIONS.name()); } else if (exportType.equalsIgnoreCase(ExportStudentFormatEnums.explicitEligibility.name())) { List<String> headerExplicitEligibilityList = templateDownloadMap .get(FormatType.EXPLICITELIGIBILITY); headerColumns = headerExplicitEligibilityList .toArray(new String[headerExplicitEligibilityList.size()]); } } else { headerColumns = this.headersMap.get(formatType); } final Row header = sheet.createRow(0); for (int i = 0; i < headerColumns.length; i++) { final Cell cell = header.createCell(i); cell.setCellValue(headerColumns[i]); } // DataRow Begin if (!CollectionUtils.isEmpty(entityList)) { int rowCount = 1; for (final TestRegistrationBase entity : entityList) { // if format is user then we need to customize export to include role associations as separate rows switch (FormatType.valueOf(formatType)) { case USER: rowCount = exportUser(sheet, rowCount, entity); break; case STUDENTGROUP: rowCount = exportStudentGroup(sheet, rowCount, entity); break; case STUDENT: rowCount = exportStudent(sheet, rowCount, (Student) entity, exportType); break; default: final Row rowData = sheet.createRow(rowCount); final String[] columnData = this.testRegistrationViewTransformer.transform(entity); addData(rowData, 0, columnData.length, columnData); } rowCount++; } } }
From source file:org.pentaho.di.concurrency.JobMapConcurrencyTest.java
@Test public void updateGetAndReplaceConcurrently() throws Exception { AtomicBoolean condition = new AtomicBoolean(true); AtomicInteger generator = new AtomicInteger(10); List<Updater> updaters = new ArrayList<>(); for (int i = 0; i < updatersAmount; i++) { Updater updater = new Updater(jobMap, generator, updatersCycles); updaters.add(updater);/*from www .j a v a2 s . com*/ } List<Getter> getters = new ArrayList<>(); for (int i = 0; i < gettersAmount; i++) { getters.add(new Getter(jobMap, condition)); } List<Replacer> replacers = new ArrayList<>(); for (int i = 0; i < replaceAmount; i++) { replacers.add(new Replacer(jobMap, condition)); } //noinspection unchecked ConcurrencyTestRunner.runAndCheckNoExceptionRaised(updaters, ListUtils.union(replacers, getters), condition); }
From source file:org.pentaho.di.concurrency.JobTrackerConcurrencyTest.java
@Test public void readAndUpdateTrackerConcurrently() throws Exception { final AtomicBoolean condition = new AtomicBoolean(true); List<Getter> getters = new ArrayList<Getter>(gettersAmount); for (int i = 0; i < gettersAmount; i++) { getters.add(new Getter(condition, tracker)); }// w w w. ja v a2s.co m List<Searcher> searchers = new ArrayList<Searcher>(searchersAmount); for (int i = 0; i < searchersAmount; i++) { int lookingFor = updatersAmount * updatersCycles / 2 + i; assertTrue("We are looking for reachable index", lookingFor < updatersAmount * updatersCycles); searchers .add(new Searcher(condition, tracker, mockJobEntryCopy("job-entry-" + lookingFor, lookingFor))); } final AtomicInteger generator = new AtomicInteger(0); List<Updater> updaters = new ArrayList<Updater>(updatersAmount); for (int i = 0; i < updatersAmount; i++) { updaters.add(new Updater(tracker, updatersCycles, generator, "job-entry-%d")); } //noinspection unchecked ConcurrencyTestRunner.runAndCheckNoExceptionRaised(updaters, ListUtils.union(getters, searchers), condition); assertEquals(updatersAmount * updatersCycles, generator.get()); }
From source file:org.pentaho.platform.engine.core.system.objfac.spring.BarrierBeanProcessor.java
/** * This method can be run multiple times for multiple barrierBean property sets. Only one list of barrierBeans is maintained * so that plugins can add their own barrierBeans if necessary. Registered barrierBeans will be held just prior * to bean initialization. See {@link BarrierBeanPostProcessor} * /* www .j a v a 2s .c o m*/ * @param barrierBeanFilePath * @return */ @SuppressWarnings("unchecked") public void registerBarrierBeans(Properties barrierBeanProperties) { Enumeration<Object> enuKeys = barrierBeanProperties.keys(); while (enuKeys.hasMoreElements()) { String barrierName = (String) enuKeys.nextElement(); IServiceBarrier barrier = serviceBarrierManager.getServiceBarrier(barrierName); List<BarrierBean> theseBarrierBeans = BarrierBean .convertString(barrierBeanProperties.getProperty(barrierName)); if (theseBarrierBeans.size() > 0) { for (BarrierBean barrierBean : theseBarrierBeans) { //Add the beans/barriers to the maps if (beanBarriers.containsKey(barrierBean.getBeanName())) { beanBarriers.get(barrierBean.getBeanName()).add(barrierName); } else { Set<String> newSet = new HashSet<String>(); newSet.add(barrierName); beanBarriers.put(barrierBean.getBeanName(), newSet); } } List<BarrierBean> finalBarrierBeans = (List<BarrierBean>) barrierBeans.get(barrierName); finalBarrierBeans = finalBarrierBeans == null ? theseBarrierBeans : ListUtils.union(finalBarrierBeans, theseBarrierBeans); barrierBeans.put(barrierName, finalBarrierBeans); } } }
From source file:org.sonar.plugins.redmine.client.RedmineAdapter.java
public List<Issue> collectProjectIssues(final String projectKey, final java.util.Date projectDate) throws RedmineException { final String date = projectDate == null ? null : new java.text.SimpleDateFormat("yyyy-MM-dd").format(projectDate); //Get open issues first Map<String, String> parameters = new HashMap<String, String>(); parameters.put("project_id", projectKey); parameters.put("status_id", "open"); if (projectDate != null) { parameters.put("created_on", "<=" + date); }/* www . ja v a 2 s. c om*/ List<Issue> issues = redmineMgr.getIssues(parameters); //If a date was specified, also get the issues that have been closed since if (projectDate != null) { parameters.put("status_id", "closed"); parameters.put("created_on", "<=" + date); parameters.put("closed_on", ">=" + date); issues = ListUtils.union(issues, redmineMgr.getIssues(parameters)); } return issues; }
From source file:org.talend.dataprep.configuration.EncodingSupport.java
/** * Init the charset lists./* w ww .j ava2 s. c o m*/ */ @PostConstruct @SuppressWarnings("unchecked") private void initCharsets() { final List<Charset> certifiedCharsets = Arrays.stream(certifiedEncoding).map(Charset::forName) .collect(Collectors.toList()); this.supportedCharsets = new LinkedHashSet<>( ListUtils.union(certifiedCharsets, new ArrayList<>(Charset.availableCharsets().values()))); }
From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtil.java
/** * Does a substring of shorttext exist within longtext such that the * substring is at least half the length of longtext? * * @param longtext Longer string.//w ww . j av a 2s .c om * @param shorttext Shorter string. * @param i Start index of quarter length substring within longtext. * @return Five element String array, containing the prefix of longtext, the * suffix of longtext, the prefix of shorttext, the suffix of shorttext * and the common middle. Or null if there was no match. */ private List<T>[] diff_halfMatchI(List<T> longtext, List<T> shorttext, int i) { // Start with a 1/4 length substring at position i as a seed. List<T> seed = longtext.subList(i, i + longtext.size() / 4); int j = -1; List<T> best_common = new ArrayList<T>(); List<T> best_longtext_a = new ArrayList<T>(), best_longtext_b = new ArrayList<T>(); List<T> best_shorttext_a = new ArrayList<T>(), best_shorttext_b = new ArrayList<T>(); while ((j = indexOf(shorttext, seed, j + 1)) != -1) { int prefixLength = diff_commonPrefix(longtext.subList(i, longtext.size()), shorttext.subList(j, shorttext.size())); int suffixLength = diff_commonSuffix(longtext.subList(0, i), shorttext.subList(0, j)); if (best_common.size() < suffixLength + prefixLength) { best_common = ListUtils.union(shorttext.subList(j - suffixLength, j), shorttext.subList(j, j + prefixLength)); best_longtext_a = longtext.subList(0, i - suffixLength); best_longtext_b = longtext.subList(i + prefixLength, longtext.size()); best_shorttext_a = shorttext.subList(0, j - suffixLength); best_shorttext_b = shorttext.subList(j + prefixLength, shorttext.size()); } } if (best_common.size() * 2 >= longtext.size()) { return new List[] { best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b, best_common }; } else { return null; } }