Example usage for java.util Collections frequency

List of usage examples for java.util Collections frequency

Introduction

In this page you can find the example usage for java.util Collections frequency.

Prototype

public static int frequency(Collection<?> c, Object o) 

Source Link

Document

Returns the number of elements in the specified collection equal to the specified object.

Usage

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathStatistics.java

/**
 * test linear selection/* ww  w.  ja  v  a  2s  . c o  m*/
 */
@Test
public final void linearselection() {
    final List<ITerm> l_return = Collections.synchronizedList(new ArrayList<>());

    IntStream.range(0, 6500).parallel()
            .forEach(i -> new CLinearSelection().execute(false, IContext.EMPTYPLAN,
                    Stream.of(Stream.of("c", "d").collect(Collectors.toList()),
                            Stream.of(3, 7).collect(Collectors.toList())).map(CRawTerm::from)
                            .collect(Collectors.toList()),
                    l_return));

    Assert.assertEquals(
            (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "c")
                    / l_return.size(),
            0.3, 0.05);

    Assert.assertEquals(
            (double) Collections.frequency(l_return.stream().map(ITerm::raw).collect(Collectors.toList()), "d")
                    / l_return.size(),
            0.7, 0.05);
}

From source file:hydrograph.ui.propertywindow.widgets.dialogs.join.JoinMapDialog.java

private void createOutputFieldColumnInMappingTable() {
    TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(mappingTableViewer, SWT.NONE);
    TableColumn tblclmnPropertyValue = tableViewerColumn_1.getColumn();
    tblclmnPropertyValue.setWidth(148);// ww w .ja  va 2  s  .  co m
    tblclmnPropertyValue.setText(JoinMapDialogConstants.OUTPUT_FIELD);
    outputEditingSupport = new JoinMappingEditingSupport(mappingTableViewer,
            JoinMapDialogConstants.OUTPUT_FIELD);
    WidgetUtility.addVerifyListnerToOutputEditingSupport(outputEditingSupport);
    tableViewerColumn_1.setEditingSupport(outputEditingSupport);
    tableViewerColumn_1.setLabelProvider(new ColumnLabelProvider() {

        String tooltipText;

        @Override
        public Image getImage(Object element) {
            Image image = ImagePathConstant.DELETE_ICON.getImageFromRegistry();

            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;

            if (StringUtils.isBlank(lookupMapProperty.getOutput_Field()))
                return image;
            else
                return super.getImage(element);
        }

        private List<String> getOutputFieldList() {
            List<String> outputFieldList = new LinkedList<>();
            for (LookupMapProperty lookupMapProperty : mappingTableItemList) {
                outputFieldList.add(lookupMapProperty.getOutput_Field());
            }
            return outputFieldList;
        }

        @Override
        public String getToolTipText(Object element) {
            tooltipText = null;

            int occurrences = Collections.frequency(getOutputFieldList(),
                    ((LookupMapProperty) element).getOutput_Field());
            if (occurrences > 1) {
                tooltipText = FIELD_TOOLTIP_MESSAGE_DUPLICATE_FIELDS;
            }

            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;
            if (StringUtils.isBlank(lookupMapProperty.getSource_Field()))
                tooltipText = FIELD_TOOLTIP_MESSAGE_FIELD_CANT_BE_EMPTY;

            return tooltipText;
        }

        @Override
        public Color getForeground(Object element) {
            int occurrences = Collections.frequency(getOutputFieldList(),
                    ((LookupMapProperty) element).getOutput_Field());
            if (occurrences > 1) {
                return CustomColorRegistry.INSTANCE.getColorFromRegistry(255, 0, 0);
            } else {
                return super.getForeground(element);
            }

        }

        @Override
        public Color getBackground(Object element) {
            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;

            if (StringUtils.isBlank(lookupMapProperty.getOutput_Field()))
                return CustomColorRegistry.INSTANCE.getColorFromRegistry(0xFF, 0xDD, 0xDD);
            else
                return super.getBackground(element);
        }

        @Override
        public String getText(Object element) {
            LookupMapProperty lookupMapProperty = (LookupMapProperty) element;

            if (ParameterUtil.isParameter(lookupMapProperty.getOutput_Field()))
                lookupMapProperty.setSource_Field(lookupMapProperty.getOutput_Field());

            return lookupMapProperty.getOutput_Field();
        }
    });
}

