/** * Judge if the ArrayList<String> contains the String variable * * @param s * @param arrayList * @return If only a String in ArrayList equals the variable return true */ public static boolean ifStringExactlyInList(String s, ArrayList<String> arrayList) { if (BasicUtils.judgeNotNull(s) && BasicUtils.judgeNotNull(arrayList)) { for (String str : arrayList) { if (str.equals(s)) return true; } } return false; }
public static void iterateListHashMap(List list) { //support concurrent try { for (Iterator it = list.iterator(); it.hasNext(); ) { iterateHashMapConcurrent((HashMap) it.next()); } } catch (Exception e) { e.printStackTrace(); Logs.e(e.getMessage()); } }
/** * Judge if the ArrayList<String> contains the String variable * This method judges trim String. * * @param s * @param arrayList * @return If a String in ArrayList contains the variable return true */ public static boolean ifStringInList(String s, ArrayList<String> arrayList) { if (BasicUtils.judgeNotNull(s) && BasicUtils.judgeNotNull(arrayList)) { for (String str : arrayList) { if (str.trim().contains(s)) return true; } } return false; }
/** * Indicates if the file represents a directory exists. * * @param directoryPath * @return */ public static boolean isFolderExist(String directoryPath) { if (!BasicUtils.judgeNotNull(directoryPath)) { return false; } File dire = new File(directoryPath); return (dire.exists() && dire.isDirectory()); }
/** * Indicates if the file represents a file exists. * * @param filePath * @return */ public static boolean isFileExist(String filePath) { if (!BasicUtils.judgeNotNull(filePath)) { return false; } File file = new File(filePath); return (file.exists() && file.isFile()); }
/** * Initialize * * @param context * @param crashFilePath */ public void init(Context context, String crashFilePath, String showMessage) { mContext = context; mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); // this.systemServiceObject = systemServiceObject; this.crashFilePath = crashFilePath; if (BasicUtils.judgeNotNull(showMessage)) { this.showMessage = showMessage; } }
/** * Get size of the file * * @param path * @return Return the length of the file in bytes. Return -1 if the file does not exist. */ public static long getFileSize(String path) { if (!BasicUtils.judgeNotNull(path)) { return -1; } File file = new File(path); return (file.exists() && file.isFile() ? file.length() : -1); }
/** * @param list * @param lists * @return * @see #judgeNotNull(java.util.List) */ public static boolean judgeNotNull(List list, List... lists) { boolean flag = true; if (list == null || list.size() == 0) return false; if (judgeNotNull(lists)) for (List l : lists) { if (l == null || l.size() == 0) { flag = false; return false; } } return flag; }
/** * Get extension of the file * * @param filePath * @return */ public static String getFileExtension(String filePath) { if (!BasicUtils.judgeNotNull(filePath)) { return ""; } int extenPosi = filePath.lastIndexOf("."); int filePosi = filePath.lastIndexOf(File.separator); if (extenPosi == -1) { return ""; } return (filePosi >= extenPosi) ? "" : filePath.substring(extenPosi + 1); }
public void loadRepositoryInfo(Subscriber<RepositoryList> subscriber, String query, String language, String sort, String order) { githubApiServiceInterface.getRepositoryBySearch(BasicUtils.judgeNotNull(language) ? query + URLDecoder.decode("+") + "language:" + language : query, sort, order) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(subscriber); }
/** * Get file which from assets * * @param context * @param fileName The name of the asset to open. * @return */ public static String getFileFromAssets(Context context, String fileName) { if (context == null || BasicUtils.judgeNotNull(fileName)) { return null; } StringBuilder s = new StringBuilder(""); try { InputStreamReader in = new InputStreamReader(context.getResources().getAssets().open(fileName)); BufferedReader br = new BufferedReader(in); String line; while ((line = br.readLine()) != null) { s.append(line); } return s.toString(); } catch (IOException e) { e.printStackTrace(); return null; } }
/** * whether the app whost package's name is packageName is on the top of the stack * <ul> * Attentions: * <li>You should add android.permission.GET_TASKS in manifest</li> * </ul> * * @param context * @param packageName * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of * stack */ public static Boolean isTopActivity(Context context, String packageName) { if (context == null || !BasicUtils.judgeNotNull(packageName)) { return null; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (!BasicUtils.judgeNotNull(tasksInfo)) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
if (BasicUtils.judgeNotNull(content)) { return false;
(BasicUtils.judgeNotNull(crashFilePath) ? crashFilePath : "/crash/"); Logs.d("path----" + path); File dir = new File(path);