java.lang.Double.equals()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中java.lang.Double.equals()方法的一些代码示例,展示了Double.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double.equals()方法的具体详情如下:
包路径:java.lang.Double
类名称:Double
方法名:equals

Double.equals介绍

[英]Tests this double for equality with object. To be equal, object must be an instance of Double and doubleToLongBits must give the same value for both objects.

Note that, unlike ==, -0.0 and +0.0 compare unequal, and NaNs compare equal by this method.
[中]测试此double是否与object相等。若要相等,对象必须是Double的实例,doubleToLongBits必须为两个对象提供相同的值。
请注意,与==、-0.0和+0.0不同,使用此方法比较不相等,而NaN比较相等。

代码示例

代码示例来源:origin: alibaba/druid

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

代码示例来源:origin: redisson/redisson

@Override
public boolean equals(Object obj) {
  if (this == obj)
    return true;
  if (obj == null)
    return false;
  if (getClass() != obj.getClass())
    return false;
  ScoredEntry other = (ScoredEntry) obj;
  if (score == null) {
    if (other.score != null)
      return false;
  } else if (!score.equals(other.score))
    return false;
  if (value == null) {
    if (other.value != null)
      return false;
  } else if (!value.equals(other.value))
    return false;
  return true;
}

代码示例来源:origin: redisson/redisson

@Override
public boolean equals(Object obj) {
  if (this == obj)
    return true;
  if (obj == null)
    return false;
  if (getClass() != obj.getClass())
    return false;
  ScoredEntry other = (ScoredEntry) obj;
  if (score == null) {
    if (other.score != null)
      return false;
  } else if (!score.equals(other.score))
    return false;
  if (value == null) {
    if (other.value != null)
      return false;
  } else if (!value.equals(other.value))
    return false;
  return true;
}

代码示例来源:origin: spring-projects/spring-framework

public boolean valid(Double ratio) {
    return new Double(42).equals(ratio);
  }
}

代码示例来源:origin: killbill/killbill

@Override
public ValidationErrors validate(StandaloneCatalog root, ValidationErrors errors) {
  if (!CatalogSafetyInitializer.DEFAULT_NON_REQUIRED_DOUBLE_FIELD_VALUE.equals(max) &&
    !CatalogSafetyInitializer.DEFAULT_NON_REQUIRED_DOUBLE_FIELD_VALUE.equals(min) &&
    max.doubleValue() < min.doubleValue()) {
    errors.add(new ValidationError("max must be greater than min", Limit.class, ""));
  }
  return errors;
}

代码示例来源:origin: springside/springside4

/**
 * 优化的创建函数,如果为0或100时,返回更直接的采样器
 */
public static Sampler create(Double selectPercent) {
  if (selectPercent.equals(ALWAYS)) {
    return new AlwaysSampler();
  } else if (selectPercent.equals(NEVER)) {
    return new NeverSampler();
  } else {
    return new Sampler(selectPercent);
  }
}

代码示例来源:origin: vipshop/vjtools

/**
 * 优化的创建函数,如果为0或100时,返回更直接的采样器
 */
public static Sampler create(Double selectPercent) {
  if (selectPercent.equals(ALWAYS)) {
    return new AlwaysSampler();
  } else if (selectPercent.equals(NEVER)) {
    return new NeverSampler();
  } else {
    return new Sampler(selectPercent);
  }
}

代码示例来源:origin: robovm/robovm

public static /*<name>*/UIFontWeight/*</name>*/ valueOf(/*<type>*/@MachineSizedFloat double/*</type>*/ value) {
  for (/*<name>*/UIFontWeight/*</name>*/ v : values) {
    if (v.value().equals(value)) {
      return v;
    }
  }
  throw new IllegalArgumentException("No constant with value " + value + " found in " 
    + /*<name>*/UIFontWeight/*</name>*/.class.getName());
}

代码示例来源:origin: killbill/killbill

@Override
public Double getMinTopUpCredit() throws CatalogApiException {
  if (!CatalogSafetyInitializer.DEFAULT_NON_REQUIRED_DOUBLE_FIELD_VALUE.equals(minTopUpCredit) && type != BlockType.TOP_UP) {
    throw new CatalogApiException(ErrorCode.CAT_NOT_TOP_UP_BLOCK, phase.getName());
  }
  return minTopUpCredit;
}

