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:org.callimachusproject.test.TemporaryServerFactory.java

private File createCallimachus(String origin) throws Exception {
    int code = origin.hashCode() + WEBAPP_CAR.getAbsolutePath().hashCode();
    String name = TemporaryServer.class.getSimpleName() + Integer.toHexString(code);
    File dir = createDirectory(name);
    if (!dir.isDirectory() || WEBAPP_CAR.lastModified() > dir.lastModified()) {
        if (dir.isDirectory()) {
            FileUtil.deleteDir(dir);//from  ww w .jav  a  2  s  .  c o  m
        }
        dir.delete();
        String configStr = readRepositoryConfigFile();
        System.setProperty("org.callimachusproject.config.webapp", WEBAPP_CAR.getAbsolutePath());
        RepositoryConfig config = getRepositoryConfig(configStr);
        LocalRepositoryManager manager = RepositoryProvider.getRepositoryManager(dir);
        Repository repo = getRepository(manager, config);
        if (repo == null)
            throw new RepositoryConfigException("Missing repository configuration");
        File dataDir = manager.getRepositoryDir(config.getID());
        CalliRepository repository = new CalliRepository(repo, dataDir);
        repository.setDatasourceManager(new DatasourceManager(manager, config.getID()));
        CallimachusSetup setup = new CallimachusSetup(repository);
        setup.prepareWebappOrigin(origin);
        setup.createWebappOrigin(origin);
        setup.updateWebapp(origin);
        setup.finalizeWebappOrigin(origin);
        String username = email.substring(0, email.indexOf('@'));
        setup.inviteUser(email, origin);
        setup.addInvitedUserToGroup(email, ADMIN_GROUP, origin);
        setup.registerDigestUser(email, username, password, origin);
        repository.shutDown();
        manager.shutDown();
    }
    File temp = FileUtil.createTempDir(name);
    copyDir(dir, temp);
    return temp;
}

From source file:com.netflix.config.ConcurrentMapConfiguration.java

protected void addPropertyDirect(String key, Object value) {
    ReentrantLock lock = locks[Math.abs(key.hashCode()) % NUM_LOCKS];
    lock.lock();//from w w w  .ja  v a  2  s .c o  m
    try {
        Object previousValue = map.putIfAbsent(key, value);
        if (previousValue == null) {
            return;
        }
        if (previousValue instanceof List) {
            // the value is added to the existing list
            ((List) previousValue).add(value);
        } else {
            // the previous value is replaced by a list containing the previous value and the new value
            List<Object> list = new CopyOnWriteArrayList<Object>();
            list.add(previousValue);
            list.add(value);
            map.put(key, list);
        }
    } finally {
        lock.unlock();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.ImageViewerActivity.java

@Override
public void onResume() {
    super.onResume();
    if (mIntent.hasExtra("image_url")) {
        String url = mIntent.getStringExtra("image_url");
        ((App) getApplication()).objectImages.lazyLoadImage(url.hashCode(), Uri.parse(url), im);
        bitmap = mgr.getBitmap(url.hashCode(), url);
    } else if (mIntent.hasExtra("b64Bytes")) {
        String b64Bytes = mIntent.getStringExtra("b64Bytes");
        ((App) getApplication()).objectImages.lazyLoadImage(b64Bytes.hashCode(), b64Bytes, im);
        bitmap = mgr.getBitmapB64(b64Bytes.hashCode(), b64Bytes);
    } else if (mIntent.hasExtra("bytes")) {
        byte[] bytes = mIntent.getByteArrayExtra("bytes");
        ((App) getApplication()).objectImages.lazyLoadImage(bytes.hashCode(), bytes, im);
        bitmap = mgr.getBitmap(bytes.hashCode(), bytes);
    } else if (mIntent.hasExtra("obj")) {
        try {//from w  w w  .j a v  a 2 s .com
            final JSONObject content = new JSONObject(mIntent.getStringExtra("obj"));
            byte[] bytes = FastBase64.decode(content.optString(PictureObj.DATA));
            ((App) getApplication()).objectImages.lazyLoadImage(bytes.hashCode(), bytes, im);
            bitmap = mgr.getBitmap(bytes.hashCode(), bytes);
        } catch (JSONException e) {
        }
    }

    if (mIntent.hasExtra("objHash")) {
        if (!ContentCorral.CONTENT_CORRAL_ENABLED) {
            return;
        }

        long objHash = mIntent.getLongExtra("objHash", -1);
        final DbObj obj = App.instance().getMusubi().objForHash(objHash);
        final JSONObject json = obj.getJson();
        if (json.has(CorralClient.OBJ_LOCAL_URI)) {
            // TODO: this is a proof-of-concept.
            new Thread() {
                public void run() {
                    try {
                        if (!mCorralClient.fileAvailableLocally(obj)) {
                            //toast("Trying to go HD...");
                        }
                        // Log.d(TAG, "Trying to go HD...");
                        final Uri fileUri = mCorralClient.fetchContent(obj);
                        if (fileUri == null) {
                            try {
                                Log.d(TAG, "Failed to go HD for " + json.getString(CorralClient.OBJ_LOCAL_URI));
                            } catch (JSONException e) {
                                Log.d(TAG, "Failed to go HD for " + json);
                            }
                            return;
                        }
                        // Log.d(TAG, "Opening HD file " + fileUri);

                        InputStream is = getContentResolver().openInputStream(fileUri);
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        options.inSampleSize = 4;

                        Matrix matrix = new Matrix();
                        float rotation = PhotoTaker.rotationForImage(ImageViewerActivity.this, fileUri);
                        if (rotation != 0f) {
                            matrix.preRotate(rotation);
                        }
                        bitmap = BitmapFactory.decodeStream(is, null, options);

                        int width = bitmap.getWidth();
                        int height = bitmap.getHeight();
                        bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                im.setImageBitmap(bitmap);
                            }
                        });
                    } catch (IOException e) {
                        // toast("Failed to go HD");
                        Log.e(TAG, "Failed to get hd content", e);
                        // continue
                    }
                };
            }.start();
        }
    }
}

