org.apache.sis.util.Utilities.deepEquals()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(100)

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

Utilities.deepEquals介绍

[英]Convenience method for testing two objects for equality using the given level of strictness. If at least one of the given objects implement the LenientComparable interface, then the comparison is performed using the LenientComparable#equals(Object,ComparisonMode)method. Otherwise this method performs the same work than the Objects#deepEquals(Object,Object) convenience method.

If both arguments are arrays or collections, then the elements are compared recursively.
[中]使用给定的严格程度测试两个对象是否相等的简便方法。如果至少有一个给定对象实现了LenientCompariable接口,则使用LenientCompariable#equals(Object,ComparisonMode)方法执行比较。否则,该方法执行的工作与Objects#deepEquals(Object,Object)便利方法相同。
如果两个参数都是数组或集合,则递归地比较元素。

代码示例

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
   * Compares this converter with the given object for equality, optionally ignoring rounding errors.
   */
  @Override
  public boolean equals(final Object other, final ComparisonMode mode) {
    if (other instanceof ConcatenatedConverter) {
      final ConcatenatedConverter o = (ConcatenatedConverter) other;
      return Utilities.deepEquals(c1, o.c1, mode) &&
          Utilities.deepEquals(c2, o.c2, mode);
    }
    return false;
  }
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Returns {@code true} if a candidate found by {@code IdentifiedObjectFinder} should be considered equals to the
 * requested object. This method invokes the {@code equals(…)} method on the {@code candidate} argument instead
 * than on the user-specified {@code object} on the assumption that implementations coming from the factory are
 * more reliable than user-specified objects.
 */
private boolean match(final IdentifiedObject candidate, final IdentifiedObject object) {
  return Utilities.deepEquals(candidate, object, ignoreAxes ? ComparisonMode.ALLOW_VARIANT : COMPARISON_MODE);
}

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

/**
   * Compares this converter with the given object for equality, optionally ignoring rounding errors.
   */
  @Override
  public boolean equals(final Object other, final ComparisonMode mode) {
    if (other instanceof ConcatenatedConverter) {
      final ConcatenatedConverter o = (ConcatenatedConverter) other;
      return Utilities.deepEquals(c1, o.c1, mode) &&
          Utilities.deepEquals(c2, o.c2, mode);
    }
    return false;
  }
}

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

/**
 * Returns {@code true} if a candidate found by {@code IdentifiedObjectFinder} should be considered equals to the
 * requested object. This method invokes the {@code equals(…)} method on the {@code candidate} argument instead
 * than on the user-specified {@code object} on the assumption that implementations coming from the factory are
 * more reliable than user-specified objects.
 */
