Example usage for java.util List removeAll

List of usage examples for java.util List removeAll

Introduction

In this page you can find the example usage for java.util List removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:au.org.ala.delta.model.format.AttributeFormatter.java

private String formatIntegerAttribute(IntegerAttribute attribute) {
    StringBuilder builder = new StringBuilder();

    int minValue = attribute.getCharacter().getMinimumValue();
    int maxValue = attribute.getCharacter().getMaximumValue();

    // Need to determine if values below the minimum and or above the maximum are present - these are handled by outputting "or less" and "or more"
    boolean belowMinimumPresent = false;
    boolean aboveMaximumPresent = false;

    List<Integer> valuesCopy = new ArrayList<Integer>(attribute.getPresentValues());
    Collections.sort(valuesCopy);

    Set<Integer> belowMinAboveMaxValues = new HashSet<Integer>();
    for (int value : valuesCopy) {
        if (value < minValue) {
            belowMinimumPresent = true;/*  www  .j a  v a 2s.c o m*/
            belowMinAboveMaxValues.add(value);
        } else if (value > maxValue) {
            aboveMaximumPresent = true;
            belowMinAboveMaxValues.add(value);
        }
    }

    // Remove any values above the maximum or below the minimum from the list as they will be handled specially.
    valuesCopy.removeAll(belowMinAboveMaxValues);

    List<IntRange> intRanges = new ArrayList<IntRange>();

    if (valuesCopy.size() == 1) {
        intRanges.add(new IntRange(valuesCopy.get(0), valuesCopy.get(0)));
    } else {
        int startCurrentRange = 0;
        for (int i = 0; i < valuesCopy.size(); i++) {
            int num = valuesCopy.get(i);
            if (i > 0) {
                int prevNum = valuesCopy.get(i - 1);

                if (num != prevNum + 1) {
                    intRanges.add(new IntRange(startCurrentRange, prevNum));
                    startCurrentRange = num;
                }

                if (i == valuesCopy.size() - 1) {
                    intRanges.add(new IntRange(startCurrentRange, num));
                }
            } else {
                startCurrentRange = num;
            }
        }
    }

    String orSeparator = getOrSeparator(attribute);

    if (belowMinimumPresent) {
        builder.append(String.format(_orLessCaption, Integer.toString(minValue - 1)));
        if (intRanges.size() > 0 || aboveMaximumPresent) {
            builder.append(orSeparator);
        }
    }

    for (int i = 0; i < intRanges.size(); i++) {
        IntRange range = intRanges.get(i);

        if (range.getMinimumInteger() == range.getMaximumInteger()) {
            builder.append(Integer.toString(range.getMinimumInteger()));
        } else {
            builder.append(Integer.toString(range.getMinimumInteger()) + "-"
                    + Integer.toString(range.getMaximumInteger()));
        }

        if (i != intRanges.size() - 1 || aboveMaximumPresent) {
            builder.append(orSeparator);
        }
    }

    if (aboveMaximumPresent) {
        builder.append(String.format(_orMoreCaption, Integer.toString(maxValue + 1)));
    }

    String units = attribute.getCharacter().getUnits();
    if (!StringUtils.isBlank(units)) {
        builder.append(" ");
        builder.append(units);
    }

    return defaultFormat(builder.toString());
}

From source file:gov.nih.nci.caarray.plugins.illumina.CsvDataHandler.java

private void checkSdrfHybridizations(FileValidationResult result, List<String> fileHybNames,
        Map<String, List<Hybridization>> sdrfHybsMap) {
    // get collection of hyb names from sdrf as strings
    for (final List<Hybridization> hybList : sdrfHybsMap.values()) {
        final List<String> sdrfHybStrs = new ArrayList<String>();
        for (final Hybridization hyb : hybList) {
            sdrfHybStrs.add(hyb.getName());
        }/*from ww  w . j a  v  a  2s .  c  o m*/

        if (!sdrfHybStrs.containsAll(fileHybNames)) {
            final StringBuilder sb = new StringBuilder(
                    "This data file contains the following hybridization names"
                            + " that are not referenced in the SDRF document:");
            sdrfHybStrs.removeAll(fileHybNames);
            sb.append(StringUtils.join(sdrfHybStrs.iterator(), ','));
            result.addMessage(Type.ERROR, sb.toString());
        }
    }
}

