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.manager.protein.ProteinSequenceReconstructionManager.java

private List<List<Sequence>> loadCdsNucleatides(List<Gene> cdsList, long referenceId, Chromosome chromosome) {
    if (CollectionUtils.isEmpty(cdsList)) {
        return null;
    }/*  w w w.  ja v a  2  s . c o m*/

    // Load reference nucleotides for CDS.
    List<List<Sequence>> cdsNucleotides;
    try {
        cdsNucleotides = loadNucleotidesForReferenceCds(chromosome, referenceId, cdsList);
    } catch (IOException e) {
        LOGGER.error("Error during protein sequence reconstruction.", e);
        return null;
    }
    Assert.notNull(cdsNucleotides, "Cannot load nucleotides for cds list.");

    return cdsNucleotides;
}

From source file:com.oneops.inductor.Config.java

public boolean isCloudStubbed(CmsWorkOrderSimpleBase bwo) {
    boolean stubbedMode = false;
    String cloudName = StringUtils.EMPTY;
    if (!CollectionUtils.isEmpty(stubbedCloudsList)) {
        if (bwo != null) {
            cloudName = getCloud(bwo, cloudName);
            if (StringUtils.isEmpty(cloudName)) {
                stubbedMode = false;/*from  www.  j  a  va 2s .  co m*/
            } else if (stubbedCloudsList.contains(cloudName.toLowerCase())) {
                stubbedMode = true;
            }
        }
    }
    if (stubbedMode) {
        logger.warn("Cloud :" + cloudName + " is running in stub mode.");
    }
    return stubbedMode;
}

From source file:nc.noumea.mairie.appock.viewmodel.ListePoleViewModel.java

@Command
@NotifyChange({ "poleDirectionServiceTree", "popupCreatePoleVisible" })
public void addPole() {
    if (showErrorPopup(this.popupCreatePole)) {
        return;//from   w  w w.j  a  v  a 2  s . c  o  m
    }

    List<Pole> listePoleWithSameLibelle = poleRepository.findAllByLibelle(this.popupCreatePole.getLibelle());
    if (!CollectionUtils.isEmpty(listePoleWithSameLibelle)) {
        showErrorPopup("Le libell " + this.popupCreatePole.getLibelle() + " est dj utilis");
        return;
    }

    this.setPopupCreatePoleVisible(false);
    poleRepository.save(this.popupCreatePole);
    this.rechargeOngletListe();
}

From source file:io.cloudslang.lang.compiler.validator.PreCompileValidatorImpl.java

private void validateFlow(Flow compiledFlow, ExecutableModellingResult result) {
    if (CollectionUtils.isEmpty(compiledFlow.getWorkflow().getSteps())) {
        result.getErrors().add(new RuntimeException("Flow: " + compiledFlow.getName() + " has no steps"));
    } else {/*w w w .j  a  va  2s  .  c o  m*/
        Set<String> reachableStepNames = new HashSet<>();
        Set<String> reachableResultNames = new HashSet<>();
        List<String> resultNames = getResultNames(compiledFlow);
        Deque<Step> steps = compiledFlow.getWorkflow().getSteps();

        List<RuntimeException> validationErrors = new ArrayList<>();

        validateNavigation(compiledFlow.getWorkflow().getSteps().getFirst(), steps, resultNames,
                reachableStepNames, reachableResultNames, validationErrors);
        validateStepsAreReachable(reachableStepNames, steps, validationErrors);
        validateResultsAreReachable(reachableResultNames, resultNames, validationErrors);

        // convert all the errors for this flow into one which indicates the flow as well
        if (CollectionUtils.isNotEmpty(validationErrors)) {
            StringBuilder stringBuilder = new StringBuilder();

            validationErrors.forEach((err) -> stringBuilder.append('\n').append(err.getMessage()));

            result.getErrors().add(new RuntimeException(
                    "Flow " + compiledFlow.getName() + " has errors:" + stringBuilder.toString()));
        }
    }
}

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