From source file:com.github.rinde.rinsim.scenario.measure.MetricsTest.java

static <T> boolean areAllValuesTheSame(List<T> list) {
    if (list.isEmpty()) {
        return true;
    }//from   w w w . jav a 2 s . com
    return Collections.frequency(list, list.get(0)) == list.size();
}

From source file:au.org.ala.delta.key.Key.java

private boolean compareStateDistributions(List<Set<Item>> dist1, List<Set<Item>> dist2) {

    for (Set<Item> dist1Item : dist1) {
        if (dist1Item.isEmpty()) {
            continue;
        }// www  .  j a v a2 s. c  o m

        if (Collections.frequency(dist1, dist1Item) != Collections.frequency(dist2, dist1Item)) {
            return false;
        }
    }

    return true;
}

From source file:pt.ua.tm.neji.web.server.Server.java

/**
 * Validates the service parameters./* ww  w . ja va 2s .  c o  m*/
 *
 * @param service   service to validate
 * @param logo      logo
 * @param fp        false positives 
 * @param addOrEdit true if it is a validation for an add, false if it is for an edit
 * @throws NejiException
 */
private void validateService(Service service, InputStream logo, InputStream fp, boolean addOrEdit)
        throws NejiException {

    boolean stat = false;

    // Verify if name has invalid characters
    if (service.getName().trim().length() == 0) {
        throw new NejiException("The name is required");
    } else if (!service.getName().matches("^[a-zA-Z0-9._-]+$")) {
        throw new NejiException(
                "The name can only consist of alphabetical, number, underscore(_), hifen(-) and dot(.) characters");
    }

    // Verify if already exists a service with the same name
    try {
        stat = db.existsService(service);
    } catch (NejiException ex) {
        throw new NejiException("There was a problem adding the service.\n" + "Please try again later.", ex);
    }

    // In add should not exist
    if (addOrEdit && stat) {
        throw new NejiException("There is already a service with the name '" + service.getName()
                + "'.\nPlease change it and try again.");
    } else if ((!addOrEdit) && (!stat)) {
        throw new NejiException(
                "Wasn't found a service with the name '" + service.getName() + "'.\nPlease try again.");
    }

    // Verify if were added at least one dictionary or model
    if (((service.getDictionaries() == null) || (service.getDictionaries().isEmpty()))
            && ((service.getModels() == null) || (service.getModels().isEmpty()))) {
        throw new NejiException("It is required at least one dictionary or model");
    }

    // Verify groups normalization
    Map<String, String> groupsNormalization = service.getGroupsNormalization();
    List<String> normalizedNames = new ArrayList<>(groupsNormalization.values());
    for (Entry<String, String> group : groupsNormalization.entrySet()) {

        // Verify if mapping name is valid
        if (!group.getValue().matches("^[a-zA-Z0-9._\\s-]*$")) {
            throw new NejiException("The mapping name " + group.getValue()
                    + " is invalid. The mapping name can only consist of alphabetical, "
                    + "number, underscore(_), hifen(-) and dot(.) characters");
        }

        // If no normalization, maintain the group name
        if (group.getValue().trim().length() == 0) {
            group.setValue(group.getKey());
            normalizedNames.add(group.getKey());
        }

        // Verify if there are repeated names
        if (Collections.frequency(normalizedNames, group.getValue()) != 1) {
            throw new NejiException("Two or more semantic groups can't be mapped " + "to the same name '"
                    + group.getValue() + "'.\nPlease " + "change it and try again.");
        }
    }

    // Set service logo
    if (service.getLogo() != null) {
        try {
            byte[] logoBytes = IOUtils.toByteArray(logo);
            service.setLogo(logoBytes);
        } catch (IOException ex) {
            service.setLogo(null);
            throw new NejiException("The provided logo is not valid.", ex);
        }
    }

    // Set service false positives
    if (service.getFalsePositives() != null) {
        try {
            String falsePositivesString = IOUtils.toString(fp, StandardCharsets.UTF_8.name());
            service.setFalsePositives(falsePositivesString);
        } catch (IOException ex) {
            service.setFalsePositives(null);
            throw new NejiException("There was an error loading the false " + "positives file.", ex);
        }
    }
}