From source file:io.pravega.controller.store.stream.PersistentStreamBase.java

private List<Integer> getNewActiveSegments(final List<Integer> createdSegments,
        final List<Integer> sealedSegments, final HistoryRecord lastRecord) {
    final List<Integer> segments = lastRecord.getSegments();
    segments.removeAll(sealedSegments);
    segments.addAll(createdSegments);//from  w ww .j av  a 2  s.com
    return segments;
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.RuleAssetsBean.java

private List<VesselTransportMeans> extractVesselTransportMeans(FLUXFAReportMessage message) {
    List<VesselTransportMeans> vessTranspMeans = new ArrayList<>();
    List<FAReportDocument> faReportDocuments = message.getFAReportDocuments() != null
            ? message.getFAReportDocuments()
            : Collections.<FAReportDocument>emptyList();
    for (FAReportDocument faRepDoc : faReportDocuments) {
        vessTranspMeans.add(faRepDoc.getSpecifiedVesselTransportMeans());
        List<FishingActivity> specifiedFishingActivities = faRepDoc.getSpecifiedFishingActivities() != null
                ? faRepDoc.getSpecifiedFishingActivities()
                : Collections.<FishingActivity>emptyList();
        for (FishingActivity fishActivity : specifiedFishingActivities) {
            vessTranspMeans.addAll(fishActivity.getRelatedVesselTransportMeans());
        }/*  w  w w  .j  a  v  a2s . c om*/
    }
    vessTranspMeans.removeAll(singleton(null));
    return vessTranspMeans;
}

From source file:org.openmrs.module.sdmxhdintegration.web.controller.MapIndicatorDialogController.java

/**
 * Handles submission of indicator mapping dialog
 *//*from  w  w w.ja v  a  2s  . c  om*/
@RequestMapping(method = RequestMethod.POST)
public String handleDialogSubmit(HttpSession httpSession,
        @RequestParam("mappedOMRSIndicatorId") Integer mappedOMRSIndicatorId,
        @RequestParam("messageId") Integer messageId, @RequestParam("sdmxhdIndicator") String sdmxhdIndicator,
        @RequestParam("keyFamilyId") String keyFamilyId) throws Exception {
    sdmxhdIndicator = URLDecoder.decode(sdmxhdIndicator);

    SDMXHDService service = Context.getService(SDMXHDService.class);
    SDMXHDMessage message = service.getMessage(messageId);
    DSD sdmxhdDSD = Utils.getDataSetDefinition(message);

    // get Indicator obj
    // TODO do this properly with either uuid or create method in service to fetch by id
    IndicatorService is = Context.getService(IndicatorService.class);
    CohortIndicator omrsIndicator = null;
    List<Indicator> allIndicators = is.getAllDefinitions(false);
    for (Indicator i : allIndicators) {
        if (i.getId().equals(mappedOMRSIndicatorId)) {
            omrsIndicator = (CohortIndicator) i;
            break;
        }
    }

    SDMXHDCohortIndicatorDataSetDefinition omrsDSD = Utils.getDataSetDefinition(message, keyFamilyId);

    // remove previous column specification if there is one
    List<String> columnNames = omrsDSD.getIndicatorColumnMapping().get(sdmxhdIndicator);
    if (columnNames != null) {
        for (Iterator<String> iterator = columnNames.iterator(); iterator.hasNext();) {
            String columnName = iterator.next();
            omrsDSD.removeColumn(columnName);
        }
    }
    omrsDSD.removeIndicatorColumnMappings(sdmxhdIndicator);

    // Map Indicator
    omrsDSD.mapIndicator(sdmxhdIndicator, mappedOMRSIndicatorId);

    try {
        // add column specifications for this indicator
        // find all combinations of dimensions for this indicator
        List<List<DimensionWrapper>> allCombinationofDimensionsForIndicator = sdmxhdDSD
                .getAllCombinationofDimensionsForIndicator(sdmxhdIndicator, keyFamilyId);
        List<String> baseFixedDimensionToBeMapped = new ArrayList<String>();

        // if there is no disaggregation hierarchy for this indicator... use all (non-fixed) dimensions for disagregation
        if (allCombinationofDimensionsForIndicator == null
                || allCombinationofDimensionsForIndicator.size() < 0) {
            Set<String> smxhdFixedDimensions = omrsDSD.getFixedDimensionValues().keySet();
            List<Dimension> allNonStanadrdDimensions = sdmxhdDSD.getAllNonStanadrdDimensions(keyFamilyId);
            List<Dimension> listToBeRemoved = new ArrayList<Dimension>();
            for (Iterator<Dimension> iterator = allNonStanadrdDimensions.iterator(); iterator.hasNext();) {
                Dimension dimension = iterator.next();
                if (smxhdFixedDimensions.contains(dimension.getConceptRef())) {
                    listToBeRemoved.add(dimension);
                }
            }
            // remove all fixed dimension from being calculated in the combination permutations ...
            allNonStanadrdDimensions.removeAll(listToBeRemoved);
            allCombinationofDimensionsForIndicator = sdmxhdDSD.getAllCombinationOfDimensions(keyFamilyId,
                    allNonStanadrdDimensions);

            // ... but save them for mapping later
            for (Dimension d : listToBeRemoved) {
                baseFixedDimensionToBeMapped.add(d.getConceptRef());
            }

            //added by Dave Thomas -- if the indicator is listed in the hierarchy as having no dimensions explicitly, just add indicator with no dimensions,
            //rather than applying all possible dimension combinations.
        } else if (allCombinationofDimensionsForIndicator.size() == 0) {

            String columnName = omrsIndicator.getName();
            Mapped<CohortIndicator> mappedOMRSIndicator = new Mapped<CohortIndicator>(omrsIndicator,
                    IndicatorUtil.getDefaultParameterMappings());
            omrsDSD.addColumn(columnName, columnName, mappedOMRSIndicator, new HashMap<String, String>()); //empty map = no dimensions
            omrsDSD.addIndicatorColumnMapping(sdmxhdIndicator, columnName);

        }

        for (List<DimensionWrapper> combinationOfDimensions : allCombinationofDimensionsForIndicator) {
            // construct a dim option mapping for each combination
            //List<DimensionWrapper> combinationOfDimensions = sdmxhdDSD.getDimensionHierarchy(sdmxhdIndicator);
            StringBuilder dimOptsString = new StringBuilder();
            StringBuilder fixedDimsString = new StringBuilder();
            Map<String, String> dimOpts = new HashMap<String, String>();
            List<String> fixedDimensionToBeMapped = new ArrayList<String>();

            for (DimensionWrapper dw : combinationOfDimensions) {
                String omrsMappedDimensionOption = omrsDSD.getORMSMappedDimensionOption(
                        dw.getDimension().getConceptRef(), dw.getCode().getDescription().getDefaultStr());
                Integer omrsMappedDimensionId = omrsDSD
                        .getOMRSMappedDimension(dw.getDimension().getConceptRef());

                if (omrsMappedDimensionOption == null || omrsMappedDimensionId == null) {
                    if (omrsDSD.getFixedDimensionValues(dw.getDimension().getConceptRef()) == null) {
                        throw new DimensionNotMappedException(dw.getDimension());
                    } else {
                        // Fixed value is set, no need to add this dimension
                        // Just save it for mapping once we know the column name
                        String sdmxhdDimension = dw.getDimension().getConceptRef();
                        fixedDimensionToBeMapped.add(sdmxhdDimension);
                        if (fixedDimsString.length() > 0) {
                            fixedDimsString.append(", ");
                        }
                        fixedDimsString.append(
                                sdmxhdDimension + "=" + omrsDSD.getFixedDimensionValues(sdmxhdDimension));
                        continue;
                    }
                }

                dimOpts.put(omrsMappedDimensionId + "", omrsMappedDimensionOption);
                if (dimOptsString.length() > 0) {
                    dimOptsString.append(", ");
                }
                dimOptsString.append(omrsMappedDimensionId + "=" + omrsMappedDimensionOption);
            }

            dimOptsString.insert(0, " Dims[");
            dimOptsString.append("]");

            // make sure base fixed dimensions are included
            for (String sdmxhdDimension : baseFixedDimensionToBeMapped) {
                fixedDimsString
                        .append(sdmxhdDimension + "=" + omrsDSD.getFixedDimensionValues(sdmxhdDimension));
            }

            fixedDimsString.insert(0, " FixedValDims:[");
            fixedDimsString.append("]");

            String columnName = omrsIndicator.getName() + dimOptsString.toString() + fixedDimsString.toString();

            Mapped<CohortIndicator> mappedOMRSIndicator = new Mapped<CohortIndicator>(omrsIndicator,
                    IndicatorUtil.getDefaultParameterMappings());

            // add column specification for each dimension combination
            omrsDSD.addColumn(columnName, columnName, mappedOMRSIndicator, dimOpts);
            omrsDSD.addIndicatorColumnMapping(sdmxhdIndicator, columnName);

            // add base fixed value dimension (if any)
            fixedDimensionToBeMapped.addAll(baseFixedDimensionToBeMapped);
            // map fixed value dimensions
            Iterator<String> iter = fixedDimensionToBeMapped.iterator();
            while (iter.hasNext()) {
                String sdmxhdDimension = iter.next();
                omrsDSD.mapFixedDimension(columnName, sdmxhdDimension);
            }
        }

        // save dataset
        DataSetDefinitionService dss = Context.getService(DataSetDefinitionService.class);
        dss.saveDefinition(omrsDSD);

    } catch (DimensionNotMappedException e) {
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                "Indicator could not be mapped as one or more Dimensions that are used by this indicator have not been mapped");
    }

    return "redirect:redirectParent.form?url=keyFamilyMapping.form?messageId=" + messageId + "%26keyFamilyId="
            + keyFamilyId;
}

