Example usage for java.lang String hashCode

List of usage examples for java.lang String hashCode

Introduction

In this page you can find the example usage for java.lang String hashCode.

Prototype

public int hashCode() 

Source Link

Document

Returns a hash code for this string.

Usage

From source file:cm.aptoide.pt.data.webservices.ManagerDownloads.java

public ViewCache downloadMyapp(String uriString, String myappName) {
    ViewCache cache = managerCache.getNewMyappDownloadViewCache(myappName);
    if (!managerCache.isMyAppCached(myappName)) {
        ViewNotification notification = serviceData.getManagerNotifications()
                .getNewViewNotification(EnumNotificationTypes.GET_MYAPP, "myapp", myappName.hashCode());
        ViewDownload download = getNewViewDownload(uriString, cache, notification);

        try {// w  w w. j  a va 2s .c om
            download(download, false);
        } catch (Exception e) {
            download(download, false);
        }

    }
    return cache;
}

From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java

public List<String> backupLocalFiles(String outputPath) {
    List<String> files = new ArrayList<>();

    Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
        try {//from w  w w. ja va  2s  . co m
            f.setAccessible(true);
            String fPath = (String) f.get(n);
            if (fPath == null) {
                try {
                    fPath = (String) n.getClass().getMethod("get" + StringUtils.capitalize(f.getName()))
                            .invoke(n);
                } catch (NoSuchMethodException | InvocationTargetException ignored) {
                }
            }

            if (fPath == null) {
                return null;
            }

            File fFile = new File(fPath);
            String fName = fFile.getName();

            // Hash the path to uniquely flatten all files into the output directory
            Path newName = Paths.get(outputPath, Math.abs(fPath.hashCode()) + "-" + fName);
            File parent = newName.toFile().getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            } else if (fFile.getParent().equals(parent.toString())) {
                // Don't move paths that are already in the right folder
                return fPath;
            }
            Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);

            f.set(n, newName.toString());
            return newName.toString();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
        } catch (IOException e) {
            throw new HalException(FATAL, "Failed to backup user file: " + e.getMessage(), e);
        } finally {
            f.setAccessible(false);
        }
    }).filter(Objects::nonNull).collect(Collectors.toList()));
    recursiveConsume(fileFinder);

    return files;
}

From source file:com.tcity.android.sync.SyncService.java

private void notify(@NotNull String buildConfigurationId, @NotNull String parentProjectId, int size) {
    Notification.Builder builder = new Notification.Builder(this);

    String title = size + " new build" + (size == 1 ? "" : "s");
    String projectName = myDB.getProjectName(parentProjectId);
    String buildConfigurationName = myDB.getBuildConfigurationName(buildConfigurationId);

    Intent activityIntent = new Intent(this, BuildConfigurationOverviewActivity.class);
    activityIntent.putExtra(BuildConfigurationOverviewActivity.ID_INTENT_KEY, buildConfigurationId);
    activityIntent.setAction(Long.toString(System.currentTimeMillis()));

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);

    //noinspection deprecation
    Notification notification = builder.setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
            .setContentText(projectName + " - " + buildConfigurationName).setContentIntent(contentIntent)
            .setAutoCancel(true).getNotification();

    myManager.notify(buildConfigurationId.hashCode(), notification);
}

From source file:com.cognitect.transit.TransitTest.java

public void testKeywordHashCode() {

    String s = "foo";
    Keyword k1 = TransitFactory.keyword("foo");
    Keyword k2 = TransitFactory.keyword("!foo".substring(1));
    Keyword k3 = TransitFactory.keyword("bar");
    Symbol symbol = TransitFactory.symbol("bar");

    assertEquals(k1.hashCode(), k2.hashCode());
    assertFalse(k3.hashCode() == k1.hashCode());
    assertFalse(symbol.hashCode() == k1.hashCode());
    assertFalse(s.hashCode() == k1.hashCode());
}

From source file:com.xpn.xwiki.plugin.activitystream.impl.ActivityStreamImpl.java

/**
 * Generate event ID for the given ID. Note that this method does not perform the set of the ID in the event object.
 * //ww w.  ja v  a 2  s . c o  m
 * @param event event to generate the ID for
 * @param context the XWiki context
 * @return the generated ID
 */
