List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:Main.java
public static String getLatestIosPlatformVersion() { List<String> platforms = listAvailableIosPlatformVersions(); if (!platforms.isEmpty()) { return platforms.get(0); }//w w w. j a va2 s. c om return "4.3"; }
From source file:Main.java
/** * Checks if the application is in the background (i.e behind another application's Activity). * * @param context {@link Context}/*w w w. j a va 2s . co m*/ * @return true if another application is above this one. */ public static boolean isApplicationBroughtToBackground(final Context context) { if (context.checkCallingOrSelfPermission(Manifest.permission.GET_TASKS) == PackageManager.PERMISSION_DENIED) return false; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName()) && !topActivity.getPackageName().equals("com.google.android.voicesearch")) { return true; } } return false; }
From source file:Main.java
public static boolean isApplicationToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }// w w w.ja v a 2s.c o m } return false; }
From source file:Main.java
public static double getLonByLocation(Context context, String ciudad) { Geocoder geocoder = new Geocoder(context); try {//from w w w . j a va 2s .co m List<Address> result = geocoder.getFromLocationName(ciudad, 1); if (result != null && result.isEmpty() == false) { return result.get(0).getLongitude(); } } catch (IOException e) { return 0D; } return 0D; }
From source file:Main.java
public static AccessibilityNodeInfo findNodeInfosByText(AccessibilityNodeInfo nodeInfo, String text) { List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText(text); if (list == null || list.isEmpty()) { return null; }//from ww w.ja va 2s . c o m return list.get(0); }
From source file:Main.java
/** * Returns the last element of the collection. * //from w w w. ja v a2 s . c o m * @param <T> * the element type * @param iterable * the collection * @return the last element or null if the list is empty */ public static <T> T last(Iterable<T> iterable) { if (iterable instanceof Deque<?>) return ((Deque<T>) iterable).getLast(); if (iterable instanceof List<?>) { List<T> list = (List<T>) iterable; return list.isEmpty() ? null : list.get(list.size() - 1); } Iterator<T> iterator = iterable.iterator(); T last = null; while (iterator.hasNext()) last = iterator.next(); return last; }
From source file:Main.java
public static AccessibilityNodeInfo findNodeInfoByText(AccessibilityNodeInfo nodeInfo, String text) { List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText(text); if (list == null || list.isEmpty()) { return null; }/* w ww . ja v a 2 s. c om*/ return list.get(0); }
From source file:Main.java
/** * Gets the next or same closest date from the specified days in * {@code daysOfWeek List} at specified {@code hour} and {@code min}. * // w ww . j av a 2 s. com * @param daysOfWeek * the days of week * @param hour * the hour * @param min * the min * @return the next or same date from the days of week at specified time * @throws IllegalArgumentException * if the {@code daysOfWeek List} is empty. */ public static LocalDateTime getNextClosestDateTime(List<DayOfWeek> daysOfWeek, int hour, int min) throws IllegalArgumentException { if (daysOfWeek.isEmpty()) { throw new IllegalArgumentException("daysOfWeek should not be empty."); } final LocalDateTime dateNow = LocalDateTime.now(); final LocalDateTime dateNowWithDifferentTime = dateNow.withHour(hour).withMinute(min).withSecond(0); // @formatter:off return daysOfWeek.stream().map(d -> dateNowWithDifferentTime.with(TemporalAdjusters.nextOrSame(d))) .filter(d -> d.isAfter(dateNow)).min(Comparator.naturalOrder()) .orElse(dateNowWithDifferentTime.with(TemporalAdjusters.next(daysOfWeek.get(0)))); // @formatter:on }
From source file:fr.dutra.confluence2wordpress.util.CollectionUtils.java
/** * @param tagNames/*from ww w . ja va2 s .co m*/ * @param sep * @return */ public static String join(List<String> tagNames, String sep) { if (tagNames == null || tagNames.isEmpty()) { return null; } return Joiner.on(sep).join(tagNames); }
From source file:Main.java
/** * @param list// w ww .j a va 2s. c om * @param splitSize * @return splited collection */ public static <T> List<List<T>> split(List<T> list, int splitSize) { if (list == null || list.isEmpty() || splitSize <= 0) { return Collections.emptyList(); } List<List<T>> result = new ArrayList<List<T>>(); if (list.size() > splitSize) { int fromIndex = 0; while (true) { int toIndex = fromIndex + splitSize; if (toIndex > list.size()) { toIndex = list.size(); } result.add(list.subList(fromIndex, toIndex)); fromIndex += splitSize; if (fromIndex >= list.size()) { break; } } } else { result.add(list); } return result; }