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

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

Introduction

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

Prototype

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

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

From source file:co.rsk.net.discovery.PeerExplorer.java

private void loadInitialBootNodes(List<String> nodes) {
    if (CollectionUtils.isNotEmpty(nodes)) {
        for (String node : nodes) {
            String[] addressData = StringUtils.split(node, ":");
            if (addressData != null && addressData.length == 2) {
                List<String> dataList = Arrays.asList(addressData);
                bootNodes.add(new InetSocketAddress(dataList.get(0), Integer.parseInt(dataList.get(1))));
            } else {
                logger.debug("Invalid bootNode address: {}", node);
            }/*from w ww. ja va  2  s  .  c  o m*/
        }
    }
}

From source file:com.daphne.es.maintain.staticresource.web.controller.StaticResourceVersionController.java

private Map<String, List<StaticResource>> findStaticResources(String realPath) throws IOException {

    final Map<String, List<StaticResource>> resources = Maps.newTreeMap();

    final int realPathLength = realPath.length();

    Collection<File> files = FileUtils.listFiles(new File(realPath), new String[] { "jspf" }, true);

    for (File file : files) {

        String fileName = file.getAbsolutePath().substring(realPathLength);
        List<String> contents = FileUtils.readLines(file);

        List<StaticResource> resourceList = resources.get(fileName);
        if (resourceList == null) {
            resourceList = Lists.newArrayList();
        }//from  w w  w  .ja  va2  s .c  o  m

        for (String content : contents) {
            if (!StringUtils.isEmpty(content)) {
                StaticResource resource = extractResource(fileName, content);
                if (resource != null) {
                    resourceList.add(resource);
                }
            }
        }

        if (CollectionUtils.isNotEmpty(resourceList)) {
            resources.put(fileName, resourceList);
        }
    }

    return resources;
}

From source file:io.github.swagger2markup.internal.component.PathOperationComponent.java

private void buildConsumesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
    List<String> consumes = operation.getOperation().getConsumes();
    if (CollectionUtils.isNotEmpty(consumes)) {
        consumesComponent.apply(markupDocBuilder,
                ConsumesComponent.parameters(consumes, getSectionTitleLevel()));
    }/*from w  ww .j av a2 s  . c  o m*/

}

From source file:com.epam.catgenome.manager.protein.ProteinSequenceReconstructionManager.java

/**
 * Loads nucleotide sequences for specified CDS with variations.
 *
 * @param chromosome        chromosome//from w w w .  java  2  s .  c om
 * @param referenceId       reference id
 * @param variationToCdsMap map of pairs {Variation, List of CDS(-es), changed by this variation}
 * @return map of pairs {CDS, List of possible nucleotide sequences}
 * @throws IOException            if errors occurred during working with reference file
 */
@Transactional(propagation = Propagation.REQUIRED)
public Map<Gene, List<List<Sequence>>> loadNucleotidesForReferenceVariationCds(final Chromosome chromosome,
        final Long referenceId, final Map<Variation, List<Gene>> variationToCdsMap) throws IOException {
    double time1 = Utils.getSystemTimeMilliseconds();
    Map<Gene, List<List<Sequence>>> cdsToAlternativeNucleotidesMap = new HashMap<>();

    for (Map.Entry<Variation, List<Gene>> variationToCdsEntry : variationToCdsMap.entrySet()) {
        List<Gene> cdsList = variationToCdsEntry.getValue();
        for (Gene cds : cdsList) {
            List<List<Sequence>> nucleotideSequences;

            if (cdsToAlternativeNucleotidesMap.containsKey(cds)) {
                // If nucleotide sequence was already changed by another variation,
                // work with changed nucleotide sequence.
                nucleotideSequences = cdsToAlternativeNucleotidesMap.get(cds);
            } else {
                // Load nucleotideSequences for CDS.
                LOGGER.debug(
                        "Try read reference. Start:" + cds.getStartIndex() + ", end: " + cds.getEndIndex());
                nucleotideSequences = Collections.singletonList(referenceManager.getNucleotidesFromNibFile(
                        cds.getStartIndex(), cds.getEndIndex(), referenceId, chromosome.getName()));
            }

            List<List<Sequence>> cdsNucleotides = new ArrayList<>(cdsList.size());
            for (List<Sequence> nucleotideSeq : nucleotideSequences) {
                // Take into account variations on nucleotide sequences.
                changeMRnaByVariations(variationToCdsEntry.getKey(), cdsNucleotides, nucleotideSeq);
            }
            if (!cdsToAlternativeNucleotidesMap.containsKey(cds)
                    || CollectionUtils.isNotEmpty(cdsNucleotides)) {
                cdsToAlternativeNucleotidesMap.put(cds, cdsNucleotides);
            }
        }
    }

    Map<Gene, List<List<Sequence>>> geneListMap = processStrand(cdsToAlternativeNucleotidesMap);
    double time2 = Utils.getSystemTimeMilliseconds();
    LOGGER.debug("Loading nucleotides for reference variation cds {} ms", Thread.currentThread().getName(),
            time2 - time1);
    return geneListMap;
}

From source file:com.epam.catgenome.manager.protein.ProteinSequenceManager.java

private Map<Variation, List<Gene>> findIntersections(final Track<Variation> variations,
        final Set<Gene> allCds) {
    Map<Variation, List<Gene>> intersections = new HashMap<>();
    for (Variation variation : variations.getBlocks()) {
        List<Gene> currIntersections = allCds.stream()
                .filter(geneFeature -> variation.getStartIndex() >= geneFeature.getStartIndex()
                        && variation.getStartIndex() <= geneFeature.getEndIndex())
                .collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(currIntersections)) {
            intersections.put(variation, currIntersections);
        }//from w w  w . ja  va2 s.co  m
    }
    return intersections;
}

