Example usage for java.lang Double equals

List of usage examples for java.lang Double equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object against the specified object.

Usage

From source file:DoubleDemo.java

public static void main(String args[]) {
    Double d1 = new Double(3.14159);
    Double d2 = new Double("314159E-5");

    System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
}

From source file:MainClass.java

public static void main(String args[]) {
    Double d1 = new Double(3.14159);
    Double d2 = new Double("314159E-5");
    System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
}

From source file:Main.java

public static void main(String[] args) {
    Double obj1 = new Double("2");
    Double obj2 = new Double("2.0");
    System.out.print(obj1 + " = " + obj2);
    System.out.println(" ?  " + obj1.equals(obj2));

    obj1 = new Double("3");
    obj2 = new Double("4");
    System.out.print(obj1 + " = " + obj2);
    System.out.println(" ?  " + obj1.equals(obj2));
}

From source file:Main.java

public static void main(String[] args) {
    Double d1 = new Double(+0.0);
    System.out.println(d1.doubleValue());

    Double d2 = new Double(-0.0);
    System.out.println(d2.doubleValue());
    System.out.println(d1.equals(d2));
    System.out.println(+0.0 == -0.0);

}

From source file:Main.java

public static boolean doubleEqual(@Nullable Double one, @Nullable Double another) {
    return !(one != null ? !one.equals(another) : another != null);
}

From source file:edu.isi.misd.scanner.network.modules.worker.processors.oceans.OceansLogisticRegressionProcessor.java

/**
 * Formats a double to a fixed (currently three) number of decimal places.
 *//*from  ww  w . j a  va2s  .  co  m*/
public static double df(double a) {
    DecimalFormat f = new DecimalFormat(".000");
    Double input = Double.valueOf(a);
    // check for special values so that they are not parsed
    if (input.equals(Double.NEGATIVE_INFINITY) || input.equals(Double.POSITIVE_INFINITY)
            || input.equals(Double.NaN)) {
        return input.doubleValue();
    }
    return Double.parseDouble(f.format(input));
}

From source file:mlflex.helper.MathUtilities.java

/** Identifies the maximum numeric value in a list.
 *
 * @param values Numeric values to test/* w  w  w.j a va  2s.c  o m*/
 * @return Maximum value
 * @throws Exception
 */
public static double Max(ArrayList<Double> values) throws Exception {
    ArrayList<Double> values2 = new ArrayList<Double>();
    for (Double value : values)
        if (!value.equals(Double.NaN))
            values2.add(value);

    if (values2.size() == 0)
        throw new Exception("The list was empty, so Max could not be determined.");

    int indexOfMax = 0;

    for (int i = 1; i < values2.size(); i++) {
        Double value = values2.get(i);

        if (value > values2.get(indexOfMax))
            indexOfMax = i;
    }

    return values2.get(indexOfMax);
}

From source file:com.btobits.automator.fix.utils.FixUtils.java

private static boolean compareDouble(String inDouble1, String inDouble2) {
    if (StringUtils.equals(inDouble1, inDouble2))
        return true;

    if (inDouble1 == null || inDouble2 == null)
        return false;

    Double a = getDouble(inDouble1);
    Double b = getDouble(inDouble2);

    return a.equals(b);
}

From source file:com.microsoft.azure.storage.table.TableEntitySerializer.java

/**
 * Reserved for internal use. Writes an entity to the specified <code>JsonGenerator</code> as a JSON resource
 * //  w  w  w.  jav a  2  s .  co  m
 * @param generator
 *            The <code>JsonGenerator</code> to write the entity to.
 * @param options
 *            The {@link TableRequestOptions} to use for serializing.
 * @param entity
 *            The instance implementing {@link TableEntity} to write to the output stream.
 * @param isTableEntry
 *            A flag indicating the entity is a reference to a table at the top level of the storage service when
 *            <code>true<code> and a reference to an entity within a table when <code>false</code>.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * 
 * @throws StorageException
 *             if a Storage service error occurs.
 * @throws IOException
 *             if an error occurs while accessing the stream.
 */
private static void writeJsonEntity(final JsonGenerator generator, final TableRequestOptions options,
        final TableEntity entity, final boolean isTableEntry, final OperationContext opContext)
        throws StorageException, IOException {

    Map<String, EntityProperty> properties = getPropertiesFromDictionary(entity, options, opContext);

    // start object
    generator.writeStartObject();

    if (!isTableEntry) {
        Utility.assertNotNull(TableConstants.PARTITION_KEY, entity.getPartitionKey());
        Utility.assertNotNull(TableConstants.ROW_KEY, entity.getRowKey());
        Utility.assertNotNull(TableConstants.TIMESTAMP, entity.getTimestamp());

        // PartitionKey
        generator.writeStringField(TableConstants.PARTITION_KEY, entity.getPartitionKey());

        // RowKey
        generator.writeStringField(TableConstants.ROW_KEY, entity.getRowKey());

        // Timestamp
        generator.writeStringField(TableConstants.TIMESTAMP, Utility.getJavaISO8601Time(entity.getTimestamp()));
    }

    for (final Entry<String, EntityProperty> ent : properties.entrySet()) {
        if (ent.getKey().equals(TableConstants.PARTITION_KEY) || ent.getKey().equals(TableConstants.ROW_KEY)
                || ent.getKey().equals(TableConstants.TIMESTAMP) || ent.getKey().equals("Etag")) {
            continue;
        }

        EntityProperty currProp = ent.getValue();
        if (currProp.getEdmType().mustAnnotateType()) {
            final String edmTypeString = currProp.getEdmType().toString();

            // property type
            generator.writeStringField(ent.getKey() + ODataConstants.ODATA_TYPE_SUFFIX, edmTypeString);

            // property key and value
            generator.writeStringField(ent.getKey(), ent.getValue().getValueAsString());
        } else if (currProp.getEdmType() == EdmType.DOUBLE && currProp.getIsNull() == false) {
            final String edmTypeString = currProp.getEdmType().toString();
            final Double value = currProp.getValueAsDouble();

            // property type, if needed
            if (value.equals(Double.POSITIVE_INFINITY) || value.equals(Double.NEGATIVE_INFINITY)
                    || value.equals(Double.NaN)) {
                generator.writeStringField(ent.getKey() + ODataConstants.ODATA_TYPE_SUFFIX, edmTypeString);

                // property key and value
                generator.writeStringField(ent.getKey(), ent.getValue().getValueAsString());
            } else {
                writeJsonProperty(generator, ent);
            }

        } else {
            writeJsonProperty(generator, ent);
        }
    }

    // end object
    generator.writeEndObject();
}

From source file:org.openbitcoinwidget.WidgetProvider.java

private static int getColorFromValueChange(Double prevValue, Double nowValue, ColorMode colorMode) {
    if (prevValue == null || nowValue == null || prevValue.equals(nowValue)) {
        return getColor(colorMode, WidgetColor.StartValue);
    } else if (prevValue < nowValue) {
        return getColor(colorMode, WidgetColor.Increase);
    } else {/* ww w. j  a va2  s  .c o m*/
        return getColor(colorMode, WidgetColor.Decrease);
    }
}