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:com.github.stephanarts.cas.ticket.registry.provider.GetTicketsMethodTest.java

@Test
public void testValidInput() throws Exception {
    final HashMap<Integer, Ticket> map = new HashMap<Integer, Ticket>();
    final JSONObject params = new JSONObject();
    final IMethod method = new GetTicketsMethod(map);
    final JSONObject result;

    final String ticketId = "ST-1234567890ABCDEFGHIJKL-crud";
    final ServiceTicket ticket = mock(ServiceTicket.class, withSettings().serializable());
    when(ticket.getId()).thenReturn(ticketId);

    map.put(ticketId.hashCode(), ticket);

    try {/*from  w  w w.ja v  a  2  s.co m*/
        result = method.execute(params);
    } catch (final JSONRPCException e) {
        Assert.fail(e.getMessage());
    } catch (final Exception e) {
        throw new Exception(e);
    }
}

From source file:com.opengamma.component.factory.master.RemoteMastersComponentFactory.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case -332625701: // baseUri
        setBaseUri((URI) newValue);
        return;//from w w w. ja  va  2 s  .c  o  m
    case -614707837: // publishRest
        setPublishRest((Boolean) newValue);
        return;
    case -1495762275: // jmsConnector
        setJmsConnector((JmsConnector) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}

From source file:de.schildbach.wallet.data.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();

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) {
        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates();

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

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null)
        return null;

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

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final org.bitcoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:de.tudarmstadt.lt.lm.service.UimaStringProvider.java

@Override
public List<String>[] getNgrams(String text, String language_code) throws Exception {
    String docid = "#" + Integer.toHexString(text.hashCode());
    LOG.debug("[{}] Processing text '{}' (length {}).", docid, StringUtils.abbreviate(text, 30), text.length());
    return getNgramsInner(text.trim(), language_code, docid, 0, 0);
}

From source file:edu.ucsb.eucalyptus.transport.query.WalrusQuerySecurityHandler.java

private String getStringStats(String s) {
    int len = s.length();
    String out = "length=" + len + " buf[n-1]=" + s.getBytes()[len - 1] + " hash=" + s.hashCode();
    return out;/*from w ww  .  j  a  v a2 s.  c om*/
}

From source file:cn.mdict.services.DownloadService.java

public void downloadFile(final String url, final String title, final String targetFile,
        Class<?> activityClass) {
    if (downloading.containsKey(url))
        return;// w w  w  .  j ava2s  . c o m
    final PendingIntent contentIntent = PendingIntent.getActivity(context, url.hashCode(),
            new Intent(context, activityClass), 0);
    final DownloadTask downloadTask = new DownloadTask();
    downloading.put(url, downloadTask);
    executorService.execute(new Runnable() {
        @Override
        public void run() {
            downloadTask.download(context, contentIntent, title, url, targetFile);
            //TODO Need more works to notify caller that the job is done.
            //MiscUtils.installApk(context, targetFile);
        }
    });
}

From source file:com.npower.dm.bootstrap.BootstrapServiceXmlImpl.java

public long bootstrap(String msisdn, String serverPassword, String serverNonce, String clientUsername,
        String clientPassword, String clientNonce, OMACPSecurityMethod pinType, String pin, long scheduleTime,
        int maxRetry, long maxDuration) throws DMException, SmsException {
    try {/* ww  w.  j  a  va2 s  . c om*/
        ClientProvTemplate template = findOTATemplate(null, null);

        // Prepare profile for OTA Template.
        Properties profile = prepareProfile(serverPassword, serverNonce, clientUsername, clientPassword,
                clientNonce);

        // Build template parameters
        OMAClientProvSettings settings = new OMAClientProvSettings();
        // Build NAP or Proxy
        String napDefNapID = this.getProperty(profile, "napdef_napid");
        if (StringUtils.isNotEmpty(napDefNapID)) {
            // NAP
            NAPDefElement nap = this.createNAPDef(profile);
            settings.addNAPDefElement(nap);
        }
        String pxLogicID = this.getProperty(profile, "pxlogic_id");
        if (StringUtils.isNotEmpty(pxLogicID)) {
            // NAP with Proxy
            PXLogicalElement proxy = this.createProxyDef(profile, napDefNapID);
            settings.addPXLogicalElement(proxy);
        }

        // Build and add DM document.
        ApplicationElement app = buildDMApplication(profile, napDefNapID, pxLogicID, msisdn);
        settings.addApplicationElement(app);

        // Merge Profile template with profile.
        ProvisioningDoc doc = template.merge(settings);
        OMAClientProvDoc provDoc = new OMAClientProvDoc(doc.getContent());
        if (pinType == null) {
            pinType = OMACPSecurityMethod.USERPIN;
        }
        provDoc.setSecurityMethod(pinType);
        provDoc.setPIN(pin);

        log.info("Bootstrap, device msisdn: " + msisdn + ", Content: " + doc.getContent());
        String msgID = this.getSmsSender().send(provDoc.getSmsWapPushMessage(), msisdn, msisdn, scheduleTime,
                maxRetry, maxDuration);
        return msgID.hashCode();
    } catch (OTAException e) {
        throw new DMException("Error in find OTA Template.", e);
    } catch (SmsException e) {
        throw e;
    } catch (IOException e) {
        throw new DMException("Error in Send SMS for bootstrap.", e);
    } catch (Exception e) {
        throw new DMException("Error in Send SMS for bootstrap.", e);
    }
}