@Test
public void handleNeighbors() throws Exception {
    List<String> nodes = new ArrayList<>();
    nodes.add(HOST_1 + ":" + PORT_1);

    ECKey key1 = ECKey.fromPrivate(Hex.decode(KEY_1)).decompress();
    ECKey key2 = ECKey.fromPrivate(Hex.decode(KEY_2)).decompress();

    Node node1 = new Node(key1.getNodeId(), HOST_1, PORT_1);
    Node node2 = new Node(key2.getNodeId(), HOST_2, PORT_2);
    NodeDistanceTable distanceTable = new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE,
            node2);//from   w ww.  java  2  s  .  co m
    PeerExplorer peerExplorer = new PeerExplorer(nodes, node2, distanceTable, key2, TIMEOUT, REFRESH);

    Channel internalChannel = Mockito.mock(Channel.class);
    UDPTestChannel channel = new UDPTestChannel(internalChannel, peerExplorer);
    ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
    peerExplorer.setUDPChannel(channel);
    Assert.assertTrue(CollectionUtils.isEmpty(peerExplorer.getNodes()));

    //We try to process a Message without previous connection
    List<Node> newNodes = new ArrayList<>();
    newNodes.add(new Node(Hex.decode(NODE_ID_3), HOST_3, PORT_3));
    NeighborsPeerMessage neighborsPeerMessage = NeighborsPeerMessage.create(newNodes,
            UUID.randomUUID().toString(), key1);
    DiscoveryEvent neighborsEvent = new DiscoveryEvent(neighborsPeerMessage,
            new InetSocketAddress(HOST_1, PORT_1));
    channel.clearEvents();
    channel.channelRead0(ctx, neighborsEvent);
    List<DiscoveryEvent> sentEvents = channel.getEventsWritten();
    Assert.assertEquals(0, sentEvents.size());

    //we establish a connection but we dont send the findnode message.
    peerExplorer.startConversationWithNewNodes();
    PongPeerMessage incomingPongMessage = PongPeerMessage.create(HOST_1, PORT_1,
            ((PingPeerMessage) sentEvents.get(0).getMessage()).getMessageId(), key1);
    DiscoveryEvent incomingPongEvent = new DiscoveryEvent(incomingPongMessage,
            new InetSocketAddress(HOST_1, PORT_1));
    channel.channelRead0(ctx, incomingPongEvent);
    channel.clearEvents();
    channel.channelRead0(ctx, neighborsEvent);
    sentEvents = channel.getEventsWritten();
    Assert.assertEquals(0, sentEvents.size());

    //We send a findNode first
    channel.clearEvents();
    peerExplorer.sendFindNode(node1);
    FindNodePeerMessage findNodePeerMessage = (FindNodePeerMessage) channel.getEventsWritten().get(0)
            .getMessage();
    neighborsPeerMessage = NeighborsPeerMessage.create(newNodes, findNodePeerMessage.getMessageId(), key1);
    neighborsEvent = new DiscoveryEvent(neighborsPeerMessage, new InetSocketAddress(HOST_1, PORT_1));
    channel.clearEvents();
    channel.channelRead0(ctx, neighborsEvent);

    sentEvents = channel.getEventsWritten();
    Assert.assertEquals(1, sentEvents.size());
    DiscoveryEvent discoveryEvent = sentEvents.get(0);
    Assert.assertEquals(new InetSocketAddress(HOST_3, PORT_3), discoveryEvent.getAddress());
    Assert.assertEquals(DiscoveryMessageType.PING, discoveryEvent.getMessage().getMessageType());
}

From source file:musiccrawler.App.java

private void getMusicByOption(Map<String, String> values, DefaultTableModel defaultTableModel) {
    List<Music> musics = musicCrawler.getMusicByOption(values);
    if (!CollectionUtils.isEmpty(musics)) {
        AtomicInteger count = new AtomicInteger();
        musics.forEach(music -> {//from   w  w  w  .ja  v a2  s .com
            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);
        });
        tbResult.setModel(defaultTableModel);
        defaultTableModel.fireTableDataChanged();
        tbResult.setVisible(true);
    }
}

From source file:de.micromata.genome.db.jpa.logging.BaseJpaLoggingImpl.java

/**
 * {@inheritDoc}// w  w  w.  j a v a  2s  .  c om
 *
 */

