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:it.gulch.linuxday.android.adapters.EventsAdapter.java

private void bindView(ViewHolder viewHolder, Event event) {
    viewHolder.event = event;//from  w  w  w.  jav a  2 s  .  c  o  m

    String eventTitle = event.getTitle();
    SpannableString spannableString;
    if (CollectionUtils.isEmpty(event.getPeople())) {
        spannableString = new SpannableString(eventTitle);
    } else {
        String personsSummary = StringUtils.join(event.getPeople(), ", ");
        spannableString = new SpannableString(String.format("%1$s\n%2$s", eventTitle, personsSummary));
    }

    spannableString.setSpan(viewHolder.titleSizeSpan, 0, eventTitle.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.title.setText(spannableString);
    int bookmarkDrawable = event.isBookmarked() ? R.drawable.ic_small_starred : 0;
    viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(0, 0, bookmarkDrawable, 0);

    viewHolder.trackName.setText(event.getTrack().getTitle());

    Date startTime = event.getStartDate();
    Date endTime = event.getEndDate();

    String startTimeString = (startTime != null) ? TIME_DATE_FORMAT.format(startTime) : "?";
    String endTimeString = (endTime != null) ? TIME_DATE_FORMAT.format(endTime) : "?";
    String details;

    String roomName = event.getTrack().getRoom().getName();
    if (showDay) {
        details = String.format("%1$s, %2$s  %3$s  |  %4$s", event.getTrack().getDay().getName(),
                startTimeString, endTimeString, roomName);
    } else {
        details = String.format("%1$s  %2$s  |  %3$s", startTimeString, endTimeString, roomName);
    }
    viewHolder.details.setText(details);
}

From source file:com.mirth.connect.server.api.servlets.CodeTemplateServlet.java

@Override
public CodeTemplate getCodeTemplate(String codeTemplateId) {
    try {/*from  w w  w  .j  a v a 2 s.c  om*/
        List<CodeTemplate> codeTemplates = codeTemplateController
                .getCodeTemplates(Collections.singleton(codeTemplateId));
        if (CollectionUtils.isEmpty(codeTemplates)) {
            throw new MirthApiException(Status.NOT_FOUND);
        }
        return codeTemplates.iterator().next();
    } catch (ControllerException e) {
        throw new MirthApiException(e);
    }
}

From source file:at.gv.egiz.pdfas.lib.impl.signing.pdfbox.LTVEnabledPADESPDFBOXSigner.java

/**
 * Adds previously collected LTV verification data to the provided pdf document.
 *
 * @param pdDocument/*from www .j  av a  2 s  .c  om*/
 *            The pdf document (required; must not be {@code null}).
 * @param ltvVerificationInfo
 *            The certificate verification info data (required; must not be {@code null}).
 * @throws CertificateEncodingException
 *             In case of an error with certificate encoding.
 * @throws CRLException
 *             In case there was an error encoding CRL data.
 * @throws IOException
 *             In case there was an error adding a pdf stream to the document.
 */
private void addLTVInfo(PDDocument pdDocument, CertificateVerificationData ltvVerificationInfo)
        throws CertificateEncodingException, CRLException, IOException {
    // expect at least the certificate(s)
    if (CollectionUtils.isEmpty(Objects.requireNonNull(ltvVerificationInfo).getChainCerts())) {
        throw new IllegalStateException(
                "LTV data has not been retrieved yet. At least the signer certificate's chain is must be provided.");
    }
    log.debug("Adding LTV info to document.");
    addDSS(Objects.requireNonNull(pdDocument), ltvVerificationInfo);
    if (CollectionUtils.isNotEmpty(ltvVerificationInfo.getCRLs())
            || CollectionUtils.isNotEmpty(ltvVerificationInfo.getEncodedOCSPResponses())) {
        log.info("LTV data (certchain and revocation info) added to document.");
    } else {
        log.info("LTV data (certchain but no revocation info) added to document.");
    }
}

From source file:com.mirth.connect.server.controllers.DefaultCodeTemplateController.java

@Override
public List<CodeTemplateLibrary> getLibraries(Set<String> libraryIds, boolean includeCodeTemplates)
        throws ControllerException {
    logger.debug("Getting code template libraries, libraryIds=" + String.valueOf(libraryIds));
    if (CollectionUtils.isEmpty(libraryIds)) {
        libraryIds = null;/* w w w.ja  v a 2 s. co m*/
    } else {
        libraryIds = new HashSet<String>(libraryIds);
    }

    Map<String, CodeTemplateLibrary> libraryMap = libraryCache.getAllItems();
    List<CodeTemplateLibrary> libraries = new ArrayList<CodeTemplateLibrary>();
    Map<String, CodeTemplate> codeTemplateMap = codeTemplateCache.getAllItems();

    for (CodeTemplateLibrary library : libraryMap.values()) {
        if (libraryIds == null || libraryIds.contains(library.getId())) {
            addCodeTemplatesToLibrary(library, codeTemplateMap);
            if (!includeCodeTemplates) {
                library.replaceCodeTemplatesWithIds();
            }

            libraries.add(library);

            if (libraryIds != null) {
                libraryIds.remove(library.getId());
            }
        }

        for (CodeTemplate codeTemplate : library.getCodeTemplates()) {
            codeTemplateMap.remove(codeTemplate.getId());
        }
    }

    if (libraryIds != null) {
        for (String libraryId : libraryIds) {
            logger.warn("Cannot find code template library, it may have been removed: " + libraryId);
        }
    }

    return libraries;
}

From source file:com.movies.jsf.JsfUtil.java

public static String getCollectionAsString(Collection<?> collection) {
    if (CollectionUtils.isEmpty(collection)) {
        return "(No Items)";
    }/*w ww.j  a  v  a  2s . c om*/
    StringBuilder sb = new StringBuilder();
    int i = 0;
    for (Object item : collection) {
        if (i > 0) {
            sb.append("<br />");
        }
        sb.append(item);
        i++;
    }
    return sb.toString();
}

From source file:fr.landel.utils.commons.CastUtilsTest.java

/**
 * Check cast list// ww w . ja va  2  s  .c o  m
 */
@Test
public void testGetList() {

    List<String> list = new ArrayList<>();
    list.add("value1");
    list.add(null);
    list.add("value2");

    assertTrue(CollectionUtils.isEmpty(CastUtils.getArrayList(null, String.class)));
    assertTrue(CollectionUtils.isEmpty(CastUtils.getVector(null, String.class)));
    assertTrue(CollectionUtils.isEmpty(CastUtils.getLinkedListAsList(null, String.class)));

    List<String> result = CastUtils.getArrayList(list, String.class);
    assertEquals("value1", result.get(0));
    assertNull(result.get(1));
    assertEquals("value2", result.get(2));

    result = CastUtils.getVector(list, String.class);
    assertEquals("value1", result.get(0));
    assertNull(result.get(1));
    assertEquals("value2", result.get(2));

    result = CastUtils.getLinkedListAsList(list, String.class);
    assertEquals("value1", result.get(0));
    assertNull(result.get(1));
    assertEquals("value2", result.get(2));

    assertEquals(0, CastUtils.getArrayList(list, null).size());
    assertEquals(0, CastUtils.getArrayList(null, null).size());
    assertEquals(0, CastUtils.getArrayList(12, String.class).size());
    assertEquals(0, CastUtils.getArrayList(Arrays.asList(12), String.class).size());
}

From source file:com.fredhopper.connector.query.populators.SearchResponseResultsPopulatorTest.java

/**
 * Test method for//from   w w w . j  av a2 s. co  m
 * {@link com.fredhopper.connector.template.query.populators.response.SearchResponseResultsPopulator#populate(com.fredhopper.webservice.client.Page, de.hybris.platform.commerceservices.search.facetdata.FacetSearchPageData)}
 * .
 */
@Test
public void test() {
    final FhSearchResponse source = new FhSearchResponse();
    source.setPage(getPage("fredhoppersearch/test/response-template/rootCatalog.xml"));
    final FacetSearchPageData<SolrSearchQueryData, SearchResultValueData> target = new FacetSearchPageData();
    populator.populate(source, target);

    final List<Item> items = source.getPage().getUniverses().getUniverse().get(1).getItemsSection().getItems()
            .getItem();
    final List<SearchResultValueData> results = target.getResults();

    assertFalse(CollectionUtils.isEmpty(items));
    assertEquals(items.size(), results.size());

    final Item item = items.get(0);
    final String id = item.getId();

    final Optional<SearchResultValueData> optional = results.stream()
            .filter(data -> data.getValues().containsValue(id)).findAny();
    assertTrue(optional.isPresent());
    final Map<String, Object> valueMap = optional.get().getValues();

    for (final Attribute attribute : item.getAttribute()) {
        final Object object = valueMap.get(attribute.getName());
        assertNotNull(object);
    }
}

From source file:c3.ops.priam.PriamServer.java

public void intialize() throws Exception {
    if (id.getInstance().isOutOfService())
        return;//from   w  w w  . ja  v a2s . c o m

    // start to schedule jobs
    scheduler.start();

    // update security settings.
    if (config.isMultiDC()) {
        scheduler.runTaskNow(UpdateSecuritySettings.class);
        // sleep for 150 sec if this is a new node with new IP for SG to be updated by other seed nodes
        if (id.isReplace() || id.isTokenPregenerated())
            sleeper.sleep(150 * 1000);
        else if (UpdateSecuritySettings.firstTimeUpdated)
            sleeper.sleep(60 * 1000);

        scheduler.addTask(UpdateSecuritySettings.JOBNAME, UpdateSecuritySettings.class,
                UpdateSecuritySettings.getTimer(id));
    }

    // Run the task to tune Cassandra
    scheduler.runTaskNow(TuneCassandra.class);

    // restore from backup else start cassandra.
    if (!config.getRestoreSnapshot().equals(""))
        scheduler.addTask(Restore.JOBNAME, Restore.class, Restore.getTimer());
    else {
        cassProcess.start(true);
    }

    /*
     *  Run the delayed task (after 10 seconds) to Monitor Cassandra
     *  If Restore option is chosen, then Running Cassandra instance is stopped 
     *  Hence waiting for Cassandra to stop
     */
    scheduler.addTaskWithDelay(CassandraMonitor.JOBNAME, CassandraMonitor.class, CassandraMonitor.getTimer(),
            CASSANDRA_MONITORING_INITIAL_DELAY);

    // Start the snapshot backup schedule - Always run this. (If you want to
    // set it off, set backup hour to -1)
    if (config.getBackupHour() >= 0 && (CollectionUtils.isEmpty(config.getBackupRacs())
            || config.getBackupRacs().contains(config.getRac()))) {
        scheduler.addTask(SnapshotBackup.JOBNAME, SnapshotBackup.class, SnapshotBackup.getTimer(config));

        // Start the Incremental backup schedule if enabled
        if (config.isIncrBackup())
            scheduler.addTask(IncrementalBackup.JOBNAME, IncrementalBackup.class, IncrementalBackup.getTimer());
    }

    if (config.isBackingUpCommitLogs()) {
        scheduler.addTask(CommitLogBackupTask.JOBNAME, CommitLogBackupTask.class,
                CommitLogBackupTask.getTimer(config));
    }

    //Set cleanup
    scheduler.addTask(UpdateCleanupPolicy.JOBNAME, UpdateCleanupPolicy.class, UpdateCleanupPolicy.getTimer());
}

From source file:co.runrightfast.core.utils.JmxUtils.java

static void unregisterMBeans(final String domain, final Set<MBeanRegistration<?>> mBeanRegistrations) {
    if (CollectionUtils.isEmpty(mBeanRegistrations)) {
        return;/*from  w  w  w.j av  a2  s .co m*/
    }
    checkArgument(StringUtils.isNotBlank(domain));
    mBeanRegistrations.stream().forEach(reg -> unregisterApplicationMBean(domain, reg.getMbeanType()));
}

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

@Command
public void creeCommande() {
    if (CollectionUtils.isEmpty(selectedListeDemande)) {
        Messagebox.show("Vous devez slectionner au moins une demande pour pouvoir crer une commande",
                "Cration refuse", Messagebox.OK, Messagebox.INFORMATION);
        return;// ww w.  ja v a2 s  . c o m
    }

    Commande commande = commandeService.creeCommandeFromListeDemande(selectedListeDemande);
    if (commande == null) {
        return;
    }

    rechargeOngletListeReferentAchat();
    ouvreOnglet(commande, "/layout/editCommandeAPasser.zul");

    showNotificationStandard("Commande " + commande.getNumero() + " cr");
}