From source file:edu.duke.cabig.c3pr.dao.StudySubjectDao.java

public List<Study> getMostEnrolledStudies(Date startDate, Date endDate) {
    List<Study> listStudies = new ArrayList<Study>();

    List<StudySubject> studySubjects = getHibernateTemplate().find(
            "select ss from StudySubject ss where ss.regWorkflowStatus=? and ss.startDate between ? and ? order by ss.id desc",
            new Object[] { RegistrationWorkFlowStatus.ON_STUDY, startDate, endDate });
    for (StudySubject ss : studySubjects) {
        Study s = ss.getStudySite().getStudy();
        listStudies.add(s);/*from  w ww .  j av  a2s.  c o  m*/
    }

    Set<Study> setStudy = new HashSet<Study>();
    setStudy.addAll(listStudies);

    for (Study study : setStudy) {
        study.setAccrualCount(Collections.frequency(listStudies, study));
    }

    List<Study> studies = new ArrayList<Study>();

    studies.addAll(setStudy);
    Collections.sort(studies, new AccrualCountComparator());

    return studies;
}

From source file:org.finra.herd.service.helper.BusinessObjectDataHelper.java

/**
 * Validates a list of partition value filters or a standalone partition filter. This method makes sure that a partition value filter contains exactly one
 * partition value range or a non-empty partition value list. This method also makes sure that there is no more than one partition value range specified
 * across all partition value filters./*from  w w  w . jav  a 2 s.  c  o m*/
 *
 * @param partitionValueFilters the list of partition value filters to validate
 * @param standalonePartitionValueFilter the standalone partition value filter to validate
 * @param allowPartitionValueTokens specifies whether the partition value filter is allowed to contain partition value tokens
 */