private boolean match(final IdentifiedObject candidate, final IdentifiedObject object) {
  return Utilities.deepEquals(candidate, object, ignoreAxes ? ComparisonMode.ALLOW_VARIANT : COMPARISON_MODE);
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Returns {@code true} if at least one of the specified CRS is null, or both CRS are equals.
 * This special processing for {@code null} values is different from the usual contract of an
 * {@code equals} method, but allow to handle the case where the CRS is unknown.
 *
 * <p>Note that in debug mode (to be used in assertions only), the comparisons are actually a
 * bit more relax than just "ignoring metadata", since some rounding errors are tolerated.</p>
 */
static boolean equalsIgnoreMetadata(final CoordinateReferenceSystem crs1,
                  final CoordinateReferenceSystem crs2, final boolean debug)
{
  return (crs1 == null) || (crs2 == null) || Utilities.deepEquals(crs1, crs2,
      debug ? ComparisonMode.DEBUG : ComparisonMode.IGNORE_METADATA);
}

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

/**
 * Returns {@code true} if at least one of the specified CRS is null, or both CRS are equals.
 * This special processing for {@code null} values is different from the usual contract of an
 * {@code equals} method, but allow to handle the case where the CRS is unknown.
 *
 * <p>Note that in debug mode (to be used in assertions only), the comparisons are actually a
 * bit more relax than just "ignoring metadata", since some rounding errors are tolerated.</p>
 */
static boolean equalsIgnoreMetadata(final CoordinateReferenceSystem crs1,
                  final CoordinateReferenceSystem crs2, final boolean debug)
{
  return (crs1 == null) || (crs2 == null) || Utilities.deepEquals(crs1, crs2,
      debug ? ComparisonMode.DEBUG : ComparisonMode.IGNORE_METADATA);
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Compares the given objects in {@link ComparisonMode#DEBUG} mode.
 *
 * @param  o1 The first object to compare.
 * @param  o2 The second object to compare.
 * @return {@code true} if the given objects are equal.
 * @throws AssertionError If the given objects are not equal and the cause can be
 *         specified in the exception message.
 *
 * @since 3.20
 */
public static boolean debugEquals(final Object o1, final Object o2) throws AssertionError {
  return Utilities.deepEquals(o1, o2, ComparisonMode.DEBUG);
}

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

/**
 * Compares the specified object with this math transform for equality.
 */
@Override
public final boolean equals(final Object object, final ComparisonMode mode) {
  if (super.equals(object, mode)) {
    final SpecializableTransform other = (SpecializableTransform) object;
    return Utilities.deepEquals(global, other.global, mode) &&
        Utilities.deepEquals(domains, other.domains, mode);
  }
  return false;
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
   * Compares this coordinate system with the specified object for equality.
   *
   * @param  object  the object to compare to {@code this}.
   * @param  mode    {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or
   *                 {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only
   *                 properties relevant to coordinate transformations.
   * @return {@code true} if both objects are equal.
   */
  @Override
  public boolean equals(final Object object, final ComparisonMode mode) {
    if (!(object instanceof DefaultCompoundCS && super.equals(object, mode))) {
      return false;
    }
    return deepEquals(components, ((DefaultCompoundCS) object).components, mode);
  }
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Compares this object with the specified one for equality.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
  if (object == this) {
    return true;                            // Slight optimization.
  }
  if (super.equals(object, mode)) {
    final TensorValues<?> that = (TensorValues<?>) object;
    return Utilities.deepEquals(descriptors, that.descriptors, mode) &&
        Utilities.deepEquals(values(),    that.values(),    mode);
  }
  return false;
}

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

/**
 * Compares this object with the specified one for equality.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
  if (object == this) {
    return true;                            // Slight optimization.
  }
  if (super.equals(object, mode)) {
    final TensorValues<?> that = (TensorValues<?>) object;
    return Utilities.deepEquals(descriptors, that.descriptors, mode) &&
        Utilities.deepEquals(values(),    that.values(),    mode);
  }
  return false;
}

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

/**
 * Asserts that the two given objects are equal ignoring metadata.
 * See {@link ComparisonMode#IGNORE_METADATA} for more information.
 *
 * @param  expected  the expected object.
 * @param  actual    the actual object.
 */
public static void assertEqualsIgnoreMetadata(final Object expected, final Object actual) {
  assertTrue("Shall be approximately equals",         Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
  assertTrue("DEBUG inconsistent with APPROXIMATIVE", Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATIVE));
  assertTrue("Shall be equal, ignoring metadata",     Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA));
}

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

/**
 * Asserts that the two given objects are approximately equal, while slightly different.
 * More specifically, this method asserts that the given objects are equal according the
 * {@link ComparisonMode#APPROXIMATIVE} criterion, but not equal according the
 * {@link ComparisonMode#IGNORE_METADATA} criterion.
 *
 * @param  expected  the expected object.
 * @param  actual    the actual object.
 */
public static void assertAlmostEquals(final Object expected, final Object actual) {
  assertFalse("Shall not be strictly equals",          Utilities.deepEquals(expected, actual, ComparisonMode.STRICT));
  assertFalse("Shall be slightly different",           Utilities.deepEquals(expected, actual, ComparisonMode.IGNORE_METADATA));
  assertTrue ("Shall be approximately equals",         Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
  assertTrue ("DEBUG inconsistent with APPROXIMATIVE", Utilities.deepEquals(expected, actual, ComparisonMode.APPROXIMATIVE));
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Compares the unit and direction of this axis with the ones of the given axis.
 * The range minimum and maximum values are compared only if {@code cr} is {@code true},
 * i.e. it is caller responsibility to determine if range shall be considered as metadata.
 *
 * @param  that  the axis to compare with this axis.
 * @param  mode  whether the unit comparison is approximative or exact.
 * @param  cr    {@code true} for comparing also the range minimum and maximum values.
 * @return {@code true} if unit, direction and optionally range extremum are equal.
 */
private boolean equalsIgnoreMetadata(final CoordinateSystemAxis that, final ComparisonMode mode, final boolean cr) {
  return Objects.equals(getDirection(), that.getDirection()) &&
      Utilities.deepEquals(getUnit(), that.getUnit(), mode) &&
      (!cr || (doubleToLongBits(getMinimumValue()) == doubleToLongBits(that.getMinimumValue()) &&
          doubleToLongBits(getMaximumValue()) == doubleToLongBits(that.getMaximumValue())));
}

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

/**
 * Compares the unit and direction of this axis with the ones of the given axis.
 * The range minimum and maximum values are compared only if {@code cr} is {@code true},
 * i.e. it is caller responsibility to determine if range shall be considered as metadata.
 *
 * @param  that  the axis to compare with this axis.
 * @param  mode  whether the unit comparison is an approximation or exact.
 * @param  cr    {@code true} for comparing also the range minimum and maximum values.
 * @return {@code true} if unit, direction and optionally range extremum are equal.
 */
private boolean equalsIgnoreMetadata(final CoordinateSystemAxis that, final ComparisonMode mode, final boolean cr) {
  return Objects.equals(getDirection(), that.getDirection()) &&
      Utilities.deepEquals(getUnit(), that.getUnit(), mode) &&
      (!cr || (doubleToLongBits(getMinimumValue()) == doubleToLongBits(that.getMinimumValue()) &&
          doubleToLongBits(getMaximumValue()) == doubleToLongBits(that.getMaximumValue())));
}

代码示例来源:origin: org.apache.sis.core/sis-referencing

/**
 * Returns the best parameters matching the given criteria, or {@code null} if none.
 */
private BursaWolfParameters select(final GeodeticDatum targetDatum, final ExtentSelector<BursaWolfParameters> selector) {
  if (bursaWolf == null) {
    return null;
  }
  for (final BursaWolfParameters candidate : bursaWolf) {
    if (deepEquals(targetDatum, candidate.getTargetDatum(), ComparisonMode.IGNORE_METADATA)) {
      selector.evaluate(candidate.getDomainOfValidity(), candidate);
    }
  }
  return selector.best();
}

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

/**
 * Returns the best parameters matching the given criteria, or {@code null} if none.
 */
private BursaWolfParameters select(final GeodeticDatum targetDatum, final ExtentSelector<BursaWolfParameters> selector) {
  if (bursaWolf == null) {
    return null;
  }
  for (final BursaWolfParameters candidate : bursaWolf) {
    if (deepEquals(targetDatum, candidate.getTargetDatum(), ComparisonMode.IGNORE_METADATA)) {
      selector.evaluate(candidate.getDomainOfValidity(), candidate);
    }
  }
  return selector.best();
}

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

/**
 * Asserts that the two given objects are not equal.
 * This method tests all {@link ComparisonMode} except {@code DEBUG}.
 *
 * @param  o1  the first object.
 * @param  o2  the second object.
 */
public static void assertNotDeepEquals(final Object o1, final Object o2) {
  assertNotSame("same", o1, o2);
  assertFalse("equals",                      Objects  .equals    (o1, o2));
  assertFalse("deepEquals",                  Objects  .deepEquals(o1, o2));
  assertFalse("deepEquals(STRICT)",          Utilities.deepEquals(o1, o2, ComparisonMode.STRICT));
  assertFalse("deepEquals(BY_CONTRACT)",     Utilities.deepEquals(o1, o2, ComparisonMode.BY_CONTRACT));
  assertFalse("deepEquals(IGNORE_METADATA)", Utilities.deepEquals(o1, o2, ComparisonMode.IGNORE_METADATA));
  assertFalse("deepEquals(APPROXIMATIVE)",   Utilities.deepEquals(o1, o2, ComparisonMode.APPROXIMATIVE));
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Asserts that the two given objects are not equal.
 *
 * @param o1  The first object.
 * @param o2  The second object.
 *
 * @since 3.20
 */
public static void assertNotDeepEquals(final Object o1, final Object o2) {
  assertNotSame("same", o1, o2);
  assertFalse("equals",                      Objects  .equals    (o1, o2));
  assertFalse("deepEquals",                  Objects  .deepEquals(o1, o2));
  assertFalse("deepEquals(STRICT)",          Utilities.deepEquals(o1, o2, ComparisonMode.STRICT));
  assertFalse("deepEquals(IGNORE_METADATA)", Utilities.deepEquals(o1, o2, ComparisonMode.IGNORE_METADATA));
  assertFalse("deepEquals(APPROXIMATIVE)",   Utilities.deepEquals(o1, o2, ComparisonMode.APPROXIMATIVE));
}

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

/**
 * Asserts that the result of {@link CRS#forCode(String)} is the given CRS.
 */
private static void verifyForCode(final SingleCRS expected, final String code) throws FactoryException {
  final CoordinateReferenceSystem actual = CRS.forCode(code);
  assertTrue(code, Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG));
  if (!EPSGFactoryFallback.FORCE_HARDCODED) {
    assertSame(code, expected, actual);
  }
}

相关文章