Example usage for java.lang Double hashCode

List of usage examples for java.lang Double hashCode

Introduction

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

Prototype

@Override
public int hashCode() 

Source Link

Document

Returns a hash code for this Double object.

Usage

From source file:Main.java

public static void main(String[] args) {

    Double d = new Double("3.0001");

    int retval = d.hashCode();
    System.out.println("Value = " + retval);
}

From source file:com.itemanalysis.psychometrics.reliability.AbstractScoreReliability.java

public int hashCode() {
    Double v = new Double(value());
    return v.hashCode();
}

From source file:com.itemanalysis.psychometrics.polycor.PearsonCorrelation.java

@Override
public int hashCode() {
    Double v = new Double(this.value());
    return v.hashCode();
}

From source file:org.bibsonomy.rest.utils.HeaderUtils.java

/**
 * // w  ww.  jav  a 2s  . c o  m
 * @param acceptHeader 
 *          the HTML ACCEPT Header
 *          <br/>example: 
 *             <code>ACCEPT: text/xml,text/html;q=0.9,text/plain;q=0.8,image/png</code>
 *             would be interpreted in the following precedence:
 *              <ol>
 *             <li>text/xml</li>
 *             <li>image/png</li>
 *             <li>text/html</li>
 *             <li>text/plain</li>
 *              </ol>
 *          )    
 * @return a sorted map with the precedences
 */
public static SortedMap<Double, Vector<String>> getPreferredTypes(final String acceptHeader) {
    // maps the q-value to output format (reverse order)
    final SortedMap<Double, Vector<String>> preferredTypes = new TreeMap<Double, Vector<String>>(
            new Comparator<Double>() {
                @Override
                public int compare(Double o1, Double o2) {
                    if (o1.doubleValue() > o2.doubleValue())
                        return -1;
                    else if (o1.doubleValue() < o2.doubleValue())
                        return 1;
                    else
                        return o1.hashCode() - o2.hashCode();
                }
            });

    if (!present(acceptHeader)) {
        return preferredTypes;
    }

    // fill map with q-values and formats
    final Scanner scanner = new Scanner(acceptHeader.toLowerCase());
    scanner.useDelimiter(",");

    while (scanner.hasNext()) {
        final String[] types = scanner.next().split(";");
        final String type = types[0];
        double qValue = 1;

        if (types.length != 1) {
            /*
             * FIXME: we get 
             *   java.lang.NumberFormatException: For input string: "screen"
             * in the error log because the format we assume seems to be 
             * different by some clients. Until we find out, what is really 
             * wrong (our parsing or the client), we are more careful with
             * parsing external data.
             */
            try {
                qValue = Double.parseDouble(types[1].split("=")[1]);
            } catch (NumberFormatException e) {
                qValue = 0;
                log.error("Couldn't parse accept header '" + acceptHeader + "'");
            }
        }

        Vector<String> v = preferredTypes.get(qValue);
        if (!preferredTypes.containsKey(qValue)) {
            v = new Vector<String>();
            preferredTypes.put(qValue, v);
        }
        v.add(type);
    }
    return preferredTypes;
}

From source file:ubic.gemma.analysis.preprocess.svd.ExpressionDataSVD.java

/**
 * Implements method described in Skillicorn et al., "Strategies for winnowing microarray data" (also section 3.5.5
 * of his book)//from  w  ww. j a v a 2  s  .co  m
 * 
 * @param thresholdQuantile Enter 0.5 for median. Value must be > 0 and < 1.
 * @return a filtered matrix
 */
