Example usage for java.util Arrays hashCode

List of usage examples for java.util Arrays hashCode

Introduction

In this page you can find the example usage for java.util Arrays hashCode.

Prototype

public static int hashCode(Object a[]) 

Source Link

Document

Returns a hash code based on the contents of the specified array.

Usage

From source file:com.cloudbees.plugins.credentials.SecretBytes.java

/**
 * {@inheritDoc}
 */
@Override
public int hashCode() {
    return Arrays.hashCode(value);
}

From source file:org.apache.kylin.storage.hbase.util.HbaseStreamingInput.java

public static void randomScan(String tableName) throws IOException {

    final Semaphore semaphore = new Semaphore(0);
    new Thread(new Runnable() {
        @Override/*w w  w. j a  va  2 s .c  o  m*/
        public void run() {
            scheduleJob(semaphore, 60000);//1 minutes a batch
        }
    }).start();

    while (true) {
        try {
            semaphore.acquire();
            int waiting = semaphore.drainPermits();
            if (waiting > 0) {
                logger.warn("Too many queries to handle! Blocking " + waiting + " sets of scan requests");
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            e.printStackTrace();
        }

        Random r = new Random();
        Connection conn = getConnection();
        Table table = conn.getTable(TableName.valueOf(tableName));

        long leftBound = getFirstKeyTime(table);
        long rightBound = System.currentTimeMillis();

        for (int t = 0; t < 5; ++t) {
            long start = (long) (leftBound + r.nextDouble() * (rightBound - leftBound));
            long end = start + 600000;//a period of 10 minutes
            logger.info("A scan from " + formatTime(start) + " to " + formatTime(end));

            Scan scan = new Scan();
            scan.setStartRow(Bytes.toBytes(start));
            scan.setStopRow(Bytes.toBytes(end));
            scan.addFamily(CF);
            ResultScanner scanner = table.getScanner(scan);
            long hash = 0;
            int rowCount = 0;
            for (Result result : scanner) {
                Cell cell = result.getColumnLatestCell(CF, QN);
                byte[] value = cell.getValueArray();
                if (cell.getValueLength() != CELL_SIZE) {
                    logger.error("value size invalid!!!!!");
                }

                hash += Arrays.hashCode(Arrays.copyOfRange(value, cell.getValueOffset(),
                        cell.getValueLength() + cell.getValueOffset()));
                rowCount++;
            }
            scanner.close();
            logger.info("Scanned " + rowCount + " rows, the (meaningless) hash for the scan is " + hash);
        }
        table.close();
        conn.close();
    }
}

From source file:com.microsoft.tfs.core.externaltools.ExternalTool.java

/**
 * {@inheritDoc}//from  w ww  .jav a  2  s  .c  o  m
 */
@Override
public int hashCode() {
    int result = 17;

    result = result * 37 + command.hashCode();
    result = result * 37 + Arrays.hashCode(arguments);

    return result;
}

From source file:uk.ac.starlink.dpac.math.PolynomialFunction.java

/** {@inheritDoc} */
@Override//  w ww  . ja v  a  2  s  .  c o m
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + Arrays.hashCode(coefficients);
    return result;
}

From source file:de.hsheilbronn.mi.configuration.SvmConfigurationImpl.java

@Override
public int hashCode() {
    int result;/*from ww w.j  av  a2s. co m*/
    long temp;
    result = svmType != null ? svmType.hashCode() : 0;
    result = 31 * result + (kernelType != null ? kernelType.hashCode() : 0);
    result = 31 * result + degree;
    temp = Double.doubleToLongBits(gamma);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(coef0);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(nu);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(cacheSize);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(cost);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(eps);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(p);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    result = 31 * result + shrinking;
    result = 31 * result + probability;
    result = 31 * result + nrWeight;
    result = 31 * result + crossValidation;
    result = 31 * result + (weightLabel != null ? Arrays.hashCode(weightLabel) : 0);
    result = 31 * result + (weight != null ? Arrays.hashCode(weight) : 0);
    result = 31 * result + nFold;
    return result;
}

From source file:com.mapr.hbase.support.objects.MHRegionInfo090x.java

private void setHashCode() {
    int result = Arrays.hashCode(this.regionName);
    result ^= this.regionId;
    result ^= Arrays.hashCode(this.startKey);
    result ^= Arrays.hashCode(this.endKey);
    result ^= Boolean.valueOf(this.offLine).hashCode();
    result ^= this.tableDesc.hashCode();
    this.hashCode = result;
}

From source file:org.loklak.api.server.push.AbstractPushServlet.java

