Example usage for org.apache.commons.collections4 CollectionUtils isEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is empty.

Usage

From source file:com.epam.catgenome.dao.index.FeatureIndexDao.java

public Set<String> searchGenesInVcfFiles(String gene, List<VcfFile> vcfFiles) throws IOException {
    if (CollectionUtils.isEmpty(vcfFiles)) {
        return Collections.emptySet();
    }/*from   www .j a  v a  2s.c om*/

    BooleanQuery.Builder builder = new BooleanQuery.Builder();

    PrefixQuery geneIdPrefixQuery = new PrefixQuery(
            new Term(FeatureIndexFields.GENE_ID.getFieldName(), gene.toLowerCase()));
    PrefixQuery geneNamePrefixQuery = new PrefixQuery(
            new Term(FeatureIndexFields.GENE_NAME.getFieldName(), gene.toLowerCase()));
    BooleanQuery.Builder geneIdOrNameQuery = new BooleanQuery.Builder();
    geneIdOrNameQuery.add(geneIdPrefixQuery, BooleanClause.Occur.SHOULD);
    geneIdOrNameQuery.add(geneNamePrefixQuery, BooleanClause.Occur.SHOULD);

    builder.add(geneIdOrNameQuery.build(), BooleanClause.Occur.MUST);
    BooleanQuery query = builder.build();

    Set<String> geneIds;

    SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(vcfFiles);

    try (MultiReader reader = openMultiReader(indexes)) {
        if (reader.numDocs() == 0) {
            return Collections.emptySet();
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        final TopDocs docs = searcher.search(query, reader.numDocs());
        final ScoreDoc[] hits = docs.scoreDocs;

        geneIds = fetchGeneIds(hits, searcher);
    } catch (IOException e) {
        LOGGER.error(MessageHelper.getMessage(MessagesConstants.ERROR_FEATURE_INDEX_SEARCH_FAILED), e);
        return Collections.emptySet();
    }

    return geneIds;
}

From source file:cgeo.geocaching.CacheListActivity.java

private void checkIfEmptyAndRemoveAfterConfirm() {
    final boolean isNonDefaultList = isConcreteList() && listId != StoredList.STANDARD_LIST_ID;
    // Check local cacheList first, and Datastore only if needed (because of filtered lists)
    // Checking is done in this order for performance reasons
    if (isNonDefaultList && CollectionUtils.isEmpty(cacheList)
            && DataStore.getAllStoredCachesCount(CacheType.ALL, listId) == 0) {
        // ask user, if he wants to delete the now empty list
        Dialogs.confirmYesNo(this, R.string.list_dialog_remove_title, R.string.list_dialog_remove_nowempty,
                new DialogInterface.OnClickListener() {
                    @Override/*from www.  j av a2  s .com*/
                    public void onClick(final DialogInterface dialog, final int whichButton) {
                        removeListInternal();
                    }
                });
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

/**
 * Processes a {@code <field-map-ref>} element.
 *
 * @param attrs/* w  w w .j  a v a2s.  c o m*/
 *            List of element attributes
 *
 * @throws SAXException
 *             if error occurs parsing element
 */
@SuppressWarnings("unchecked")
private void processFieldMapReference(Attributes attrs) throws SAXException {
    if (currField == null) {
        throw new SAXParseException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.malformed.configuration3", FIELD_MAP_REF_ELMT, FIELD_ELMT, FIELD_LOC_ELMT),
                currParseLocation);
    }

    if (CollectionUtils.isEmpty(currField.getLocators()) && currLocatorData == null) {
        throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.element.no.binding", FIELD_MAP_REF_ELMT, FIELD_LOC_ELMT,
                getLocationInfo()));
    }

    String reference = null;
    for (int i = 0; i < attrs.getLength(); i++) {
        String attName = attrs.getQName(i);
        String attValue = attrs.getValue(i);
        if (RESOURCE_ATTR.equals(attName)) {
            reference = attValue;
        }
    }

    notEmpty(reference, FIELD_MAP_REF_ELMT, RESOURCE_ATTR);

    Object val = Utils.getMapValueByPath(reference, resourcesMap);

    if (val instanceof Map) {
        AttributesImpl mappingAttrs = new AttributesImpl();
        for (Map.Entry<String, ?> entry : ((Map<String, ?>) val).entrySet()) {
            mappingAttrs.clear();
            mappingAttrs.addAttribute(null, null, SOURCE_ATTR, null, entry.getKey());
            mappingAttrs.addAttribute(null, null, TARGET_ATTR, null, String.valueOf(entry.getValue()));

            processFieldMap(mappingAttrs);
        }
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopWindow.java

@Override
public void removeStyleName(String styleName) {
    if (StringUtils.isEmpty(styleName) || CollectionUtils.isEmpty(styles) || !styles.contains(styleName))
        return;//from w w w . j  a v  a  2 s.c  om

    StringTokenizer tokenizer = new StringTokenizer(styleName, " ");
    while (tokenizer.hasMoreTokens()) {
        styles.remove(tokenizer.nextToken());
    }
}

From source file:cgeo.geocaching.CacheListActivity.java

private boolean cacheToShow() {
    if (search == null || CollectionUtils.isEmpty(cacheList)) {
        showToast(res.getString(R.string.warn_no_cache_coord));
        return false;
    }//ww w.j ava2s .  c o  m
    return true;
}

From source file:cgeo.geocaching.CacheListActivity.java

private void showFooterMoreCaches() {
    // no footer in offline lists
    if (listFooter == null) {
        return;/*from ww  w  . j av a 2  s .  co  m*/
    }

    boolean enableMore = type != CacheListType.OFFLINE && cacheList.size() < MAX_LIST_ITEMS;
    if (enableMore && search != null) {
        final int count = search.getTotalCountGC();
        enableMore = count > 0 && cacheList.size() < count;
    }

    listFooter.setClickable(enableMore);
    if (enableMore) {
        listFooterText.setText(res.getString(R.string.caches_more_caches) + " ("
                + res.getString(R.string.caches_more_caches_currently) + ": " + cacheList.size() + ")");
        listFooter.setOnClickListener(new MoreCachesListener());
    } else if (type != CacheListType.OFFLINE) {
        listFooterText.setText(res.getString(CollectionUtils.isEmpty(cacheList) ? R.string.caches_no_cache
                : R.string.caches_more_caches_no));
        listFooter.setOnClickListener(null);
    } else {
        // hiding footer for offline list is not possible, it must be removed instead
        // http://stackoverflow.com/questions/7576099/hiding-footer-in-listview
        getListView().removeFooterView(listFooter);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebDataGrid.java

protected List<SortOrder> convertToDataGridSortOrder(List<com.vaadin.data.sort.SortOrder> gridSortOrder) {
    if (CollectionUtils.isEmpty(gridSortOrder)) {
        return Collections.emptyList();
    }//from  w ww.  ja  v  a 2s  .c o  m

    return gridSortOrder.stream().map(sortOrder -> {
        Column column = getColumnByPropertyId(sortOrder.getPropertyId());
        return new SortOrder(column != null ? column.getId() : null,
                convertToDataGridSortDirection(sortOrder.getDirection()));
    }).collect(Collectors.toList());
}

From source file:cgeo.geocaching.CacheListActivity.java

private void removeList() {
    // if there are no caches on this list, don't bother the user with questions.
    // there is no harm in deleting the list, he could recreate it easily
    if (CollectionUtils.isEmpty(cacheList)) {
        removeListInternal();//from   ww w . j ava2 s.  co m
        return;
    }

    // ask him, if there are caches on the list
    Dialogs.confirm(this, R.string.list_dialog_remove_title, R.string.list_dialog_remove_description,
            R.string.list_dialog_remove, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int whichButton) {
                    removeListInternal();
                }
            });
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandler.java

private void validateActivityField(ActivityField aField, String qName) throws SAXException {
    if (CollectionUtils.isEmpty(aField.getLocators())) {
        throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ConfigParserHandler.element.must.have", qName, LOCATOR_ATTR, VALUE_ATTR, FIELD_LOC_ELMT,
                getLocationInfo()));/*w  w w .  jav a 2  s  .c  o  m*/
    }

    List<String> dynamicLocators = new ArrayList<>();
    Utils.resolveCfgVariables(dynamicLocators, aField.getFieldTypeName(), aField.getValueType());

    for (String dLoc : dynamicLocators) {
        if (!aField.hasDynamicLocator(dLoc)) {
            throw new SAXException(StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                    "ConfigParserHandler.element.ref.missing", qName, FIELD_LOC_ELMT, dLoc, getLocationInfo()));
        }
    }
}