From source file:com.github.stephanarts.cas.ticket.registry.provider.AddMethodTest.java

@Test
public void testDuplicateTicket() throws Exception {
    final byte[] serializedTicket;
    final HashMap<Integer, Ticket> map = new HashMap<Integer, Ticket>();
    final JSONObject params = new JSONObject();
    final IMethod method = new AddMethod(map);

    final String ticketId = "ST-1234567890ABCDEFGHIJKL-crud";
    final ServiceTicket ticket = mock(ServiceTicket.class, withSettings().serializable());
    when(ticket.getId()).thenReturn(ticketId);

    map.put(ticketId.hashCode(), ticket);

    try {//from   w  w  w  .j  a v  a  2  s .  c  o m
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream so = new ObjectOutputStream(bo);
        so.writeObject(ticket);
        so.flush();
        serializedTicket = bo.toByteArray();

        params.put("ticket-id", ticketId);
        params.put("ticket", DatatypeConverter.printBase64Binary(serializedTicket));
        method.execute(params);

    } catch (final JSONRPCException e) {
        Assert.assertEquals(-32502, e.getCode());
        Assert.assertTrue(e.getMessage().equals("Duplicate Ticket"));
        return;
    } catch (final Exception e) {
        throw new Exception(e);
    }

    Assert.fail("No Exception Thrown");
}

From source file:com.example.app.resource.model.ResourceTypeUserType.java

@Override
public int hashCode(Object x) throws HibernateException {
    if (x == null)
        return 0;
    ResourceType resourceType = (ResourceType) x;
    String factory = _resourceTypeService.getFactoryIdentifier(
            new ResourceTypeService.Context(_siteContext.getOperationalSite()), resourceType);
    if (factory == null)
        throw new HibernateException("Invalid ResourceType: " + x);
    int res = factory.hashCode();
    res = res * 37 + resourceType.getIdentifier().hashCode();
    return res;/*from   w w  w .j  a va2 s . c o  m*/
}

From source file:com.npower.dm.bootstrap.BootstrapServiceXmlImpl.java

public long bootstrap(String deviceExternalID, OMACPSecurityMethod pinType, String pin, long scheduleTime,
        int maxRetry, long maxDuration) throws DMException, SmsException {
    DeviceBean deviceBean = this.getBeanFactory().createDeviceBean();
    Device device = deviceBean.getDeviceByExternalID(deviceExternalID);
    if (device == null) {
        throw new DMException("Bootstrap device not not found, externalID: " + deviceExternalID);
    }/* ww w  .j a v  a 2 s  . c o  m*/
    String msisdn = AbstractBootstrapService.caculatePhoneNumber(device);

    try {
        ClientProvTemplate template = findOTATemplate(device);

        // Prepare profile for OTA Template.
        Properties profile = prepareProfile(device);

        // Build template parameters
        OMAClientProvSettings settings = new OMAClientProvSettings();
        // Build NAP or Proxy
        String napDefNapID = this.getProperty(profile, "napdef_napid");
        if (StringUtils.isNotEmpty(napDefNapID)) {
            // NAP
            NAPDefElement nap = this.createNAPDef(profile);
            settings.addNAPDefElement(nap);
        }
        String pxLogicID = this.getProperty(profile, "pxlogic_id");
        if (StringUtils.isNotEmpty(pxLogicID)) {
            // NAP with Proxy
            PXLogicalElement proxy = this.createProxyDef(profile, napDefNapID);
            settings.addPXLogicalElement(proxy);
        }

        // Build and add DM document.
        ApplicationElement app = buildDMApplication(profile, napDefNapID, pxLogicID, msisdn);
        settings.addApplicationElement(app);

        // Merge Profile template with profile.
        ProvisioningDoc doc = template.merge(settings);
        OMAClientProvDoc provDoc = new OMAClientProvDoc(doc.getContent());
        if (pinType == null) {
            pinType = OMACPSecurityMethod.USERPIN;
        }
        provDoc.setSecurityMethod(pinType);
        provDoc.setPIN(pin);

        log.info("Bootstrap, device msisdn: " + msisdn + ", Content: " + doc.getContent());
        String msgID = this.getSmsSender().send(provDoc.getSmsWapPushMessage(), msisdn, msisdn, scheduleTime,
                maxRetry, maxDuration);
        return msgID.hashCode();
    } catch (OTAException e) {
        throw new DMException("Error in find OTA Template.", e);
    } catch (SmsException e) {
        throw e;
    } catch (IOException e) {
        throw new DMException("Error in Send SMS for bootstrap.", e);
    } catch (Exception e) {
        throw new DMException("Error in Send SMS for bootstrap.", e);
    }

}