本文整理了Java中java.util.Set.equals()
方法的一些代码示例,展示了Set.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Set.equals()
方法的具体详情如下:
包路径:java.util.Set
类名称:Set
方法名:equals
[英]Compares the specified object to this set, and returns true if they represent the same object using a class specific comparison. Equality for a set means that both sets have the same size and the same elements.
[中]将指定对象与此集合进行比较,如果它们使用特定于类的比较表示相同对象,则返回true。一个集合的相等意味着两个集合具有相同的大小和相同的元素。
代码示例来源:origin: google/guava
/** An implementation of {@link Map#equals}. */
static boolean equalsImpl(Map<?, ?> map, Object object) {
if (map == object) {
return true;
} else if (object instanceof Map) {
Map<?, ?> o = (Map<?, ?>) object;
return map.entrySet().equals(o.entrySet());
}
return false;
}
代码示例来源:origin: robolectric/robolectric
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InstrumentationConfiguration that = (InstrumentationConfiguration) o;
if (!classNameTranslations.equals(that.classNameTranslations)) return false;
if (!classesToNotAcquire.equals(that.classesToNotAcquire)) return false;
if (!instrumentedPackages.equals(that.instrumentedPackages)) return false;
if (!instrumentedClasses.equals(that.instrumentedClasses)) return false;
if (!interceptedMethods.equals(that.interceptedMethods)) return false;
return true;
}
代码示例来源:origin: commons-collections/commons-collections
public boolean equals(Object obj) {
return map.keySet().equals(obj);
}
代码示例来源:origin: linkedin/cruise-control
private boolean paramEquals(Map<String, String[]> parameters) {
boolean isSameParameters = _requestParameters.keySet().equals(parameters.keySet());
if (isSameParameters) {
for (Map.Entry<String, String[]> entry : _requestParameters.entrySet()) {
Set<String> param1 = new HashSet<>(Arrays.asList(entry.getValue()));
Set<String> param2 = new HashSet<>(Arrays.asList(parameters.get(entry.getKey())));
if (!param1.equals(param2)) {
return false;
}
}
}
return isSameParameters;
}
代码示例来源:origin: apache/incubator-druid
public static Map<String, Long> subtract(Map<String, Long> xs, Map<String, Long> ys)
{
assert xs.keySet().equals(ys.keySet());
final Map<String, Long> zs = new HashMap<String, Long>();
for (String k : xs.keySet()) {
zs.put(k, xs.get(k) - ys.get(k));
}
return zs;
}
}
代码示例来源:origin: apache/storm
for (TopologyDetails topo : topologies.getTopologies()) {
String id = topo.getId();
Set<List<Integer>> allExecs = topoToExec.get(id);
Set<List<Integer>> aliveExecs = topoToAliveExecutors.get(id);
int numDesiredWorkers = topo.getNumWorkers();
int numAssignedWorkers = numUsedWorkers(topoToSchedAssignment.get(id));
if (allExecs == null || allExecs.isEmpty() || !allExecs.equals(aliveExecs) || numDesiredWorkers > numAssignedWorkers) {
missingAssignmentTopologies.add(id);
for (Entry<String, Map<WorkerSlot, WorkerResources>> uglyWorkerResources : cluster.getWorkerResourcesMap().entrySet()) {
Map<WorkerSlot, WorkerResources> slotToResources = new HashMap<>();
for (Entry<WorkerSlot, WorkerResources> uglySlotToResources : uglyWorkerResources.getValue().entrySet()) {
WorkerResources wr = uglySlotToResources.getValue();
slotToResources.put(uglySlotToResources.getKey(), wr);
代码示例来源:origin: apache/storm
private boolean shouldPunctuate(String parentStream) {
punctuationState.add(parentStream);
return punctuationState.equals(context.getWindowedParentStreams());
}
}
代码示例来源:origin: spring-projects/spring-framework
String column = JdbcUtils.lookupColumnName(rsmd, index);
String field = lowerCaseName(StringUtils.delete(column, " "));
PropertyDescriptor pd = (this.mappedFields != null ? this.mappedFields.get(field) : null);
if (pd != null) {
try {
populatedProperties.add(pd.getName());
if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " +
"necessary to populate object of class [" + this.mappedClass.getName() + "]: " +
代码示例来源:origin: prestodb/presto
this.partitionHandles = ImmutableList.copyOf(partitionHandles);
checkArgument(splitSources.keySet().equals(ImmutableSet.copyOf(schedulingOrder)));
partitionHandles.equals(ImmutableList.of(NOT_PARTITIONED)) != stageExecutionDescriptor.isStageGroupedExecution(),
"PartitionHandles should be [NOT_PARTITIONED] if and only if all scan nodes use ungrouped execution strategy");
int nodeCount = nodes.size();
Optional<LifespanScheduler> groupedLifespanScheduler = Optional.empty();
for (PlanNodeId planNodeId : schedulingOrder) {
SplitSource splitSource = splitSources.get(planNodeId);
boolean groupedExecutionForScanNode = stageExecutionDescriptor.isScanGroupedExecution(planNodeId);
SourceScheduler sourceScheduler = newSourcePartitionedSchedulerAsSourceScheduler(
代码示例来源:origin: apache/hbase
public List<String> getGroupAuths(String[] groups) {
this.lock.readLock().lock();
try {
List<String> auths = EMPTY_LIST;
Set<Integer> authOrdinals = getGroupAuthsAsOrdinals(groups);
if (!authOrdinals.equals(EMPTY_SET)) {
auths = new ArrayList<>(authOrdinals.size());
for (Integer authOrdinal : authOrdinals) {
auths.add(ordinalVsLabels.get(authOrdinal));
}
}
return auths;
} finally {
this.lock.readLock().unlock();
}
}
代码示例来源:origin: prestodb/presto
for (DiskRange mergedRange : mergedRanges) {
LazyBufferLoader mergedRangeLazyLoader = new LazyBufferLoader(mergedRange);
for (Entry<K, DiskRange> diskRangeEntry : diskRanges.entrySet()) {
DiskRange diskRange = diskRangeEntry.getValue();
if (mergedRange.contains(diskRange)) {
for (Entry<K, DiskRange> entry : diskRanges.entrySet()) {
slices.put(entry.getKey(), new OrcDataSourceInput(getDiskRangeSlice(entry.getValue(), buffers).getInput(), entry.getValue().getLength()));
verify(sliceStreams.keySet().equals(diskRanges.keySet()));
return sliceStreams;
代码示例来源:origin: apache/geode
.getAllLocatorsInfo();
if (!allLocators.equals(locators)) {
for (Map.Entry<Integer, Set<DistributionLocatorId>> entry : locators.entrySet()) {
Set<DistributionLocatorId> existingValue = allLocators.putIfAbsent(entry.getKey(),
new CopyOnWriteHashSet<DistributionLocatorId>(entry.getValue()));
if (!localLocators.equals(entry.getValue())) {
entry.getValue().removeAll(localLocators);
for (DistributionLocatorId locator : entry.getValue()) {
localLocators.add(locator);
addServerLocator(entry.getKey(), locatorListener, locator);
locatorListener.locatorJoined(entry.getKey(), locator, null);
代码示例来源:origin: apache/geode
@Test
public void testEquals() { // TODO: reduce test runtime
Set s1, s2;
s1 = new CompactConcurrentHashSet2();
s2 = new HashSet();
for (int i = 0; i < 10000; i++) {
int nexti = random.nextInt(RANGE);
s1.add(nexti);
s2.add(nexti);
assertTrue("expected s1 and s2 to be equal", s1.equals(s2));
assertTrue("expected s1 and s2 to be equal", s2.equals(s1));
}
assertTrue(s1.hashCode() != 0);
s2 = new CompactConcurrentHashSet2(2);
s2.addAll(s1);
assertTrue("expected s1 and s2 to be equal", s1.equals(s2));
assertTrue("expected s1 and s2 to be equal", s2.equals(s1));
}
代码示例来源:origin: apache/kafka
public MetricName metricInstance(MetricNameTemplate template, Map<String, String> tags) {
// check to make sure that the runtime defined tags contain all the template tags.
Set<String> runtimeTagKeys = new HashSet<>(tags.keySet());
runtimeTagKeys.addAll(config().tags().keySet());
Set<String> templateTagKeys = template.tags();
if (!runtimeTagKeys.equals(templateTagKeys)) {
throw new IllegalArgumentException("For '" + template.name() + "', runtime-defined metric tags do not match the tags in the template. "
+ "Runtime = " + runtimeTagKeys.toString() + " Template = " + templateTagKeys.toString());
}
return this.metricName(template.name(), template.group(), template.description(), tags);
}
代码示例来源:origin: apache/geode
|| ((this.fixedPAttrs == null) != (other.getFixedPartitionAttributes() == null))
|| (this.fixedPAttrs != null
&& !this.fixedPAttrs.equals(other.getFixedPartitionAttributes()))) {
return false;
for (int i = 0; i < otherPListeners.length; i++) {
PartitionListener listener = otherPListeners[i];
otherListenerClassName.add(listener.getClass().getName());
thisListenerClassName.add(listener.getClass().getName());
if (!thisListenerClassName.equals(otherListenerClassName)) {
return false;
代码示例来源:origin: debezium/debezium
/**
* Determine if one or more replica sets has been added or removed since the prior state.
*
* @param priorState the prior state of the replica sets; may be null
* @return {@code true} if the replica sets have changed since the prior state, or {@code false} otherwise
*/
public boolean haveChangedSince(ReplicaSets priorState) {
if (priorState.replicaSetCount() != this.replicaSetCount()) {
// At least one replica set has been added or removed ...
return true;
}
if (this.replicaSetsByName.size() != priorState.replicaSetsByName.size()) {
// The total number of replica sets hasn't changed, but the number of named replica sets has changed ...
return true;
}
// We have the same number of named replica sets ...
if (!this.replicaSetsByName.isEmpty()) {
if (!this.replicaSetsByName.keySet().equals(priorState.replicaSetsByName.keySet())) {
// The replica sets have different names ...
return true;
}
// Otherwise, they have the same names and we don't care about the members ...
}
// None of the named replica sets has changed, so we have no choice to be compare the non-replica set members ...
return this.nonReplicaSets.equals(priorState.nonReplicaSets) ? false : true;
}
代码示例来源:origin: linkedin/cruise-control
private boolean hasTheSameHttpParameter(Map<String, String[]> params1, Map<String, String[]> params2) {
boolean isSameParameters = params1.keySet().equals(params2.keySet());
if (isSameParameters) {
for (Map.Entry<String, String[]> entry : params1.entrySet()) {
Set<String> values1 = new HashSet<>(Arrays.asList(entry.getValue()));
Set<String> values2 = new HashSet<>(Arrays.asList(params2.get(entry.getKey())));
if (!values1.equals(values2)) {
return false;
}
}
}
return isSameParameters;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Inspect the {@code expectedModel} to see if all elements in the
* model appear and are equal.
* @param mav the ModelAndView to test against (never {@code null})
* @param expectedModel the expected model
*/
public static void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) {
Map<String, Object> model = mav.getModel();
if (!model.keySet().equals(expectedModel.keySet())) {
StringBuilder sb = new StringBuilder("Keyset of expected model does not match.\n");
appendNonMatchingSetsErrorMessage(expectedModel.keySet(), model.keySet(), sb);
fail(sb.toString());
}
StringBuilder sb = new StringBuilder();
model.forEach((modelName, mavValue) -> {
Object assertionValue = expectedModel.get(modelName);
if (!assertionValue.equals(mavValue)) {
sb.append("Value under name '").append(modelName).append("' differs, should have been '").append(
assertionValue).append("' but was '").append(mavValue).append("'\n");
}
});
if (sb.length() != 0) {
sb.insert(0, "Values of expected model do not match.\n");
fail(sb.toString());
}
}
代码示例来源:origin: robolectric/robolectric
LogItem throwLessLogItem = new LogItem(log.type, log.tag, log.msg, null);
if (expectedLogs.contains(throwLessLogItem)) {
observedLogs.add(throwLessLogItem);
continue;
observedTags.add(log.tag);
continue;
if (!expectedLogs.equals(observedLogs)) {
throw new AssertionError(
"Some expected logs were not printed."
+ observedLogs);
if (!expectedTags.equals(observedTags) && !shouldIgnoreMissingLoggedTags) {
throw new AssertionError(
"Some expected tags were not printed. "
代码示例来源:origin: prestodb/presto
/** An implementation of {@link Map#equals}. */
static boolean equalsImpl(Map<?, ?> map, Object object) {
if (map == object) {
return true;
} else if (object instanceof Map) {
Map<?, ?> o = (Map<?, ?>) object;
return map.entrySet().equals(o.entrySet());
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!