From source file:org.apache.nifi.audit.SnippetAuditor.java

/**
 * Audits the specified snippet.//from w  w w  .  j a v  a  2  s  . c om
 */
private void auditSnippet(final FlowSnippetDTO snippet) {
    final Collection<Action> actions = new ArrayList<>();
    final Date timestamp = new Date();

    // input ports
    for (final PortDTO inputPort : snippet.getInputPorts()) {
        actions.add(generateAuditRecord(inputPort.getId(), inputPort.getName(), Component.InputPort,
                Operation.Add, timestamp));
    }

    // output ports
    for (final PortDTO outputPort : snippet.getOutputPorts()) {
        actions.add(generateAuditRecord(outputPort.getId(), outputPort.getName(), Component.OutputPort,
                Operation.Add, timestamp));
    }

    // remote processor groups
    for (final RemoteProcessGroupDTO remoteProcessGroup : snippet.getRemoteProcessGroups()) {
        FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
        remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());

        final FlowChangeAction action = generateAuditRecord(remoteProcessGroup.getId(),
                remoteProcessGroup.getName(), Component.RemoteProcessGroup, Operation.Add, timestamp);
        action.setComponentDetails(remoteProcessGroupDetails);
        actions.add(action);
    }

    // processor groups
    for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
        actions.add(generateAuditRecord(processGroup.getId(), processGroup.getName(), Component.ProcessGroup,
                Operation.Add, timestamp));
    }

    // processors
    for (final ProcessorDTO processor : snippet.getProcessors()) {
        final FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(StringUtils.substringAfterLast(processor.getType(), "."));

        final FlowChangeAction action = generateAuditRecord(processor.getId(), processor.getName(),
                Component.Processor, Operation.Add, timestamp);
        action.setComponentDetails(processorDetails);
        actions.add(action);
    }

    // funnels
    for (final FunnelDTO funnel : snippet.getFunnels()) {
        actions.add(generateAuditRecord(funnel.getId(), StringUtils.EMPTY, Component.Funnel, Operation.Add,
                timestamp));
    }

    // connections
    for (final ConnectionDTO connection : snippet.getConnections()) {
        final ConnectableDTO source = connection.getSource();
        final ConnectableDTO destination = connection.getDestination();

        // determine the relationships and connection name
        final String relationships = CollectionUtils.isEmpty(connection.getSelectedRelationships())
                ? StringUtils.EMPTY
                : StringUtils.join(connection.getSelectedRelationships(), ", ");
        final String name = StringUtils.isBlank(connection.getName()) ? relationships : connection.getName();

        // create the connect details
        FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
        connectDetails.setSourceId(source.getId());
        connectDetails.setSourceName(source.getName());
        connectDetails.setSourceType(determineConnectableType(source));
        connectDetails.setRelationship(relationships);
        connectDetails.setDestinationId(destination.getId());
        connectDetails.setDestinationName(destination.getName());
        connectDetails.setDestinationType(determineConnectableType(destination));

        // create the audit record
        final FlowChangeAction action = generateAuditRecord(connection.getId(), name, Component.Connection,
                Operation.Connect, timestamp);
        action.setActionDetails(connectDetails);
        actions.add(action);
    }

    // save the actions
    if (!actions.isEmpty()) {
        saveActions(actions, logger);
    }
}