java.util.List.equals()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(111)

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

List.equals介绍

[英]Compares the given object with the List, and returns true if they represent the same object using a class specific comparison. For Lists, this means that they contain the same elements in exactly the same order.
[中]将给定对象与列表进行比较,如果它们使用特定于类的比较表示相同对象,则返回true。对于列表,这意味着它们以完全相同的顺序包含相同的元素。

代码示例

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

@Override
public boolean equals(Object other) {
  return (this == other || (other instanceof MutablePropertyValues &&
      this.propertyValueList.equals(((MutablePropertyValues) other).propertyValueList)));
}

代码示例来源:origin: square/okhttp

@Override public boolean equals(@Nullable Object other) {
 if (!(other instanceof Handshake)) return false;
 Handshake that = (Handshake) other;
 return tlsVersion.equals(that.tlsVersion)
   && cipherSuite.equals(that.cipherSuite)
   && peerCertificates.equals(that.peerCertificates)
   && localCertificates.equals(that.localCertificates);
}

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

@Override
 public boolean equals(@Nullable Object o) {
  if (o instanceof MethodIdentifier) {
   MethodIdentifier ident = (MethodIdentifier) o;
   return name.equals(ident.name) && parameterTypes.equals(ident.parameterTypes);
  }
  return false;
 }
}

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

@Override
public boolean equals(@Nullable Object obj) {
 if (obj instanceof OrPredicate) {
  OrPredicate<?> that = (OrPredicate<?>) obj;
  return components.equals(that.components);
 }
 return false;
}

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

@Override
public boolean equals(Object obj) {
 if (obj instanceof TypeParameterSignature) {
  TypeParameterSignature other = (TypeParameterSignature) obj;
  /*
   * The name is here only for display purposes; <E extends Number> and <T
   * extends Number> are equivalent.
   */
  return bounds.equals(other.bounds);
 }
 return false;
}

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

@Override
public boolean equals(@Nullable Object obj) {
 if (obj instanceof AndPredicate) {
  AndPredicate<?> that = (AndPredicate<?>) obj;
  return components.equals(that.components);
 }
 return false;
}

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

@Override
public boolean equals(Object o) {
 if (o == this) {
  return true;
 }
 synchronized (mutex) {
  return delegate().equals(o);
 }
}

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

@Override
public boolean equals(Object obj) {
 if (obj instanceof TypeSignature) {
  TypeSignature other = (TypeSignature) obj;
  return parameterSignatures.equals(other.parameterSignatures);
 }
 return false;
}

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

@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException {
  for (ContentNegotiationStrategy strategy : this.strategies) {
    List<MediaType> mediaTypes = strategy.resolveMediaTypes(request);
    if (mediaTypes.equals(MEDIA_TYPE_ALL_LIST)) {
      continue;
    }
    return mediaTypes;
  }
  return MEDIA_TYPE_ALL_LIST;
}

代码示例来源:origin: square/okhttp

boolean equalsNonHost(Address that) {
 return this.dns.equals(that.dns)
   && this.proxyAuthenticator.equals(that.proxyAuthenticator)
   && this.protocols.equals(that.protocols)
   && this.connectionSpecs.equals(that.connectionSpecs)
   && this.proxySelector.equals(that.proxySelector)
   && Objects.equals(this.proxy, that.proxy)
   && Objects.equals(this.sslSocketFactory, that.sslSocketFactory)
   && Objects.equals(this.hostnameVerifier, that.hostnameVerifier)
   && Objects.equals(this.certificatePinner, that.certificatePinner)
   && this.url().port() == that.url().port();
}

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

@Override
 public String toString() {
  return (bounds.equals(ImmutableList.of(Object.class)))
    ? name
    : name + " extends " + getTypesString(bounds);
 }
}

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

@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_otherListContainingNull() {
 List<E> other = new ArrayList<>(getSampleElements());
 other.set(other.size() / 2, null);
 assertFalse(
   "Two Lists should not be equal if exactly one of them has null at a given index.",
   getList().equals(other));
}

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

public void testEquals_otherListWithSameElements() {
 assertTrue(
   "A List should equal any other List containing the same elements.",
   getList().equals(new ArrayList<E>(getOrderedElements())));
}

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

@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEquals_containingNull() {
 ArrayList<E> elements = new ArrayList<>(getSampleElements());
 elements.set(elements.size() / 2, null);
 collection = getSubjectGenerator().create(elements.toArray());
 List<E> other = new ArrayList<>(getSampleElements());
 assertFalse(
   "Two Lists should not be equal if exactly one of them has null at a given index.",
   getList().equals(other));
}

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

public void testEquals_longerList() {
 Collection<E> moreElements = getSampleElements(getNumElements() + 1);
 assertFalse(
   "Lists of different sizes should not be equal.",
   getList().equals(new ArrayList<E>(moreElements)));
}

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

@Override
public boolean equals(Object obj) {
 if (obj instanceof MethodSignature) {
  MethodSignature other = (MethodSignature) obj;
  return name.equals(other.name)
    && parameterTypes.equals(other.parameterTypes)
    && typeSignature.equals(other.typeSignature);
 }
 return false;
}

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

@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_otherListWithDifferentElements() {
 ArrayList<E> other = new ArrayList<>(getSampleElements());
 other.set(other.size() / 2, getSubjectGenerator().samples().e3());
 assertFalse(
   "A List should not equal another List containing different elements.",
   getList().equals(other));
}

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

@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_shorterList() {
 Collection<E> fewerElements = getSampleElements(getNumElements() - 1);
 assertFalse(
   "Lists of different sizes should not be equal.",
   getList().equals(new ArrayList<E>(fewerElements)));
}

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

public void testAsListEquals() {
 assertEquals(Booleans.asList(EMPTY), Collections.emptyList());
 assertEquals(Booleans.asList(ARRAY_FALSE), Booleans.asList(ARRAY_FALSE));
 assertFalse(Booleans.asList(ARRAY_FALSE).equals(ARRAY_FALSE));
 assertFalse(Booleans.asList(ARRAY_FALSE).equals(null));
 assertFalse(Booleans.asList(ARRAY_FALSE).equals(Booleans.asList(ARRAY_FALSE_TRUE)));
 assertFalse(Booleans.asList(ARRAY_FALSE_FALSE).equals(Booleans.asList(ARRAY_FALSE_TRUE)));
 assertEquals(1, Booleans.asList(ARRAY_FALSE_TRUE).lastIndexOf(true));
 List<Boolean> reference = Booleans.asList(ARRAY_FALSE);
 assertEquals(Booleans.asList(ARRAY_FALSE), reference);
 assertEquals(reference, reference);
}

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

@Test
public void varyBy() {
  Mono<ServerResponse> result = ServerResponse.ok().varyBy("foo").build();
  List<String> expected = Collections.singletonList("foo");
  StepVerifier.create(result)
      .expectNextMatches(response -> expected.equals(response.headers().getVary()))
      .expectComplete()
      .verify();
}

相关文章