代码示例来源:origin: killbill/killbill

@Override
public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) {
  // Safety check
  if (type == null) {
    throw new IllegalStateException("type should have been automatically been initialized with VANILLA ");
  }
  if (type == BlockType.TOP_UP && CatalogSafetyInitializer.DEFAULT_NON_REQUIRED_DOUBLE_FIELD_VALUE.equals(minTopUpCredit)) {
    errors.add(new ValidationError(String.format("TOP_UP block needs to define minTopUpCredit for phase %s",
                           phase.getName()), DefaultUsage.class, ""));
  }
  return errors;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
  if (this == o)
    return true;
  if (o == null || getClass() != o.getClass())
    return false;
  ExternalizableTestObject1 obj = (ExternalizableTestObject1)o;
  return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
    doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
    Arrays.equals(longArr, obj.longArr) &&
    Arrays.equals(doubleArr, obj.doubleArr);
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public boolean equals(Object o) {
  if (this == o)
    return true;
  if (o == null || getClass() != o.getClass())
    return false;
  ExternalizableTestObject2 obj = (ExternalizableTestObject2)o;
  return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
    doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
    Arrays.equals(longArr, obj.longArr) &&
    Arrays.equals(doubleArr, obj.doubleArr);
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;
    TestObject obj = (TestObject)o;
    return longVal != null ? longVal.equals(obj.longVal) : obj.longVal == null &&
      doubleVal != null ? doubleVal.equals(obj.doubleVal) : obj.doubleVal == null &&
      Arrays.equals(longArr, obj.longArr) &&
      Arrays.equals(doubleArr, obj.doubleArr);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public boolean equals(Object o) {
  if ( this == o ) {
    return true;
  }
  if ( o == null || getClass() != o.getClass() ) {
    return false;
  }
  DesignContract that = (DesignContract) o;
  if ( pk != null ? !pk.equals( that.pk ) : that.pk != null ) {
    return false;
  }
  return goal != null ? goal.equals( that.goal ) : that.goal == null;
}

代码示例来源:origin: google/guava

@Override
public boolean compare(@Nullable Double actual, @Nullable Double expected) {
 // Test for equality to allow non-finite values to match; otherwise, use the finite test.
 return actual.equals(expected)
   || FINITE_QUANTILE_CORRESPONDENCE.compare(actual, expected);
}

代码示例来源:origin: spring-projects/spring-framework

assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2")));
assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2()));
assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2")));
assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2()));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal")));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal()));

代码示例来源:origin: spring-projects/spring-framework

assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2")));
assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2()));
assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2")));
assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2()));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal")));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal()));

代码示例来源:origin: spring-projects/spring-framework

assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2")));
assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2()));
assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1")));
assertTrue("Correct double1 value", tb.getDouble1() == 5.1);
assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2")));
assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2()));
assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal")));
assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal()));

代码示例来源:origin: hibernate/hibernate-orm

public boolean equals(Object aObj) {
  if (aObj == this)
    return true;
  if (!(aObj instanceof BasketItemsPK))
    return false;
  BasketItemsPK basketitemspk = (BasketItemsPK)aObj;
  if (getShoppingBaskets() == null && basketitemspk.getShoppingBaskets() != null)
    return false;
  if (!getShoppingBaskets().equals(basketitemspk.getShoppingBaskets()))
    return false;
  if ((getCost() != null && !getCost().equals(basketitemspk.getCost())) || (getCost() == null && basketitemspk.getCost() != null))
    return false;
  return true;
}

代码示例来源:origin: spring-projects/spring-framework

request.addParameter("paramEmpty", "");
assertTrue(ServletRequestUtils.getDoubleParameter(request, "param1").equals(new Double(5.5)));
assertTrue(ServletRequestUtils.getDoubleParameter(request, "param1", 6.5) == 5.5);
assertTrue(ServletRequestUtils.getRequiredDoubleParameter(request, "param1") == 5.5);

相关文章