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

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

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

Enum.equals介绍

[英]Compares this object with the specified object and indicates if they are equal. In order to be equal, object must be identical to this enum constant.
[中]将此对象与指定对象进行比较,并指示它们是否相等。若要相等,对象必须与此枚举常量相同。

代码示例

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

/**
 * {@inheritDoc}
 */
public boolean represents(Object value) {
  return enumeration.equals(value);
}

代码示例来源:origin: stackoverflow.com

public enum Type
{
 AMPHIBIAN,
 MAMMAL,
 REPTILE,
 BIRD
}

public enum Animal 
{
 ELEPHANT(Type.MAMMAL),
 GIRAFFE(Type.MAMMAL),
 TURTLE(Type.REPTILE),
 SNAKE(Type.REPTILE),
 FROG(Type.AMPHIBIAN);

 private final Type type; 
 private Animal(final Type type) { this.type = type; }
 public boolean isMammal() { return this.type.equals(Type.MAMMAL); }
 public boolean isAmphibian() { return this.type.equals(Type.AMPHIBIAN); }
 public boolean isReptile() { return this.type.equals(Type.REPTILE); }
 // etc...
}

代码示例来源:origin: stackoverflow.com

public enum Gender { MALE, FEMALE, UNKNOWN }

@Entity
public Person {
  private Gender g;
  private long id;

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  public long getId() { return id; }
  public void setId(long id) { this.id = id; }

  public Gender getGender() { return g; }    
  public void setGender(Gender g) { this.g = g; }

  @Transient
  public boolean isMale() {
    return Gender.MALE.equals(g);
  }

  @Transient
  public boolean isFemale() {
    return Gender.FEMALE.equals(g);
  }
}

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

@SuppressWarnings("unchecked")
@Override
public boolean equals(Object object) {
  if (!enumMap.hasMapping[ordinal]) {
    return false;
  }
  boolean isEqual = false;
  if (object instanceof Map.Entry) {
    Map.Entry<KT, VT> entry = (Map.Entry<KT, VT>) object;
    Object enumKey = entry.getKey();
    if (key.equals(enumKey)) {
      Object theValue = entry.getValue();
      if (enumMap.values[ordinal] == null) {
        isEqual = (theValue == null);
      } else {
        isEqual = enumMap.values[ordinal].equals(theValue);
      }
    }
  }
  return isEqual;
}

代码示例来源:origin: nutzam/nutz

@Override
@SuppressWarnings("unchecked")
public boolean isEnum(String key, Enum<?>... eus) {
  if (null == eus || eus.length == 0)
    return false;
  try {
    Enum<?> v = getEnum(key, eus[0].getClass());
    for (Enum<?> eu : eus)
      if (!v.equals(eu))
        return false;
    return true;
  }
  catch (Exception e) {
    return false;
  }
}

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

@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  } else if (!(other instanceof AnnotationValue.Loaded<?>)) {
    return false;
  }
  AnnotationValue.Loaded<?> annotationValue = (AnnotationValue.Loaded<?>) other;
  return annotationValue.getState().isResolved() && enumeration.equals(annotationValue.resolve());
}

代码示例来源:origin: stackoverflow.com

public enum A
{
    B(0),
    C(10),
    None(11);
    int id;
    private A(int i){id = i;}

    public int GetID(){return id;}
    public boolean IsEmpty(){return this.equals(A.None);}
    public boolean Compare(int i){return id == i;}
    public static A GetValue(int _id)
    {
      A[] As = A.values();
      for(int i = 0; i < As.length; i++)
      {
        if(As[i].Compare(_id))
          return As[i];
      }
      return A.None;
    }
}

代码示例来源:origin: MorphiaOrg/morphia

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

代码示例来源:origin: stackoverflow.com

notifyObservers(guess.equals(hidden));

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