public void validatePartitionValueFilters(List<PartitionValueFilter> partitionValueFilters,
        PartitionValueFilter standalonePartitionValueFilter, boolean allowPartitionValueTokens) {
    // Make sure that request does not contain both a list of partition value filters and a standalone partition value filter.
    Assert.isTrue(partitionValueFilters == null || standalonePartitionValueFilter == null,
            "A list of partition value filters and a standalone partition value filter cannot be both specified.");

    List<PartitionValueFilter> partitionValueFiltersToValidate = new ArrayList<>();

    if (partitionValueFilters != null) {
        partitionValueFiltersToValidate.addAll(partitionValueFilters);
    }

    if (standalonePartitionValueFilter != null) {
        partitionValueFiltersToValidate.add(standalonePartitionValueFilter);
    }

    // Make sure that at least one partition value filter is specified.
    Assert.notEmpty(partitionValueFiltersToValidate, "At least one partition value filter must be specified.");

    // Validate and trim partition value filters.
    int partitionValueRangesCount = 0;
    for (PartitionValueFilter partitionValueFilter : partitionValueFiltersToValidate) {
        // Partition key is required when request contains a partition value filter list.
        if (partitionValueFilters != null) {
            Assert.hasText(partitionValueFilter.getPartitionKey(), "A partition key must be specified.");
        }

        // Trim partition key value.
        if (StringUtils.isNotBlank(partitionValueFilter.getPartitionKey())) {
            partitionValueFilter.setPartitionKey(partitionValueFilter.getPartitionKey().trim());
        }

        PartitionValueRange partitionValueRange = partitionValueFilter.getPartitionValueRange();
        List<String> partitionValues = partitionValueFilter.getPartitionValues();
        LatestBeforePartitionValue latestBeforePartitionValue = partitionValueFilter
                .getLatestBeforePartitionValue();
        LatestAfterPartitionValue latestAfterPartitionValue = partitionValueFilter
                .getLatestAfterPartitionValue();

        // Validate that we have exactly one partition filter option specified.
        List<Boolean> partitionFilterOptions = Arrays.asList(partitionValueRange != null,
                partitionValues != null, latestBeforePartitionValue != null, latestAfterPartitionValue != null);
        Assert.isTrue(Collections.frequency(partitionFilterOptions, Boolean.TRUE) == 1,
                "Exactly one partition value filter option must be specified.");

        if (partitionValueRange != null) {
            // A "partition value range" filter option is specified.

            // Only one partition value range is allowed across all partition value filters.
            partitionValueRangesCount++;
            Assert.isTrue(partitionValueRangesCount < 2, "Cannot specify more than one partition value range.");

            // Validate start partition value for the partition value range.
            Assert.hasText(partitionValueRange.getStartPartitionValue(),
                    "A start partition value for the partition value range must be specified.");
            partitionValueRange.setStartPartitionValue(partitionValueRange.getStartPartitionValue().trim());

            // Validate end partition value for the partition value range.
            Assert.hasText(partitionValueRange.getEndPartitionValue(),
                    "An end partition value for the partition value range must be specified.");
            partitionValueRange.setEndPartitionValue(partitionValueRange.getEndPartitionValue().trim());

            // Validate that partition value tokens are not specified as start and end partition values.
            // This check is required, regardless if partition value tokens are allowed or not.
            Assert.isTrue(
                    !partitionValueRange.getStartPartitionValue()
                            .equals(BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN)
                            && !partitionValueRange.getStartPartitionValue()
                                    .equals(BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN)
                            && !partitionValueRange.getEndPartitionValue()
                                    .equals(BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN)
                            && !partitionValueRange.getEndPartitionValue()
                                    .equals(BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN),
                    "A partition value token cannot be specified with a partition value range.");

            // Using string compare, validate that start partition value is less than or equal to end partition value.
            Assert.isTrue(
                    partitionValueRange.getStartPartitionValue()
                            .compareTo(partitionValueRange.getEndPartitionValue()) <= 0,
                    String.format(
                            "The start partition value \"%s\" cannot be greater than the end partition value \"%s\".",
                            partitionValueRange.getStartPartitionValue(),
                            partitionValueRange.getEndPartitionValue()));
        } else if (partitionValues != null) {
            // A "partition value list" filter option is specified.

            // Validate that the list contains at least one partition value.
            Assert.isTrue(!partitionValues.isEmpty(), "At least one partition value must be specified.");

            for (int i = 0; i < partitionValues.size(); i++) {
                String partitionValue = partitionValues.get(i);
                Assert.hasText(partitionValue, "A partition value must be specified.");
                partitionValue = partitionValue.trim();

                // When partition value tokens are not allowed, validate that they are not specified as one of partition values.
                if (!allowPartitionValueTokens) {
                    Assert.isTrue(!partitionValue.equals(BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN)
                            && !partitionValue.equals(BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN),
                            "A partition value token cannot be specified as one of partition values.");
                }

                partitionValues.set(i, partitionValue);
            }
        } else if (latestBeforePartitionValue != null) {
            // A "latest before partition value" filter option is specified.
            Assert.hasText(latestBeforePartitionValue.getPartitionValue(),
                    "A partition value must be specified.");
            latestBeforePartitionValue.setPartitionValue(latestBeforePartitionValue.getPartitionValue().trim());
        } else {
            // A "latest after partition value" filter option is specified.
            Assert.hasText(latestAfterPartitionValue.getPartitionValue(),
                    "A partition value must be specified.");
            latestAfterPartitionValue.setPartitionValue(latestAfterPartitionValue.getPartitionValue().trim());
        }
    }
}

