List of usage examples for java.lang String hashCode
public int hashCode()
From source file:com.dtolabs.rundeck.core.execution.commands.ScriptURLCommandInterpreter.java
private static String hashURL(final String url) { try {/*from w ww . j a v a 2 s . co m*/ MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.reset(); digest.update(url.getBytes(Charset.forName("UTF-8"))); return new String(Hex.encodeHex(digest.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return Integer.toString(url.hashCode()); }
From source file:edu.umd.cs.submit.CommandLineSubmit.java
public static String[] getSubmitUserForOpenId(String courseKey, String projectNumber, String baseURL) throws UnsupportedEncodingException, URISyntaxException, IOException { Console console = System.console(); boolean requested = false; String encodedProjectNumber = URLEncoder.encode(projectNumber, "UTF-8"); URI u = new URI(baseURL + "/view/submitStatus.jsp?courseKey=" + courseKey + "&projectNumber=" + encodedProjectNumber);/* w w w. j av a 2s. co m*/ if (java.awt.Desktop.isDesktopSupported()) { Desktop desktop = java.awt.Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { System.out.println( "Your browser will connect to the submit server, which may require you to authenticate yourself"); System.out.println("Please do so, and then you will be shown a page with a textfield on it"); System.out.println("Then copy that text and paste it into the prompt here"); desktop.browse(u); requested = true; } } if (!requested) { System.out.println("Please enter the following URL into your browser"); System.out.println(" " + u); System.out.println(); System.out.println( "Your browser will connect to the submit server, which may require you to authenticate yourself"); System.out.println("Please do so, and then you will be shown a page with a textfield on it"); System.out.println("Then copy that text and paste it into the prompt here"); } while (true) { System.out.println(); System.out.println("Submission verification information from browser? "); String info = new String(console.readLine()); if (info.length() > 2) { int checksum = Integer.parseInt(info.substring(info.length() - 1), 16); info = info.substring(0, info.length() - 1); int hash = info.hashCode() & 0x0f; if (checksum == hash) { String fields[] = info.split(";"); if (fields.length == 2) { return fields; } } } System.out.println("That doesn't seem right"); System.out.println( "The information should be your account name and a string of hexidecimal digits, separated by a semicolon"); System.out.println("Please try again"); System.out.println(); } }
From source file:Main.java
public static String getPsuedoUniqueID() { String devIDShort = "35" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { devIDShort += (Build.SUPPORTED_ABIS[0].length() % 10); } else {/* ww w. j av a 2s . c o m*/ devIDShort += (Build.CPU_ABI.length() % 10); } devIDShort += (Build.DEVICE.length() % 10) + (Build.MANUFACTURER.length() % 10) + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10); String serial; try { serial = Build.class.getField("SERIAL").get(null).toString(); return new UUID(devIDShort.hashCode(), serial.hashCode()).toString(); } catch (Exception e) { serial = "ESYDV000"; } return new UUID(devIDShort.hashCode(), serial.hashCode()).toString(); }
From source file:com.asakusafw.runtime.windows.WinUtilsInstaller.java
private static String getUserHash() { String base = System.getProperty("user.name", UUID.randomUUID().toString()); //$NON-NLS-1$ StringBuilder buf = new StringBuilder(); for (char c : base.toCharArray()) { if ('0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_' || c == '-') { buf.append(c);//from w ww .j a v a 2 s.com } } if (buf.length() < 4) { buf.append('-'); buf.append(Integer.toHexString(base.hashCode())); } return buf.toString(); }
From source file:com.android.volley.Request.java
/** * @return The hashcode of the URL's host component, or 0 if there is none. *///from w w w . ja va 2 s.co m private static int findDefaultTrafficStatsTag(String url) { if (!TextUtils.isEmpty(url)) { Uri uri = Uri.parse(url); if (uri != null) { String host = uri.getHost(); if (host != null) { return host.hashCode(); } } } return 0; }
From source file:com.google.visualization.datasource.render.JsonRenderer.java
/** * Returns a String-form 32-bit hash of this table's json. * Note: the signature ignores formatting. * * @param data The data table.//from www. j a va 2s. c o m * * @return a String-form 64-bit hash of this table. */ public static String getSignature(DataTable data) { String tableAsString = renderDataTable(data, true, false, true).toString(); // Casting to long to avoid bug with abs(Integer.MIN_VALUE) being negative. long longHashCode = tableAsString.hashCode(); return String.valueOf(Math.abs(longHashCode)); }
From source file:de.ingrid.portal.global.UtilsFileHelper.java
/** * Create mapfile and GML file for temporary map services * // w ww.j av a 2s . c om * @param fileTitle * @return path of mapfile * @throws Exception * @throws ConfigurationException */ public static String createNewService(String fileTitle, String typ, String path) throws ConfigurationException, Exception { File directory; File file; directory = new File(path); directory.mkdirs(); file = new File( directory.getAbsolutePath() + "/" + generateFilename(Integer.toString(fileTitle.hashCode()), typ)); if (file.exists()) { if (log.isDebugEnabled()) { log.debug("File: " + file.getName() + " already exist!"); } } else { file.createNewFile(); if (log.isDebugEnabled()) { log.debug("Create " + typ + " File: " + file.getAbsolutePath()); } } return file.getName(); }
From source file:Main.java
private static String getDeviceId(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = null;/*from ww w .j av a 2 s . co m*/ String tmSerial = null; String androidId = null; try { tmDevice = tm.getDeviceId(); } catch (Exception e) { Log.w(LOG_TAG, e); } try { tmSerial = tm.getSimSerialNumber(); } catch (Exception e) { Log.w(LOG_TAG, e); } androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (tmDevice == null) { tmDevice = ""; } if (tmSerial == null) { tmSerial = ""; } if (androidId == null) { androidId = ""; } UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); return "lsa-kp" + deviceUuid.toString(); }
From source file:com.facebook.notifications.NotificationsManager.java
/** * Present a {@link Notification} to be presented from a GCM push bundle. * <p/>//from w w w . j a va 2 s . c o m * This does not present a notification immediately, instead it caches the assets from the * notification bundle, and then presents a notification to the user. This allows for a smoother * interaction without loading indicators for the user. * <p/> * Note that only one notification can be created for a specific push bundle, should you attempt * to present a new notification with the same payload bundle as an existing notification, it will * replace and update the old notification. * * @param context The context to send the notification from * @param notificationBundle The content of the push notification * @param launcherIntent The launcher intent that contains your Application's activity. * This will be modified with the FLAG_ACTIVITY_CLEAR_TOP and * FLAG_ACTIVITY_SINGLE_TOP flags, in order to properly show the * notification in an already running application. * <p/> * Should you not want this behavior, you may use the notificationExtender * parameter to customize the contentIntent of the notification before * presenting it. * @param notificationExtender A nullable argument that allows you to customize the notification * before displaying it. Use this to configure Icons, text, sounds, * etc. before we pass the notification off to the OS. */ public static boolean presentNotification(@NonNull final Context context, @NonNull final Bundle notificationBundle, @NonNull final Intent launcherIntent, @Nullable final NotificationExtender notificationExtender) { final JSONObject alert; final int payloadHash; try { String payload = notificationBundle.getString(CARD_PAYLOAD_KEY); if (payload == null) { return false; } payloadHash = payload.hashCode(); JSONObject payloadObject = new JSONObject(payload); alert = payloadObject.optJSONObject("alert") != null ? payloadObject.optJSONObject("alert") : new JSONObject(); } catch (JSONException ex) { Log.e(LOG_TAG, "Error while parsing notification bundle JSON", ex); return false; } final boolean[] success = new boolean[1]; final Thread backgroundThread = new Thread(new Runnable() { @Override public void run() { Looper.prepare(); prepareCard(context, notificationBundle, new PrepareCallback() { @Override public void onPrepared(@NonNull Intent presentationIntent) { Intent contentIntent = new Intent(launcherIntent); contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); contentIntent.putExtra(EXTRA_PAYLOAD_INTENT, presentationIntent); NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setContentTitle(alert.optString("title")).setContentText(alert.optString("body")) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context.getApplicationContext(), payloadHash, contentIntent, PendingIntent.FLAG_ONE_SHOT)); if (notificationExtender != null) { builder = notificationExtender.extendNotification(builder); } manager.notify(NOTIFICATION_TAG, payloadHash, builder.getNotification()); success[0] = true; Looper.myLooper().quit(); } @Override public void onError(@NonNull Exception exception) { Log.e(LOG_TAG, "Error while preparing card", exception); Looper.myLooper().quit(); } }); Looper.loop(); } }); backgroundThread.start(); try { backgroundThread.join(); } catch (InterruptedException ex) { Log.e(LOG_TAG, "Failed to wait for background thread", ex); return false; } return success[0]; }
From source file:org.apache.falcon.regression.core.util.Util.java
/** * Get prefix for test entities./*from ww w. j a v a 2 s.c o m*/ * @param testClass object of test class * @return test class name if is_deprecate=false or 'A' and hash if is_deprecate=true */ public static String getEntityPrefix(Object testClass) { String className = testClass.getClass().getSimpleName(); if (MerlinConstants.IS_DEPRECATE) { return 'A' + Integer.toHexString(className.hashCode()); } else { return className; } }