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.strider.datadefender.functions.CoreFunctions.java

/**
 * Creates a string list of values by querying the database.
 * /* w w w  . j a va 2  s  . c  o  m*/
 * @param keyName
 * @param query
 * @return 
 * @throws java.sql.SQLException 
 */
protected void generateStringListFromDb(final String keyName, final String query) throws SQLException {
    if (!stringLists.containsKey(keyName + query.hashCode())) {
        log.info("*** reading from database column: " + keyName);
        final List<String> values = new ArrayList<>();

        log.debug("Query:" + query);
        try (Statement stmt = db.createStatement(); ResultSet rs = stmt.executeQuery(query)) {
            while (rs.next()) {
                values.add(rs.getString(1));
            }
        }

        if (values.isEmpty()) {
            // TODO: throw a meaningful exception here
            log.error("!!! Database column " + keyName + " did not return any values");
        }
        stringLists.put(keyName + query.hashCode(), values);
    }
}

From source file:com.opengamma.masterdb.security.hibernate.option.BondFutureOptionSecurityBean.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case -266326457: // optionExerciseType
        setOptionExerciseType((OptionExerciseType) newValue);
        return;//from   w  ww.  j a v a  2  s.  c o  m
    case 1373587791: // optionType
        setOptionType((OptionType) newValue);
        return;
    case -891985998: // strike
        setStrike((Double) newValue);
        return;
    case -1289159373: // expiry
        setExpiry((ExpiryBean) newValue);
        return;
    case 575402001: // currency
        setCurrency((CurrencyBean) newValue);
        return;
    case -661485980: // tradingExchange
        setTradingExchange((ExchangeBean) newValue);
        return;
    case 389497452: // settlementExchange
        setSettlementExchange((ExchangeBean) newValue);
        return;
    case 1257391553: // pointValue
        setPointValue((Double) newValue);
        return;
    case -1770633379: // underlying
        setUnderlying((ExternalIdBean) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}

From source file:com.opengamma.masterdb.security.hibernate.option.EquityIndexDividendFutureOptionSecurityBean.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case -266326457: // optionExerciseType
        setOptionExerciseType((OptionExerciseType) newValue);
        return;//w  ww. j a va 2s  .  c  om
    case 1373587791: // optionType
        setOptionType((OptionType) newValue);
        return;
    case -891985998: // strike
        setStrike((Double) newValue);
        return;
    case -1289159373: // expiry
        setExpiry((ExpiryBean) newValue);
        return;
    case 575402001: // currency
        setCurrency((CurrencyBean) newValue);
        return;
    case 1989774883: // exchange
        setExchange((ExchangeBean) newValue);
        return;
    case 243392205: // margined
        setMargined((Boolean) newValue);
        return;
    case 1257391553: // pointValue
        setPointValue((Double) newValue);
        return;
    case -1770633379: // underlying
        setUnderlying((ExternalIdBean) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}

From source file:org.mahasen.util.PutUtil.java

/**
 * @param part//w w w .ja  va 2s  .c o m
 * @param parentFileName
 * @param partName
 * @throws MahasenConfigurationException
 * @throws PastException
 * @throws InterruptedException
 */