From source file:de.uni_potsdam.hpi.asg.logictool.mapping.SequenceBasedAndGateDecomposer.java

private void getNewSteps(IOBehaviourSimulationStep step, Signal sig, Set<IOBehaviour> newSequences,
        Deque<IOBehaviourSimulationStep> newSteps, Set<Signal> relevant) {

    int occurrences = Collections.frequency(step.getStates(), step.getNextState());
    if (occurrences >= 2) {
        boolean isLoop = false;
        int[] a = new int[occurrences];
        int index = 0;
        for (int i = step.getStates().size() - 1; i >= 0; i--) {
            if (step.getStates().get(i) == step.getNextState()) {
                a[index++] = i;//from  w ww.  j a  va 2s . c o m
            }
        }

        Map<Integer, List<State>> lists = new HashMap<>();

        int endindex = step.getStates().size();
        List<State> xlist = null;
        for (int startindex : a) {
            xlist = step.getStates().subList(startindex, endindex);
            lists.put(endindex, xlist);
            endindex = startindex;
        }

        boolean finished = false;
        int smallesidloop = -1;
        for (Entry<Integer, List<State>> l1 : lists.entrySet()) {
            for (Entry<Integer, List<State>> l2 : lists.entrySet()) {
                if (l1.getKey() != l2.getKey()) {
                    if (l1.getValue().equals(l2.getValue())) {
                        //                     System.out.println("loop: listmatch!");
                        isLoop = true;
                        smallesidloop = l1.getKey() < l2.getKey() ? l1.getKey() : l2.getKey();
                        xlist = l1.getValue();
                        finished = true;
                        break;
                    }
                }
            }
            if (finished) {
                break;
            }
        }

        if (isLoop) {
            //            System.out.println("Loop: " + xlist + ", listsize: " + lists.size());
            //            System.out.println("Smallestid : " + smallesidloop + ", size: " + step.getStates().size());
            step.findStateAndClean(step.getStates().size() - smallesidloop - 1, pool, newSteps);
            return;
        }
    }

    for (Entry<Transition, State> entry : step.getNextState().getNextStates().entrySet()) {
        //System.out.println(entry.toString());
        if (entry.getKey().getSignal() == sig) {
            List<Transition> seq = new ArrayList<>(step.getSequence());
            IOBehaviour beh = new IOBehaviour(seq, step.getStart(), step.getNextState());
            newSequences.add(beh);
        } else {
            IOBehaviourSimulationStep newStep;
            try {
                newStep = pool.borrowObject();
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("Could not borrow object");
                return;
            }
            newStep.getSequence().addAll(step.getSequence());
            if (relevant.contains(entry.getKey().getSignal())) {
                newStep.getSequence().add(entry.getKey());
            }
            newStep.setStart(step.getStart());
            newStep.setNextState(entry.getValue());
            newStep.getStates().addAll(step.getStates());
            newStep.getStates().add(step.getNextState());
            newStep.setPrevStep(step);
            step.getNextSteps().add(newStep);
            newSteps.add(newStep);
        }
    }
    step.killIfCan(pool);
}

From source file:org.finra.dm.service.impl.BusinessObjectDataServiceImpl.java

/**
 * Validates a list of partition value filters or a standalone partition filter.  This method makes sure that a partition value filter contains exactly one
 * partition value range or a non-empty partition value list.  This method also makes sure that there is no more than one partition value range specified
 * across all partition value filters./*from w w  w. jav a2  s  . c  o  m*/
 *
 * @param partitionValueFilters the list of partition value filters to validate
 * @param standalonePartitionValueFilter the standalone partition value filter to validate
 * @param allowPartitionValueTokens specifies whether the partition value filter is allowed to contain partition value tokens
 */
