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

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

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

Field.equals介绍

[英]Indicates whether or not the specified object is equal to this field. To be equal, the specified object must be an instance of Field with the same declaring class, type and name as this field.
[中]指示指定的对象是否等于此字段。若要相等,指定的对象必须是与此字段具有相同声明类、类型和名称的字段实例。

代码示例

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

public static boolean callEquals(Field thiz, Object a0) {
  return thiz.equals(a0);
}

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

@Override
  public boolean accept(Field field) {
    return !field.equals(ignoredField);
  }
}

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

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  InstanceField that = (InstanceField) o;
  return field.equals(that.field) && instance.equals(that.instance);
}

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

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  InstanceField that = (InstanceField) o;
  if (!field.equals(that.field)) return false;
  if (!instance.equals(that.instance)) return false;
  return true;
}

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

@Override
public boolean equals(Object obj) {
  if (obj == null) {
    return false;
  }
  if (getClass() != obj.getClass()) {
    return false;
  }
  final FieldDescriptor other = (FieldDescriptor) obj;
  if (this.field != other.field && (this.field == null || !this.field.equals(other.field))) {
    return false;
  }
  return true;
}

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

private boolean anotherCandidateMatchesMockName(final Collection<Object> mocks,
                          final Field candidateFieldToBeInjected,
                          final List<Field> allRemainingCandidateFields) {
    String mockName = getMockName(mocks.iterator().next()).toString();

    for (Field otherCandidateField : allRemainingCandidateFields) {
      if (!otherCandidateField.equals(candidateFieldToBeInjected)
          && otherCandidateField.getType().equals(candidateFieldToBeInjected.getType())
          && otherCandidateField.getName().equals(mockName)) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: h2oai/h2o-3

/**
 * Update the parameters from checkpoint to user-specified
 *
 * @param srcParms source: user-specified parameters
 * @param tgtParms target: parameters to be modified
 * @param doIt     whether to overwrite target parameters (or just print the message)
 * @param quiet    whether to suppress the notifications about parameter changes
 */
static void updateParametersDuringCheckpointRestart(hex.deepwater.DeepWaterParameters srcParms, hex.deepwater.DeepWaterParameters tgtParms/*actually used during training*/, boolean doIt, boolean quiet) {
 for (Field fTarget : tgtParms.getClass().getFields()) {
  if (ArrayUtils.contains(cp_modifiable, fTarget.getName())) {
   for (Field fSource : srcParms.getClass().getFields()) {
    if (fTarget.equals(fSource)) {
     try {
      if (fSource.get(srcParms) == null || fTarget.get(tgtParms) == null || !fTarget.get(tgtParms).toString().equals(fSource.get(srcParms).toString())) { // if either of the two parameters is null, skip the toString()
       if (fTarget.get(tgtParms) == null && fSource.get(srcParms) == null)
        continue; //if both parameters are null, we don't need to do anything
       if (!tgtParms._quiet_mode && !quiet)
        Log.info("Applying user-requested modification of '" + fTarget.getName() + "': " + fTarget.get(tgtParms) + " -> " + fSource.get(srcParms));
       if (doIt)
        fTarget.set(tgtParms, fSource.get(srcParms));
      }
     } catch (IllegalAccessException e) {
      e.printStackTrace();
     }
    }
   }
  }
 }
}

代码示例来源:origin: h2oai/h2o-3

/**
 * Update the parameters from checkpoint to user-specified
 *
 * @param srcParms     source: user-specified parameters
 * @param tgtParms     target: parameters to be modified
 * @param doIt         whether to overwrite target parameters (or just print the message)
 * @param quiet        whether to suppress the notifications about parameter changes
 */
static void updateParametersDuringCheckpointRestart(DeepLearningParameters srcParms, DeepLearningParameters tgtParms/*actually used during training*/, boolean doIt, boolean quiet) {
 for (Field fTarget : tgtParms.getClass().getFields()) {
  if (ArrayUtils.contains(cp_modifiable, fTarget.getName())) {
   for (Field fSource : srcParms.getClass().getFields()) {
    if (fTarget.equals(fSource)) {
     try {
      if (fSource.get(srcParms) == null || fTarget.get(tgtParms) == null || !fTarget.get(tgtParms).toString().equals(fSource.get(srcParms).toString())) { // if either of the two parameters is null, skip the toString()
       if (fTarget.get(tgtParms) == null && fSource.get(srcParms) == null)
        continue; //if both parameters are null, we don't need to do anything
       if (!tgtParms._quiet_mode && !quiet)
        Log.info("Applying user-requested modification of '" + fTarget.getName() + "': " + fTarget.get(tgtParms) + " -> " + fSource.get(srcParms));
       if (doIt)
        fTarget.set(tgtParms, fSource.get(srcParms));
      }
     } catch (IllegalAccessException e) {
      e.printStackTrace();
     }
    }
   }
  }
 }
}

代码示例来源:origin: h2oai/h2o-3

/** This method will take actual parameters and validate them with parameters of
  * requested checkpoint. In case of problem, it throws an API exception.
  *
  * @param checkpointParameters checkpoint parameters
  */
 public void validateWithCheckpoint(SharedTreeParameters checkpointParameters) {
  for (Field fAfter : this.getClass().getFields()) {
   // only look at non-modifiable fields
   if (ArrayUtils.contains(getCheckpointNonModifiableFields(),fAfter.getName())) {
    for (Field fBefore : checkpointParameters.getClass().getFields()) {
     if (fBefore.equals(fAfter)) {
      try {
       if (!PojoUtils.equals(this, fAfter, checkpointParameters, checkpointParameters.getClass().getField(fAfter.getName()))) {
        throw new H2OIllegalArgumentException(fAfter.getName(), "TreeBuilder", "Field " + fAfter.getName() + " cannot be modified if checkpoint is specified!");
       }
      } catch (NoSuchFieldException e) {
       throw new H2OIllegalArgumentException(fAfter.getName(), "TreeBuilder", "Field " + fAfter.getName() + " is not supported by checkpoint!");
      }
     }
    }
   }
  }
 }
}

代码示例来源:origin: h2oai/h2o-3

if (ArrayUtils.contains(cp_not_modifiable, fBefore.getName())) {
 for (Field fAfter : newP.getClass().getFields()) {
  if (fBefore.equals(fAfter)) {
   try {
    if (fAfter.get(newP) == null || fBefore.get(oldP) == null || !fBefore.get(oldP).toString().equals(fAfter.get(newP).toString())) { // if either of the two parameters is null, skip the toString()

代码示例来源:origin: h2oai/h2o-3

if (ArrayUtils.contains(cp_not_modifiable, fBefore.getName())) {
 for (Field fAfter : newP.getClass().getFields()) {
  if (fBefore.equals(fAfter)) {
   try {
    if (fAfter.get(newP) == null || fBefore.get(oldP) == null || !fBefore.get(oldP).toString().equals(fAfter.get(newP).toString())) { // if either of the two parameters is null, skip the toString()

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

@Override
public boolean equals( Object obj ) {
 if ( this == obj ) {
  return true;
 }
 if ( obj == null ) {
  return false;
 }
 if ( getClass() != obj.getClass() ) {
  return false;
 }
 FieldGetter<?> other = (FieldGetter<?>) obj;
 if ( field == null ) {
  if ( other.field != null ) {
   return false;
  }
 } else {
  if ( !field.equals( other.field ) ) {
   return false;
  }
 }
 return true;
}

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

else if(fieldType.equals(double[].class)) {
  setValueFor(fieldType,varArr.data().asDouble());
else if(fieldType.equals(int.class)) {
  setValueFor(fieldType,varArr.getInt(0));
else if(fieldType.equals(double.class)) {
  setValueFor(fieldType,varArr.getDouble(0));

代码示例来源:origin: h2oai/h2o-2

if (!expert_mode && Utils.contains(expert_options, fA.getName())) continue;
for (Field fB : B.getClass().getDeclaredFields()) {
 if (fA.equals(fB)) {
  try {
   if (fB.get(B) == null || fA.get(A) == null || !fA.get(A).toString().equals(fB.get(B).toString())) { // if either of the two parameters is null, skip the toString()

代码示例来源:origin: EsotericSoftware/reflectasm

public int getIndex (Field field) {
  for (int i = 0, n = fields.length; i < n; i++)
    if (fields[i].equals(field)) return i;
  throw new IllegalArgumentException("Unable to find non-private field: " + field);
}

代码示例来源:origin: webx/citrus

@Override
public boolean equals(Object other) {
  if (other == this) {
    return true;
  }
  if (other == null || !other.getClass().equals(getClass())) {
    return false;
  }
  FieldImpl otherField = (FieldImpl) other;
  return field.equals(otherField.field);
}

代码示例来源:origin: jfaster/mango

private static int indexOfFields(@Nullable Field field, List<Field> fields) {
 if (field != null) {
  for (int i = 0; i < fields.size(); i++) {
   if (field.equals(fields.get(i))) {
    return i;
   }
  }
 }
 return MISS_FLAG;
}

代码示例来源:origin: webx/citrus

@Override
public boolean equals(Object other) {
  if (other == this) {
    return true;
  }
  if (other == null || !other.getClass().equals(getClass())) {
    return false;
  }
  FieldImpl otherField = (FieldImpl) other;
  return field.equals(otherField.field);
}

代码示例来源:origin: webx/citrus

@Override
public boolean equals(Object other) {
  if (other == this) {
    return true;
  }
  if (other == null || !other.getClass().equals(getClass())) {
    return false;
  }
  FieldImpl otherField = (FieldImpl) other;
  return field.equals(otherField.field);
}

代码示例来源:origin: b3log/latke

public static boolean matchInheritance(final Field subclassField, final Field superclassField) {
  if (Modifier.isStatic(superclassField.getModifiers()) || subclassField.equals(superclassField)) {
    return false;
  }
  final Package subclassPackage = superclassField.getDeclaringClass().getPackage();
  final Package superclassPackage = superclassField.getDeclaringClass().getPackage();
  final int superFieldModifiers = superclassField.getModifiers();
  return isAccessable(subclassPackage, superclassPackage, superFieldModifiers);
}

相关文章

微信公众号

最新文章

更多