assertThat(specialAttrs.size(), is(6));
assertTrue(String.class.isAssignableFrom(specialAttrs.getClass("clazz")));
assertTrue(specialAttrs.getEnum("state").equals(Thread.State.NEW));
assertTrue(nestedAnno.getEnum("anEnum").equals(SomeEnum.LABEL1));
assertArrayEquals(new Class<?>[] {String.class}, (Class<?>[]) nestedAnno.get("classArray"));
assertThat(nestedAnnoArray.length, is(2));
assertThat(nestedAnnoArray[0].getString("value"), is("default"));
assertTrue(nestedAnnoArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT));
assertArrayEquals(new Class<?>[] {Void.class}, (Class<?>[]) nestedAnnoArray[0].get("classArray"));
assertThat(nestedAnnoArray[1].getString("value"), is("na1"));
assertTrue(nestedAnnoArray[1].getEnum("anEnum").equals(SomeEnum.LABEL2));
assertArrayEquals(new Class<?>[] {Number.class}, (Class<?>[]) nestedAnnoArray[1].get("classArray"));
assertArrayEquals(new Class<?>[] {Number.class}, nestedAnnoArray[1].getClassArray("classArray"));
assertTrue(optional.getEnum("anEnum").equals(SomeEnum.DEFAULT));
assertArrayEquals(new Class<?>[] {Void.class}, (Class<?>[]) optional.get("classArray"));
assertArrayEquals(new Class<?>[] {Void.class}, optional.getClassArray("classArray"));
assertThat(optionalArray.length, is(1));
assertThat(optionalArray[0].getString("value"), is("optional"));
assertTrue(optionalArray[0].getEnum("anEnum").equals(SomeEnum.DEFAULT));
assertArrayEquals(new Class<?>[] {Void.class}, (Class<?>[]) optionalArray[0].get("classArray"));
assertArrayEquals(new Class<?>[] {Void.class}, optionalArray[0].getClassArray("classArray"));

代码示例来源:origin: stackoverflow.com

import java.util.Date;

public class EnumCompareSpeedTest {

  static enum TestEnum {ONE, TWO, THREE }

  public static void main(String [] args) {

    Date before = new Date();
    int c = 0;

    for(int y=0;y<5;++y) {
      for(int x=0;x<Integer.MAX_VALUE;++x) {
        if(TestEnum.ONE.equals(TestEnum.TWO)) {++c;}
        if(TestEnum.ONE == TestEnum.TWO){++c;}              
      }
    }

    System.out.println(new Date().getTime() - before.getTime());
  }   

}

代码示例来源:origin: jamesagnew/hapi-fhir

public static <T extends Enum<?>> boolean matches(Enumeration<T> e1, Enumeration<T> e2, MatchProfile profile)  {
 if (e1 == null || e2 == null)
   return false;
 return e1.getValue().equals(e2.getValue());
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static <T extends Enum<?>> boolean matches(Enumeration<T> e1, Enumeration<T> e2, MatchProfile profile)  {
 if (e1 == null || e2 == null)
   return false;
 return e1.getValue().equals(e2.getValue());
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static <T extends Enum<?>> boolean matches(Enumeration<T> e1, Enumeration<T> e2, MatchProfile profile)  {
 if (e1 == null || e2 == null)
   return false;
 return e1.getValue().equals(e2.getValue());
}

代码示例来源:origin: stackoverflow.com

if( eT .equals(this))   return true;

代码示例来源:origin: stackoverflow.com

return (behavior.equals(Behavior.CAPITALIZE_BEFORE_MARKER)
    || behavior.equals(Behavior.CAPITALIZE_BEFORE_AND_AFTER_MARKER));
return (behavior.equals(Behavior.CAPITALIZE_AFTER_MARKER)
    || behavior.equals(Behavior.CAPITALIZE_BEFORE_AND_AFTER_MARKER));

代码示例来源:origin: youseries/urule

if(right instanceof Enum){
  Enum<?> e2=(Enum<?>)right;
  return e1.equals(e2);
}else{
  Enum<?> e2=Enum.valueOf(e1.getClass(), right.toString());
  return e1.equals(e2);

代码示例来源:origin: youseries/urule

if(right instanceof Enum){
  Enum<?> e2=(Enum<?>)right;
  return e1.equals(e2);
}else{
  Enum<?> e2=Enum.valueOf(e1.getClass(), right.toString());
  return e1.equals(e2);

代码示例来源:origin: stackoverflow.com

if(p.getType().equals(PathActionType.MOVE_TO)){
  super.moveTo(p.getX(), p.getY());
} else if(p.getType().equals(PathActionType.LINE_TO)){
  super.lineTo(p.getX(), p.getY());

代码示例来源:origin: stackoverflow.com

public enum SoonilsDataType {
  A, B, C;
  // Just an example of what's possible
  public static SoonilsDataType getCompositeValue(SoonilsDataType item1,
     SoonilsDataType item2) {
     if (item1.equals(A) && 
          item2.equals(B)) {
       return C;
     }
  }
}

相关文章