@Override
protected void selectLogsImpl(Timestamp start, Timestamp end, Integer loglevel, String category, String msg,
        List<Pair<String, String>> logAttributes, final int startRow, final int maxRow, List<OrderBy> orderBy,
        final boolean masterOnly, final LogEntryCallback callback) throws EndOfSearch {

    final StopWatch sw = new StopWatch();
    sw.start();

    final StringBuilder queryStringBuilder = new StringBuilder(
            "select lm from " + getMasterClass().getName() + "  as lm");
    if (masterOnly == false) {
        queryStringBuilder.append(" left outer join fetch lm.attributes");
    }

    boolean firstWhere = true;
    // final List<Object> args = new ArrayList<Object>();
    Map<String, Object> argmap = new HashMap<>();
    if (start != null) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.createdAt >= :createdAtMin");
        argmap.put("createdAtMin", start);
    }
    if (end != null) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.createdAt <= :createdAtMax");
        argmap.put("createdAtMax", end);
    }
    if (loglevel != null) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.loglevel >= :logLevelMin");
        argmap.put("logLevelMin", new Short(loglevel.shortValue()));
    }
    if (StringUtils.isNotBlank(category) == true) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.category = :category");
        argmap.put("category", category);
    }
    if (StringUtils.isNotBlank(msg) == true) {
        firstWhere = addWhere(queryStringBuilder, firstWhere, "lm.shortmessage like :message");
        argmap.put("message", msg + "%");
    }
    if (logAttributes != null) {
        int attrNum = 0;
        for (Pair<String, String> pat : logAttributes) {
            ++attrNum;
            LogAttributeType at = getAttributeTypeByString(pat.getFirst());
            if (at == null) {
                GLog.warn(GenomeLogCategory.Configuration,
                        "SelLogs; Cannot find LogAttribute: " + pat.getFirst());
                continue;
            }
            if (at.isSearchKey() == false) {
                GLog.warn(GenomeLogCategory.Configuration,
                        "SelLogs; LogAttribute not searchable: " + pat.getFirst());
                continue;
            }
            if (StringUtils.contains(pat.getSecond(), "%") == false) {
                firstWhere = addWhere(queryStringBuilder, firstWhere, at.columnName(), " = :attr" + attrNum);
            } else {
                firstWhere = addWhere(queryStringBuilder, firstWhere, at.columnName(), " like :attr" + attrNum);
            }

            argmap.put("attr" + attrNum, pat.getSecond());
        }
    }

    if (CollectionUtils.isEmpty(orderBy) == false) {
        queryStringBuilder.append(" order by ");
        boolean first = true;
        for (OrderBy order : orderBy) {
            if (first == true) {
                first = false;
            } else {
                queryStringBuilder.append(", ");
            }
            String propertyName = convertColumnNameToPropertyName(order.getColumn());
            queryStringBuilder.append("lm.").append((propertyName != null) ? propertyName : order.getColumn()); // eventually
            // requires
            // translation
            // to
            // propertynames
            queryStringBuilder.append(order.isDescending() ? " desc" : " asc");
        }
    }

    EmgrFactory<DefaultEmgr> mgrfac = getEmgrFactory();
    mgrfac.runInTrans(new EmgrCallable<Void, DefaultEmgr>() {
        @Override
        public Void call(DefaultEmgr mgr) {

            Query query = mgr.createQuery(queryStringBuilder.toString());
            for (Map.Entry<String, Object> arg : argmap.entrySet()) {
                query.setParameter(arg.getKey(), arg.getValue());
            }
            query.setFirstResult(startRow);
            if (masterOnly == true) {
                query.setMaxResults(maxRow);
            } else {
                query.setMaxResults(maxRow * 10); // pessimistic assumption:
                // 10 attributes per
                // master entry
            }

            List<M> res = query.getResultList();

            for (M lmDo : res) {
                LogEntry le = new LogEntry();
                copyMasterFields(le, lmDo, masterOnly);
                try {
                    callback.onRow(le);
                } catch (EndOfSearch eos) {
                    break;
                }
            }
            return null;
        }
    });
}

