List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:Main.java
/** * Judge whether an app is in background * * @param context/*from ww w . ja v a2s. c om*/ * @return */ public static boolean isAppInBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskList = am.getRunningTasks(1); if (taskList != null && !taskList.isEmpty()) { ComponentName topActivity = taskList.get(0).topActivity; if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; }
From source file:io.milton.cloud.server.web.templating.EncodeUtils.java
public static boolean isEmpty(Object val) { if (val == null) { return true; } else if (val instanceof List) { List list = (List) val; return list.isEmpty(); } else if (val instanceof String) { String s = (String) val; return StringUtils.isBlank(s); } else {//from w w w. j av a2 s.com return false; } }
From source file:Main.java
public static boolean isAppBackground(Context context) { if (context != null) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); @SuppressWarnings("deprecation") List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from w w w . ja v a2 s .c o m*/ } } return false; }
From source file:Main.java
public static boolean isAppForeground(Context context, String packageName) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); @SuppressWarnings("deprecation") List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); return tasks != null && !tasks.isEmpty() && tasks.get(0).topActivity.getPackageName().equals(packageName); }
From source file:Main.java
public static <T> void addFirstAndRemoveOldIfNeed(List<T> dest, List<T> src) { if (dest == null) { return;//from w w w. j a v a2 s .c o m } if (src == null || src.isEmpty()) { return; } removeDuplicate(dest, src); dest.addAll(0, src); }
From source file:Main.java
private static <T> List<T> copyList(List<T> original) { List<T> copy = null;/*from w w w . j av a 2 s . co m*/ if (original != null) { copy = new ArrayList<T>(); if (!original.isEmpty()) { copy.addAll(original); } } return copy; }
From source file:de.codesourcery.eve.skills.db.dao.HibernateDAO.java
protected static <T> T getExactlyOneResult(List<T> result) { if (result.isEmpty()) { throw new EmptyResultDataAccessException(1); }//from w w w . j ava 2 s . com if (result.size() > 1) { throw new IncorrectResultSizeDataAccessException("Internal error, got more than I expected?", 1, result.size()); } return result.get(0); }
From source file:com.mpush.test.client.ConnClientTestMain.java
private static void testConnClient(int count, String userPrefix, int printDelay, boolean sync) throws Exception { Logs.init();//from w w w.j a v a2 s. c om ConnClientBoot boot = new ConnClientBoot(); boot.start().get(); List<ServiceNode> serverList = boot.getServers(); if (serverList.isEmpty()) { boot.stop(); System.out.println("no mpush server."); return; } if (printDelay > 0) { Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( () -> System.err.println(ConnClientChannelHandler.STATISTICS), 3, printDelay, TimeUnit.SECONDS); } for (int i = 0; i < count; i++) { String clientVersion = "1.0." + i; String osName = "android"; String osVersion = "1.0.1"; String userId = userPrefix + "user-" + i; String deviceId = userPrefix + "test-device-id-" + i; byte[] clientKey = CipherBox.I.randomAESKey(); byte[] iv = CipherBox.I.randomAESIV(); ClientConfig config = new ClientConfig(); config.setClientKey(clientKey); config.setIv(iv); config.setClientVersion(clientVersion); config.setDeviceId(deviceId); config.setOsName(osName); config.setOsVersion(osVersion); config.setUserId(userId); int L = serverList.size(); int index = (int) ((Math.random() % L) * L); ServiceNode node = serverList.get(index); ChannelFuture future = boot.connect(node.getAttr(ATTR_PUBLIC_IP), node.getPort(), config); if (sync) future.awaitUninterruptibly(); } }
From source file:ro.allevo.fintpws.security.RolesUtils.java
public static boolean hasReadAuthorityOnQueue(QueueEntity queueEntity) { EntityManagerFactory configEntityManagerFactory = Persistence.createEntityManagerFactory("fintpCFG"); EntityManager entityManagerConfig = configEntityManagerFactory.createEntityManager(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); UserEntity loggedUser = (UserEntity) authentication.getPrincipal(); Query query = entityManagerConfig .createQuery("SELECT ur.roleid FROM UserRoleEntity ur, QueuesRoleMapEntity qr " + "WHERE ur.roleid = qr.roleid " + "AND ur.userid=:userid " + "AND qr.queueid=:queueid"); query.setParameter("userid", loggedUser.getUserid()); query.setParameter("queueid", queueEntity.getGuid()); List roles = query.getResultList(); if (roles.isEmpty()) { return false; }/*from w w w.jav a2s . c om*/ return true; }
From source file:ro.allevo.fintpws.security.RolesUtils.java
public static boolean hasWriteAuthorityOnQueue(QueueEntity queueEntity) { EntityManagerFactory configEntityManagerFactory = Persistence.createEntityManagerFactory("fintpCFG"); EntityManager entityManagerConfig = configEntityManagerFactory.createEntityManager(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); UserEntity loggedUser = (UserEntity) authentication.getPrincipal(); Query query = entityManagerConfig.createQuery( "SELECT ur.roleid FROM UserRoleEntity ur, QueuesRoleMapEntity qr " + "WHERE ur.roleid = qr.roleid " + "AND ur.userid=:userid " + "AND qr.queueid=:queueid " + "AND qr.actiontype = 'RW'"); query.setParameter("userid", loggedUser.getUserid()); query.setParameter("queueid", queueEntity.getGuid()); List roles = query.getResultList(); if (roles.isEmpty()) { return false; }/*from w w w .j a v a 2 s. c om*/ return true; }