public void replicateFilePart(File part, String parentFileName, String partName)
        throws MahasenConfigurationException, PastException, InterruptedException, MahasenException {
    Vector<String> nodeIpsToPut = getNodeIpsToPut();

    String resourcePath = MahasenConstants.ROOT_REGISTRY_PATH + parentFileName;
    Id parentFileId = Id.build(String.valueOf(resourcePath.hashCode()));

    while (mahasenManager.lookupDHT(parentFileId) == null) {
        Thread.sleep(1000);
    }
    MahasenResource mahasenResourceToUpdate = mahasenManager.lookupDHT(parentFileId);

    getReplicaReference().put(partName, 0);

    Random random = new Random();

    Hashtable<String, Vector<String>> spittedPartsStoredIps = mahasenResourceToUpdate.getSplittedPartsIpTable();
    Vector<String> currentPartStoredIps = spittedPartsStoredIps.get(partName);
    List<String> replicateIds = new ArrayList<String>();
    final BlockFlag blockFlag = new BlockFlag(true, 3000);

    while (true) {

        if (nodeIpsToPut.size() >= MahasenConstants.NUMBER_OF_REPLICAS + 1) {
            if (getReplicaReference().get(partName) == MahasenConstants.NUMBER_OF_REPLICAS) {
                log.info("Success in replicating :" + getReplicaReference().get(partName) + " parts");
                break;
            }

            String nodeIp = nodeIpsToPut.get(random.nextInt(nodeIpsToPut.size()));

            if (!currentPartStoredIps.contains(nodeIp) && !replicateIds.contains(nodeIp)) {
                replicateIds.add(nodeIp);
                try {
                    sendReplicateRequest(nodeIp, part, partName, mahasenResourceToUpdate, parentFileId);
                } catch (URISyntaxException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
            }
        } else {

            for (String ip : nodeIpsToPut) {
                if (!currentPartStoredIps.contains(ip)) {
                    try {
                        sendReplicateRequest(ip, part, partName, mahasenResourceToUpdate, parentFileId);
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }
            blockFlag.unblock();
            break;

        }

        if (blockFlag.isBlocked()) {

            mahasenManager.getNode().getEnvironment().getTimeSource().sleep(10);
        } else {
            throw new MahasenException("Time out in storing " + part.getName());
        }
        Thread.sleep(100);
    }
}

From source file:com.opengamma.masterdb.security.hibernate.option.SwaptionSecurityBean.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case -1289159373: // expiry
        setExpiry((ExpiryBean) newValue);
        return;/*from  w ww .j  a v  a2s  .c  om*/
    case -1770633379: // underlying
        setUnderlying((ExternalIdBean) newValue);
        return;
    case -871053882: // cashSettled
        setCashSettled((Boolean) newValue);
        return;
    case 116685664: // longShort
        setLongShort((Boolean) newValue);
        return;
    case 106443605: // payer
        setPayer((Boolean) newValue);
        return;
    case 575402001: // currency
        setCurrency((CurrencyBean) newValue);
        return;
    case 1585636160: // notional
        setNotional((Double) newValue);
        return;
    case -266326457: // optionExerciseType
        setOptionExerciseType((OptionExerciseType) newValue);
        return;
    case -295948169: // settlementDate
        setSettlementDate((ZonedDateTimeBean) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}

From source file:fr.aliasource.webmail.common.conversation.ListConversationsCommand.java

private RawMessage parseHeaders(HashSet<Long> unseen, HashSet<Long> withAttachments, HashSet<Long> starred,
        HashSet<Long> answered, IMAPHeaders head, long uid, HashSet<Long> withInvitations) {
    boolean read = !unseen.contains(uid);
    boolean attach = withAttachments.contains(uid);
    boolean invitation = withInvitations.contains(uid);
    boolean answer = answered.contains(uid);
    boolean star = starred.contains(uid);
    String subject = head.getSubject();
    String smtpId = head.getRawHeader("message-id");
    String pri = head.getRawHeader("x-priority");
    boolean prio = pri != null && pri.trim().startsWith("1");
    // generate a stable uid when none is found in the message
    if (smtpId == null) {
        smtpId = "<" + subject.hashCode() + "-" + uid + "@generated.minig.org>";
    }//from  w w  w.j  av  a 2s .c om

    String inReplyTo = head.getRawHeader("in-reply-to");
    Address a = null;
    List<Address> ccA = Collections.emptyList();
    List<Address> toA = Collections.emptyList();
    if (isShowRecipientsFolder) {
        toA = head.getTo();
        ccA = head.getCc();
    } else {
        a = head.getFrom();
    }

    RawMessage msg = new RawMessage(uid, smtpId, inReplyTo, subject, read, head.getDate().getTime(), a, attach,
            star, invitation, toA, ccA, answer, prio);
    return msg;
}

From source file:com.opengamma.masterdb.security.hibernate.option.NonDeliverableFXDigitalOptionSecurityBean.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case -984864697: // putAmount
        setPutAmount((Double) newValue);
        return;/*w w w . ja v a  2 s.  c  o  m*/
    case 1066661974: // callAmount
        setCallAmount((Double) newValue);
        return;
    case -1289159373: // expiry
        setExpiry((ExpiryBean) newValue);
        return;
    case 516393024: // putCurrency
        setPutCurrency((CurrencyBean) newValue);
        return;
    case 643534991: // callCurrency
        setCallCurrency((CurrencyBean) newValue);
        return;
    case -225763273: // paymentCurrency
        setPaymentCurrency((CurrencyBean) newValue);
        return;
    case -295948169: // settlementDate
        setSettlementDate((ZonedDateTimeBean) newValue);
        return;
    case -1180327226: // isLong
        setIsLong((Boolean) newValue);
        return;
    case -141503783: // deliverInCallCurrency
        setDeliverInCallCurrency((Boolean) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}

From source file:com.opengamma.masterdb.security.hibernate.option.NonDeliverableFXOptionSecurityBean.java

@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
    case -984864697: // putAmount
        setPutAmount((Double) newValue);
        return;/*from   w w w  . j av a2s .  c  o  m*/
    case 1066661974: // callAmount
        setCallAmount((Double) newValue);
        return;
    case -1289159373: // expiry
        setExpiry((ExpiryBean) newValue);
        return;
    case 516393024: // putCurrency
        setPutCurrency((CurrencyBean) newValue);
        return;
    case 643534991: // callCurrency
        setCallCurrency((CurrencyBean) newValue);
        return;
    case -295948169: // settlementDate
        setSettlementDate((ZonedDateTimeBean) newValue);
        return;
    case -1180327226: // isLong
        setIsLong((Boolean) newValue);
        return;
    case -266326457: // optionExerciseType
        setOptionExerciseType((OptionExerciseType) newValue);
        return;
    case -426676942: // isDeliveryInCallCurrency
        setIsDeliveryInCallCurrency((Boolean) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
}

From source file:com.battlelancer.seriesguide.util.ImageDownloader.java

Bitmap downloadBitmap(String url, boolean isDiskCaching) {

    File imagefile = null;//from   w w  w. ja  v a 2 s.  c  om
    if (isDiskCaching) {
        String filename = Integer.toHexString(url.hashCode()) + "." + CompressFormat.JPEG.name();
        imagefile = new File(mDiskCacheDir + "/" + filename);

        if (Utils.isExtStorageAvailable()) {
            // try to get bitmap from disk cache first
            if (imagefile.exists()) {
                // disk cache hit
                final Bitmap bitmap = BitmapFactory.decodeFile(imagefile.getAbsolutePath());
                if (bitmap != null) {
                    return bitmap;
                }
            }
        }
    }

    // if loading from disk fails, download it
    final HttpClient client = new DefaultHttpClient();
    final HttpGet getRequest = new HttpGet(url);

    try {
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = null;
            try {
                inputStream = entity.getContent();
                // return BitmapFactory.decodeStream(inputStream);
                // Bug on slow connections, fixed in future release.
                // Bitmap bitmap = BitmapFactory.decodeStream(new
                // FlushedInputStream(inputStream));

                // write directly to disk
                Bitmap bitmap;
                if (isDiskCaching && Utils.isExtStorageAvailable()) {
                    FileOutputStream outputstream = new FileOutputStream(imagefile);
                    Utils.copy(new FlushedInputStream(inputStream), outputstream);
                    outputstream.close();
                    bitmap = BitmapFactory.decodeFile(imagefile.getAbsolutePath());
                } else {
                    // if we have no external storage, decode directly
                    bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream));
                }

                // // TODO look if we can return the bitmap first, then save
                // in
                // // the background
                // if (Utils.isExtStorageAvailable()) {
                // // write the bitmap to the disk cache
                // FileOutputStream os = new FileOutputStream(imagefile);
                //
                // @SuppressWarnings("unused")
                // boolean isreconstructable =
                // bitmap.compress(CompressFormat.JPEG, 90, os);
                // os.close();
                // }

                return bitmap;
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                entity.consumeContent();
            }
        }
    } catch (IOException e) {
        getRequest.abort();
        Log.w(LOG_TAG, "I/O error while retrieving bitmap from " + url, e);
    } catch (IllegalStateException e) {
        getRequest.abort();
        Log.w(LOG_TAG, "Incorrect URL: " + url);
    } catch (Exception e) {
        getRequest.abort();
        Log.w(LOG_TAG, "Error while retrieving bitmap from " + url, e);
    }
    return null;
}

From source file:net.jmhertlein.alphonseirc.AlphonseBot.java

private void handleHashCommand(String target, String sender, String[] args, String cmd, String rest) {
    sendMessage(target, "hashcode() of \"" + rest + "\": " + rest.hashCode());
}