List of usage examples for java.lang CharSequence toString
public String toString();
From source file:Main.java
/** * Get the longest NCName that is a suffix of a character sequence. * /*from w w w .ja va 2s. c o m*/ * @param s * The character sequence. * @return The String which is the longest suffix of the character sequence * {@code s} that is an NCName, or {@code null} if the character * sequence {@code s} does not have a suffix that is an NCName. */ @Nullable public static String getNCNameSuffix(CharSequence s) { if (s.length() > 1 && s.charAt(0) == '_' && s.charAt(1) == ':') { return null; } int localPartStartIndex = getNCNameSuffixIndex(s); if (localPartStartIndex > -1) { return s.toString().substring(localPartStartIndex); } else { return null; } }
From source file:Main.java
private static CharSequence extract(StringBuilder data, boolean isSpanned) { CharSequence len = cut(data, 0, NUM_LEN); int l = intFromHexString(len); CharSequence ret = null; switch (l) {//from w w w . jav a2s. c o m case FLAG_NULL: ret = null; break; case FLAG_SPANNED: ret = extract(data, true); break; default: ret = cut(data, 0, l); if (isSpanned) { ret = Html.fromHtml(ret.toString()); } } return ret; }
From source file:dk.netarkivet.harvester.harvesting.extractor.ExtractorJS.java
public static long considerStrings(CrawlURI curi, CharSequence cs, CrawlController controller, boolean handlingJSFile) { long foundLinks = 0; Matcher strings = TextUtils.getMatcher(JAVASCRIPT_STRING_EXTRACTOR, cs); while (strings.find()) { CharSequence subsequence = cs.subSequence(strings.start(2), strings.end(2)); if (UriUtils.isLikelyUriJavascriptContextLegacy(subsequence)) { String string = subsequence.toString(); string = StringEscapeUtils.unescapeJavaScript(string); string = UriUtils.speculativeFixup(string, curi.getUURI()); foundLinks++;/* w ww . j a v a2 s . c om*/ try { if (handlingJSFile) { curi.createAndAddLinkRelativeToVia(string, Link.JS_MISC, Link.SPECULATIVE_HOP); } else { curi.createAndAddLinkRelativeToBase(string, Link.JS_MISC, Link.SPECULATIVE_HOP); } } catch (URIException e) { // There may not be a controller (e.g. If we're being run // by the extractor tool). if (controller != null) { controller.logUriError(e, curi.getUURI(), string); } else { LOGGER.info(curi + ", " + string + ": " + e.getMessage()); } } } else { foundLinks += considerStrings(curi, subsequence, controller, handlingJSFile); } } TextUtils.recycleMatcher(strings); return foundLinks; }
From source file:hrytsenko.csv.IO.java
static Path getPath(Map<String, ?> args) { CharSequence path = (CharSequence) args.get("path"); if (path == null) { throw new IllegalArgumentException("Path not defined."); }//from www.ja v a 2 s . c o m return Paths.get(path.toString()); }
From source file:com.amazonaws.mobileconnectors.util.ClientContext.java
/** * Gets the client info, including installation_id_id, app_title, * app_version_name, app_version_code, and app_package_name. * * @param context context of the app//from ww w . j a v a2s .c o m * @return an JSONObject that has the client info * @throws JSONException */ static JSONObject getClientInfo(Context context) throws JSONException { final JSONObject client = new JSONObject(); final PackageManager packageManager = context.getPackageManager(); try { final PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); final ApplicationInfo applicationInfo = context.getApplicationInfo(); client.put("installation_id", getInstallationId(context)) .put("app_version_name", packageInfo.versionName) .put("app_version_code", String.valueOf(packageInfo.versionCode)) .put("app_package_name", packageInfo.packageName); // If null is returned for some reason, fall back to "Unknown" final CharSequence title = packageManager.getApplicationLabel(applicationInfo); client.put("app_title", title == null ? "Unknown" : title.toString()); } catch (final NameNotFoundException e) { // When device starts, PackageManager will gather package // information by scanning them. It will take a while to finish. // This exception may be thrown when scan doesn't finish. LOGGER.warn("Failed to load package info: " + context.getPackageName(), e); } return client; }
From source file:com.hmsinc.epicenter.classifier.util.ClassifierUtils.java
public static CharSequence filterAllowNumbers(final CharSequence complaint, final Set<String> stopwords) { String ret = ""; if (complaint != null) { // Lowercase, alphabetic only, remove extra spaces.. final String cleaned = StringUtils.trimToNull(complaint.toString().toLowerCase(Locale.getDefault()) .replaceAll("h/a", "headache").replaceAll("n/v", "nausea vomiting").replaceAll("[/,]", " ") .replaceAll("[^a-z\\s\\d]", " ")); if (cleaned != null) { final StringBuilder buf = new StringBuilder(); final String[] sp = cleaned.split("\\s"); for (int i = 0; i < sp.length; i++) { if (sp[i] != null && sp[i].length() > 1 && !stopwords.contains(sp[i])) { if (buf.length() > 0) { buf.append(" "); }/*from www . j a va2s. c o m*/ buf.append(sp[i]); } } if (buf.length() > 0) { ret = buf.toString(); } } } return ret; }
From source file:com.hmsinc.epicenter.classifier.util.ClassifierUtils.java
public static CharSequence filter(final CharSequence complaint, final Set<String> stopwords) { String ret = ""; if (complaint != null) { // Lowercase, alphabetic only, remove extra spaces.. final String cleaned = StringUtils.trimToNull(complaint.toString().toLowerCase(Locale.getDefault()) .replaceAll("h/a", "headache").replaceAll("n/v", "nausea vomiting").replaceAll("[/,]", " ") .replaceAll("[^a-z\\s]", " ")); if (cleaned != null) { final StringBuilder buf = new StringBuilder(); final String[] sp = cleaned.split("\\s"); for (int i = 0; i < sp.length; i++) { if (sp[i] != null && sp[i].length() > 1 && !stopwords.contains(sp[i])) { if (buf.length() > 0) { buf.append(" "); }/* www. j a v a 2 s. c o m*/ buf.append(sp[i]); } } if (buf.length() > 0) { ret = buf.toString(); } } } return ret; }
From source file:eu.faircode.netguard.ServiceJob.java
private static void submit(Rule rule, PersistableBundle bundle, Context context) { PackageManager pm = context.getPackageManager(); JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); // Get english application label String label = null;//from www. j ava 2 s .c o m try { Configuration config = new Configuration(); config.setLocale(new Locale("en")); Resources res = pm.getResourcesForApplication(rule.info.packageName); res.updateConfiguration(config, res.getDisplayMetrics()); label = res.getString(rule.info.applicationInfo.labelRes); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); CharSequence cs = rule.info.applicationInfo.loadLabel(pm); if (cs != null) label = cs.toString(); } // Add application data bundle.putInt("uid", rule.info.applicationInfo.uid); bundle.putString("package", rule.info.packageName); bundle.putInt("version_code", rule.info.versionCode); bundle.putString("version_name", rule.info.versionName); bundle.putString("label", label); bundle.putInt("system", rule.system ? 1 : 0); try { bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName)); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); bundle.putString("installer", null); } // Cancel overlapping jobs for (JobInfo pending : scheduler.getAllPendingJobs()) { String type = pending.getExtras().getString("type"); if (type != null && type.equals(bundle.getString("type"))) { if (type.equals("rule")) { int uid = pending.getExtras().getInt("uid"); if (uid == bundle.getInt("uid")) { Log.i(TAG, "Canceling id=" + pending.getId()); scheduler.cancel(pending.getId()); } } else if (type.equals("host")) { int uid = pending.getExtras().getInt("uid"); int version = pending.getExtras().getInt("version"); int protocol = pending.getExtras().getInt("protocol"); String daddr = pending.getExtras().getString("daddr"); int dport = pending.getExtras().getInt("dport"); if (uid == bundle.getInt("uid") && version == bundle.getInt("version") && protocol == bundle.getInt("protocol") && daddr != null && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) { Log.i(TAG, "Canceling id=" + pending.getId()); scheduler.cancel(pending.getId()); } } } } // Schedule job ComponentName serviceName = new ComponentName(context, ServiceJob.class); JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED) .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle) .setPersisted(true).build(); if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS) Log.i(TAG, "Scheduled job=" + job.getId() + " success"); else Log.e(TAG, "Scheduled job=" + job.getId() + " failed"); }
From source file:Main.java
/** * Green implementation of regionMatches. * * @param cs the {@code CharSequence} to be processed * @param ignoreCase whether or not to be case insensitive * @param thisStart the index to start on the {@code cs} CharSequence * @param substring the {@code CharSequence} to be looked for * @param start the index to start on the {@code substring} CharSequence * @param length character length of the region * @return whether the region matched/* ww w . ja va2s.co m*/ */ static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length) { if (cs instanceof String && substring instanceof String) { return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length); } else { // TODO: Implement rather than convert to String return cs.toString().regionMatches(ignoreCase, thisStart, substring.toString(), start, length); } }
From source file:Main.java
public static void printAllPermission(Context context) { if (!debug) { return;/*ww w .j a va2 s. co m*/ } PackageManager pm = context.getPackageManager(); CharSequence csPermissionGroupLabel; CharSequence csPermissionLabel; List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.GET_PERMISSIONS); for (PermissionGroupInfo pgi : lstGroups) { csPermissionGroupLabel = pgi.loadLabel(pm); Log.d("ldx", "PermissionGroup: " + pgi.name + " [" + csPermissionGroupLabel.toString() + "]"); try { List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0); for (PermissionInfo pi : lstPermissions) { csPermissionLabel = pi.loadLabel(pm); Log.d("ldx", " PermissionChild" + pi.name + " [" + csPermissionLabel.toString() + "]"); } } catch (Exception ex) { ex.printStackTrace(); } } }