List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:com.flexive.shared.cmis.search.CmisResultValue.java
@SuppressWarnings({ "unchecked" }) private static CmisResultValue createListValue(Object value) { final Collection list = (Collection) value; return list.isEmpty() ? new NullResult() : new MultivaluedResult(list); }
From source file:de.thischwa.pmcms.tool.file.FileTool.java
/** * Just a wrapper to {@link #copyToDirectoryUnique(File, File)}. * // w w w.j a v a 2s. c o m * @param filesToCopy * @param directory * @return Collection of the copied files. * @throws IOException */ public static List<File> copyToDirectoryUnique(final Collection<File> filesToCopy, final File directory) throws IOException { if (filesToCopy.isEmpty()) return null; List<File> copiedFiles = new ArrayList<File>(filesToCopy.size()); for (File srcFile : filesToCopy) copiedFiles.add(copyToDirectoryUnique(srcFile, directory)); return copiedFiles; }
From source file:Main.java
/** * Make the log more meanings//from ww w .j a v a 2 s . c om * * @param <E> * @param collec * @return */ public static <E> String toLog(String separator, Collection<E> collec) { // using StringBuffer instead of String because expect there are many append operation StringBuffer sb = new StringBuffer(); if (collec == null) { return null; } if (collec.isEmpty()) { return collec.toString(); } sb.append("["); for (Iterator<E> iterator = collec.iterator(); iterator.hasNext();) { E value = iterator.next(); sb.append(separator).append(toString4Log(value)).append(separator); if (iterator.hasNext()) { sb.append(", "); } } sb.append("]"); return sb.toString(); }
From source file:com.baifendian.swordfish.common.mail.MailSendUtil.java
/** * ??//from www. j av a 2 s.co m * * @param receivers * @param title * @param content * @return */ public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } // ?? email HtmlEmail email = new HtmlEmail(); try { // SMTP ?????, 163 "smtp.163.com" email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); // ? email.setCharset("UTF-8"); // for (String receiver : receivers) { email.addTo(receiver); } // ?? email.setFrom(mailSender, mailSender); // ???????-?????? email.setAuthentication(mailSender, mailPasswd); // ??? email.setSubject(title); // ???? HtmlEmail? HTML email.setMsg(content); // ?? email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; }
From source file:ca.simplegames.micro.utils.UrlResource.java
/** * Convenience method to return a Collection as a delimited (e.g. CSV) * String. E.g. useful for <code>toString()</code> implementations. * * @param coll the Collection to display * @param delim the delimiter to use (probably a ",") * @param prefix the String to start each element with * @param suffix the String to end each element with * @return the delimited String/*from w w w . j a va 2 s . com*/ */ public static String collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix) { if (coll == null || coll.isEmpty()) { return ""; } StringBuffer sb = new StringBuffer(); Iterator it = coll.iterator(); while (it.hasNext()) { sb.append(prefix).append(it.next()).append(suffix); if (it.hasNext()) { sb.append(delim); } } return sb.toString(); }
From source file:com.github.drbookings.ui.controller.UpcomingController.java
private static void addCleaningSummary(final LocalDate date, final VBox box, final Collection<CleaningEntry> upcomingBookings) { final TextFlow tf = new TextFlow(); if (upcomingBookings.isEmpty()) { // final Text t0 = new Text("and no cleaning."); // tf.getChildren().add(t0); } else {/*www. j a v a2 s.co m*/ final Text t0 = new Text("and "); final Text t1 = new Text(upcomingBookings.size() + " "); t1.getStyleClass().add("emphasis"); final Text t2 = new Text(" cleaning" + (upcomingBookings.size() > 1 ? "s." : ".")); t2.getStyleClass().add("emphasis"); tf.getChildren().addAll(t0, t1, t2); } box.getChildren().add(tf); }
From source file:net.kamhon.ieagle.util.CollectionUtil.java
/** * true if collection is not null and not empty. * /* w w w . j av a2s . c om*/ * @param collection * @return */ public static boolean isNotEmpty(Collection<?> collection) { return collection != null && !collection.isEmpty(); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java
private static boolean pushAllProjectionsOnTopOf(Collection<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef, IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException { if (toPush.isEmpty()) { return false; }//w ww. jav a2 s .co m AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (context.checkAndAddToAlreadyCompared(initialOp, op)) { return false; } switch (op.getOperatorTag()) { case EXCHANGE: { opRef = opRef.getValue().getInputs().get(0); op = (AbstractLogicalOperator) opRef.getValue(); break; } case PROJECT: { return false; } } ProjectOperator pi2 = new ProjectOperator(new ArrayList<LogicalVariable>(toPush)); pi2.getInputs().add(new MutableObject<ILogicalOperator>(op)); opRef.setValue(pi2); pi2.setExecutionMode(op.getExecutionMode()); context.computeAndSetTypeEnvironmentForOperator(pi2); return true; }
From source file:com.kingen.web.CommonController.java
public static String serializeOnlyGivenFields(Object o, Collection<String> fields) throws JsonProcessingException { if ((fields == null) || fields.isEmpty()) fields = new HashSet<String>(); Set<String> properties = new HashSet<String>(fields); SimpleBeanPropertyFilter filter = new SimpleBeanPropertyFilter.FilterExceptFilter(properties); SimpleFilterProvider fProvider = new SimpleFilterProvider(); fProvider.addFilter(FILTER_NAME, filter); ObjectMapper mapper = new ObjectMapper(); mapper.setAnnotationIntrospector(new AnnotationIntrospector()); String json = mapper.writer(fProvider).writeValueAsString(o); return json;/*from w ww . j a v a 2s . c o m*/ }
From source file:com.nextep.datadesigner.sqlgen.impl.GeneratorFactory.java
/** * Retrieves the correct SQL generator which is able to generate the specified model object in * SQL.//w w w .java 2 s . c om * * @param type type of the item to generate * @return the appropriate generator */ public static ISQLGenerator getGenerator(IElementType type, DBVendor vendor) { // Loading extensiongs Collection<IConfigurationElement> conf = Designer.getInstance().getExtensions(GENERATOR_EXTENSION_ID, "sqlGenerator", "typeId", type.getId()); //$NON-NLS-1$ //$NON-NLS-2$ if (conf == null || conf.isEmpty()) { LOGGER.debug("No generator found for type <" + type.getId() + ">, will not generate."); // throw new ErrorException("No generator found for type <" + type.getId() + ">"); return new NullGenerator(); } else { try { ISQLGenerator generator = null; // First looking for vendor-specific generator for (IConfigurationElement elt : conf) { final String extensionVendor = elt.getAttribute(ATTR_VENDOR); if (vendor.name().equals(extensionVendor)) { generator = (ISQLGenerator) elt.createExecutableExtension("class"); //$NON-NLS-1$ generator.setVendor(vendor); return generator; } } // Falling back here if no vendor specific extension found, looking for generic // support for (IConfigurationElement elt : conf) { final String extensionVendor = elt.getAttribute(ATTR_VENDOR); if (extensionVendor == null || "".equals(extensionVendor)) { //$NON-NLS-1$ generator = (ISQLGenerator) elt.createExecutableExtension("class"); //$NON-NLS-1$ generator.setVendor(vendor); } } // If we do not have a vendor-specific generator BUT we have a generic generator, we // use it if (generator != null) { return generator; } else { // We fall here if we have no generator for the current vendor AND no generic // generator LOGGER.info("No generator found for type <" + type.getId() + "> and vendor " + vendor.toString() + ", will not generate."); return new NullGenerator(); } } catch (CoreException e) { LOGGER.error("Error while instantiating generator for type <" + type.getId() + ">"); //$NON-NLS-2$ throw new ErrorException(e); } } }