private String generateEventId(ActivityEvent event, XWikiContext context) {
    String keySeparator = EVENT_ID_ELEMENTS_SEPARATOR;
    String wikiSpaceSeparator = ":";

    String key = event.getStream() + keySeparator + event.getApplication() + keySeparator + event.getWiki()
            + wikiSpaceSeparator + event.getPage() + keySeparator + event.getType();
    long hash = key.hashCode();
    if (hash < 0) {
        hash = -hash;
    }

    String id = "" + hash + keySeparator + event.getDate().getTime() + keySeparator
            + RandomStringUtils.randomAlphanumeric(8);
    if (context.get(REQUEST_ID_CONTEXT_KEY) == null) {
        context.put(REQUEST_ID_CONTEXT_KEY, id);
    }

    return id;
}

From source file:io.atomix.cluster.messaging.impl.NettyMessagingService.java

private int getChannelOffset(String messageType) {
    return Math.abs(messageType.hashCode() % CHANNEL_POOL_SIZE);
}

From source file:com.torrenttunes.android.model.MusicProvider.java

private MediaMetadataCompat buildFromJSON(JSONObject json, String basePath) throws JSONException {
    LogHelper.i(TAG, json);/*ww  w.  jav  a 2  s  . c  om*/
    String title = json.getString(JSON_TITLE);
    String album = json.getString(JSON_ALBUM);
    String artist = json.getString(JSON_ARTIST);
    String genre = json.getString(JSON_GENRE);
    String source = json.getString(JSON_SOURCE);
    String iconUrl = json.getString(JSON_IMAGE);
    int trackNumber = json.getInt(JSON_TRACK_NUMBER);
    long totalTrackCount = json.getLong(JSON_TOTAL_TRACK_COUNT);
    int duration = json.getInt(JSON_DURATION) * 1000; // ms

    LogHelper.d(TAG, "Found music track: ", json);

    // Media is stored relative to JSON file
    if (!source.startsWith("http")) {
        source = basePath + source;
    }
    if (!iconUrl.startsWith("http")) {
        iconUrl = basePath + iconUrl;
    }
    // Since we don't have a unique ID in the server, we fake one using the hashcode of
    // the music source. In a real world app, this could come from the server.
    String id = String.valueOf(source.hashCode());

    // Adding the music source to the MediaMetadataCompat (and consequently using it in the
    // mediaSession.setMetadata) is not a good idea for a real world music app, because
    // the session metadata can be accessed by notification listeners. This is done in this
    // sample for convenience only.
    return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id)
            //                .putString(CUSTOM_METADATA_TRACK_SOURCE, source)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album)
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration)
            .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl)
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
            .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber)
            // Note: With MediaMetadataCompat we seem to crash when setting the total track count.
            // .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount * 1L)

            .build();
}

From source file:com.cognitect.transit.TransitTest.java

public void testSymbolHashCode() {

    String s = "foo";
    Symbol sym1 = TransitFactory.symbol("foo");
    Symbol sym2 = TransitFactory.symbol("!foo".substring(1));
    Symbol sym3 = TransitFactory.symbol("bar");
    Keyword symbol = TransitFactory.keyword("bar");

    assertEquals(sym1.hashCode(), sym2.hashCode());
    assertFalse(sym3.hashCode() == sym1.hashCode());
    assertFalse(symbol.hashCode() == sym1.hashCode());
    assertFalse(s.hashCode() == sym1.hashCode());
}

From source file:fuse.okuyamafs.OkuyamaFilesystem.java

public int rename(String from, String to) throws FuseException {
    log.info("rename " + from + " " + to);
    String[] pathInfo = null;//from  w  w  w.  ja  v  a2s.co  m
    StringBuilder newPathInfo = new StringBuilder();
    try {

        synchronized (this.parallelDataAccessSync[((from.hashCode() << 1) >>> 1) % 100]) {

            // ???????????flush?
            List bufferedDataFhList = writeBufFpMap.removeGroupingData(from);
            if (bufferedDataFhList != null) {
                for (int idx = 0; idx < bufferedDataFhList.size(); idx++) {
                    Object bFh = bufferedDataFhList.get(idx);
                    this.fixNoCommitData(bFh);
                }
            }

            String pathInfoStr = client.getPathDetail(from.trim());
            if (pathInfoStr == null || pathInfoStr.trim().equals(""))
                return Errno.ENOENT;

            pathInfo = pathInfoStr.split("\t");

            if (!client.addPathDetail(to.trim(), pathInfoStr)) {
                return Errno.EEXIST;
            }
            if (!client.setDirAttribute(to.trim(), pathInfo[0])) {
                return Errno.EEXIST;
            }

            if (client.removePathDetail(from.trim()) == false)
                return Errno.EIO;
            if (client.removeAttribute(from.trim()) == false)
                return Errno.EIO;
        }
    } catch (FuseException fe) {
        throw fe;
    } catch (Exception e) {
        new FuseException(e).initErrno(FuseException.EACCES);
    }
    return 0;
}