private void validatePartitionValueFilters(List<PartitionValueFilter> partitionValueFilters,
        PartitionValueFilter standalonePartitionValueFilter, boolean allowPartitionValueTokens) {
    // Make sure that request does not contain both a list of partition value filters and a standalone partition value filter.
    Assert.isTrue(partitionValueFilters == null || standalonePartitionValueFilter == null,
            "A list of partition value filters and a standalone partition value filter cannot be both specified.");

    List<PartitionValueFilter> partitionValueFiltersToValidate = new ArrayList<>();

    if (partitionValueFilters != null) {
        partitionValueFiltersToValidate.addAll(partitionValueFilters);
    }

    if (standalonePartitionValueFilter != null) {
        partitionValueFiltersToValidate.add(standalonePartitionValueFilter);
    }

    // Make sure that at least one partition value filter is specified.
    Assert.notEmpty(partitionValueFiltersToValidate, "At least one partition value filter must be specified.");

    // Validate and trim partition value filters.
    int partitionValueRangesCount = 0;
    for (PartitionValueFilter partitionValueFilter : partitionValueFiltersToValidate) {
        // Partition key is required when request contains a partition value filter list.
        if (partitionValueFilters != null) {
            Assert.hasText(partitionValueFilter.getPartitionKey(), "A partition key must be specified.");
        }

        // Trim partition key value.
        if (StringUtils.isNotBlank(partitionValueFilter.getPartitionKey())) {
            partitionValueFilter.setPartitionKey(partitionValueFilter.getPartitionKey().trim());
        }

        PartitionValueRange partitionValueRange = partitionValueFilter.getPartitionValueRange();
        List<String> partitionValues = partitionValueFilter.getPartitionValues();
        LatestBeforePartitionValue latestBeforePartitionValue = partitionValueFilter
                .getLatestBeforePartitionValue();
        LatestAfterPartitionValue latestAfterPartitionValue = partitionValueFilter
                .getLatestAfterPartitionValue();

        // Validate that we have exactly one partition filter option specified.
        List<Boolean> partitionFilterOptions = Arrays.asList(partitionValueRange != null,
                partitionValues != null, latestBeforePartitionValue != null, latestAfterPartitionValue != null);
        Assert.isTrue(Collections.frequency(partitionFilterOptions, Boolean.TRUE) == 1,
                "Exactly one partition value filter option must be specified.");

        if (partitionValueRange != null) {
            // A "partition value range" filter option is specified.

            // Only one partition value range is allowed across all partition value filters.
            partitionValueRangesCount++;
            Assert.isTrue(partitionValueRangesCount < 2, "Cannot specify more than one partition value range.");

            // Validate start partition value for the partition value range.
            Assert.hasText(partitionValueRange.getStartPartitionValue(),
                    "A start partition value for the partition value range must be specified.");
            partitionValueRange.setStartPartitionValue(partitionValueRange.getStartPartitionValue().trim());

            // Validate end partition value for the partition value range.
            Assert.hasText(partitionValueRange.getEndPartitionValue(),
                    "An end partition value for the partition value range must be specified.");
            partitionValueRange.setEndPartitionValue(partitionValueRange.getEndPartitionValue().trim());

            // Validate that partition value tokens are not specified as start and end partition values.
            // This check is required, regardless if partition value tokens are allowed or not.
            Assert.isTrue(
                    !partitionValueRange.getStartPartitionValue().equals(MAX_PARTITION_VALUE_TOKEN)
                            && !partitionValueRange.getStartPartitionValue().equals(MIN_PARTITION_VALUE_TOKEN)
                            && !partitionValueRange.getEndPartitionValue().equals(MAX_PARTITION_VALUE_TOKEN)
                            && !partitionValueRange.getEndPartitionValue().equals(MIN_PARTITION_VALUE_TOKEN),
                    "A partition value token cannot be specified with a partition value range.");

            // Using string compare, validate that start partition value is less than or equal to end partition value.
            Assert.isTrue(
                    partitionValueRange.getStartPartitionValue()
                            .compareTo(partitionValueRange.getEndPartitionValue()) <= 0,
                    String.format(
                            "The start partition value \"%s\" cannot be greater than the end partition value \"%s\".",
                            partitionValueRange.getStartPartitionValue(),
                            partitionValueRange.getEndPartitionValue()));
        } else if (partitionValues != null) {
            // A "partition value list" filter option is specified.

            // Validate that the list contains at least one partition value.
            Assert.isTrue(!partitionValues.isEmpty(), "At least one partition value must be specified.");

            for (int i = 0; i < partitionValues.size(); i++) {
                String partitionValue = partitionValues.get(i);
                Assert.hasText(partitionValue, "A partition value must be specified.");
                partitionValue = partitionValue.trim();

                // When partition value tokens are not allowed, validate that they are not specified as one of partition values.
                if (!allowPartitionValueTokens) {
                    Assert.isTrue(
                            !partitionValue.equals(MAX_PARTITION_VALUE_TOKEN)
                                    && !partitionValue.equals(MIN_PARTITION_VALUE_TOKEN),
                            "A partition value token cannot be specified as one of partition values.");
                }

                partitionValues.set(i, partitionValue);
            }
        } else if (latestBeforePartitionValue != null) {
            // A "latest before partition value" filter option is specified.
            Assert.hasText(latestBeforePartitionValue.getPartitionValue(),
                    "A partition value must be specified.");
            latestBeforePartitionValue.setPartitionValue(latestBeforePartitionValue.getPartitionValue().trim());
        } else {
            // A "latest after partition value" filter option is specified.
            Assert.hasText(latestAfterPartitionValue.getPartitionValue(),
                    "A partition value must be specified.");
            latestAfterPartitionValue.setPartitionValue(latestAfterPartitionValue.getPartitionValue().trim());
        }
    }
}