From source file:com.opengamma.financial.analytics.ircurve.strips.CurveNodeWithIdentifier.java

@Override
protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
    case 771167121: // curveNode
        return getCurveNode();
    case -1618432855: // identifier
        return getIdentifier();
    case -386794640: // dataField
        return getDataField();
    case 1265211220: // fieldType
        return getFieldType();
    }/*from  ww w .j a v  a2s .com*/
    return super.propertyGet(propertyName, quiet);
}

From source file:de.schildbach.wallet.elysium.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = getElysiumCharts();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*from   w  ww  .ja  v a 2  s .c  om*/
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String code = selectionArgs[0];
        final ExchangeRate rate = exchangeRates.get(code);
        try {
            cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        } catch (NullPointerException e) {
            Log.e("Elysium", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:de.schildbach.wallet.marscoin.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();

    if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = getmarscoinCharts();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//  w  ww  .  j a  va 2 s. com
        }
    }

    if (exchangeRates == null)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String code = selectionArgs[0];
        final ExchangeRate rate = exchangeRates.get(code);
        try {
            cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        } catch (NullPointerException e) {
            Log.e("marscoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:com.coinomi.wallet.ExchangeRatesProvider.java

private void addRow(MatrixCursor cursor, ExchangeRate exchangeRate) {
    final ExchangeRateBase rate = exchangeRate.rate;
    final String codeId = exchangeRate.currencyCodeId;
    cursor.newRow().add(codeId.hashCode()).add(codeId).add(rate.value1.value).add(rate.value1.type.getSymbol())
            .add(rate.value2.value).add(rate.value2.type.getSymbol()).add(exchangeRate.source);
}

From source file:gov.nih.nci.evs.browser.utils.CacheController.java

private static String getSubConceptKey(String codingScheme, String version, String code) {
    if (version == null)
        return getSubConceptKey(codingScheme, code);
    return String
            .valueOf("SubConcept".hashCode() + codingScheme.hashCode() + version.hashCode() + code.hashCode());
}

From source file:com.twapime.app.util.AsyncImageLoader.java

/**
 * @param imageUrl/*from   w ww .j  ava 2s.  c o m*/
 * @return
 */
private File getFileFromUrl(String imageUrl) {
    return new File(cacheDir, String.valueOf(imageUrl.hashCode()));
}

From source file:cn.vlabs.duckling.vwb.service.auth.permissions.PagePermission.java

/**
 * Returns the hash code for this PagePermission.
 * @see java.lang.Object#hashCode()/*from  w w  w. j ava2 s. com*/
 */
public final int hashCode() {
    //  If the wiki has not been set, uses a dummy value for the hashcode
    //  calculation.  This may occur if the page given does not refer
    //  to any particular wiki
    String page = m_page != null ? m_page : "dummy_value";
    return m_mask + ((13 * m_actionString.hashCode()) * 23 * page.hashCode());
}