From source file:io.github.swagger2markup.internal.component.PathOperationComponent.java

private void buildProducesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
    List<String> produces = operation.getOperation().getProduces();
    if (CollectionUtils.isNotEmpty(produces)) {
        producesComponent.apply(markupDocBuilder,
                ProducesComponent.parameters(produces, getSectionTitleLevel()));
    }//from   w ww. j  a  va  2  s.c  o  m
}

From source file:io.github.swagger2markup.internal.document.builder.DefinitionsDocumentBuilder.java

/**
 * Builds inline schema definitions//from  w ww . j av  a 2  s  .co m
 *
 * @param definitions  all inline definitions to display
 * @param uniquePrefix unique prefix to prepend to inline object names to enforce unicity
 * @param docBuilder   the docbuilder do use for output
 */
private void inlineDefinitions(List<ObjectType> definitions, String uniquePrefix, MarkupDocBuilder docBuilder) {
    if (CollectionUtils.isNotEmpty(definitions)) {
        for (ObjectType definition : definitions) {
            addInlineDefinitionTitle(definition.getName(), definition.getUniqueName(), docBuilder);
            List<ObjectType> localDefinitions = buildPropertiesTable(definition.getProperties(), uniquePrefix,
                    new DefinitionDocumentResolverFromDefinition(), docBuilder);
            for (ObjectType localDefinition : localDefinitions)
                inlineDefinitions(Collections.singletonList(localDefinition), localDefinition.getUniqueName(),
                        docBuilder);
        }
    }
}

From source file:io.github.swagger2markup.internal.component.PathOperationComponent.java

private void buildTagsSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
    if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
        List<String> tags = operation.getOperation().getTags();
        if (CollectionUtils.isNotEmpty(tags)) {
            buildSectionTitle(markupDocBuilder, labels.getLabel(TAGS));
            if (config.getTagOrdering() != null) {
                tags.sort(config.getTagOrdering());
            }/*from  w  w w.  j  a  va2 s  .c  o m*/
            markupDocBuilder.unorderedList(tags);
        }
    }
}

From source file:musiccrawler.App.java

private void btnCrawlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrawlActionPerformed
    if (Utils.isNull(rdgOptionCrawl.getSelection())) {
        JOptionPane.showMessageDialog(this, "Plz, check option before perform action crawl");
        return;/* ww  w  .  j ava2 s.  co  m*/
    }
    String path = txtUrlInput.getText();
    if (StringUtils.isEmpty(path)) {
        lblError.setText("Path is require");
        lblError.setForeground(Color.RED);
        return;
    }
    boolean isGetAll = rdbGetAll.isSelected();
    path = Validator.validPath(path);
    final DefaultTableModel defaultTableModel = new DefaultTableModel(isGetAll ? COLUMN_NAMES : COLUMN_STREAM,
            0);
    AtomicInteger count = new AtomicInteger();
    if (isGetAll) {
        List<Music> musics = musicCrawler.crawl(path);
        if (CollectionUtils.isNotEmpty(musics)) {
            musics.forEach(music -> {
                Object[] row = { count.getAndIncrement(), music.getId(), music.getTitle(), music.getImage(),
                        music.getUrl(), music.getLyric(), music.getDescription(), music.getStream(),
                        music.getQualityType().toString(), music.getSinger().getName(),
                        music.getSinger().getAge(), music.getSinger().getDescription(),
                        music.getSinger().getAvatar() };
                defaultTableModel.addRow(row);
            });
        }
    } else {
        Map<String, List<String>> results = musicCrawler.reCrawlLinkStream(path);
        List<String> musicIds = results.get("id");
        List<String> listStream = results.get("stream");
        musicIds.forEach(id -> {
            int index = count.getAndIncrement();
            Object[] row = { index, id, listStream.get(index) };
            defaultTableModel.addRow(row);
        });
    }
    tbResultCrawlOnl.setModel(defaultTableModel);
    defaultTableModel.fireTableDataChanged();
    tbResultCrawlOnl.setVisible(true);
}

From source file:com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesManager.java

protected void doFetchDynamicAttributes(MetaClass metaClass, Collection<BaseGenericIdEntity> entities) {
    List<Object> ids = entities.stream().map(e -> referenceToEntitySupport.getReferenceId(e))
            .collect(Collectors.toList());

    Multimap<Object, CategoryAttributeValue> allAttributeValues = HashMultimap.create();

    List<Object> currentIds = new ArrayList<>();
    for (Object id : ids) {
        currentIds.add(id);/*from   w  w  w .  j  a v a 2s  .  c  om*/
        if (currentIds.size() >= MAX_ENTITIES_FOR_ATTRIBUTE_VALUES_BATCH) {
            handleAttributeValuesForIds(metaClass, currentIds, allAttributeValues);
            currentIds = new ArrayList<>();
        }
    }
    handleAttributeValuesForIds(metaClass, currentIds, allAttributeValues);

    for (BaseGenericIdEntity entity : entities) {
        Collection<CategoryAttributeValue> entityAttributeValues = allAttributeValues
                .get(referenceToEntitySupport.getReferenceId(entity));
        Map<String, CategoryAttributeValue> map = new HashMap<>();
        entity.setDynamicAttributes(map);
        if (CollectionUtils.isNotEmpty(entityAttributeValues)) {
            for (CategoryAttributeValue categoryAttributeValue : entityAttributeValues) {
                CategoryAttribute attribute = categoryAttributeValue.getCategoryAttribute();
                if (attribute != null) {
                    map.put(attribute.getCode(), categoryAttributeValue);
                }
            }
        }
    }
}