List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:grails.plugins.sitemapper.ValidationUtils.java
public static void assertDataObjects(List<PageMapDataObject> dataObjectList) { if (dataObjectList == null || dataObjectList.isEmpty()) throw new SitemapperException("Data objects can not be null or empty"); }
From source file:Main.java
/** * Determine if the app is currently visible to the user * * @param context//from ww w . ja va2s . com * @return boolean Return true if the app is visible to the user otherwise false */ public static boolean isAppInForeground(Context context) { final List<RunningTaskInfo> task = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getRunningTasks(1); if (task.isEmpty() && task.size() > 0) { return false; } return task.get(0).topActivity.getPackageName().equalsIgnoreCase(context.getPackageName()); }
From source file:com.epam.cme.storefront.util.MetaSanitizerUtil.java
/** * Takes a List of KeywordModels and returns a comma separated list of keywords as String. * // ww w. j a va 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 kw : keywords) { keywordSet.add(kw.getKeyword()); } // Format keywords, join with comma final StringBuilder sb = new StringBuilder(); for (final String kw : keywordSet) { sb.append(kw).append(','); } if (sb.length() > 0) { // Remove last comma return sb.substring(0, sb.length() - 1); } } return ""; }
From source file:Main.java
/** * Returns the first element of the collection. * //w w w. j av a 2 s . c o m * @param <T> * the element type * @param list * the collection * @return the first element or null if the list is empty */ @SuppressWarnings("unchecked") public static <T> T first(List<T> list) { if (list instanceof Deque<?>) return ((Deque<T>) list).getFirst(); return list.isEmpty() ? null : list.get(0); }
From source file:de.metas.ui.web.view.json.JSONDocumentViewOrderBy.java
public static final List<DocumentQueryOrderBy> unwrapList(final List<JSONDocumentViewOrderBy> jsonOrderBys) { if (jsonOrderBys == null || jsonOrderBys.isEmpty()) { return ImmutableList.of(); }/*from w w w . j a v a 2 s . com*/ return jsonOrderBys.stream().map(jsonOrderBy -> unwrap(jsonOrderBy)).filter(orderBy -> orderBy != null) .collect(GuavaCollectors.toImmutableList()); }
From source file:Main.java
/** * Returns the last element of the collection. * //from w ww . j a v a 2 s. c o m * @param <T> * the element type * @param list * the collection * @return the last element or null if the list is empty */ @SuppressWarnings("unchecked") public static <T> T last(List<T> list) { if (list instanceof Deque<?>) return ((Deque<T>) list).getLast(); return list.isEmpty() ? null : list.get(list.size() - 1); }
From source file:Main.java
/** * Calculeaza deviatia maxima de la media pentru datele primite * * @param data//from w w w. j a va 2 s.c o m * @return deviatia maxima de la medie */ public static double computeFluctuations(List<Double> data) { double sum = 0; int index = 0; double media = 0; double max = 0; if (data.isEmpty()) { return 0f; } for (Double i : data) { sum = sum + i; } media = sum / data.size(); for (Double i : data) { Double difference = Math.abs(media - i); if (max < difference) { max = difference; } } return max; }
From source file:com.asakusafw.generator.HadoopBulkLoaderDDLGenerator.java
private static String findVariable(List<String> variableNames, boolean mandatory) { assert variableNames != null; assert variableNames.isEmpty() == false; String value = null;/*www.ja va 2 s. co m*/ for (String var : variableNames) { value = System.getProperty(var); if (value == null) { value = System.getenv(var); } if (value != null) { break; } } if (mandatory && value == null) { throw new IllegalStateException(MessageFormat .format("\"{0}\"??????", variableNames.get(0))); } return value; }
From source file:com.parse.ParseRESTQueryCommand.java
static <T extends ParseObject> Map<String, String> encode(ParseQuery.State<T> state, boolean count) { ParseEncoder encoder = PointerEncoder.get(); HashMap<String, String> parameters = new HashMap<>(); List<String> order = state.order(); if (!order.isEmpty()) { parameters.put("order", ParseTextUtils.join(",", order)); }//from ww w . ja va 2 s .c o m ParseQuery.QueryConstraints conditions = state.constraints(); if (!conditions.isEmpty()) { JSONObject encodedConditions = (JSONObject) encoder.encode(conditions); parameters.put("where", encodedConditions.toString()); } // This is nullable since we allow unset selectedKeys as well as no selectedKeys Set<String> selectedKeys = state.selectedKeys(); if (selectedKeys != null) { parameters.put("keys", ParseTextUtils.join(",", selectedKeys)); } Set<String> includeds = state.includes(); if (!includeds.isEmpty()) { parameters.put("include", ParseTextUtils.join(",", includeds)); } if (count) { parameters.put("count", Integer.toString(1)); } else { int limit = state.limit(); if (limit >= 0) { parameters.put("limit", Integer.toString(limit)); } int skip = state.skip(); if (skip > 0) { parameters.put("skip", Integer.toString(skip)); } } Map<String, Object> extraOptions = state.extraOptions(); for (Map.Entry<String, Object> entry : extraOptions.entrySet()) { Object encodedExtraOptions = encoder.encode(entry.getValue()); parameters.put(entry.getKey(), encodedExtraOptions.toString()); } if (state.isTracingEnabled()) { parameters.put("trace", Integer.toString(1)); } return parameters; }
From source file:Main.java
public static List<String> removeAllIgnoreCase(List<String> all, List<String> beside) { List<String> rst = new ArrayList<String>(); if (all == null || all.isEmpty()) { return rst; }//from ww w. ja v a 2s . c om if (beside == null || beside.isEmpty()) { return all; } for (String desc : all) { boolean eq = false; for (String str : beside) { if ((desc + "").equalsIgnoreCase(str)) { eq = true; break; } } if (!eq) { rst.add(desc); } } return rst; }