From source file:com.epam.catgenome.manager.ProjectManagerTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testMoveProjectToParent() throws FeatureIndexException, InterruptedException, VcfReadingException,
        NoSuchAlgorithmException, IOException {
    Project parent = new Project();
    parent.setName("testParent");
    parent.setItems(Collections/*from   w w w .  j a  v a  2 s.c om*/
            .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId()))));
    parent = projectManager.saveProject(parent);

    Project child1 = new Project();
    child1.setName("testChild1");
    child1.setItems(Collections
            .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId()))));
    child1 = projectManager.saveProject(child1, parent.getId());

    parent = projectManager.loadProject(parent.getId());
    Assert.assertFalse(parent.getNestedProjects().isEmpty());
    Assert.assertEquals(child1.getId(), parent.getNestedProjects().get(0).getId());

    Project child2 = new Project();
    child2.setName("testChild2");
    child2.setItems(Collections
            .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId()))));
    child2 = projectManager.saveProject(child2);
    projectManager.moveProjectToParent(child2.getId(), parent.getId());
    parent = projectManager.loadProject(parent.getId());

    Assert.assertEquals(parent.getNestedProjects().size(), 2);
    Assert.assertEquals(child1.getId(), parent.getNestedProjects().get(0).getId());
    Assert.assertEquals(child2.getId(), parent.getNestedProjects().get(1).getId());

    parent = projectManager.loadProject(parent.getId());
    Assert.assertEquals(parent.getNestedProjects().size(), 2);
    Assert.assertEquals(child1.getId(), parent.getNestedProjects().get(0).getId());
    Assert.assertEquals(child2.getId(), parent.getNestedProjects().get(1).getId());

    List<Project> topLevel = projectManager.loadTopLevelProjectsForCurrentUser();
    Assert.assertEquals(1, topLevel.size());

    // test loading tree
    Project child11 = new Project();
    child11.setName("tesChild11");
    child11.setItems(Collections
            .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId()))));
    projectManager.saveProject(child11, child1.getId());

    addVcfFileToProject(parent.getId(), "testVcf", TEST_VCF_FILE_PATH);

    Resource resource = context.getResource("classpath:templates/genes_sorted.gtf");

    FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest();
    request.setReferenceId(referenceId);
    request.setName("genes");
    request.setPath(resource.getFile().getAbsolutePath());

    GeneFile geneFile = gffManager.registerGeneFile(request);
    projectManager.addProjectItem(child1.getId(), geneFile.getBioDataItemId());

    referenceGenomeManager.updateReferenceGeneFileId(referenceId, geneFile.getId());
    projectManager.addProjectItem(parent.getId(), geneFile.getBioDataItemId());

    topLevel = projectManager.loadProjectTree(null);
    Assert.assertFalse(topLevel.isEmpty());
    Assert.assertFalse(topLevel.stream().anyMatch(p -> p.getNestedProjects().isEmpty()));
    Assert.assertTrue(topLevel.stream().anyMatch(p -> p.getItems().stream()
            .anyMatch(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.GENE)));
    Assert.assertFalse(topLevel.stream().anyMatch(p -> p.getItems().isEmpty()));
    Assert.assertFalse(topLevel.get(0).getNestedProjects().stream()
            .allMatch(p -> CollectionUtils.isEmpty(p.getNestedProjects())));
    Assert.assertFalse(
            topLevel.get(0).getNestedProjects().stream().allMatch(p -> CollectionUtils.isEmpty(p.getItems())));
}

From source file:com.ccserver.digital.service.LOSService.java

private String getErrorDescription(ResponseStatusType response) {
    StringBuilder resultAsString = new StringBuilder();
    resultAsString.append(response.getGlobalErrorDescription());

    List<ResponseStatusErroInfoType> listErrors = response.getErrorInfo();
    if (CollectionUtils.isEmpty(listErrors)) {
        return resultAsString.toString();
    }/*ww w.java 2 s  .co  m*/
    listErrors.forEach(x -> resultAsString.append(x.getErrorDesc()));
    return resultAsString.toString();
}

From source file:com.evolveum.midpoint.web.page.self.PageAbstractSelfCredentials.java

private boolean getPasswordOutbound(PrismObject<ShadowType> shadow, Task task, OperationResult result)
        throws ObjectNotFoundException, ExpressionEvaluationException, CommunicationException,
        ConfigurationException, SecurityViolationException {
    try {/*from  www . ja  va  2s .c  om*/
        RefinedObjectClassDefinition rOCDef = getModelInteractionService().getEditObjectClassDefinition(shadow,
                shadow.asObjectable().getResource().asPrismObject(), AuthorizationPhaseType.REQUEST, task,
                result);

        if (rOCDef != null && !CollectionUtils.isEmpty(rOCDef.getPasswordOutbound())) {
            return true;
        }
    } catch (SchemaException ex) {

    }
    return false;
}