@SuppressWarnings("unchecked")
@Override//from w ww  . ja v  a 2 s .c  o  m
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    RemoteAccess.Post post = RemoteAccess.evaluate(request);
    String remoteHash = Integer.toHexString(Math.abs(post.getClientHost().hashCode()));

    // manage DoS
    if (post.isDoS_blackout()) {
        response.sendError(503, "your request frequency is too high");
        return;
    }

    String url = post.get("url", "");
    if (url == null || url.length() == 0) {
        response.sendError(400, "your request does not contain an url to your data object");
        return;
    }
    String screen_name = post.get("screen_name", "");
    if (screen_name == null || screen_name.length() == 0) {
        response.sendError(400, "your request does not contain required screen_name parameter");
        return;
    }

    Map<String, Object> map;
    byte[] jsonText;
    try {
        jsonText = ClientConnection.download(url);
        map = DAO.jsonMapper.readValue(jsonText, DAO.jsonTypeRef);
    } catch (Exception e) {
        response.sendError(400, "error reading json file from url");
        return;
    }

    // validation phase
    ProcessingReport report = this.validator.validate(new String(jsonText));
    if (!report.isSuccess()) {
        response.sendError(400,
                "json does not conform to schema : " + this.getValidatorSchema().name() + "\n" + report);
        return;
    }

    // conversion phase
    Object extractResults = extractMessages(map);
    List<Map<String, Object>> messages;
    if (extractResults instanceof List) {
        messages = (List<Map<String, Object>>) extractResults;
    } else if (extractResults instanceof Map) {
        messages = new ArrayList<>();
        messages.add((Map<String, Object>) extractResults);
    } else {
        throw new IOException("extractMessages must return either a List or a Map. Get "
                + (extractResults == null ? "null" : extractResults.getClass().getCanonicalName())
                + " instead");
    }
    List<Map<String, Object>> convertedMessages = this.converter.convert(messages);

    PushReport nodePushReport = new PushReport();
    ObjectWriter ow = new ObjectMapper().writerWithDefaultPrettyPrinter();
    // custom treatment for each message
    for (int i = 0; i < messages.size(); i++) {
        Map<String, Object> message = convertedMessages.get(i);
        message.put("source_type", this.getSourceType().name());
        message.put("location_source", LocationSource.USER.name());
        message.put("place_context", PlaceContext.ABOUT.name());
        if (message.get("text") == null) {
            message.put("text", "");
        }

        // append rich-text attachment
        String jsonToText = ow.writeValueAsString(messages.get(i));
        message.put("text", message.get("text") + MessageEntry.RICH_TEXT_SEPARATOR + jsonToText);
        customProcessing(message);

        if (message.get("mtime") == null) {
            String existed = PushServletHelper.checkMessageExistence(message);
            // message known
            if (existed != null) {
                messages.remove(i);
                nodePushReport.incrementKnownCount(existed);
                continue;
            }
            // updated message -> save with new mtime value
            message.put("mtime", Long.toString(System.currentTimeMillis()));
        }

        try {
            message.put("id_str", PushServletHelper.computeMessageId(message, getSourceType()));
        } catch (Exception e) {
            DAO.log("Problem computing id : " + e.getMessage());
        }
    }
    try {
        PushReport savingReport = PushServletHelper.saveMessagesAndImportProfile(convertedMessages,
                Arrays.hashCode(jsonText), post, getSourceType(), screen_name);
        nodePushReport.combine(savingReport);
    } catch (IOException e) {
        response.sendError(404, e.getMessage());
        return;
    }
    String res = PushServletHelper.buildJSONResponse(post.get("callback", ""), nodePushReport);

    post.setResponse(response, "application/javascript");
    response.getOutputStream().println(res);
    DAO.log(request.getServletPath() + " -> records = " + nodePushReport.getRecordCount() + ", new = "
            + nodePushReport.getNewCount() + ", known = " + nodePushReport.getKnownCount() + ", error = "
            + nodePushReport.getErrorCount() + ", from host hash " + remoteHash);
}

From source file:org.ameba.http.Response.java

@Override
public int hashCode() {
    int result = super.hashCode();
    result = 31 * result + (message != null ? message.hashCode() : 0);
    result = 31 * result + (messageKey != null ? messageKey.hashCode() : 0);
    result = 31 * result + (obj != null ? Arrays.hashCode(obj) : 0);
    result = 31 * result + (httpStatus != null ? httpStatus.hashCode() : 0);
    return result;
}

From source file:com.opengamma.analytics.financial.instrument.payment.CouponIborRatchetDefinition.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + Arrays.hashCode(_capCoefficients);
    result = prime * result + Arrays.hashCode(_floorCoefficients);
    result = prime * result + Arrays.hashCode(_mainCoefficients);
    return result;
}

From source file:sadl.integration.MonteCarloIntegration.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + Arrays.hashCode(integral);
    result = prime * result + pointsToStore;
    result = prime * result + (preprocessed ? 1231 : 1237);
    return result;
}