public ExpressionDataDoubleMatrix winnow(double thresholdQuantile) {

    if (thresholdQuantile <= 0 || thresholdQuantile >= 1) {
        throw new IllegalArgumentException("Threshold quantile should be a value between 0 and 1 exclusive");
    }

    class NormCmp implements Comparable<NormCmp> {
        Double norm;
        int rowIndex;

        public NormCmp(int rowIndex, Double norm) {
            super();
            this.rowIndex = rowIndex;
            this.norm = norm;
        }

        @Override
        public int compareTo(NormCmp o) {
            return this.norm.compareTo(o.norm);
        }

        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#equals(java.lang.Object)
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            NormCmp other = (NormCmp) obj;
            if (norm == null) {
                if (other.norm != null)
                    return false;
            } else if (!norm.equals(other.norm))
                return false;
            return true;
        }

        public int getRowIndex() {
            return rowIndex;
        }

        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#hashCode()
         */
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((norm == null) ? 0 : norm.hashCode());
            return result;
        }

    }

    // order rows by distance from the origin. This is proportional to the 1-norm.
    Algebra a = new Algebra();
    List<NormCmp> os = new ArrayList<NormCmp>();
    for (int i = 0; i < this.expressionData.rows(); i++) {
        double[] row = this.getU().getRow(i);
        DoubleMatrix1D rom = new DenseDoubleMatrix1D(row);
        norm1 = a.norm1(rom);
        os.add(new NormCmp(i, norm1));
    }

    Collections.sort(os);

    int quantileLimit = (int) Math.floor(this.expressionData.rows() * thresholdQuantile);
    quantileLimit = Math.max(0, quantileLimit);

    List<CompositeSequence> keepers = new ArrayList<CompositeSequence>();
    for (int i = 0; i < quantileLimit; i++) {
        NormCmp x = os.get(i);
        CompositeSequence d = this.expressionData.getDesignElementForRow(x.getRowIndex());
        keepers.add(d);
    }

    // / remove genes which are near the origin in SVD space. FIXME: make sure the missing values are still masked.
    return new ExpressionDataDoubleMatrix(this.expressionData, keepers);

}

From source file:ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD.java

/**
 * Implements method described in Skillicorn et al., "Strategies for winnowing microarray data" (also section 3.5.5
 * of his book)/*from  w  ww.j av a2s .c o  m*/
 *
 * @param  thresholdQuantile Enter 0.5 for median. Value must be &gt; 0 and &lt; 1.
 * @return                   a filtered matrix
 */
public ExpressionDataDoubleMatrix winnow(double thresholdQuantile) {

    if (thresholdQuantile <= 0 || thresholdQuantile >= 1) {
        throw new IllegalArgumentException("Threshold quantile should be a value between 0 and 1 exclusive");
    }

    class NormCmp implements Comparable<NormCmp> {
        private Double norm;
        private int rowIndex;

        private NormCmp(int rowIndex, Double norm) {
            super();
            this.rowIndex = rowIndex;
            this.norm = norm;
        }

        @Override
        public int compareTo(NormCmp o) {
            return this.norm.compareTo(o.norm);
        }

        public int getRowIndex() {
            return rowIndex;
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((norm == null) ? 0 : norm.hashCode());
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (this.getClass() != obj.getClass())
                return false;
            NormCmp other = (NormCmp) obj;
            if (norm == null) {
                return other.norm == null;
            }
            return norm.equals(other.norm);
        }

    }

    // order rows by distance from the origin. This is proportional to the 1-norm.
    Algebra a = new Algebra();
    List<NormCmp> os = new ArrayList<>();
    for (int i = 0; i < this.expressionData.rows(); i++) {
        double[] row = this.getU().getRow(i);
        DoubleMatrix1D rom = new DenseDoubleMatrix1D(row);
        double norm1 = a.norm1(rom);
        os.add(new NormCmp(i, norm1));
    }

    Collections.sort(os);

    int quantileLimit = (int) Math.floor(this.expressionData.rows() * thresholdQuantile);
    quantileLimit = Math.max(0, quantileLimit);

    List<CompositeSequence> keepers = new ArrayList<>();
    for (int i = 0; i < quantileLimit; i++) {
        NormCmp x = os.get(i);
        CompositeSequence d = this.expressionData.getDesignElementForRow(x.getRowIndex());
        keepers.add(d);
    }

    // remove genes which are near the origin in SVD space. FIXME: make sure the missing values are still masked.
    return new ExpressionDataDoubleMatrix(this.expressionData, keepers);

}