java.util.Arrays.deepHashCode()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(146)

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

Arrays.deepHashCode介绍

[英]Returns a hash code based on the "deep contents" of the given array. If the array contains other arrays as its elements, the hash code is based on their contents not their identities. So it is not acceptable to invoke this method on an array that contains itself as an element, either directly or indirectly.

For any two arrays a and b, if Arrays.deepEquals(a, b) returns true, it means that the return value of Arrays.deepHashCode(a) equals Arrays.deepHashCode(b).

The computation of the value returned by this method is similar to that of the value returned by List#hashCode() invoked on a List containing a sequence of instances representing the elements of array in the same order. The difference is: If an element e of array is itself an array, its hash code is computed by calling the appropriate overloading of Arrays.hashCode(e) if e is an array of a primitive type, or by calling Arrays.deepHashCode(e) recursively if e is an array of a reference type. The value returned by this method is the same value as the method Arrays.asList(array).hashCode(). If the array is null, the return value is 0.
[中]基于给定数组的“深层内容”返回哈希代码。如果数组包含其他数组作为其元素,则哈希代码基于它们的内容而不是它们的标识。因此,直接或间接地在包含自身作为元素的数组上调用此方法是不可接受的。
对于任意两个数组a和b,如果是数组。deepEquals(a,b)返回true,这意味着数组的返回值。deepHashCode(a)等于数组。深度哈希代码(b)。
此方法返回的值的计算与List#hashCode()返回的值的计算类似,List#hashCode()在包含以相同顺序表示数组元素的实例序列的列表上调用。区别在于:如果数组的元素e本身就是数组,则通过调用适当的数组重载来计算其哈希代码。hashCode(e),如果e是基元类型的数组,或者通过调用数组。如果e是引用类型的数组,则递归地使用deepHashCode(e)。此方法返回的值与方法数组的值相同。asList(数组)。hashCode()。如果数组为null,则返回值为0。

代码示例

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

@Override
public int hashCode() {
  return Arrays.deepHashCode(fields);
}

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

/**
 * Create a new {@link SimpleKey} instance.
 * @param elements the elements of the key
 */
public SimpleKey(Object... elements) {
  Assert.notNull(elements, "Elements must not be null");
  this.params = new Object[elements.length];
  System.arraycopy(elements, 0, this.params, 0, elements.length);
  this.hashCode = Arrays.deepHashCode(this.params);
}

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

/**
 * Get the hash code of this principal.
 *
 * @return the hash code of this principal
 */
public int hashCode() {
  return Arrays.deepHashCode(p);
}

代码示例来源:origin: pentaho/pentaho-kettle

private int calculateHashCode( Object[] keyFields ) {
 // deep used because Binary type is a native byte[]
 return Arrays.deepHashCode( keyFields );
}

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

@Override
public int hashCode(Object o) {
 Object[] oa = (Object[]) o;
 return Arrays.deepHashCode(oa);
}

代码示例来源:origin: org.apache.commons/commons-math3

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

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

