List of usage examples for org.apache.commons.collections CollectionUtils addIgnoreNull
public static boolean addIgnoreNull(Collection collection, Object object)
From source file:org.mifos.accounts.api.StandardAccountService.java
/** * method created for undo transaction import ability MIFOS-5702 * changed return type /*from ww w .j a v a2 s . c o m*/ * */ @Override public List<AccountTrxDto> makePaymentsForImport( List<AccountPaymentParametersDto> accountPaymentParametersDtoList) throws PersistenceException, AccountException { /* * We're counting on rollback on exception behavior in BaseAction. If we want to expose makePayments via a * non-Mifos-Web-UI service, we'll need to handle the rollback here. */ List<AccountTrxDto> trxIds = new ArrayList<AccountTrxDto>(); List<AccountBO> accounts = new ArrayList<AccountBO>(); StaticHibernateUtil.startTransaction(); int i = 0; for (AccountPaymentParametersDto accountPaymentParametersDTO : accountPaymentParametersDtoList) { CollectionUtils.addIgnoreNull(accounts, makeImportedPayments(accountPaymentParametersDTO)); if (i % 30 == 0) { StaticHibernateUtil.getSessionTL().flush(); StaticHibernateUtil.getSessionTL().clear(); } i++; } StaticHibernateUtil.getSessionTL().flush(); StaticHibernateUtil.getSessionTL().clear(); StaticHibernateUtil.commitTransaction(); for (AccountBO account : accounts) { trxIds.add(new AccountTrxDto(getAccTrxId(account))); } return trxIds; }
From source file:org.openmrs.module.clinicalsummary.web.controller.utils.OrderedObsListController.java
/** * @param firstMapping/*from www.j av a2 s . c om*/ * @param selectedStatusType * @return */ private List<String[]> serialize(final Map<Object, Map<Object, Object[]>> firstMapping, final StatusType selectedStatusType) { List<StatusType> statuses = Arrays.asList(StatusType.values()); if (selectedStatusType != null) statuses = Arrays.asList(selectedStatusType); List<String[]> serialized = new ArrayList<String[]>(); for (Object groupingObject : firstMapping.keySet()) { Map<Object, Object[]> groupedObjects = firstMapping.get(groupingObject); // when user don't pick any status, some grouping for a certain status might not have data for (StatusType statusType : statuses) { // name of the grouping element (ex: concept name, location name, person name) String groupingName = WebUtils.getStringValue(groupingObject); // id of the grouping element (ex: concept id, location id, person id) String groupingId = WebUtils.getIdValue(groupingObject); // the data is not there and we need to fill the missing values String[] strings = new String[] { groupingName, groupingId, statusType.getValue(), String.valueOf(0) }; if (groupedObjects.containsKey(statusType)) { Object[] object = groupedObjects.get(statusType); // total number of the element in the grouping strings[strings.length - 1] = WebUtils.getStringValue(object[object.length - 1]); } CollectionUtils.addIgnoreNull(serialized, strings); } } return serialized; }
From source file:org.reusables.dbunit.DbUnitDatasetExecutionListener.java
/** * Create the datasets for the given annotation. If no annotation is supplied * or when the annotation contains no dataset resources, this method tries to find a dataset on the default location. * /* w w w .ja v a 2s . c o m*/ * @param testContext The context for the current test. * @param annotation The dataset resource information. * @param methodAnnotation If true, indicates that the annotation being processed is a method level annotation, false is for class level annotations. * @return The datasets found for the given annotation, or default dataset. * * @throws Exception Any error. * @since 1.3.0 */ protected Collection<IDataSet> createDataSets(final TestContext testContext, final DbUnitDataset annotation, final boolean methodAnnotation) throws Exception { final Collection<IDataSet> datasets = new ArrayList<IDataSet>(); if (annotation == null || ArrayUtils.isEmpty(annotation.value())) { if (methodAnnotation) { CollectionUtils.addIgnoreNull(datasets, getDefaultMethodDataSet(testContext, annotation)); } else { CollectionUtils.addIgnoreNull(datasets, getDefaultClassDataSet(testContext, annotation)); } } else { for (final String resource : annotation.value()) { LOG.debug("Adding dataset file from classpath '{}'", resource); datasets.add(createDataSet(getClass().getResourceAsStream(resource), annotation)); } } return datasets; }
From source file:org.wte4j.impl.word.Docx4JWordTemplate.java
private List<HeaderPart> listHeaderParts() { List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections(); List<HeaderPart> headerParts = new LinkedList<HeaderPart>(); for (SectionWrapper sectionWrapper : sectionWrappers) { HeaderFooterPolicy policy = sectionWrapper.getHeaderFooterPolicy(); CollectionUtils.addIgnoreNull(headerParts, policy.getDefaultHeader()); CollectionUtils.addIgnoreNull(headerParts, policy.getEvenHeader()); CollectionUtils.addIgnoreNull(headerParts, policy.getFirstHeader()); }/*from w w w . j a v a 2 s . c o m*/ return headerParts; }
From source file:org.wte4j.impl.word.Docx4JWordTemplate.java
private List<FooterPart> listFooterParts() { List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections(); List<FooterPart> footerParts = new LinkedList<FooterPart>(); for (SectionWrapper sectionWrapper : sectionWrappers) { HeaderFooterPolicy policy = sectionWrapper.getHeaderFooterPolicy(); CollectionUtils.addIgnoreNull(footerParts, policy.getDefaultFooter()); CollectionUtils.addIgnoreNull(footerParts, policy.getEvenFooter()); CollectionUtils.addIgnoreNull(footerParts, policy.getFirstFooter()); }/* w ww . j a va2 s . com*/ return footerParts; }
From source file:org.xlrnet.metadict.core.util.FormatUtils.java
/** * Returns a formatted and human-readable representation of the additional information in a {@link * DictionaryObject}. This includes all data except for the general form and the {@link Language} object. * <p>// w w w . j a va 2s . c om * If the formatted object contains no additional information, an empty string will be returned. * * @param dictionaryObject * The object whose additional information should be formatted. * @return A formatted string. */ @NotNull public static String formatDictionaryObjectRepresentation(DictionaryObject dictionaryObject) { List<String> contentList = new ArrayList<>(); CollectionUtils.addIgnoreNull(contentList, dictionaryObject.getDescription()); if (dictionaryObject.getAdditionalForms().size() > 0) { Map<GrammaticalForm, String> additionalForms = dictionaryObject.getAdditionalForms(); // Forms for nouns if (additionalForms.containsKey(GrammaticalNumber.SINGULAR)) contentList.add("sg.: " + additionalForms.get(GrammaticalNumber.SINGULAR)); if (additionalForms.containsKey(GrammaticalNumber.PLURAL)) contentList.add("pl.: " + additionalForms.get(GrammaticalNumber.PLURAL)); // Tenses if (additionalForms.containsKey(GrammaticalTense.PRESENT_TENSE)) contentList.add("pr.: " + additionalForms.get(GrammaticalTense.PRESENT_TENSE)); if (additionalForms.containsKey(GrammaticalTense.PAST_TENSE)) contentList.add("pa.: " + additionalForms.get(GrammaticalTense.PAST_TENSE)); if (additionalForms.containsKey(GrammaticalTense.PAST_PERFECT)) contentList.add("par.: " + additionalForms.get(GrammaticalTense.PAST_PERFECT)); if (additionalForms.containsKey(GrammaticalTense.PERFECT_PARTICIPLE)) contentList.add("per.: " + additionalForms.get(GrammaticalTense.PERFECT_PARTICIPLE)); // Adjective forms: if (additionalForms.containsKey(GrammaticalComparison.POSITIVE)) contentList.add("pos.: " + additionalForms.get(GrammaticalComparison.POSITIVE)); if (additionalForms.containsKey(GrammaticalComparison.COMPARATIVE)) contentList.add("comp.: " + additionalForms.get(GrammaticalComparison.COMPARATIVE)); if (additionalForms.containsKey(GrammaticalComparison.SUPERLATIVE)) contentList.add("sup.: " + additionalForms.get(GrammaticalComparison.SUPERLATIVE)); if (additionalForms.containsKey(GrammaticalCase.DEFINITE_FORM)) contentList.add("def.: " + additionalForms.get(GrammaticalCase.DEFINITE_FORM)); } if (dictionaryObject.getAbbreviation() != null) { contentList.add("abbr.: " + dictionaryObject.getAbbreviation()); } if (dictionaryObject.getDomain() != null) { contentList.add("dom.: " + dictionaryObject.getDomain()); } if (dictionaryObject.getGrammaticalGender() != null && !GrammaticalGender.NONE.equals(dictionaryObject.getGrammaticalGender()) && !GrammaticalGender.UNKNOWN.equals(dictionaryObject.getGrammaticalGender())) { contentList.add("(" + dictionaryObject.getGrammaticalGender().getFormIdentifier() + ")"); } return StringUtils.join(contentList, ", "); }