List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:com.mooing.wss.common.util.BeanUtil.java
public static <T> List<Integer> getIds(List<T> beanList) { if (beanList.isEmpty()) { return Collections.emptyList(); }/*w w w.ja v a2 s . co m*/ List<Integer> ids = new ArrayList<Integer>(); Class<? extends Object> beanClass = beanList.get(0).getClass(); try { Method method = beanClass.getMethod("getId"); for (T beanObj : beanList) { ids.add((Integer) method.invoke(beanObj)); } } catch (Exception e) { throw new IllegalArgumentException("Element of argument must be support getId() method"); } return ids; }
From source file:Main.java
/** * Gets the last element of the list. If the list is null or empty, null * is returned.//from w ww .j a va 2 s . c o m * * @param <T> * The type of element in the list. * @param list * The list to get the last element from. * @return * The last element from the list, if one exists. Otherwise, null. */ public static <T> T getLast(final List<? extends T> list) { if (list == null || list.isEmpty()) { return null; } else { return list.get(list.size() - 1); } }
From source file:org.ambraproject.wombat.util.ReproxyUtil.java
/** * Apply reproxying information for a requested asset to a response. * <p/>/*www . j av a2 s .c o m*/ * The request may not support the reproxying protocol, and there may not be any reproxy URLs for the asset. In either * case, the response is not touched. The return value indicates this. * <p/> * Note that both {@code request} and {@code response} are for the client. Neither is for the service that reproxies * the asset. It is assumed that the caller has already queried the service that reproxies the asset, which provides * the {@code reproxyUrls} argument. * * @param request a request from the client * @param response a response to the client * @param reproxyUrls a list of available reproxy URLs for the requested asset (empty and {@code null} are allowed, * indicating none are available) * @param cacheFor number of seconds to instruct the client to cache the reproxy information * @return {@code true} if the response was filled with reproxy information, in which case nothing should be written * to the response body; {@code false} if not, in which case the response body should be written */ public static boolean applyReproxy(HttpServletRequest request, HttpServletResponse response, List<String> reproxyUrls, int cacheFor) { if (reproxyUrls != null && !reproxyUrls.isEmpty() && supportsReproxy(request)) { response.setStatus(HttpStatus.SC_OK); response.setHeader(X_REPROXY_URL, REPROXY_URL_JOINER.join(reproxyUrls)); response.setHeader(X_REPROXY_CACHE_FOR, cacheFor + "; Last-Modified Content-Type Content-Disposition"); return true; } return false; }
From source file:com.docd.purefm.commandline.CommandDu.java
public static long du_s(@NonNull final GenericFile file) { final List<String> result = CommandLine.executeForResult(new CommandDu(file)); if (result == null || result.isEmpty()) { return 0L; }//from w ww.ja v a2s. c o m final String res = result.get(0); final int resLength = res.length(); final StringBuilder lengthString = new StringBuilder(resLength); for (int i = 0; i < resLength; i++) { final char character = res.charAt(i); if (Character.isDigit(character)) { lengthString.append(character); } else { break; } } try { return Long.parseLong(lengthString.toString()) * FileUtils.ONE_KB; } catch (NumberFormatException e) { return 0L; } }
From source file:Main.java
public static Node getFirstMatchingChildNode(Node node, String str, String str2, List<String> list) { if (node == null || str == null) { return null; }/*w ww . j a v a2s . c om*/ List matchingChildNodes = getMatchingChildNodes(node, str, str2, list); return (matchingChildNodes == null || matchingChildNodes.isEmpty()) ? null : (Node) matchingChildNodes.get(0); }
From source file:org.drools.container.spring.namespace.XsdParser.java
@SuppressWarnings("unchecked") public static void parse(Element element, ParserContext parserContext, BeanDefinitionBuilder factory) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "jaxb-conf"); if (!childElements.isEmpty()) { Element conf = childElements.get(0); String systemId = conf.getAttribute(SYSTEM_ID); systemId = (systemId != null && systemId.trim().length() > 0) ? systemId : "xsd"; String schemaLanguage = conf.getAttribute(SCHEMA_LANGUAGE); schemaLanguage = (schemaLanguage != null && schemaLanguage.trim().length() > 0) ? schemaLanguage : "XMLSCHEMA"; Options options = new Options(); options.setSchemaLanguage(Language.valueOf(schemaLanguage)); JaxbConfiguration jaxbConf = KnowledgeBuilderFactory.newJaxbConfiguration(new Options(), systemId); factory.addPropertyValue("resourceConfiguration", jaxbConf); } else {// w w w. ja va2 s .co m JaxbConfiguration jaxbConf = KnowledgeBuilderFactory.newJaxbConfiguration(new Options(), "xsd"); factory.addPropertyValue("resourceConfiguration", jaxbConf); } }
From source file:Main.java
/** * Calculeaza deviatia medie de la media pentru datele primite * * @param data/*w w w.j a va 2s .com*/ * @return deviatia medie */ public static double computeAverageFluctuations(List<Double> data) { double sum = 0; int index = 0; double media = 0; double max = 0; if (data.isEmpty()) { return 0; } for (Double i : data) { sum = sum + i; } media = sum / data.size(); double dev = 0; for (Double i : data) { dev += Math.abs(media - i); } return dev / data.size(); }
From source file:Main.java
/** * Compares two lists. Caution: Lists can hold same values multiple times. * /*w w w .j a va 2 s. com*/ * @param list1 * @param list2 * @return -1 if no common elements or any of lists are empty/null. * 0 if two lists have the same contents. * x (x>0) if there are x elements in common. */ public static int compareLists(List<? extends Object> list1, List<? extends Object> list2) { if (null == list1 || null == list2 || list1.isEmpty() || list2.isEmpty()) { return -1; } int count = 0; for (Object o : list1) { if (list2.contains(o)) count++; } return count; }
From source file:com.acc.storefront.util.MetaSanitizerUtil.java
/** * Takes a List of KeywordModels and returns a comma separated list of keywords as String. * //w ww. j av a 2s .c o m * @param keywords * List of KeywordModel objects * @return String of comma separated keywords */ public static String sanitizeKeywords(final List<KeywordModel> keywords) { if (keywords != null && !keywords.isEmpty()) { // Remove duplicates final Set<String> keywordSet = new HashSet<String>(keywords.size()); for (final KeywordModel keyword : keywords) { keywordSet.add(keyword.getKeyword()); } // Format keywords, join with comma final StringBuilder stringBuilder = new StringBuilder(); for (final String keyword : keywordSet) { stringBuilder.append(keyword).append(','); } if (stringBuilder.length() > 0) { // Remove last comma return stringBuilder.substring(0, stringBuilder.length() - 1); } } return ""; }
From source file:com.pedra.storefront.util.MetaSanitizerUtil.java
/** * Takes a List of KeywordModels and returns a comma separated list of keywords as String. * /*from w ww . ja v a 2s . com*/ * @param keywords * List of KeywordModel objects * @return String of comma separated keywords */ public static String sanitizeKeywords(final List<KeywordModel> keywords) { if (keywords != null && !keywords.isEmpty()) { // Remove duplicates final Set<String> keywordSet = new HashSet<String>(keywords.size()); for (final KeywordModel kw : keywords) { keywordSet.add(kw.getKeyword()); } // Format keywords, join with comma final StringBuilder stringBuilder = new StringBuilder(); for (final String kw : keywordSet) { stringBuilder.append(kw).append(','); } if (stringBuilder.length() > 0) { // Remove last comma return stringBuilder.substring(0, stringBuilder.length() - 1); } } return ""; }