List of usage examples for java.lang Integer MAX_VALUE
int MAX_VALUE
To view the source code for java.lang Integer MAX_VALUE.
Click Source Link
From source file:Main.java
/** * whether the service is running.// www . j ava 2s . c o m */ public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> servicesList = activityManager .getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo si : servicesList) { if (className.equals(si.service.getClassName())) { isRunning = true; } } return isRunning; }
From source file:Main.java
/** * Checks if is service running./*from ww w. j a va 2 s.co m*/ * * @param ctx the ctx * @param theService the the service * @return true, if is service running */ public static boolean isServiceRunning(Context ctx, Class theService) { ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (theService.getName().equals(service.service.getClassName())) { return true; } } return false; }
From source file:Main.java
public static int min(int[] x, int length) { int m = Integer.MAX_VALUE; for (int i = 0; i < length; i++) if (x[i] < m) m = x[i];//from w w w . jav a2s . c om return m; }
From source file:TestLargest.java
/** * Return the largest element in a list. * /* w w w .j a v a2 s . c o m*/ * @param list * A list of integers * @return The largest number in the given list */ public static int largest(int[] list) { int index, max = Integer.MAX_VALUE; for (index = 0; index < list.length - 1; index++) { if (list[index] > max) { max = list[index]; } } return max; }
From source file:Main.java
public static final boolean checkServiceRunning(Context c, Class<? extends Service> cls) { ComponentName service = new ComponentName(c, cls); ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) throw new RuntimeException("Cannot check running services: ActivityManager is not available"); for (ActivityManager.RunningServiceInfo runningService : am.getRunningServices(Integer.MAX_VALUE)) { if (runningService.service.equals(service)) return true; }//from ww w . j av a 2 s . c o m return false; }
From source file:TestLargest.java
/** * Return the largest element in a list. * // w w w . j a v a 2 s. com * @param list * A list of integers * @return The largest number in the given list */ public static int largest(int[] list) { int index, max = Integer.MAX_VALUE; for (index = 0; index < list.length - 1; index++) { if (list[index] > max) { max = list[index]; } } return max; }
From source file:Main.java
public static String[] getStackTrace(long threadID) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo threadInfo = threadMXBean.getThreadInfo(threadID, Integer.MAX_VALUE); List<String> buf = new ArrayList<String>(); if (threadInfo == null) { return buf.toArray((String[]) Array.newInstance(String.class, buf.size())); }//w w w. java 2s . c o m StackTraceElement[] stackTrace = threadInfo.getStackTrace(); for (int i = 0; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace[i]; buf.add("\t" + ste.toString()); if (i == 0 && threadInfo.getLockInfo() != null) { Thread.State ts = threadInfo.getThreadState(); switch (ts) { case BLOCKED: buf.add("\t- blocked on " + threadInfo.getLockInfo()); break; case WAITING: buf.add("\t- waiting on " + threadInfo.getLockInfo()); break; case TIMED_WAITING: buf.add("\t- waiting on " + threadInfo.getLockInfo()); break; default: } } for (MonitorInfo mi : threadInfo.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { buf.add("\t- locked " + mi); } } } LockInfo[] locks = threadInfo.getLockedSynchronizers(); if (locks.length > 0) { buf.add("\n\tNumber of locked synchronizers = " + locks.length); for (LockInfo li : locks) { buf.add("\t- " + li); } } return buf.toArray((String[]) Array.newInstance(String.class, buf.size())); }
From source file:Main.java
public static int subAndCheck(int x, int y) { long s = (long) x - (long) y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new ArithmeticException("overflow: subtract"); }//from ww w. j a va 2 s . co m return (int) s; }
From source file:Main.java
/** * Returns the concatenation of the input arrays in a single array. For example, * {@code concat(new byte[] {a, b}, new byte[] {}, new byte[] {c}} returns the array * {@code {a, b, c}}./*from w w w . j av a 2 s . c o m*/ * * @return a single array containing all the values from the source arrays, in order */ public static byte[] concat(byte[]... chunks) throws GeneralSecurityException { int length = 0; for (byte[] chunk : chunks) { if (length > Integer.MAX_VALUE - chunk.length) { throw new GeneralSecurityException("exceeded size limit"); } length += chunk.length; } byte[] res = new byte[length]; int pos = 0; for (byte[] chunk : chunks) { System.arraycopy(chunk, 0, res, pos, chunk.length); pos += chunk.length; } return res; }
From source file:Main.java
/** * Check whether my service is running.// w w w . jav a 2 s . co m * @param context application's context * @param serviceClass class of the service to look for * @return true if the service is running, false otherwise */ public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) if (serviceClass.getName().equals(service.service.getClassName())) return true; return false; }