From source file:org.nuclos.server.masterdata.ejb3.MasterDataFacadeHelper.java

public static void validateRoleDependants(DependantMasterDataMap mpDependants)
        throws CommonValidationException {

    for (String entityName : mpDependants.getEntityNames()) {
        RoleDependant dependant = RoleDependant.getByEntityName(entityName);
        if (dependant != null) {
            List<String> names = CollectionUtils.transform(
                    mpDependants.getData(dependant.getEntity().getEntityName()),
                    new EntityObjectVO.GetTypedField<String>(dependant.getEntityFieldName(), String.class));

            for (String name : names) {
                if (Collections.frequency(names, name) > 1) {
                    if (dependant.getSubFieldName() != null) {
                        List<String> subFieldNames = new ArrayList<String>();

                        for (EntityObjectVO mdVO : mpDependants.getData(dependant.getEntity().getEntityName()))
                            if (mdVO.getField(dependant.getEntityFieldName(), String.class).equals(name))
                                subFieldNames.add(mdVO.getField(dependant.getSubFieldName(), String.class));

                        for (String subName : subFieldNames) {
                            if (Collections.frequency(subFieldNames, subName) > 1) {
                                throw new CommonValidationException(StringUtils
                                        .getParameterizedExceptionMessage("role.error.validation.dependant.sub",
                                                name, subName, dependant.getResourceId()));
                            }/*from   w  w  w  .j  a  va  2 s.c  o m*/
                        }
                    } else {
                        throw new CommonValidationException(StringUtils.getParameterizedExceptionMessage(
                                "role.error.validation.dependant", name, dependant.getResourceId()));
                    }
                }
            }
        }
    }
}