From source file:com.inkubator.hrm.web.recruitment.RecruitHireApplyFormController.java

private RecruitHireApplyModel convertJsonToModel(String jsonData) throws Exception {

    RecruitHireApplyModel model = null;/*  w  ww  . j av a 2s  .c o m*/
    Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();

    JsonParser parser = new JsonParser();
    JsonObject jsonObject = (JsonObject) parser.parse(jsonData);
    RecruitHireApply recruitHireApply = gson.fromJson(jsonObject, RecruitHireApply.class);
    model = getModelFromEntity(recruitHireApply);

    JsonArray arrayDetailRecruitmentRequest = jsonObject.getAsJsonArray("listDetailRecruitHireApply");
    List<OrgTypeOfSpecList> listTypeOfSpec = new ArrayList<>();

    if (null != arrayDetailRecruitmentRequest) {
        for (int i = 0; i < arrayDetailRecruitmentRequest.size(); i++) {
            RecruitHireApplyDetail detail = gson.fromJson(arrayDetailRecruitmentRequest.get(i),
                    RecruitHireApplyDetail.class);
            listTypeOfSpec.add(detail.getOrgTypeOfSpecList());
        }
    }

    //Group list by OrgTypeOfSpec.name
    Group<OrgTypeOfSpecList> groupOrgTypeOfSpecList = Lambda.group(listTypeOfSpec,
            Lambda.by(Lambda.on(OrgTypeOfSpecList.class).getOrgTypeOfSpec().getId()));

    //iterate each group list element
    for (String key : groupOrgTypeOfSpecList.keySet()) {

        List<OrgTypeOfSpecList> listGroupedOrgTypeOfSpecList = groupOrgTypeOfSpecList.find(key);
        OrgTypeOfSpec orgTypeOfSpec = orgTypeOfSpecService.getEntiyByPK(Long.parseLong(key));
        int index = name.indexOf(orgTypeOfSpec.getName());

        if (index != -1) {

            List<OrgTypeOfSpecList> listSource = dataForRenders.get(index).getSource();
            List<OrgTypeOfSpecList> listSourceToRemove = Lambda.select(listSource,
                    Lambda.having(Lambda.on(OrgTypeOfSpecList.class).getCode(),
                            Matchers.isIn(Lambda.extract(listGroupedOrgTypeOfSpecList,
                                    Lambda.on(OrgTypeOfSpecList.class).getCode()))));
            listSource.removeAll(listSourceToRemove);

            dataForRenders.get(index).setTarget(listGroupedOrgTypeOfSpecList);
            dataForRenders.get(index).setSource(listSource);
        }
    }

    List<RecruitMppApplyDetail> listMppDetail = recruitMppApplyDetailService
            .getListInSelectedMppPeriodIdWithApprovalStatus(model.getRecruitMppPeriodId(),
                    HRMConstant.APPROVAL_STATUS_APPROVED);
    for (RecruitMppApplyDetail detail : listMppDetail) {
        mapJabatan.put(detail.getJabatan().getName(), detail.getJabatan().getId());
    }

    return model;
}