private static <T> int listHashCode(List<T> alist) {
  if (alist == null) {
    return 1;
  } else {
    return Arrays.deepHashCode(alist.toArray());
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Calculates a simple hashCode of all the native data objects in the supplied row. This method will return a better
 * distribution of values for rows of numbers or rows with the same values in different positions. NOTE: This method
 * performs against the native values, not the values returned by ValueMeta. This means that if you have two rows with
 * different primitive values ['2008-01-01:12:30'] and ['2008-01-01:00:00'] that use a format object to change the
 * value (as Date yyyy-MM-dd), the hashCodes will be different resulting in the two rows not being considered equal
 * via the hashCode even though compare() or equals() might consider them to be.
 *
 * @param rowData The data to calculate a hashCode with
 * @return the calculated hashCode
 * @throws KettleValueException in case there is a data conversion error
 */
@Override
public int hashCode( Object[] rowData ) throws KettleValueException {
 return Arrays.deepHashCode( rowData );
}

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

@Override
public int hashCode() {
  return Arrays.deepHashCode(data);
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Create a new {@link SimpleKey} instance.
 * @param elements the elements of the key
 */
public SimpleKey(Object... elements) {
  Assert.notNull(elements, "Elements must not be null");
  this.params = new Object[elements.length];
  System.arraycopy(elements, 0, this.params, 0, elements.length);
  this.hashCode = Arrays.deepHashCode(this.params);
}

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

@Override
public int hashCode() {
  int hash = 5;
  hash = 29 * hash + Objects.hashCode(this.fullName);
  hash = 29 * hash + Arrays.deepHashCode(this.parameters);
  return hash;
}

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

@Override
public int hashCode() {
  if (value == null) {
    return 31;
  }
  if (value instanceof Object[]) {
    return 31 + Arrays.deepHashCode((Object[]) value);
  }
  return 31 + value.hashCode();
}

代码示例来源:origin: com.google.inject/guice

/** Implements {@link Annotation#hashCode}. */
private static int annotationHashCode(
  Class<? extends Annotation> type, Map<String, Object> members) throws Exception {
 int result = 0;
 for (Method method : type.getDeclaredMethods()) {
  String name = method.getName();
  Object value = members.get(name);
  result += (127 * name.hashCode()) ^ (Arrays.deepHashCode(new Object[] {value}) - 31);
 }
 return result;
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Returns the hash code for the given object. If the object is {@code null}, this method returns zero. Otherwise
 * calls the method {@code hashCode} of the given object.
 *
 * @param o the given object.
 * @return the hash code for the given object
 */
public static int hashCodeFor(Object o) {
 if (o == null) return 0;
 return isArray(o) && !o.getClass().getComponentType().isPrimitive() ? java.util.Arrays.deepHashCode((Object[]) o) : o.hashCode() ;
}

代码示例来源:origin: addthis/stream-lib

@Override
public int hashCode() {
  int result;
  long temp;
  result = depth;
  result = 31 * result + width;
  result = 31 * result + Arrays.deepHashCode(table);
  result = 31 * result + Arrays.hashCode(hashA);
  result = 31 * result + (int) (size ^ (size >>> 32));
  temp = Double.doubleToLongBits(eps);
  result = 31 * result + (int) (temp ^ (temp >>> 32));
  temp = Double.doubleToLongBits(confidence);
  result = 31 * result + (int) (temp ^ (temp >>> 32));
  return result;
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Returns the hash code for the given object. If the object is {@code null}, this method returns zero. Otherwise
 * calls the method {@code hashCode} of the given object.
 *
 * @param o the given object.
 * @return the hash code for the given object
 */
public static int hashCodeFor(Object o) {
 if (o == null) return 0;
 return isArray(o) && !o.getClass().getComponentType().isPrimitive() ? java.util.Arrays.deepHashCode((Object[]) o) : o.hashCode() ;
}

代码示例来源:origin: spring-cloud/spring-cloud-config

public int hashCode() {
  final int PRIME = 59;
  int result = 1;
  result = result * PRIME + java.util.Arrays.deepHashCode(this.getPaths());
  return result;
}

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

for (Object o : selectedFields) {
  if (o instanceof List) {
    out.putInt(Arrays.deepHashCode(((List) o).toArray()));
  } else if (o instanceof Object[]) {
    out.putInt(Arrays.deepHashCode((Object[]) o));
  } else if (o instanceof byte[]) {
    out.putInt(Arrays.hashCode((byte[]) o));

代码示例来源:origin: deeplearning4j/nd4j

@Override
public int hashCode() {
  int result = super.hashCode();
  result = 31 * result + Arrays.deepHashCode(axes);
  result = 31 * result + (addedEdges ? 1 : 0);
  result = 31 * result + (mMulTranspose != null ? mMulTranspose.hashCode() : 0);
  return result;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public int hashCode() {
  int hash = 5;
  hash = 73 * hash + (this.pos != null ? this.pos.hashCode() : 0);
  hash = 73 * hash + (this.norm != null ? this.norm.hashCode() : 0);
  hash = 73 * hash + (this.tang4d != null ? this.tang4d.hashCode() : 0);
  hash = 73 * hash + (this.tang != null ? this.tang.hashCode() : 0);
  hash = 73 * hash + (this.uv0 != null ? this.uv0.hashCode() : 0);
  hash = 73 * hash + (this.uv1 != null ? this.uv1.hashCode() : 0);
  hash = 73 * hash + (this.color != null ? this.color.hashCode() : 0);
  hash = 73 * hash + (this.material != null ? this.material.hashCode() : 0);
  hash = 73 * hash + (this.smoothing != null ? this.smoothing.hashCode() : 0);
  hash = 73 * hash + Arrays.deepHashCode(this.boneWeightsIndices);
  return hash;
}

相关文章