From source file:com.evolveum.midpoint.web.component.assignment.MultipleAssignmentSelectorPanel.java

private void reset(MultipleAssignmentSelector panel) {
    List<AssignmentEditorDto> assignmentsList = (List<AssignmentEditorDto>) panel.getModel().getObject();
    List<AssignmentEditorDto> listToBeRemoved = new ArrayList<>();
    for (AssignmentEditorDto dto : assignmentsList) {
        if (dto.getStatus().equals(UserDtoStatus.ADD)) {
            listToBeRemoved.add(dto);/*w w  w.  ja va2 s  . co m*/
        } else if (dto.getStatus() == UserDtoStatus.DELETE) {
            dto.setStatus(UserDtoStatus.MODIFY);
        }
    }
    assignmentsList.removeAll(listToBeRemoved);
}

From source file:pt.ist.fenixedu.delegates.ui.services.DelegateService.java

public List<DelegateBean> searchDelegates(DelegateSearchBean delegateSearchBean) {
    DateTime beginDate = delegateSearchBean.getExecutionYear().getBeginDateYearMonthDay()
            .toDateTimeAtMidnight();//ww w  .ja v a 2  s.  c  o m
    DateTime endDate = delegateSearchBean.getExecutionYear().getEndDateYearMonthDay().toDateTimeAtMidnight();
    Interval executionYearSpan = new Interval(beginDate, endDate);
    List<Delegate> toRemove = new ArrayList<Delegate>();
    List<Delegate> withDuplicates = delegateSearchBean.getDegree().getDelegateSet().stream().filter(d -> {
        DateTime start = d.getStart();
        DateTime end = d.getEnd();
        Interval activity = new Interval(start, end);
        if (executionYearSpan.overlaps(activity)) {
            return true;
        }
        return false;
    }).collect(Collectors.toList());

    for (Delegate delegate : withDuplicates) {
        for (Delegate delegate2 : withDuplicates) {
            if (delegate.getClass().isInstance(delegate2)) {
                if (delegate.samePosition(delegate2) && delegate.getStart().isBefore(delegate2.getStart())) {
                    toRemove.add(delegate);
                }
            }
        }
    }
    withDuplicates.removeAll(toRemove);

    return withDuplicates.stream().map(p -> p.getBean()).collect(Collectors.toList());
}

From source file:com.flexive.war.beans.admin.main.AccountBean.java

/**
 * Getter for roles implicitly set from groups
 *
 * @return roles implicitly set from groups
 * @throws FxApplicationException on errors
 *///from w  ww .j a  v  a2 s  .c om
public List<Role> getRolesGroups() throws FxApplicationException {
    if (groups == null)
        return new ArrayList<Role>(0);
    List<Role> result = new ArrayList<Role>(Role.values().length);
    for (long groupId : groups) {
        List<Role> tmp = EJBLookup.getUserGroupEngine().getRoles(groupId);
        result.removeAll(tmp);
        result.addAll(tmp);
    }
    return result;
}

From source file:com.github.gekoh.yagen.ddl.CreateDDL.java

private static List<String> getHistoryRelevantColumns(Set<String> columnNames, String[] ignoreColumns,
        String hstColName) {/*  w  w w  .  jav a  2 s  .c  o m*/
    List<String> cols = new ArrayList<String>(columnNames);

    cols.removeAll(AUDIT_COLUMNS);
    cols.remove(VERSION_COLUMN_NAME);
    cols.remove(hstColName);

    for (String ignoreColumn : ignoreColumns) {
        cols.remove(ignoreColumn.toLowerCase());
    }

    return cols;
}